@nocobase/database 0.10.0-alpha.5 → 0.11.0-alpha.1

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.
Files changed (41) hide show
  1. package/lib/collection-importer.d.ts +1 -1
  2. package/lib/collection.d.ts +4 -4
  3. package/lib/collection.js +2 -2
  4. package/lib/database.d.ts +4 -4
  5. package/lib/database.js +1 -1
  6. package/lib/decorators/must-have-filter-decorator.js +1 -1
  7. package/lib/fields/index.d.ts +1 -1
  8. package/lib/fields/relation-field.d.ts +1 -1
  9. package/lib/fields/uid-field.js +1 -1
  10. package/lib/filter-parser.d.ts +1 -1
  11. package/lib/index.d.ts +3 -2
  12. package/lib/index.js +78 -13
  13. package/lib/model-hook.js +1 -1
  14. package/lib/model.d.ts +1 -1
  15. package/lib/operators/child-collection.js +28 -6
  16. package/lib/options-parser.js +4 -4
  17. package/lib/relation-repository/belongs-to-many-repository.d.ts +1 -1
  18. package/lib/relation-repository/belongs-to-repository.d.ts +1 -1
  19. package/lib/relation-repository/hasmany-repository.js +1 -1
  20. package/lib/relation-repository/multiple-relation-repository.d.ts +1 -1
  21. package/lib/relation-repository/types.d.ts +2 -2
  22. package/lib/repository.d.ts +21 -21
  23. package/lib/repository.js +10 -10
  24. package/lib/types.d.ts +43 -43
  25. package/lib/update-associations.d.ts +1 -1
  26. package/lib/update-associations.js +8 -4
  27. package/lib/update-guard.d.ts +3 -3
  28. package/lib/value-parsers/date-value-parser.js +7 -13
  29. package/lib/view/view-inference.d.ts +2 -2
  30. package/package.json +5 -5
  31. package/src/__tests__/inhertits/collection-inherits.test.ts +51 -5
  32. package/src/__tests__/update-associations.test.ts +179 -0
  33. package/src/__tests__/value-parsers/date.test.ts +2 -2
  34. package/src/database.ts +1 -1
  35. package/src/fields/uid-field.ts +1 -1
  36. package/src/filter-parser.ts +1 -0
  37. package/src/index.ts +20 -2
  38. package/src/operators/child-collection.ts +26 -7
  39. package/src/repository.ts +2 -2
  40. package/src/update-associations.ts +6 -1
  41. package/src/value-parsers/date-value-parser.ts +7 -4
