@nocobase/database 0.7.0-alpha.4 → 0.7.0-alpha.56

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 (290) hide show
  1. package/lib/collection-importer.js +101 -67
  2. package/lib/collection.js +339 -210
  3. package/lib/database.d.ts +4 -1
  4. package/lib/database.js +489 -275
  5. package/lib/fields/array-field.js +45 -25
  6. package/lib/fields/belongs-to-field.js +101 -54
  7. package/lib/fields/belongs-to-many-field.js +98 -53
  8. package/lib/fields/boolean-field.js +24 -9
  9. package/lib/fields/context-field.js +77 -42
  10. package/lib/fields/date-field.js +24 -9
  11. package/lib/fields/field.js +114 -75
  12. package/lib/fields/has-inverse-field.js +4 -2
  13. package/lib/fields/has-many-field.js +105 -56
  14. package/lib/fields/has-one-field.js +105 -54
  15. package/lib/fields/index.d.ts +3 -1
  16. package/lib/fields/index.js +277 -32
  17. package/lib/fields/json-field.js +36 -16
  18. package/lib/fields/number-field.js +53 -26
  19. package/lib/fields/password-field.js +118 -73
  20. package/lib/fields/radio-field.js +75 -47
  21. package/lib/fields/relation-field.js +41 -28
  22. package/lib/fields/sort-field.js +165 -89
  23. package/lib/fields/string-field.js +24 -9
  24. package/lib/fields/text-field.js +24 -9
  25. package/lib/fields/time-field.js +24 -9
  26. package/lib/fields/uid-field.js +57 -28
  27. package/lib/fields/uuid-field.d.ts +9 -0
  28. package/lib/fields/uuid-field.js +39 -0
  29. package/lib/fields/virtual-field.js +24 -9
  30. package/lib/filter-parser.js +288 -179
  31. package/lib/index.js +210 -29
  32. package/lib/magic-attribute-model.js +123 -71
  33. package/lib/mock-database.js +68 -34
  34. package/lib/model-hook.js +101 -60
  35. package/lib/model.js +116 -81
  36. package/lib/operators/array.js +136 -96
  37. package/lib/operators/association.js +30 -14
  38. package/lib/operators/date.js +78 -34
  39. package/lib/operators/empty.js +113 -75
  40. package/lib/operators/index.js +15 -3
  41. package/lib/operators/ne.js +27 -12
  42. package/{esm/operators/ne.d.ts → lib/operators/notIn.d.ts} +2 -2
  43. package/lib/operators/notIn.js +29 -0
  44. package/lib/operators/string.js +56 -35
  45. package/lib/operators/utils.js +18 -10
  46. package/lib/options-parser.js +323 -215
  47. package/lib/playground.js +66 -53
  48. package/lib/relation-repository/belongs-to-many-repository.js +281 -198
  49. package/lib/relation-repository/belongs-to-repository.js +10 -6
  50. package/lib/relation-repository/hasmany-repository.js +168 -121
  51. package/lib/relation-repository/hasone-repository.js +10 -6
  52. package/lib/relation-repository/multiple-relation-repository.js +263 -148
  53. package/lib/relation-repository/relation-repository.d.ts +1 -1
  54. package/lib/relation-repository/relation-repository.js +155 -95
  55. package/lib/relation-repository/single-relation-repository.js +138 -99
  56. package/lib/relation-repository/types.js +4 -2
  57. package/lib/repository.d.ts +1 -1
  58. package/lib/repository.js +465 -291
  59. package/lib/transaction-decorator.js +80 -67
  60. package/lib/update-associations.js +525 -321
  61. package/lib/update-guard.js +160 -117
  62. package/package.json +3 -8
  63. package/src/__tests__/fields/uuid-field.test.ts +30 -0
  64. package/src/__tests__/operator/notIn.test.ts +33 -0
  65. package/src/__tests__/option-parser.test.ts +20 -0
  66. package/src/database.ts +51 -4
  67. package/src/fields/context-field.ts +1 -1
  68. package/src/fields/index.ts +3 -0
  69. package/src/fields/uuid-field.ts +21 -0
  70. package/src/mock-database.ts +1 -1
  71. package/src/model-hook.ts +1 -1
  72. package/src/operators/index.ts +1 -0
  73. package/src/operators/notIn.ts +12 -0
  74. package/src/options-parser.ts +1 -1
  75. package/src/relation-repository/multiple-relation-repository.ts +6 -3
  76. package/src/relation-repository/relation-repository.ts +11 -6
  77. package/src/repository.ts +1 -1
  78. package/esm/collection-importer.d.ts +0 -7
  79. package/esm/collection-importer.js +0 -49
  80. package/esm/collection-importer.js.map +0 -1
  81. package/esm/collection.d.ts +0 -73
  82. package/esm/collection.js +0 -224
  83. package/esm/collection.js.map +0 -1
  84. package/esm/database.d.ts +0 -101
  85. package/esm/database.js +0 -275
  86. package/esm/database.js.map +0 -1
  87. package/esm/fields/array-field.d.ts +0 -11
  88. package/esm/fields/array-field.js +0 -26
  89. package/esm/fields/array-field.js.map +0 -1
  90. package/esm/fields/belongs-to-field.d.ts +0 -12
  91. package/esm/fields/belongs-to-field.js +0 -57
  92. package/esm/fields/belongs-to-field.js.map +0 -1
  93. package/esm/fields/belongs-to-many-field.d.ts +0 -11
  94. package/esm/fields/belongs-to-many-field.js +0 -55
  95. package/esm/fields/belongs-to-many-field.js.map +0 -1
  96. package/esm/fields/boolean-field.d.ts +0 -8
  97. package/esm/fields/boolean-field.js +0 -8
  98. package/esm/fields/boolean-field.js.map +0 -1
  99. package/esm/fields/context-field.d.ts +0 -13
  100. package/esm/fields/context-field.js +0 -43
  101. package/esm/fields/context-field.js.map +0 -1
  102. package/esm/fields/date-field.d.ts +0 -8
  103. package/esm/fields/date-field.js +0 -8
  104. package/esm/fields/date-field.js.map +0 -1
  105. package/esm/fields/field.d.ts +0 -37
  106. package/esm/fields/field.js +0 -74
  107. package/esm/fields/field.js.map +0 -1
  108. package/esm/fields/has-inverse-field.d.ts +0 -4
  109. package/esm/fields/has-inverse-field.js +0 -2
  110. package/esm/fields/has-inverse-field.js.map +0 -1
  111. package/esm/fields/has-many-field.d.ts +0 -64
  112. package/esm/fields/has-many-field.js +0 -58
  113. package/esm/fields/has-many-field.js.map +0 -1
  114. package/esm/fields/has-one-field.d.ts +0 -64
  115. package/esm/fields/has-one-field.js +0 -57
  116. package/esm/fields/has-one-field.js.map +0 -1
  117. package/esm/fields/index.d.ts +0 -40
  118. package/esm/fields/index.js +0 -21
  119. package/esm/fields/index.js.map +0 -1
  120. package/esm/fields/json-field.d.ts +0 -14
  121. package/esm/fields/json-field.js +0 -17
  122. package/esm/fields/json-field.js.map +0 -1
  123. package/esm/fields/number-field.d.ts +0 -32
  124. package/esm/fields/number-field.js +0 -28
  125. package/esm/fields/number-field.js.map +0 -1
  126. package/esm/fields/password-field.d.ts +0 -21
  127. package/esm/fields/password-field.js +0 -71
  128. package/esm/fields/password-field.js.map +0 -1
  129. package/esm/fields/radio-field.d.ts +0 -14
  130. package/esm/fields/radio-field.js +0 -49
  131. package/esm/fields/radio-field.js.map +0 -1
  132. package/esm/fields/relation-field.d.ts +0 -20
  133. package/esm/fields/relation-field.js +0 -27
  134. package/esm/fields/relation-field.js.map +0 -1
  135. package/esm/fields/sort-field.d.ts +0 -16
  136. package/esm/fields/sort-field.js +0 -90
  137. package/esm/fields/sort-field.js.map +0 -1
  138. package/esm/fields/string-field.d.ts +0 -8
  139. package/esm/fields/string-field.js +0 -8
  140. package/esm/fields/string-field.js.map +0 -1
  141. package/esm/fields/text-field.d.ts +0 -8
  142. package/esm/fields/text-field.js +0 -8
  143. package/esm/fields/text-field.js.map +0 -1
  144. package/esm/fields/time-field.d.ts +0 -8
  145. package/esm/fields/time-field.js +0 -8
  146. package/esm/fields/time-field.js.map +0 -1
  147. package/esm/fields/uid-field.d.ts +0 -10
  148. package/esm/fields/uid-field.js +0 -27
  149. package/esm/fields/uid-field.js.map +0 -1
  150. package/esm/fields/virtual-field.d.ts +0 -8
  151. package/esm/fields/virtual-field.js +0 -8
  152. package/esm/fields/virtual-field.js.map +0 -1
  153. package/esm/filter-parser.d.ts +0 -27
  154. package/esm/filter-parser.js +0 -185
  155. package/esm/filter-parser.js.map +0 -1
  156. package/esm/index.d.ts +0 -15
  157. package/esm/index.js +0 -16
  158. package/esm/index.js.map +0 -1
  159. package/esm/magic-attribute-model.d.ts +0 -7
  160. package/esm/magic-attribute-model.js +0 -70
  161. package/esm/magic-attribute-model.js.map +0 -1
  162. package/esm/mock-database.d.ts +0 -22
  163. package/esm/mock-database.js +0 -34
  164. package/esm/mock-database.js.map +0 -1
  165. package/esm/model-hook.d.ts +0 -12
  166. package/esm/model-hook.js +0 -61
  167. package/esm/model-hook.js.map +0 -1
  168. package/esm/model.d.ts +0 -15
  169. package/esm/model.js +0 -80
  170. package/esm/model.js.map +0 -1
  171. package/esm/operators/array.d.ts +0 -26
  172. package/esm/operators/array.js +0 -105
  173. package/esm/operators/array.js.map +0 -1
  174. package/esm/operators/association.d.ts +0 -10
  175. package/esm/operators/association.js +0 -14
  176. package/esm/operators/association.js.map +0 -1
  177. package/esm/operators/date.d.ts +0 -34
  178. package/esm/operators/date.js +0 -35
  179. package/esm/operators/date.js.map +0 -1
  180. package/esm/operators/empty.d.ts +0 -28
  181. package/esm/operators/empty.js +0 -58
  182. package/esm/operators/empty.js.map +0 -1
  183. package/esm/operators/index.d.ts +0 -2
  184. package/esm/operators/index.js +0 -2
  185. package/esm/operators/index.js.map +0 -1
  186. package/esm/operators/ne.js +0 -12
  187. package/esm/operators/ne.js.map +0 -1
  188. package/esm/operators/string.d.ts +0 -21
  189. package/esm/operators/string.js +0 -35
  190. package/esm/operators/string.js.map +0 -1
  191. package/esm/operators/utils.d.ts +0 -4
  192. package/esm/operators/utils.js +0 -11
  193. package/esm/operators/utils.js.map +0 -1
  194. package/esm/options-parser.d.ts +0 -31
  195. package/esm/options-parser.js +0 -225
  196. package/esm/options-parser.js.map +0 -1
  197. package/esm/playground.d.ts +0 -1
  198. package/esm/playground.js +0 -53
  199. package/esm/playground.js.map +0 -1
  200. package/esm/relation-repository/belongs-to-many-repository.d.ts +0 -36
  201. package/esm/relation-repository/belongs-to-many-repository.js +0 -199
  202. package/esm/relation-repository/belongs-to-many-repository.js.map +0 -1
  203. package/esm/relation-repository/belongs-to-repository.d.ts +0 -17
  204. package/esm/relation-repository/belongs-to-repository.js +0 -4
  205. package/esm/relation-repository/belongs-to-repository.js.map +0 -1
  206. package/esm/relation-repository/hasmany-repository.d.ts +0 -23
  207. package/esm/relation-repository/hasmany-repository.js +0 -125
  208. package/esm/relation-repository/hasmany-repository.js.map +0 -1
  209. package/esm/relation-repository/hasone-repository.d.ts +0 -17
  210. package/esm/relation-repository/hasone-repository.js +0 -4
  211. package/esm/relation-repository/hasone-repository.js.map +0 -1
  212. package/esm/relation-repository/multiple-relation-repository.d.ts +0 -23
  213. package/esm/relation-repository/multiple-relation-repository.js +0 -149
  214. package/esm/relation-repository/multiple-relation-repository.js.map +0 -1
  215. package/esm/relation-repository/relation-repository.d.ts +0 -32
  216. package/esm/relation-repository/relation-repository.js +0 -93
  217. package/esm/relation-repository/relation-repository.js.map +0 -1
  218. package/esm/relation-repository/single-relation-repository.d.ts +0 -23
  219. package/esm/relation-repository/single-relation-repository.js +0 -96
  220. package/esm/relation-repository/single-relation-repository.js.map +0 -1
  221. package/esm/relation-repository/types.d.ts +0 -7
  222. package/esm/relation-repository/types.js +0 -2
  223. package/esm/relation-repository/types.js.map +0 -1
  224. package/esm/repository.d.ts +0 -165
  225. package/esm/repository.js +0 -276
  226. package/esm/repository.js.map +0 -1
  227. package/esm/transaction-decorator.d.ts +0 -1
  228. package/esm/transaction-decorator.js +0 -63
  229. package/esm/transaction-decorator.js.map +0 -1
  230. package/esm/update-associations.d.ts +0 -60
  231. package/esm/update-associations.js +0 -362
  232. package/esm/update-associations.js.map +0 -1
  233. package/esm/update-guard.d.ts +0 -26
  234. package/esm/update-guard.js +0 -122
  235. package/esm/update-guard.js.map +0 -1
  236. package/lib/collection-importer.js.map +0 -1
  237. package/lib/collection.js.map +0 -1
  238. package/lib/database.js.map +0 -1
  239. package/lib/fields/array-field.js.map +0 -1
  240. package/lib/fields/belongs-to-field.js.map +0 -1
  241. package/lib/fields/belongs-to-many-field.js.map +0 -1
  242. package/lib/fields/boolean-field.js.map +0 -1
  243. package/lib/fields/context-field.js.map +0 -1
  244. package/lib/fields/date-field.js.map +0 -1
  245. package/lib/fields/field.js.map +0 -1
  246. package/lib/fields/has-inverse-field.js.map +0 -1
  247. package/lib/fields/has-many-field.js.map +0 -1
  248. package/lib/fields/has-one-field.js.map +0 -1
  249. package/lib/fields/index.js.map +0 -1
  250. package/lib/fields/json-field.js.map +0 -1
  251. package/lib/fields/number-field.js.map +0 -1
  252. package/lib/fields/password-field.js.map +0 -1
  253. package/lib/fields/radio-field.js.map +0 -1
  254. package/lib/fields/relation-field.js.map +0 -1
  255. package/lib/fields/sort-field.js.map +0 -1
  256. package/lib/fields/string-field.js.map +0 -1
  257. package/lib/fields/text-field.js.map +0 -1
  258. package/lib/fields/time-field.js.map +0 -1
  259. package/lib/fields/uid-field.js.map +0 -1
  260. package/lib/fields/virtual-field.js.map +0 -1
  261. package/lib/filter-parser.js.map +0 -1
  262. package/lib/index.js.map +0 -1
  263. package/lib/magic-attribute-model.js.map +0 -1
  264. package/lib/mock-database.js.map +0 -1
  265. package/lib/model-hook.js.map +0 -1
  266. package/lib/model.js.map +0 -1
  267. package/lib/operators/array.js.map +0 -1
  268. package/lib/operators/association.js.map +0 -1
  269. package/lib/operators/date.js.map +0 -1
  270. package/lib/operators/empty.js.map +0 -1
  271. package/lib/operators/index.js.map +0 -1
  272. package/lib/operators/ne.js.map +0 -1
  273. package/lib/operators/string.js.map +0 -1
  274. package/lib/operators/utils.js.map +0 -1
  275. package/lib/options-parser.js.map +0 -1
  276. package/lib/playground.js.map +0 -1
  277. package/lib/relation-repository/belongs-to-many-repository.js.map +0 -1
  278. package/lib/relation-repository/belongs-to-repository.js.map +0 -1
  279. package/lib/relation-repository/hasmany-repository.js.map +0 -1
  280. package/lib/relation-repository/hasone-repository.js.map +0 -1
  281. package/lib/relation-repository/multiple-relation-repository.js.map +0 -1
  282. package/lib/relation-repository/relation-repository.js.map +0 -1
  283. package/lib/relation-repository/single-relation-repository.js.map +0 -1
  284. package/lib/relation-repository/types.js.map +0 -1
  285. package/lib/repository.js.map +0 -1
  286. package/lib/transaction-decorator.js.map +0 -1
  287. package/lib/update-associations.js.map +0 -1
  288. package/lib/update-guard.js.map +0 -1
  289. package/tsconfig.build.json +0 -9
  290. package/tsconfig.json +0 -5
