@nocobase/database 0.8.0-alpha.8 → 0.8.1-alpha.3

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 (122) hide show
  1. package/lib/collection.d.ts +7 -3
  2. package/lib/collection.js +126 -22
  3. package/lib/database.d.ts +13 -7
  4. package/lib/database.js +39 -8
  5. package/lib/decorators/must-have-filter-decorator.js +4 -0
  6. package/lib/decorators/transaction-decorator.js +1 -0
  7. package/lib/features/ReferencesMap.js +14 -9
  8. package/lib/field-repository/array-field-repository.d.ts +28 -0
  9. package/lib/field-repository/array-field-repository.js +208 -0
  10. package/lib/fields/array-field.d.ts +1 -1
  11. package/lib/fields/array-field.js +15 -11
  12. package/lib/fields/belongs-to-field.d.ts +9 -1
  13. package/lib/fields/belongs-to-field.js +21 -7
  14. package/lib/fields/belongs-to-many-field.d.ts +4 -0
  15. package/lib/fields/belongs-to-many-field.js +24 -0
  16. package/lib/fields/field.d.ts +3 -2
  17. package/lib/fields/field.js +19 -13
  18. package/lib/fields/has-many-field.d.ts +2 -1
  19. package/lib/fields/has-many-field.js +18 -10
  20. package/lib/fields/has-one-field.d.ts +1 -0
  21. package/lib/fields/has-one-field.js +22 -10
  22. package/lib/fields/index.d.ts +3 -3
  23. package/lib/fields/index.js +14 -34
  24. package/lib/fields/relation-field.d.ts +2 -1
  25. package/lib/fields/relation-field.js +16 -0
  26. package/lib/fields/set-field.d.ts +10 -0
  27. package/lib/fields/set-field.js +35 -0
  28. package/lib/fields/sort-field.d.ts +1 -1
  29. package/lib/fields/sort-field.js +1 -1
  30. package/lib/filter-match.d.ts +1 -0
  31. package/lib/filter-match.js +84 -0
  32. package/lib/filter-parser.d.ts +2 -2
  33. package/lib/index.d.ts +5 -1
  34. package/lib/index.js +56 -0
  35. package/lib/inherited-collection.d.ts +13 -0
  36. package/lib/inherited-collection.js +210 -0
  37. package/lib/inherited-map.d.ts +21 -0
  38. package/lib/inherited-map.js +203 -0
  39. package/lib/model-hook.d.ts +1 -1
  40. package/lib/model.d.ts +1 -0
  41. package/lib/model.js +47 -0
  42. package/lib/operators/array.d.ts +1 -25
  43. package/lib/operators/association.d.ts +1 -9
  44. package/lib/operators/boolean.d.ts +1 -12
  45. package/lib/operators/date.d.ts +1 -33
  46. package/lib/operators/empty.d.ts +2 -25
  47. package/lib/operators/ne.d.ts +1 -13
  48. package/lib/operators/notIn.d.ts +1 -9
  49. package/lib/options-parser.d.ts +3 -2
  50. package/lib/options-parser.js +16 -1
  51. package/lib/relation-repository/relation-repository.d.ts +2 -2
  52. package/lib/relation-repository/single-relation-repository.js +2 -2
  53. package/lib/repository.d.ts +18 -10
  54. package/lib/repository.js +172 -38
  55. package/lib/sync-runner.d.ts +4 -0
  56. package/lib/sync-runner.js +181 -0
  57. package/lib/types.d.ts +2 -2
  58. package/lib/update-associations.d.ts +1 -0
  59. package/lib/update-associations.js +21 -2
  60. package/lib/update-guard.d.ts +3 -3
  61. package/lib/utils.js +5 -0
  62. package/package.json +4 -4
  63. package/src/__tests__/bigint.test.ts +48 -0
  64. package/src/__tests__/collection.test.ts +48 -13
  65. package/src/__tests__/database.test.ts +10 -0
  66. package/src/__tests__/field-repository/array-field-repository.test.ts +94 -0
  67. package/src/__tests__/fields/set.test.ts +37 -0
  68. package/src/__tests__/filter-match.test.ts +52 -0
  69. package/src/__tests__/inhertits/collection-inherits-sync.test.ts +38 -0
  70. package/src/__tests__/inhertits/collection-inherits.test.ts +994 -0
  71. package/src/__tests__/inhertits/helper.ts +3 -0
  72. package/src/__tests__/inhertits/inherited-map.test.ts +27 -0
  73. package/src/__tests__/relation-repository/belongs-to-many-repository.test.ts +2 -0
  74. package/src/__tests__/relation-repository/has-many-repository.test.ts +1 -1
  75. package/src/__tests__/repository/destroy.test.ts +122 -1
  76. package/src/__tests__/repository/update-many.test.ts +57 -0
  77. package/src/__tests__/update-association-values.test.ts +232 -0
  78. package/src/__tests__/update-associations.test.ts +6 -1
  79. package/src/collection.ts +90 -8
  80. package/src/database.ts +53 -14
  81. package/src/decorators/must-have-filter-decorator.ts +4 -0
  82. package/src/decorators/transaction-decorator.ts +1 -0
  83. package/src/features/ReferencesMap.ts +20 -9
  84. package/src/features/referential-integrity-check.ts +1 -0
  85. package/src/field-repository/array-field-repository.ts +155 -0
  86. package/src/fields/array-field.ts +4 -4
  87. package/src/fields/belongs-to-field.ts +26 -10
  88. package/src/fields/belongs-to-many-field.ts +34 -0
  89. package/src/fields/field.ts +26 -13
  90. package/src/fields/has-many-field.ts +17 -9
  91. package/src/fields/has-one-field.ts +23 -9
  92. package/src/fields/index.ts +5 -5
  93. package/src/fields/relation-field.ts +16 -0
  94. package/src/fields/set-field.ts +25 -0
  95. package/src/fields/sort-field.ts +5 -4
  96. package/src/filter-match.ts +49 -0
  97. package/src/filter-parser.ts +2 -2
  98. package/src/index.ts +5 -2
  99. package/src/inherited-collection.ts +112 -0
  100. package/src/inherited-map.ts +97 -0
  101. package/src/model-hook.ts +2 -3
  102. package/src/model.ts +43 -3
  103. package/src/operators/array.ts +1 -1
  104. package/src/operators/association.ts +1 -1
  105. package/src/operators/boolean.ts +1 -1
  106. package/src/operators/date.ts +1 -1
  107. package/src/operators/empty.ts +1 -1
  108. package/src/operators/ne.ts +1 -1
  109. package/src/operators/notIn.ts +2 -1
  110. package/src/options-parser.ts +20 -4
  111. package/src/relation-repository/relation-repository.ts +2 -2
  112. package/src/relation-repository/single-relation-repository.ts +2 -2
  113. package/src/repository.ts +144 -30
  114. package/src/sync-runner.ts +162 -0
  115. package/src/types.ts +2 -2
  116. package/src/update-associations.ts +23 -7
  117. package/src/update-guard.ts +3 -3
  118. package/src/utils.ts +5 -1
  119. package/lib/fields/sequence-field.d.ts +0 -31
  120. package/lib/fields/sequence-field.js +0 -299
  121. package/src/__tests__/fields/sequence-field.test.ts +0 -455
  122. package/src/fields/sequence-field.ts +0 -200