@@ -1,4 +1,4 @@
1
- export declare type ImportFileExtension = 'js' | 'ts' | 'json';
1
+ export type ImportFileExtension = 'js' | 'ts' | 'json';
2
2
  export declare class ImporterReader {
3
3
  directory: string;
4
4
  extensions: Set<string>;
@@ -5,12 +5,12 @@ import { Database } from './database';
5
5
  import { BelongsToField, Field, FieldOptions, HasManyField } from './fields';
6
6
  import { Model } from './model';
7
7
  import { Repository } from './repository';
8
- export declare type RepositoryType = typeof Repository;
9
- export declare type CollectionSortable = string | boolean | {
8
+ export type RepositoryType = typeof Repository;
9
+ export type CollectionSortable = string | boolean | {
10
10
  name?: string;
11
11
  scopeKey?: string;
12
12
  };
13
- declare type dumpable = 'required' | 'optional' | 'skip';
13
+ type dumpable = 'required' | 'optional' | 'skip';
14
14
  export interface CollectionOptions extends Omit<ModelOptions, 'name' | 'hooks'> {
15
15
  name: string;
16
16
  namespace?: string;
@@ -80,7 +80,7 @@ export declare class Collection<TModelAttributes extends {} = any, TCreationAttr
80
80
  resetFields(): void;
81
81
  remove(): void;
82
82
  removeFromDb(options?: QueryInterfaceDropTableOptions): Promise<void>;
83
- existsInDb(options?: Transactionable): any;
83
+ existsInDb(options?: Transactionable): Promise<boolean>;
84
84
  removeField(name: string): void | Field;
85
85
  /**
86
86
  * TODO
package/lib/collection.js CHANGED
@@ -450,7 +450,7 @@ class Collection extends _events().EventEmitter {
450
450
  fields: index
451
451
  };
452
452
  indexName = index;
453
- } else if (index === null || index === void 0 ? void 0 : index.fields) {
453
+ } else if (index !== null && index !== void 0 && index.fields) {
454
454
  indexItem = index;
455
455
  indexName = index.fields;
456
456
  }
@@ -565,7 +565,7 @@ class Collection extends _events().EventEmitter {
565
565
  }
566
566
  const schema = tableNameWithSchema.schema;
567
567
  const tableName = tableNameWithSchema.tableName;
568
- if ((options === null || options === void 0 ? void 0 : options.ignorePublicSchema) && schema === 'public') {
568
+ if (options !== null && options !== void 0 && options.ignorePublicSchema && schema === 'public') {
569
569
  return tableName;
570
570
  }
571
571
  return `${schema}.${tableName}`;
package/lib/database.d.ts CHANGED
@@ -22,7 +22,7 @@ import { CollectionGroupManager } from './collection-group-manager';
22
22
  import DatabaseUtils from './database-utils';
23
23
  import QueryInterface from './query-interface/query-interface';
24
24
  import { BaseValueParser } from './value-parsers';
25
- export declare type MergeOptions = merge.Options;
25
+ export type MergeOptions = merge.Options;
26
26
  export interface PendingOptions {
27
27
  field: RelationField;
28
28
  model: ModelStatic<Model>;
@@ -36,7 +36,7 @@ export interface IDatabaseOptions extends Options {
36
36
  usingBigIntForId?: boolean;
37
37
  underscored?: boolean;
38
38
  }
39
- export declare type DatabaseOptions = IDatabaseOptions;
39
+ export type DatabaseOptions = IDatabaseOptions;
40
40
  interface RegisterOperatorsContext {
41
41
  db?: Database;
42
42
  path?: string;
@@ -46,13 +46,13 @@ interface RegisterOperatorsContext {
46
46
  export interface CleanOptions extends QueryInterfaceDropAllTablesOptions {
47
47
  drop?: boolean;
48
48
  }
49
- export declare type AddMigrationsOptions = {
49
+ export type AddMigrationsOptions = {
50
50
  context?: any;
51
51
  namespace?: string;
52
52
  extensions?: string[];
53
53
  directory: string;
54
54
  };
55
- declare type OperatorFunc = (value: any, ctx?: RegisterOperatorsContext) => any;
55
+ type OperatorFunc = (value: any, ctx?: RegisterOperatorsContext) => any;
56
56
  export declare const DialectVersionAccessors: {
57
57
  sqlite: {
58
58
  sql: string;
package/lib/database.js CHANGED
@@ -138,7 +138,7 @@ class DatabaseVersion {
138
138
  const dialect = _Object$keys[_i];
139
139
  if (_this.db.inDialect(dialect)) {
140
140
  var _result$;
141
- if (!(versions === null || versions === void 0 ? void 0 : versions[dialect])) {
141
+ if (!(versions !== null && versions !== void 0 && versions[dialect])) {
142
142
  return false;
143
143
  }
144
144
  const _yield$_this$db$seque = yield _this.db.sequelize.query(accessors[dialect].sql),
@@ -11,7 +11,7 @@ const mustHaveFilter = () => (target, propertyKey, descriptor) => {
11
11
  if (Array.isArray(options.values)) {
12
12
  return oldValue.apply(this, arguments);
13
13
  }
14
- if (!(options === null || options === void 0 ? void 0 : options.filter) && !(options === null || options === void 0 ? void 0 : options.filterByTk) && !(options === null || options === void 0 ? void 0 : options.forceUpdate)) {
14
+ if (!(options !== null && options !== void 0 && options.filter) && !(options !== null && options !== void 0 && options.filterByTk) && !(options !== null && options !== void 0 && options.forceUpdate)) {
15
15
  throw new Error(`must provide filter or filterByTk for ${propertyKey} call, or set forceUpdate to true`);
16
16
  }
17
17
  return oldValue.apply(this, arguments);
@@ -41,4 +41,4 @@ export * from './time-field';
41
41
  export * from './uid-field';
42
42
  export * from './uuid-field';
43
43
  export * from './virtual-field';
44
- export declare type FieldOptions = BaseFieldOptions | StringFieldOptions | IntegerFieldOptions | FloatFieldOptions | DecimalFieldOptions | DoubleFieldOptions | RealFieldOptions | JsonFieldOptions | JsonbFieldOptions | BooleanFieldOptions | RadioFieldOptions | SortFieldOptions | TextFieldOptions | VirtualFieldOptions | ArrayFieldOptions | SetFieldOptions | TimeFieldOptions | DateFieldOptions | UidFieldOptions | UUIDFieldOptions | PasswordFieldOptions | ContextFieldOptions | BelongsToFieldOptions | HasOneFieldOptions | HasManyFieldOptions | BelongsToManyFieldOptions;
44
+ export type FieldOptions = BaseFieldOptions | StringFieldOptions | IntegerFieldOptions | FloatFieldOptions | DecimalFieldOptions | DoubleFieldOptions | RealFieldOptions | JsonFieldOptions | JsonbFieldOptions | BooleanFieldOptions | RadioFieldOptions | SortFieldOptions | TextFieldOptions | VirtualFieldOptions | ArrayFieldOptions | SetFieldOptions | TimeFieldOptions | DateFieldOptions | UidFieldOptions | UUIDFieldOptions | PasswordFieldOptions | ContextFieldOptions | BelongsToFieldOptions | HasOneFieldOptions | HasManyFieldOptions | BelongsToManyFieldOptions;
@@ -1,5 +1,5 @@
1
1
  import { BaseFieldOptions, Field } from './field';
2
- export declare type BaseRelationFieldOptions = BaseFieldOptions;
2
+ export type BaseRelationFieldOptions = BaseFieldOptions;
3
3
  export interface MultipleRelationFieldOptions extends BaseRelationFieldOptions {
4
4
  sortBy?: string | string[];
5
5
  }
@@ -31,7 +31,7 @@ class UidField extends _field.Field {
31
31
  _this$options$prefix = _this$options.prefix,
32
32
  prefix = _this$options$prefix === void 0 ? '' : _this$options$prefix,
33
33
  pattern = _this$options.pattern;
34
- const re = new RegExp(pattern || '^[A-Za-z0-9][A-Za-z0-9_-]*$');
34
+ const re = new RegExp(pattern || '^[A-Za-z0-9_][A-Za-z0-9_-]*$');
35
35
  this.listener = /*#__PURE__*/function () {
36
36
  var _ref = _asyncToGenerator(function* (instance) {
37
37
  const value = instance.get(name);
@@ -2,7 +2,7 @@ import { ModelStatic } from 'sequelize';
2
2
  import { Collection } from './collection';
3
3
  import { Database } from './database';
4
4
  import { Model } from './model';
5
- declare type FilterType = any;
5
+ type FilterType = any;
6
6
  interface FilterParserContext {
7
7
  collection: Collection;
8
8
  app?: any;
package/lib/index.d.ts CHANGED
@@ -1,11 +1,13 @@
1
- export { DataTypes, ModelStatic, Op, SyncOptions } from 'sequelize';
1
+ export { BaseError, BelongsToGetAssociationMixin, DataTypes, fn, HasManyCountAssociationsMixin, HasManyCreateAssociationMixin, HasManyGetAssociationsMixin, literal, ModelStatic, Op, SyncOptions, Transaction, UniqueConstraintError, ValidationError, ValidationErrorItem, where, } from 'sequelize';
2
2
  export * from './collection';
3
+ export * from './collection-group-manager';
3
4
  export * from './collection-importer';
4
5
  export * from './database';
5
6
  export { Database as default } from './database';
6
7
  export * from './field-repository/array-field-repository';
7
8
  export * from './fields';
8
9
  export * from './filter-match';
10
+ export { default as FilterParser } from './filter-parser';
9
11
  export * from './inherited-collection';
10
12
  export * from './magic-attribute-model';
11
13
  export * from './migration';
@@ -20,6 +22,5 @@ export * from './repository';
20
22
  export * from './update-associations';
21
23
  export { snakeCase } from './utils';
22
24
  export * from './value-parsers';
23
- export * from './collection-group-manager';
24
25
  export * from './view-collection';
25
26
  export * from './view/view-inference';
package/lib/index.js CHANGED
@@ -4,34 +4,97 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  var _exportNames = {
7
+ BaseError: true,
7
8
  DataTypes: true,
9
+ fn: true,
10
+ literal: true,
8
11
  Op: true,
12
+ Transaction: true,
13
+ UniqueConstraintError: true,
14
+ ValidationError: true,
15
+ ValidationErrorItem: true,
16
+ where: true,
17
+ FilterParser: true,
9
18
  snakeCase: true
10
19
  };
20
+ Object.defineProperty(exports, "BaseError", {
21
+ enumerable: true,
22
+ get: function get() {
23
+ return _sequelize().BaseError;
24
+ }
25
+ });
11
26
  Object.defineProperty(exports, "DataTypes", {
12
27
  enumerable: true,
13
28
  get: function get() {
14
29
  return _sequelize().DataTypes;
15
30
  }
16
31
  });
32
+ Object.defineProperty(exports, "FilterParser", {
33
+ enumerable: true,
34
+ get: function get() {
35
+ return _filterParser.default;
36
+ }
37
+ });
17
38
  Object.defineProperty(exports, "Op", {
18
39
  enumerable: true,
19
40
  get: function get() {
20
41
  return _sequelize().Op;
21
42
  }
22
43
  });
44
+ Object.defineProperty(exports, "Transaction", {
45
+ enumerable: true,
46
+ get: function get() {
47
+ return _sequelize().Transaction;
48
+ }
49
+ });
50
+ Object.defineProperty(exports, "UniqueConstraintError", {
51
+ enumerable: true,
52
+ get: function get() {
53
+ return _sequelize().UniqueConstraintError;
54
+ }
55
+ });
56
+ Object.defineProperty(exports, "ValidationError", {
57
+ enumerable: true,
58
+ get: function get() {
59
+ return _sequelize().ValidationError;
60
+ }
61
+ });
62
+ Object.defineProperty(exports, "ValidationErrorItem", {
63
+ enumerable: true,
64
+ get: function get() {
65
+ return _sequelize().ValidationErrorItem;
66
+ }
67
+ });
23
68
  Object.defineProperty(exports, "default", {
24
69
  enumerable: true,
25
70
  get: function get() {
26
71
  return _database.Database;
27
72
  }
28
73
  });
74
+ Object.defineProperty(exports, "fn", {
75
+ enumerable: true,
76
+ get: function get() {
77
+ return _sequelize().fn;
78
+ }
79
+ });
80
+ Object.defineProperty(exports, "literal", {
81
+ enumerable: true,
82
+ get: function get() {
83
+ return _sequelize().literal;
84
+ }
85
+ });
29
86
  Object.defineProperty(exports, "snakeCase", {
30
87
  enumerable: true,
31
88
  get: function get() {
32
89
  return _utils.snakeCase;
33
90
  }
34
91
  });
92
+ Object.defineProperty(exports, "where", {
93
+ enumerable: true,
94
+ get: function get() {
95
+ return _sequelize().where;
96
+ }
97
+ });
35
98
  function _sequelize() {
36
99
  const data = require("sequelize");
37
100
  _sequelize = function _sequelize() {
@@ -51,6 +114,18 @@ Object.keys(_collection).forEach(function (key) {
51
114
  }
52
115
  });
53
116
  });
117
+ var _collectionGroupManager = require("./collection-group-manager");
118
+ Object.keys(_collectionGroupManager).forEach(function (key) {
119
+ if (key === "default" || key === "__esModule") return;
120
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
121
+ if (key in exports && exports[key] === _collectionGroupManager[key]) return;
122
+ Object.defineProperty(exports, key, {
123
+ enumerable: true,
124
+ get: function get() {
125
+ return _collectionGroupManager[key];
126
+ }
127
+ });
128
+ });
54
129
  var _collectionImporter = require("./collection-importer");
55
130
  Object.keys(_collectionImporter).forEach(function (key) {
56
131
  if (key === "default" || key === "__esModule") return;
@@ -111,6 +186,7 @@ Object.keys(_filterMatch).forEach(function (key) {
111
186
  }
112
187
  });
113
188
  });
189
+ var _filterParser = _interopRequireDefault(require("./filter-parser"));
114
190
  var _inheritedCollection = require("./inherited-collection");
115
191
  Object.keys(_inheritedCollection).forEach(function (key) {
116
192
  if (key === "default" || key === "__esModule") return;
@@ -268,18 +344,6 @@ Object.keys(_valueParsers).forEach(function (key) {
268
344
  }
269
345
  });
270
346
  });
271
- var _collectionGroupManager = require("./collection-group-manager");
272
- Object.keys(_collectionGroupManager).forEach(function (key) {
273
- if (key === "default" || key === "__esModule") return;
274
- if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
275
- if (key in exports && exports[key] === _collectionGroupManager[key]) return;
276
- Object.defineProperty(exports, key, {
277
- enumerable: true,
278
- get: function get() {
279
- return _collectionGroupManager[key];
280
- }
281
- });
282
- });
283
347
  var _viewCollection = require("./view-collection");
284
348
  Object.keys(_viewCollection).forEach(function (key) {
285
349
  if (key === "default" || key === "__esModule") return;
@@ -303,4 +367,5 @@ Object.keys(_viewInference).forEach(function (key) {
303
367
  return _viewInference[key];
304
368
  }
305
369
  });
306
- });
370
+ });
371
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
package/lib/model-hook.js CHANGED
@@ -39,7 +39,7 @@ class ModelHook {
39
39
  try {
40
40
  for (_iterator.s(); !(_step = _iterator.n()).done;) {
41
41
  const arg = _step.value;
42
- if (arg === null || arg === void 0 ? void 0 : arg._previousDataValues) {
42
+ if (arg !== null && arg !== void 0 && arg._previousDataValues) {
43
43
  return arg.constructor.name;
44
44
  }
45
45
  if (_lodash().default.isPlainObject(arg)) {
package/lib/model.d.ts CHANGED
@@ -11,7 +11,7 @@ export declare class Model<TModelAttributes extends {} = any, TCreationAttribute
11
11
  protected _changedWithAssociations: Set<unknown>;
12
12
  protected _previousDataValuesWithAssociations: {};
13
13
  toChangedWithAssociations(): void;
14
- changedWithAssociations(key?: string, value?: any): boolean | this | unknown[];
14
+ changedWithAssociations(key?: string, value?: any): boolean | unknown[] | this;
15
15
  clearChangedWithAssociations(): void;
16
16
  toJSON<T extends TModelAttributes>(): T;
17
17
  private hiddenObjKey;
@@ -4,6 +4,13 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
+ function _lodash() {
8
+ const data = _interopRequireDefault(require("lodash"));
9
+ _lodash = function _lodash() {
10
+ return data;
11
+ };
12
+ return data;
13
+ }
7
14
  function _sequelize() {
8
15
  const data = require("sequelize");
9
16
  _sequelize = function _sequelize() {
@@ -11,22 +18,37 @@ function _sequelize() {
11
18
  };
12
19
  return data;
13
20
  }
21
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
14
22
  const mapVal = (values, db) => values.map(v => {
15
23
  const collection = db.getCollection(v);
16
24
  return _sequelize().Sequelize.literal(`'${collection.tableNameAsString()}'::regclass`);
17
25
  });
26
+ const filterItems = (values, db) => {
27
+ return _lodash().default.castArray(values).map(v => {
28
+ const collection = db.getCollection(v);
29
+ if (!collection) return null;
30
+ return `'${collection.tableNameAsString()}'::regclass`;
31
+ }).filter(Boolean);
32
+ };
33
+ const joinValues = items => items.join(', ');
18
34
  var _default = {
19
35
  $childIn(values, ctx) {
20
36
  const db = ctx.db;
21
- return {
22
- [_sequelize().Op.in]: mapVal(values, db)
23
- };
37
+ const items = filterItems(values, db);
38
+ if (items.length) {
39
+ return _sequelize().Sequelize.literal(`"${ctx.model.name}"."tableoid" IN (${joinValues(items)})`);
40
+ } else {
41
+ return _sequelize().Sequelize.literal(`1 = 2`);
42
+ }
24
43
  },
25
44
  $childNotIn(values, ctx) {
26
45
  const db = ctx.db;
27
- return {
28
- [_sequelize().Op.notIn]: mapVal(values, db)
29
- };
46
+ const items = filterItems(values, db);
47
+ if (items.length) {
48
+ return _sequelize().Sequelize.literal(`"${ctx.model.name}"."tableoid" NOT IN (${joinValues(items)})`);
49
+ } else {
50
+ return _sequelize().Sequelize.literal(`1 = 1`);
51
+ }
30
52
  }
31
53
  };
32
54
  exports.default = _default;
@@ -65,7 +65,7 @@ class OptionsParser {
65
65
  toSequelizeParams() {
66
66
  var _this$options;
67
67
  const queryParams = this.filterParser.toSequelizeParams();
68
- if ((_this$options = this.options) === null || _this$options === void 0 ? void 0 : _this$options.filterByTk) {
68
+ if ((_this$options = this.options) !== null && _this$options !== void 0 && _this$options.filterByTk) {
69
69
  queryParams.where = {
70
70
  [_sequelize().Op.and]: [queryParams.where, {
71
71
  [this.context.targetKey || this.collection.filterTargetKey]: this.options.filterByTk
@@ -130,7 +130,7 @@ class OptionsParser {
130
130
  var _this$options3, _this$options4, _this$options5, _this$options6;
131
131
  const appends = ((_this$options3 = this.options) === null || _this$options3 === void 0 ? void 0 : _this$options3.appends) || [];
132
132
  const except = [];
133
- if ((_this$options4 = this.options) === null || _this$options4 === void 0 ? void 0 : _this$options4.attributes) {
133
+ if ((_this$options4 = this.options) !== null && _this$options4 !== void 0 && _this$options4.attributes) {
134
134
  return {
135
135
  attributes: this.options.attributes
136
136
  };
@@ -142,7 +142,7 @@ class OptionsParser {
142
142
  if (this.collection.isParent()) {
143
143
  OptionsParser.appendInheritInspectAttribute(attributes.include, this.collection);
144
144
  }
145
- if ((_this$options5 = this.options) === null || _this$options5 === void 0 ? void 0 : _this$options5.fields) {
145
+ if ((_this$options5 = this.options) !== null && _this$options5 !== void 0 && _this$options5.fields) {
146
146
  attributes = [];
147
147
  if (this.collection.isParent()) {
148
148
  OptionsParser.appendInheritInspectAttribute(attributes, this.collection);
@@ -167,7 +167,7 @@ class OptionsParser {
167
167
  _iterator2.f();
168
168
  }
169
169
  }
170
- if ((_this$options6 = this.options) === null || _this$options6 === void 0 ? void 0 : _this$options6.except) {
170
+ if ((_this$options6 = this.options) !== null && _this$options6 !== void 0 && _this$options6.except) {
171
171
  var _iterator3 = _createForOfIteratorHelper(this.options.except),
172
172
  _step3;
173
173
  try {
@@ -3,7 +3,7 @@ import { Model } from '../model';
3
3
  import { AggregateOptions, CreateOptions, DestroyOptions, FindOneOptions, FindOptions, TargetKey, UpdateOptions } from '../repository';
4
4
  import { FindAndCountOptions, MultipleRelationRepository } from './multiple-relation-repository';
5
5
  import { AssociatedOptions, PrimaryKeyWithThroughValues } from './types';
6
- declare type CreateBelongsToManyOptions = CreateOptions;
6
+ type CreateBelongsToManyOptions = CreateOptions;
7
7
  interface IBelongsToManyRepository<M extends Model> {
8
8
  find(options?: FindOptions): Promise<M[]>;
9
9
  findAndCount(options?: FindAndCountOptions): Promise<[M[], number]>;
@@ -1,7 +1,7 @@
1
1
  import { Model } from '../model';
2
2
  import { CreateOptions, UpdateOptions } from '../repository';
3
3
  import { SingleRelationFindOption, SingleRelationRepository } from './single-relation-repository';
4
- declare type BelongsToFindOptions = SingleRelationFindOption;
4
+ type BelongsToFindOptions = SingleRelationFindOption;
5
5
  interface IBelongsToRepository<M extends Model> {
6
6
  find(options?: BelongsToFindOptions): Promise<M>;
7
7
  findOne(options?: BelongsToFindOptions): Promise<M>;
@@ -42,7 +42,7 @@ class HasManyRepository extends _multipleRelationRepository.MultipleRelationRepo
42
42
  const addFilter = {
43
43
  [_this.association.foreignKey]: _this.sourceKeyValue
44
44
  };
45
- if (options === null || options === void 0 ? void 0 : options.filterByTk) {
45
+ if (options !== null && options !== void 0 && options.filterByTk) {
46
46
  addFilter[_this.associationField.targetKey] = options.filterByTk;
47
47
  }
48
48
  const findOptions = _objectSpread(_objectSpread({}, (0, _lodash().omit)(options, ['filterByTk', 'where', 'values', 'attributes'])), {}, {
@@ -1,7 +1,7 @@
1
1
  import { MultiAssociationAccessors, Transaction, Transactionable } from 'sequelize';
2
2
  import { CommonFindOptions, CountOptions, DestroyOptions, Filter, FindOneOptions, FindOptions, TargetKey, TK, UpdateOptions } from '../repository';
3
3
  import { RelationRepository } from './relation-repository';
4
- export declare type FindAndCountOptions = CommonFindOptions;
4
+ export type FindAndCountOptions = CommonFindOptions;
5
5
  export interface AssociatedOptions extends Transactionable {
6
6
  tk?: TK;
7
7
  }
@@ -1,7 +1,7 @@
1
1
  import { TargetKey, Values } from '../repository';
2
2
  import { Transactionable } from 'sequelize';
3
- export declare type PrimaryKeyWithThroughValues = [TargetKey, Values];
3
+ export type PrimaryKeyWithThroughValues = [TargetKey, Values];
4
4
  export interface AssociatedOptions extends Transactionable {
5
5
  tk?: TargetKey | TargetKey[] | PrimaryKeyWithThroughValues | PrimaryKeyWithThroughValues[];
6
6
  }
7
- export declare type setAssociationOptions = TargetKey | TargetKey[] | PrimaryKeyWithThroughValues | PrimaryKeyWithThroughValues[] | AssociatedOptions;
7
+ export type setAssociationOptions = TargetKey | TargetKey[] | PrimaryKeyWithThroughValues | PrimaryKeyWithThroughValues[] | AssociatedOptions;
@@ -19,41 +19,41 @@ export { Transactionable } from 'sequelize';
19
19
  export interface FilterAble {
20
20
  filter: Filter;
21
21
  }
22
- export declare type TargetKey = string | number;
23
- export declare type TK = TargetKey | TargetKey[];
24
- declare type FieldValue = string | number | bigint | boolean | Date | Buffer | null | FieldValue[] | FilterWithOperator;
25
- declare type Operators = keyof typeof operators & keyof WhereOperators;
26
- export declare type FilterWithOperator = {
22
+ export type TargetKey = string | number;
23
+ export type TK = TargetKey | TargetKey[];
24
+ type FieldValue = string | number | bigint | boolean | Date | Buffer | null | FieldValue[] | FilterWithOperator;
25
+ type Operators = keyof typeof operators & keyof WhereOperators;
26
+ export type FilterWithOperator = {
27
27
  [key: string]: {
28
28
  [K in Operators]: FieldValue;
29
29
  } | FieldValue;
30
30
  };
31
- export declare type FilterWithValue = {
31
+ export type FilterWithValue = {
32
32
  [key: string]: FieldValue;
33
33
  };
34
- declare type FilterAnd = {
34
+ type FilterAnd = {
35
35
  $and: Filter[];
36
36
  };
37
- declare type FilterOr = {
37
+ type FilterOr = {
38
38
  $or: Filter[];
39
39
  };
40
- export declare type Filter = FilterWithOperator | FilterWithValue | FilterAnd | FilterOr;
41
- export declare type Appends = string[];
42
- export declare type Except = string[];
43
- export declare type Fields = string[];
44
- export declare type Sort = string[] | string;
45
- export declare type WhiteList = string[];
46
- export declare type BlackList = string[];
47
- export declare type AssociationKeysToBeUpdate = string[];
48
- export declare type Values = any;
49
- export declare type CountOptions = Omit<SequelizeCountOptions, 'distinct' | 'where' | 'include'> & Transactionable & {
40
+ export type Filter = FilterWithOperator | FilterWithValue | FilterAnd | FilterOr;
41
+ export type Appends = string[];
42
+ export type Except = string[];
43
+ export type Fields = string[];
44
+ export type Sort = string[] | string;
45
+ export type WhiteList = string[];
46
+ export type BlackList = string[];
47
+ export type AssociationKeysToBeUpdate = string[];
48
+ export type Values = any;
49
+ export type CountOptions = Omit<SequelizeCountOptions, 'distinct' | 'where' | 'include'> & Transactionable & {
50
50
  filter?: Filter;
51
51
  context?: any;
52
52
  } & FilterByTk;
53
53
  export interface FilterByTk {
54
54
  filterByTk?: TargetKey;
55
55
  }
56
- export declare type FindOptions = SequelizeFindOptions & CommonFindOptions & FilterByTk;
56
+ export type FindOptions = SequelizeFindOptions & CommonFindOptions & FilterByTk;
57
57
  export interface CommonFindOptions extends Transactionable {
58
58
  filter?: Filter;
59
59
  fields?: Fields;
@@ -63,14 +63,14 @@ export interface CommonFindOptions extends Transactionable {
63
63
  context?: any;
64
64
  tree?: boolean;
65
65
  }
66
- export declare type FindOneOptions = Omit<FindOptions, 'limit'>;
66
+ export type FindOneOptions = Omit<FindOptions, 'limit'>;
67
67
  export interface DestroyOptions extends SequelizeDestroyOptions {
68
68
  filter?: Filter;
69
69
  filterByTk?: TargetKey | TargetKey[];
70
70
  truncate?: boolean;
71
71
  context?: any;
72
72
  }
73
- declare type FindAndCountOptions = Omit<SequelizeAndCountOptions, 'where' | 'include' | 'order'> & CommonFindOptions;
73
+ type FindAndCountOptions = Omit<SequelizeAndCountOptions, 'where' | 'include' | 'order'> & CommonFindOptions;
74
74
  export interface CreateOptions extends SequelizeCreateOptions {
75
75
  values?: Values | Values[];
76
76
  whitelist?: WhiteList;
package/lib/repository.js CHANGED
@@ -4,6 +4,13 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.Repository = void 0;
7
+ function _flat() {
8
+ const data = require("flat");
9
+ _flat = function _flat() {
10
+ return data;
11
+ };
12
+ return data;
13
+ }
7
14
  function _lodash() {
8
15
  const data = _interopRequireDefault(require("lodash"));
9
16
  _lodash = function _lodash() {
@@ -20,6 +27,7 @@ function _sequelize() {
20
27
  }
21
28
  var _mustHaveFilterDecorator = _interopRequireDefault(require("./decorators/must-have-filter-decorator"));
22
29
  var _transactionDecorator = require("./decorators/transaction-decorator");
30
+ var _eagerLoadingTree = require("./eager-loading/eager-loading-tree");
23
31
  var _arrayFieldRepository = require("./field-repository/array-field-repository");
24
32
  var _fields = require("./fields");
25
33
  var _filterParser = _interopRequireDefault(require("./filter-parser"));
@@ -30,14 +38,6 @@ var _hasmanyRepository = require("./relation-repository/hasmany-repository");
30
38
  var _hasoneRepository = require("./relation-repository/hasone-repository");
31
39
  var _updateAssociations = require("./update-associations");
32
40
  var _updateGuard = require("./update-guard");
33
- var _eagerLoadingTree = require("./eager-loading/eager-loading-tree");
34
- function _flat() {
35
- const data = require("flat");
36
- _flat = function _flat() {
37
- return data;
38
- };
39
- return data;
40
- }
41
41
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
42
42
  function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
43
43
  function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
@@ -162,10 +162,10 @@ class Repository {
162
162
  var _queryOptions$include;
163
163
  let options = countOptions ? _lodash().default.clone(countOptions) : {};
164
164
  const transaction = yield _this.getTransaction(options);
165
- if (countOptions === null || countOptions === void 0 ? void 0 : countOptions.filter) {
165
+ if (countOptions !== null && countOptions !== void 0 && countOptions.filter) {
166
166
  options = _objectSpread(_objectSpread({}, options), _this.parseFilter(countOptions.filter, countOptions));
167
167
  }
168
- if (countOptions === null || countOptions === void 0 ? void 0 : countOptions.filterByTk) {
168
+ if (countOptions !== null && countOptions !== void 0 && countOptions.filterByTk) {
169
169
  options['where'] = {
170
170
  [_sequelize().Op.and]: [options['where'] || {}, {
171
171
  [_this.collection.filterTargetKey]: options.filterByTk