@@ -1,100 +1,160 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.RelationRepository = exports.transaction = void 0;
16
- const lodash_1 = __importDefault(require("lodash"));
17
- const filter_parser_1 = __importDefault(require("../filter-parser"));
18
- const options_parser_1 = require("../options-parser");
19
- const transaction_decorator_1 = require("../transaction-decorator");
20
- const update_associations_1 = require("../update-associations");
21
- const update_guard_1 = require("../update-guard");
22
- exports.transaction = (0, transaction_decorator_1.transactionWrapperBuilder)(function () {
23
- return this.sourceCollection.model.sequelize.transaction();
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.transaction = exports.RelationRepository = void 0;
7
+
8
+ function _lodash() {
9
+ const data = _interopRequireDefault(require("lodash"));
10
+
11
+ _lodash = function _lodash() {
12
+ return data;
13
+ };
14
+
15
+ return data;
16
+ }
17
+
18
+ var _filterParser = _interopRequireDefault(require("../filter-parser"));
19
+
20
+ var _optionsParser = require("../options-parser");
21
+
22
+ var _transactionDecorator = require("../transaction-decorator");
23
+
24
+ var _updateAssociations = require("../update-associations");
25
+
26
+ var _updateGuard = require("../update-guard");
27
+
28
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
29
+
30
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
31
+
32
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
33
+
34
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
35
+
36
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
37
+
38
+ function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
39
+
40
+ const transaction = (0, _transactionDecorator.transactionWrapperBuilder)(function () {
41
+ return this.sourceCollection.model.sequelize.transaction();
24
42
  });
43
+ exports.transaction = transaction;
44
+
25
45
  class RelationRepository {
26
- constructor(sourceCollection, association, sourceKeyValue) {
27
- this.db = sourceCollection.context.database;
28
- this.sourceCollection = sourceCollection;
29
- this.sourceKeyValue = sourceKeyValue;
30
- this.associationName = association;
31
- this.association = this.sourceCollection.model.associations[association];
32
- this.associationField = this.sourceCollection.getField(association);
33
- this.targetModel = this.association.target;
34
- this.targetCollection = this.sourceCollection.context.database.modelCollection.get(this.targetModel);
35
- }
36
- targetKey() {
37
- return this.associationField.targetKey;
38
- }
39
- accessors() {
40
- return this.association.accessors;
41
- }
42
- create(options) {
43
- return __awaiter(this, void 0, void 0, function* () {
44
- const createAccessor = this.accessors().create;
45
- const guard = update_guard_1.UpdateGuard.fromOptions(this.targetModel, options);
46
- const values = options.values;
47
- const sourceModel = yield this.getSourceModel();
48
- const instance = yield sourceModel[createAccessor](guard.sanitize(options.values), options);
49
- yield (0, update_associations_1.updateAssociations)(instance, values, options);
50
- if (options.hooks !== false) {
51
- yield this.db.emitAsync(`${this.targetCollection.name}.afterCreateWithAssociations`, instance, options);
52
- const eventName = `${this.targetCollection.name}.afterSaveWithAssociations`;
53
- yield this.db.emitAsync(eventName, instance, options);
54
- }
55
- return instance;
56
- });
57
- }
58
- getSourceModel(transaction) {
59
- return __awaiter(this, void 0, void 0, function* () {
60
- if (!this.sourceInstance) {
61
- this.sourceInstance = yield this.sourceCollection.model.findOne({
62
- where: {
63
- [this.associationField.sourceKey]: this.sourceKeyValue,
64
- },
65
- });
66
- }
67
- return this.sourceInstance;
68
- });
69
- }
70
- buildQueryOptions(options) {
71
- const parser = new options_parser_1.OptionsParser(options, {
72
- collection: this.targetCollection,
73
- targetKey: this.targetKey(),
46
+ constructor(sourceCollection, association, sourceKeyValue) {
47
+ this.sourceCollection = void 0;
48
+ this.association = void 0;
49
+ this.targetModel = void 0;
50
+ this.targetCollection = void 0;
51
+ this.associationName = void 0;
52
+ this.associationField = void 0;
53
+ this.sourceKeyValue = void 0;
54
+ this.sourceInstance = void 0;
55
+ this.db = void 0;
56
+ this.db = sourceCollection.context.database;
57
+ this.sourceCollection = sourceCollection;
58
+ this.sourceKeyValue = sourceKeyValue;
59
+ this.associationName = association;
60
+ this.association = this.sourceCollection.model.associations[association];
61
+ this.associationField = this.sourceCollection.getField(association);
62
+ this.targetModel = this.association.target;
63
+ this.targetCollection = this.sourceCollection.context.database.modelCollection.get(this.targetModel);
64
+ }
65
+
66
+ targetKey() {
67
+ return this.associationField.targetKey;
68
+ }
69
+
70
+ accessors() {
71
+ return this.association.accessors;
72
+ }
73
+
74
+ create(options) {
75
+ var _this = this;
76
+
77
+ return _asyncToGenerator(function* () {
78
+ const createAccessor = _this.accessors().create;
79
+
80
+ const guard = _updateGuard.UpdateGuard.fromOptions(_this.targetModel, options);
81
+
82
+ const values = options.values;
83
+ const transaction = yield _this.getTransaction(options);
84
+ const sourceModel = yield _this.getSourceModel(transaction);
85
+ const instance = yield sourceModel[createAccessor](guard.sanitize(options.values), _objectSpread(_objectSpread({}, options), {}, {
86
+ transaction
87
+ }));
88
+ yield (0, _updateAssociations.updateAssociations)(instance, values, _objectSpread(_objectSpread({}, options), {}, {
89
+ transaction
90
+ }));
91
+
92
+ if (options.hooks !== false) {
93
+ yield _this.db.emitAsync(`${_this.targetCollection.name}.afterCreateWithAssociations`, instance, _objectSpread(_objectSpread({}, options), {}, {
94
+ transaction
95
+ }));
96
+ const eventName = `${_this.targetCollection.name}.afterSaveWithAssociations`;
97
+ yield _this.db.emitAsync(eventName, instance, _objectSpread(_objectSpread({}, options), {}, {
98
+ transaction
99
+ }));
100
+ }
101
+
102
+ return instance;
103
+ })();
104
+ }
105
+
106
+ getSourceModel(transaction) {
107
+ var _this2 = this;
108
+
109
+ return _asyncToGenerator(function* () {
110
+ if (!_this2.sourceInstance) {
111
+ _this2.sourceInstance = yield _this2.sourceCollection.model.findOne({
112
+ where: {
113
+ [_this2.associationField.sourceKey]: _this2.sourceKeyValue
114
+ },
115
+ transaction
74
116
  });
75
- const params = parser.toSequelizeParams();
76
- return Object.assign(Object.assign({}, options), params);
77
- }
78
- parseFilter(filter, options) {
79
- const parser = new filter_parser_1.default(filter, {
80
- collection: this.targetCollection,
81
- app: {
82
- ctx: options === null || options === void 0 ? void 0 : options.context,
83
- },
84
- });
85
- return parser.toSequelizeParams();
86
- }
87
- getTransaction(options, autoGen = false) {
88
- return __awaiter(this, void 0, void 0, function* () {
89
- if (lodash_1.default.isPlainObject(options) && options.transaction) {
90
- return options.transaction;
91
- }
92
- if (autoGen) {
93
- return yield this.sourceCollection.model.sequelize.transaction();
94
- }
95
- return null;
96
- });
97
- }
117
+ }
118
+
119
+ return _this2.sourceInstance;
120
+ })();
121
+ }
122
+
123
+ buildQueryOptions(options) {
124
+ const parser = new _optionsParser.OptionsParser(options, {
125
+ collection: this.targetCollection,
126
+ targetKey: this.targetKey()
127
+ });
128
+ const params = parser.toSequelizeParams();
129
+ return _objectSpread(_objectSpread({}, options), params);
130
+ }
131
+
132
+ parseFilter(filter, options) {
133
+ const parser = new _filterParser.default(filter, {
134
+ collection: this.targetCollection,
135
+ app: {
136
+ ctx: options === null || options === void 0 ? void 0 : options.context
137
+ }
138
+ });
139
+ return parser.toSequelizeParams();
140
+ }
141
+
142
+ getTransaction(options, autoGen = false) {
143
+ var _this3 = this;
144
+
145
+ return _asyncToGenerator(function* () {
146
+ if (_lodash().default.isPlainObject(options) && options.transaction) {
147
+ return options.transaction;
148
+ }
149
+
150
+ if (autoGen) {
151
+ return yield _this3.sourceCollection.model.sequelize.transaction();
152
+ }
153
+
154
+ return null;
155
+ })();
156
+ }
157
+
98
158
  }
99
- exports.RelationRepository = RelationRepository;
100
- //# sourceMappingURL=relation-repository.js.map
159
+
160
+ exports.RelationRepository = RelationRepository;
@@ -1,103 +1,142 @@
1
1
  "use strict";
2
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
- return c > 3 && r && Object.defineProperty(target, key, r), r;
7
- };
8
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
9
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
10
- return new (P || (P = Promise))(function (resolve, reject) {
11
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
12
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
13
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
14
- step((generator = generator.apply(thisArg, _arguments || [])).next());
15
- });
16
- };
17
- var __importDefault = (this && this.__importDefault) || function (mod) {
18
- return (mod && mod.__esModule) ? mod : { "default": mod };
19
- };
20
- Object.defineProperty(exports, "__esModule", { value: true });
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
21
6
  exports.SingleRelationRepository = void 0;
22
- const lodash_1 = __importDefault(require("lodash"));
23
- const update_associations_1 = require("../update-associations");
24
- const relation_repository_1 = require("./relation-repository");
25
- class SingleRelationRepository extends relation_repository_1.RelationRepository {
26
- remove(options) {
27
- return __awaiter(this, void 0, void 0, function* () {
28
- const transaction = yield this.getTransaction(options);
29
- const sourceModel = yield this.getSourceModel(transaction);
30
- return yield sourceModel[this.accessors().set](null, {
31
- transaction,
32
- });
33
- });
34
- }
35
- set(options) {
36
- return __awaiter(this, void 0, void 0, function* () {
37
- const transaction = yield this.getTransaction(options);
38
- let handleKey = lodash_1.default.isPlainObject(options) ? options.tk : options;
39
- const sourceModel = yield this.getSourceModel(transaction);
40
- return yield sourceModel[this.accessors().set](handleKey, {
41
- transaction,
42
- });
43
- });
44
- }
45
- find(options) {
46
- return __awaiter(this, void 0, void 0, function* () {
47
- const transaction = yield this.getTransaction(options);
48
- const findOptions = this.buildQueryOptions(Object.assign({}, options));
49
- const getAccessor = this.accessors().get;
50
- const sourceModel = yield this.getSourceModel(transaction);
51
- return yield sourceModel[getAccessor](Object.assign(Object.assign({}, findOptions), { transaction }));
52
- });
53
- }
54
- findOne(options) {
55
- return __awaiter(this, void 0, void 0, function* () {
56
- return this.find(options);
57
- });
58
- }
59
- destroy(options) {
60
- return __awaiter(this, void 0, void 0, function* () {
61
- const transaction = yield this.getTransaction(options);
62
- const target = yield this.find({
63
- transaction,
64
- });
65
- yield target.destroy({
66
- transaction,
67
- });
68
- return true;
69
- });
70
- }
71
- update(options) {
72
- return __awaiter(this, void 0, void 0, function* () {
73
- const transaction = yield this.getTransaction(options);
74
- const target = yield this.find({
75
- transaction,
76
- });
77
- yield (0, update_associations_1.updateModelByValues)(target, options === null || options === void 0 ? void 0 : options.values, Object.assign(Object.assign({}, lodash_1.default.omit(options, 'values')), { transaction }));
78
- return target;
79
- });
80
- }
81
- accessors() {
82
- return super.accessors();
83
- }
7
+
8
+ function _lodash() {
9
+ const data = _interopRequireDefault(require("lodash"));
10
+
11
+ _lodash = function _lodash() {
12
+ return data;
13
+ };
14
+
15
+ return data;
16
+ }
17
+
18
+ var _updateAssociations = require("../update-associations");
19
+
20
+ var _relationRepository = require("./relation-repository");
21
+
22
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
23
+
24
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
25
+
26
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
27
+
28
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
29
+
30
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
31
+
32
+ function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
33
+
34
+ var __decorate = void 0 && (void 0).__decorate || function (decorators, target, key, desc) {
35
+ var c = arguments.length,
36
+ r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc,
37
+ d;
38
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
39
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
40
+ };
41
+
42
+ class SingleRelationRepository extends _relationRepository.RelationRepository {
43
+ remove(options) {
44
+ var _this = this;
45
+
46
+ return _asyncToGenerator(function* () {
47
+ const transaction = yield _this.getTransaction(options);
48
+ const sourceModel = yield _this.getSourceModel(transaction);
49
+ return yield sourceModel[_this.accessors().set](null, {
50
+ transaction
51
+ });
52
+ })();
53
+ }
54
+
55
+ set(options) {
56
+ var _this2 = this;
57
+
58
+ return _asyncToGenerator(function* () {
59
+ const transaction = yield _this2.getTransaction(options);
60
+ let handleKey = _lodash().default.isPlainObject(options) ? options.tk : options;
61
+ const sourceModel = yield _this2.getSourceModel(transaction);
62
+ return yield sourceModel[_this2.accessors().set](handleKey, {
63
+ transaction
64
+ });
65
+ })();
66
+ }
67
+
68
+ find(options) {
69
+ var _this3 = this;
70
+
71
+ return _asyncToGenerator(function* () {
72
+ const transaction = yield _this3.getTransaction(options);
73
+
74
+ const findOptions = _this3.buildQueryOptions(_objectSpread({}, options));
75
+
76
+ const getAccessor = _this3.accessors().get;
77
+
78
+ const sourceModel = yield _this3.getSourceModel(transaction);
79
+ return yield sourceModel[getAccessor](_objectSpread(_objectSpread({}, findOptions), {}, {
80
+ transaction
81
+ }));
82
+ })();
83
+ }
84
+
85
+ findOne(options) {
86
+ var _this4 = this;
87
+
88
+ return _asyncToGenerator(function* () {
89
+ return _this4.find(options);
90
+ })();
91
+ }
92
+
93
+ destroy(options) {
94
+ var _this5 = this;
95
+
96
+ return _asyncToGenerator(function* () {
97
+ const transaction = yield _this5.getTransaction(options);
98
+ const target = yield _this5.find({
99
+ transaction
100
+ });
101
+ yield target.destroy({
102
+ transaction
103
+ });
104
+ return true;
105
+ })();
106
+ }
107
+
108
+ update(options) {
109
+ var _this6 = this;
110
+
111
+ return _asyncToGenerator(function* () {
112
+ const transaction = yield _this6.getTransaction(options);
113
+ const target = yield _this6.find({
114
+ transaction
115
+ });
116
+ yield (0, _updateAssociations.updateModelByValues)(target, options === null || options === void 0 ? void 0 : options.values, _objectSpread(_objectSpread({}, _lodash().default.omit(options, 'values')), {}, {
117
+ transaction
118
+ }));
119
+ return target;
120
+ })();
121
+ }
122
+
123
+ accessors() {
124
+ return super.accessors();
125
+ }
126
+
84
127
  }
85
- __decorate([
86
- (0, relation_repository_1.transaction)()
87
- ], SingleRelationRepository.prototype, "remove", null);
88
- __decorate([
89
- (0, relation_repository_1.transaction)((args, transaction) => {
90
- return {
91
- tk: args[0],
92
- transaction,
93
- };
94
- })
95
- ], SingleRelationRepository.prototype, "set", null);
96
- __decorate([
97
- (0, relation_repository_1.transaction)()
98
- ], SingleRelationRepository.prototype, "destroy", null);
99
- __decorate([
100
- (0, relation_repository_1.transaction)()
101
- ], SingleRelationRepository.prototype, "update", null);
128
+
102
129
  exports.SingleRelationRepository = SingleRelationRepository;
103
- //# sourceMappingURL=single-relation-repository.js.map
130
+
131
+ __decorate([(0, _relationRepository.transaction)()], SingleRelationRepository.prototype, "remove", null);
132
+
133
+ __decorate([(0, _relationRepository.transaction)((args, transaction) => {
134
+ return {
135
+ tk: args[0],
136
+ transaction
137
+ };
138
+ })], SingleRelationRepository.prototype, "set", null);
139
+
140
+ __decorate([(0, _relationRepository.transaction)()], SingleRelationRepository.prototype, "destroy", null);
141
+
142
+ __decorate([(0, _relationRepository.transaction)()], SingleRelationRepository.prototype, "update", null);
@@ -1,3 +1,5 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=types.js.map
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
@@ -38,7 +38,7 @@ export interface FilterByTk {
38
38
  }
39
39
  export interface FindOptions extends SequelizeFindOptions, CommonFindOptions, FilterByTk {
40
40
  }
41
- export interface CommonFindOptions {
41
+ export interface CommonFindOptions extends TransactionAble {
42
42
  filter?: Filter;
43
43
  fields?: Fields;
44
44
  appends?: Appends;