@@ -3,21 +3,11 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- var _exportNames = {
7
- SequenceField: true
8
- };
9
- Object.defineProperty(exports, "SequenceField", {
10
- enumerable: true,
11
- get: function get() {
12
- return _sequenceField.SequenceField;
13
- }
14
- });
15
6
 
16
7
  var _arrayField = require("./array-field");
17
8
 
18
9
  Object.keys(_arrayField).forEach(function (key) {
19
10
  if (key === "default" || key === "__esModule") return;
20
- if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
21
11
  if (key in exports && exports[key] === _arrayField[key]) return;
22
12
  Object.defineProperty(exports, key, {
23
13
  enumerable: true,
@@ -27,11 +17,23 @@ Object.keys(_arrayField).forEach(function (key) {
27
17
  });
28
18
  });
29
19
 
20
+ var _setField = require("./set-field");
21
+
22
+ Object.keys(_setField).forEach(function (key) {
23
+ if (key === "default" || key === "__esModule") return;
24
+ if (key in exports && exports[key] === _setField[key]) return;
25
+ Object.defineProperty(exports, key, {
26
+ enumerable: true,
27
+ get: function get() {
28
+ return _setField[key];
29
+ }
30
+ });
31
+ });
32
+
30
33
  var _belongsToField = require("./belongs-to-field");
31
34
 
32
35
  Object.keys(_belongsToField).forEach(function (key) {
33
36
  if (key === "default" || key === "__esModule") return;
34
- if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
35
37
  if (key in exports && exports[key] === _belongsToField[key]) return;
36
38
  Object.defineProperty(exports, key, {
37
39
  enumerable: true,
@@ -45,7 +47,6 @@ var _belongsToManyField = require("./belongs-to-many-field");
45
47
 
46
48
  Object.keys(_belongsToManyField).forEach(function (key) {
47
49
  if (key === "default" || key === "__esModule") return;
48
- if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
49
50
  if (key in exports && exports[key] === _belongsToManyField[key]) return;
50
51
  Object.defineProperty(exports, key, {
51
52
  enumerable: true,
@@ -59,7 +60,6 @@ var _booleanField = require("./boolean-field");
59
60
 
60
61
  Object.keys(_booleanField).forEach(function (key) {
61
62
  if (key === "default" || key === "__esModule") return;
62
- if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
63
63
  if (key in exports && exports[key] === _booleanField[key]) return;
64
64
  Object.defineProperty(exports, key, {
65
65
  enumerable: true,
@@ -73,7 +73,6 @@ var _contextField = require("./context-field");
73
73
 
74
74
  Object.keys(_contextField).forEach(function (key) {
75
75
  if (key === "default" || key === "__esModule") return;
76
- if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
77
76
  if (key in exports && exports[key] === _contextField[key]) return;
78
77
  Object.defineProperty(exports, key, {
79
78
  enumerable: true,
@@ -87,7 +86,6 @@ var _dateField = require("./date-field");
87
86
 
88
87
  Object.keys(_dateField).forEach(function (key) {
89
88
  if (key === "default" || key === "__esModule") return;
90
- if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
91
89
  if (key in exports && exports[key] === _dateField[key]) return;
92
90
  Object.defineProperty(exports, key, {
93
91
  enumerable: true,
@@ -101,7 +99,6 @@ var _field = require("./field");
101
99
 
102
100
  Object.keys(_field).forEach(function (key) {
103
101
  if (key === "default" || key === "__esModule") return;
104
- if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
105
102
  if (key in exports && exports[key] === _field[key]) return;
106
103
  Object.defineProperty(exports, key, {
107
104
  enumerable: true,
@@ -115,7 +112,6 @@ var _hasManyField = require("./has-many-field");
115
112
 
116
113
  Object.keys(_hasManyField).forEach(function (key) {
117
114
  if (key === "default" || key === "__esModule") return;
118
- if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
119
115
  if (key in exports && exports[key] === _hasManyField[key]) return;
120
116
  Object.defineProperty(exports, key, {
121
117
  enumerable: true,
@@ -129,7 +125,6 @@ var _hasOneField = require("./has-one-field");
129
125
 
130
126
  Object.keys(_hasOneField).forEach(function (key) {
131
127
  if (key === "default" || key === "__esModule") return;
132
- if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
133
128
  if (key in exports && exports[key] === _hasOneField[key]) return;
134
129
  Object.defineProperty(exports, key, {
135
130
  enumerable: true,
@@ -143,7 +138,6 @@ var _jsonField = require("./json-field");
143
138
 
144
139
  Object.keys(_jsonField).forEach(function (key) {
145
140
  if (key === "default" || key === "__esModule") return;
146
- if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
147
141
  if (key in exports && exports[key] === _jsonField[key]) return;
148
142
  Object.defineProperty(exports, key, {
149
143
  enumerable: true,
@@ -157,7 +151,6 @@ var _numberField = require("./number-field");
157
151
 
158
152
  Object.keys(_numberField).forEach(function (key) {
159
153
  if (key === "default" || key === "__esModule") return;
160
- if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
161
154
  if (key in exports && exports[key] === _numberField[key]) return;
162
155
  Object.defineProperty(exports, key, {
163
156
  enumerable: true,
@@ -171,7 +164,6 @@ var _passwordField = require("./password-field");
171
164
 
172
165
  Object.keys(_passwordField).forEach(function (key) {
173
166
  if (key === "default" || key === "__esModule") return;
174
- if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
175
167
  if (key in exports && exports[key] === _passwordField[key]) return;
176
168
  Object.defineProperty(exports, key, {
177
169
  enumerable: true,
@@ -185,7 +177,6 @@ var _radioField = require("./radio-field");
185
177
 
186
178
  Object.keys(_radioField).forEach(function (key) {
187
179
  if (key === "default" || key === "__esModule") return;
188
- if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
189
180
  if (key in exports && exports[key] === _radioField[key]) return;
190
181
  Object.defineProperty(exports, key, {
191
182
  enumerable: true,
@@ -199,7 +190,6 @@ var _relationField = require("./relation-field");
199
190
 
200
191
  Object.keys(_relationField).forEach(function (key) {
201
192
  if (key === "default" || key === "__esModule") return;
202
- if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
203
193
  if (key in exports && exports[key] === _relationField[key]) return;
204
194
  Object.defineProperty(exports, key, {
205
195
  enumerable: true,
@@ -213,7 +203,6 @@ var _sortField = require("./sort-field");
213
203
 
214
204
  Object.keys(_sortField).forEach(function (key) {
215
205
  if (key === "default" || key === "__esModule") return;
216
- if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
217
206
  if (key in exports && exports[key] === _sortField[key]) return;
218
207
  Object.defineProperty(exports, key, {
219
208
  enumerable: true,
@@ -227,7 +216,6 @@ var _stringField = require("./string-field");
227
216
 
228
217
  Object.keys(_stringField).forEach(function (key) {
229
218
  if (key === "default" || key === "__esModule") return;
230
- if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
231
219
  if (key in exports && exports[key] === _stringField[key]) return;
232
220
  Object.defineProperty(exports, key, {
233
221
  enumerable: true,
@@ -241,7 +229,6 @@ var _textField = require("./text-field");
241
229
 
242
230
  Object.keys(_textField).forEach(function (key) {
243
231
  if (key === "default" || key === "__esModule") return;
244
- if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
245
232
  if (key in exports && exports[key] === _textField[key]) return;
246
233
  Object.defineProperty(exports, key, {
247
234
  enumerable: true,
@@ -255,7 +242,6 @@ var _timeField = require("./time-field");
255
242
 
256
243
  Object.keys(_timeField).forEach(function (key) {
257
244
  if (key === "default" || key === "__esModule") return;
258
- if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
259
245
  if (key in exports && exports[key] === _timeField[key]) return;
260
246
  Object.defineProperty(exports, key, {
261
247
  enumerable: true,
@@ -269,7 +255,6 @@ var _uidField = require("./uid-field");
269
255
 
270
256
  Object.keys(_uidField).forEach(function (key) {
271
257
  if (key === "default" || key === "__esModule") return;
272
- if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
273
258
  if (key in exports && exports[key] === _uidField[key]) return;
274
259
  Object.defineProperty(exports, key, {
275
260
  enumerable: true,
@@ -283,7 +268,6 @@ var _uuidField = require("./uuid-field");
283
268
 
284
269
  Object.keys(_uuidField).forEach(function (key) {
285
270
  if (key === "default" || key === "__esModule") return;
286
- if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
287
271
  if (key in exports && exports[key] === _uuidField[key]) return;
288
272
  Object.defineProperty(exports, key, {
289
273
  enumerable: true,
@@ -297,7 +281,6 @@ var _virtualField = require("./virtual-field");
297
281
 
298
282
  Object.keys(_virtualField).forEach(function (key) {
299
283
  if (key === "default" || key === "__esModule") return;
300
- if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
301
284
  if (key in exports && exports[key] === _virtualField[key]) return;
302
285
  Object.defineProperty(exports, key, {
303
286
  enumerable: true,
@@ -311,7 +294,6 @@ var _formulaField = require("./formula-field");
311
294
 
312
295
  Object.keys(_formulaField).forEach(function (key) {
313
296
  if (key === "default" || key === "__esModule") return;
314
- if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
315
297
  if (key in exports && exports[key] === _formulaField[key]) return;
316
298
  Object.defineProperty(exports, key, {
317
299
  enumerable: true,
@@ -319,6 +301,4 @@ Object.keys(_formulaField).forEach(function (key) {
319
301
  return _formulaField[key];
320
302
  }
321
303
  });
322
- });
323
-
324
- var _sequenceField = require("./sequence-field");
304
+ });
@@ -16,5 +16,6 @@ export declare abstract class RelationField extends Field {
16
16
  * get target model from database by it's name
17
17
  * @constructor
18
18
  */
19
- get TargetModel(): import("sequelize/types").ModelCtor<import("sequelize/types").Model<any, any>>;
19
+ get TargetModel(): import("sequelize").ModelCtor<import("sequelize").Model<any, any>>;
20
+ protected clearAccessors(): void;
20
21
  }
@@ -39,6 +39,22 @@ class RelationField extends _field.Field {
39
39
  return this.context.database.sequelize.models[this.target];
40
40
  }
41
41
 
42
+ clearAccessors() {
43
+ const collection = this.context.collection;
44
+ const association = collection.model.associations[this.name];
45
+
46
+ if (!association) {
47
+ return;
48
+ } // @ts-ignore
49
+
50
+
51
+ const accessors = Object.values(association.accessors);
52
+ accessors.forEach(accessor => {
53
+ // @ts-ignore
54
+ delete collection.model.prototype[accessor];
55
+ });
56
+ }
57
+
42
58
  }
43
59
 
44
60
  exports.RelationField = RelationField;
@@ -0,0 +1,10 @@
1
+ import { ArrayField } from './array-field';
2
+ import { BaseColumnFieldOptions } from './field';
3
+ export interface SetFieldOptions extends BaseColumnFieldOptions {
4
+ type: 'set';
5
+ }
6
+ export declare class SetField extends ArrayField {
7
+ beforeSave: (model: any) => void;
8
+ bind(): void;
9
+ unbind(): void;
10
+ }
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.SetField = void 0;
7
+
8
+ var _arrayField = require("./array-field");
9
+
10
+ class SetField extends _arrayField.ArrayField {
11
+ constructor(...args) {
12
+ super(...args);
13
+
14
+ this.beforeSave = model => {
15
+ const oldValue = model.get(this.options.name);
16
+
17
+ if (oldValue) {
18
+ model.set(this.options.name, [...new Set(oldValue)]);
19
+ }
20
+ };
21
+ }
22
+
23
+ bind() {
24
+ super.bind();
25
+ this.on('beforeSave', this.beforeSave);
26
+ }
27
+
28
+ unbind() {
29
+ super.unbind();
30
+ this.off('beforeSave', this.beforeSave);
31
+ }
32
+
33
+ }
34
+
35
+ exports.SetField = SetField;
@@ -1,7 +1,7 @@
1
1
  import { DataTypes } from 'sequelize';
2
2
  import { BaseColumnFieldOptions, Field } from './field';
3
3
  export declare class SortField extends Field {
4
- get dataType(): DataTypes.IntegerDataTypeConstructor;
4
+ get dataType(): DataTypes.BigIntDataTypeConstructor;
5
5
  setSortValue: (instance: any, options: any) => Promise<void>;
6
6
  onScopeChange: (instance: any, options: any) => Promise<void>;
7
7
  initRecordsSortValue: ({ transaction }: {
@@ -161,7 +161,7 @@ class SortField extends _field.Field {
161
161
  }
162
162
 
163
163
  get dataType() {
164
- return _sequelize().DataTypes.INTEGER;
164
+ return _sequelize().DataTypes.BIGINT;
165
165
  }
166
166
 
167
167
  bind() {
@@ -0,0 +1 @@
1
+ export declare function filterMatch(model: any, where: any): boolean;
@@ -0,0 +1,84 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.filterMatch = filterMatch;
7
+
8
+ function _mathjs() {
9
+ const data = require("mathjs");
10
+
11
+ _mathjs = function _mathjs() {
12
+ return data;
13
+ };
14
+
15
+ return data;
16
+ }
17
+
18
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
19
+
20
+ 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."); }
21
+
22
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
23
+
24
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
25
+
26
+ function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
27
+
28
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
29
+
30
+ function filterMatch(model, where) {
31
+ if (where.filter !== undefined) {
32
+ where = _mathjs().filter;
33
+ } // Create an object that maps operator names to functions
34
+
35
+
36
+ const operatorFunctions = {
37
+ $eq: (value, condition) => value === condition,
38
+ $not: (value, condition) => !filterMatch(model, condition),
39
+ $gt: (value, condition) => value > condition,
40
+ $gte: (value, condition) => value >= condition,
41
+ $lt: (value, condition) => value < condition,
42
+ $lte: (value, condition) => value <= condition,
43
+ $ne: (value, condition) => value !== condition,
44
+ $in: (value, condition) => condition.includes(value),
45
+ $or: (model, conditions) => Object.values(conditions).some(condition => filterMatch(model, condition)),
46
+ $and: (model, conditions) => Object.values(conditions).every(condition => filterMatch(model, condition))
47
+ };
48
+
49
+ for (var _i = 0, _Object$entries = Object.entries(where); _i < _Object$entries.length; _i++) {
50
+ const _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
51
+ key = _Object$entries$_i[0],
52
+ value = _Object$entries$_i[1];
53
+
54
+ // Check if the property value contains a logical operator
55
+ if (operatorFunctions[key] !== undefined) {
56
+ // Check if the conditions specified in the property value are satisfied
57
+ if (!operatorFunctions[key](model, value)) {
58
+ return false;
59
+ }
60
+ } else {
61
+ // Check if the property value is an object (which would contain operators)
62
+ if (typeof value === 'object') {
63
+ // Loop through each operator in the property value
64
+ for (var _i2 = 0, _Object$entries2 = Object.entries(value); _i2 < _Object$entries2.length; _i2++) {
65
+ const _Object$entries2$_i = _slicedToArray(_Object$entries2[_i2], 2),
66
+ operator = _Object$entries2$_i[0],
67
+ condition = _Object$entries2$_i[1];
68
+
69
+ // Check if the property value satisfies the condition
70
+ if (!operatorFunctions[operator](model[key], condition)) {
71
+ return false;
72
+ }
73
+ }
74
+ } else {
75
+ // Assume the default operator is "eq"
76
+ if (!operatorFunctions['$eq'](model[key], value)) {
77
+ return false;
78
+ }
79
+ }
80
+ }
81
+ }
82
+
83
+ return true;
84
+ }
@@ -1,4 +1,4 @@
1
- import { ModelCtor } from 'sequelize';
1
+ import { ModelStatic } from 'sequelize';
2
2
  import { Collection } from './collection';
3
3
  import { Database } from './database';
4
4
  import { Model } from './model';
@@ -10,7 +10,7 @@ interface FilterParserContext {
10
10
  export default class FilterParser {
11
11
  collection: Collection;
12
12
  database: Database;
13
- model: ModelCtor<Model>;
13
+ model: ModelStatic<Model>;
14
14
  filter: FilterType;
15
15
  context: FilterParserContext;
16
16
  constructor(filter: FilterType, context: FilterParserContext);
package/lib/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
- export { DataTypes, ModelCtor, Op, SyncOptions } from 'sequelize';
1
+ export { DataTypes, ModelStatic, Op, SyncOptions } from 'sequelize';
2
2
  export * from './collection';
3
+ export * from './inherited-collection';
3
4
  export * from './database';
4
5
  export { Database as default } from './database';
5
6
  export * from './fields';
@@ -14,3 +15,6 @@ export * from './relation-repository/multiple-relation-repository';
14
15
  export * from './relation-repository/single-relation-repository';
15
16
  export * from './repository';
16
17
  export * from './update-associations';
18
+ export * from './collection-importer';
19
+ export * from './filter-match';
20
+ export * from './field-repository/array-field-repository';
package/lib/index.js CHANGED
@@ -50,6 +50,20 @@ Object.keys(_collection).forEach(function (key) {
50
50
  });
51
51
  });
52
52
 
53
+ var _inheritedCollection = require("./inherited-collection");
54
+
55
+ Object.keys(_inheritedCollection).forEach(function (key) {
56
+ if (key === "default" || key === "__esModule") return;
57
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
58
+ if (key in exports && exports[key] === _inheritedCollection[key]) return;
59
+ Object.defineProperty(exports, key, {
60
+ enumerable: true,
61
+ get: function get() {
62
+ return _inheritedCollection[key];
63
+ }
64
+ });
65
+ });
66
+
53
67
  var _database = require("./database");
54
68
 
55
69
  Object.keys(_database).forEach(function (key) {
@@ -230,4 +244,46 @@ Object.keys(_updateAssociations).forEach(function (key) {
230
244
  return _updateAssociations[key];
231
245
  }
232
246
  });
247
+ });
248
+
249
+ var _collectionImporter = require("./collection-importer");
250
+
251
+ Object.keys(_collectionImporter).forEach(function (key) {
252
+ if (key === "default" || key === "__esModule") return;
253
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
254
+ if (key in exports && exports[key] === _collectionImporter[key]) return;
255
+ Object.defineProperty(exports, key, {
256
+ enumerable: true,
257
+ get: function get() {
258
+ return _collectionImporter[key];
259
+ }
260
+ });
261
+ });
262
+
263
+ var _filterMatch = require("./filter-match");
264
+
265
+ Object.keys(_filterMatch).forEach(function (key) {
266
+ if (key === "default" || key === "__esModule") return;
267
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
268
+ if (key in exports && exports[key] === _filterMatch[key]) return;
269
+ Object.defineProperty(exports, key, {
270
+ enumerable: true,
271
+ get: function get() {
272
+ return _filterMatch[key];
273
+ }
274
+ });
275
+ });
276
+
277
+ var _arrayFieldRepository = require("./field-repository/array-field-repository");
278
+
279
+ Object.keys(_arrayFieldRepository).forEach(function (key) {
280
+ if (key === "default" || key === "__esModule") return;
281
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
282
+ if (key in exports && exports[key] === _arrayFieldRepository[key]) return;
283
+ Object.defineProperty(exports, key, {
284
+ enumerable: true,
285
+ get: function get() {
286
+ return _arrayFieldRepository[key];
287
+ }
288
+ });
233
289
  });
@@ -0,0 +1,13 @@
1
+ import { Collection, CollectionContext, CollectionOptions } from './collection';
2
+ import { Field } from '.';
3
+ export declare class InheritedCollection extends Collection {
4
+ parents?: Collection[];
5
+ constructor(options: CollectionOptions, context: CollectionContext);
6
+ protected bindParents(): void;
7
+ protected setParents(inherits: string | string[]): void;
8
+ protected setParentFields(): void;
9
+ getParents(): Collection<any, any>[];
10
+ parentFields(): Map<string, Field>;
11
+ parentAttributes(): {};
12
+ isInherited(): boolean;
13
+ }