@nocobase/database 0.7.0-alpha.34 → 0.7.0-alpha.57

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 (280) hide show
  1. package/lib/collection-importer.js +101 -67
  2. package/lib/collection.js +339 -210
  3. package/lib/database.js +488 -304
  4. package/lib/fields/array-field.js +45 -25
  5. package/lib/fields/belongs-to-field.js +101 -54
  6. package/lib/fields/belongs-to-many-field.js +98 -53
  7. package/lib/fields/boolean-field.js +24 -9
  8. package/lib/fields/context-field.js +77 -45
  9. package/lib/fields/date-field.js +24 -9
  10. package/lib/fields/field.js +114 -75
  11. package/lib/fields/has-inverse-field.js +4 -2
  12. package/lib/fields/has-many-field.js +105 -56
  13. package/lib/fields/has-one-field.js +105 -54
  14. package/lib/fields/index.js +277 -33
  15. package/lib/fields/json-field.js +36 -16
  16. package/lib/fields/number-field.js +53 -26
  17. package/lib/fields/password-field.js +118 -73
  18. package/lib/fields/radio-field.js +75 -47
  19. package/lib/fields/relation-field.js +41 -28
  20. package/lib/fields/sort-field.js +165 -89
  21. package/lib/fields/string-field.js +24 -9
  22. package/lib/fields/text-field.js +24 -9
  23. package/lib/fields/time-field.js +24 -9
  24. package/lib/fields/uid-field.js +57 -28
  25. package/lib/fields/uuid-field.js +36 -12
  26. package/lib/fields/virtual-field.js +24 -9
  27. package/lib/filter-parser.js +288 -179
  28. package/lib/index.js +210 -29
  29. package/lib/magic-attribute-model.js +123 -71
  30. package/lib/mock-database.js +68 -34
  31. package/lib/model-hook.js +101 -59
  32. package/lib/model.js +116 -81
  33. package/lib/operators/array.js +136 -96
  34. package/lib/operators/association.js +30 -14
  35. package/lib/operators/date.js +78 -34
  36. package/lib/operators/empty.js +113 -75
  37. package/lib/operators/index.js +15 -3
  38. package/lib/operators/ne.js +27 -12
  39. package/lib/operators/notIn.js +27 -12
  40. package/lib/operators/string.js +56 -35
  41. package/lib/operators/utils.js +18 -10
  42. package/lib/options-parser.js +323 -215
  43. package/lib/playground.js +66 -53
  44. package/lib/relation-repository/belongs-to-many-repository.js +281 -198
  45. package/lib/relation-repository/belongs-to-repository.js +10 -6
  46. package/lib/relation-repository/hasmany-repository.js +168 -121
  47. package/lib/relation-repository/hasone-repository.js +10 -6
  48. package/lib/relation-repository/multiple-relation-repository.js +263 -148
  49. package/lib/relation-repository/relation-repository.js +155 -97
  50. package/lib/relation-repository/single-relation-repository.js +138 -99
  51. package/lib/relation-repository/types.js +4 -2
  52. package/lib/repository.js +465 -291
  53. package/lib/transaction-decorator.js +80 -67
  54. package/lib/update-associations.js +525 -321
  55. package/lib/update-guard.js +160 -117
  56. package/package.json +3 -8
  57. package/src/database.ts +9 -3
  58. package/src/mock-database.ts +1 -1
  59. package/esm/collection-importer.d.ts +0 -7
  60. package/esm/collection-importer.js +0 -49
  61. package/esm/collection-importer.js.map +0 -1
  62. package/esm/collection.d.ts +0 -73
  63. package/esm/collection.js +0 -224
  64. package/esm/collection.js.map +0 -1
  65. package/esm/database.d.ts +0 -104
  66. package/esm/database.js +0 -305
  67. package/esm/database.js.map +0 -1
  68. package/esm/fields/array-field.d.ts +0 -11
  69. package/esm/fields/array-field.js +0 -26
  70. package/esm/fields/array-field.js.map +0 -1
  71. package/esm/fields/belongs-to-field.d.ts +0 -12
  72. package/esm/fields/belongs-to-field.js +0 -57
  73. package/esm/fields/belongs-to-field.js.map +0 -1
  74. package/esm/fields/belongs-to-many-field.d.ts +0 -11
  75. package/esm/fields/belongs-to-many-field.js +0 -55
  76. package/esm/fields/belongs-to-many-field.js.map +0 -1
  77. package/esm/fields/boolean-field.d.ts +0 -8
  78. package/esm/fields/boolean-field.js +0 -8
  79. package/esm/fields/boolean-field.js.map +0 -1
  80. package/esm/fields/context-field.d.ts +0 -13
  81. package/esm/fields/context-field.js +0 -43
  82. package/esm/fields/context-field.js.map +0 -1
  83. package/esm/fields/date-field.d.ts +0 -8
  84. package/esm/fields/date-field.js +0 -8
  85. package/esm/fields/date-field.js.map +0 -1
  86. package/esm/fields/field.d.ts +0 -37
  87. package/esm/fields/field.js +0 -74
  88. package/esm/fields/field.js.map +0 -1
  89. package/esm/fields/has-inverse-field.d.ts +0 -4
  90. package/esm/fields/has-inverse-field.js +0 -2
  91. package/esm/fields/has-inverse-field.js.map +0 -1
  92. package/esm/fields/has-many-field.d.ts +0 -64
  93. package/esm/fields/has-many-field.js +0 -58
  94. package/esm/fields/has-many-field.js.map +0 -1
  95. package/esm/fields/has-one-field.d.ts +0 -64
  96. package/esm/fields/has-one-field.js +0 -57
  97. package/esm/fields/has-one-field.js.map +0 -1
  98. package/esm/fields/index.d.ts +0 -42
  99. package/esm/fields/index.js +0 -22
  100. package/esm/fields/index.js.map +0 -1
  101. package/esm/fields/json-field.d.ts +0 -14
  102. package/esm/fields/json-field.js +0 -17
  103. package/esm/fields/json-field.js.map +0 -1
  104. package/esm/fields/number-field.d.ts +0 -32
  105. package/esm/fields/number-field.js +0 -28
  106. package/esm/fields/number-field.js.map +0 -1
  107. package/esm/fields/password-field.d.ts +0 -21
  108. package/esm/fields/password-field.js +0 -71
  109. package/esm/fields/password-field.js.map +0 -1
  110. package/esm/fields/radio-field.d.ts +0 -14
  111. package/esm/fields/radio-field.js +0 -49
  112. package/esm/fields/radio-field.js.map +0 -1
  113. package/esm/fields/relation-field.d.ts +0 -20
  114. package/esm/fields/relation-field.js +0 -27
  115. package/esm/fields/relation-field.js.map +0 -1
  116. package/esm/fields/sort-field.d.ts +0 -16
  117. package/esm/fields/sort-field.js +0 -90
  118. package/esm/fields/sort-field.js.map +0 -1
  119. package/esm/fields/string-field.d.ts +0 -8
  120. package/esm/fields/string-field.js +0 -8
  121. package/esm/fields/string-field.js.map +0 -1
  122. package/esm/fields/text-field.d.ts +0 -8
  123. package/esm/fields/text-field.js +0 -8
  124. package/esm/fields/text-field.js.map +0 -1
  125. package/esm/fields/time-field.d.ts +0 -8
  126. package/esm/fields/time-field.js +0 -8
  127. package/esm/fields/time-field.js.map +0 -1
  128. package/esm/fields/uid-field.d.ts +0 -10
  129. package/esm/fields/uid-field.js +0 -27
  130. package/esm/fields/uid-field.js.map +0 -1
  131. package/esm/fields/uuid-field.d.ts +0 -9
  132. package/esm/fields/uuid-field.js +0 -11
  133. package/esm/fields/uuid-field.js.map +0 -1
  134. package/esm/fields/virtual-field.d.ts +0 -8
  135. package/esm/fields/virtual-field.js +0 -8
  136. package/esm/fields/virtual-field.js.map +0 -1
  137. package/esm/filter-parser.d.ts +0 -27
  138. package/esm/filter-parser.js +0 -185
  139. package/esm/filter-parser.js.map +0 -1
  140. package/esm/index.d.ts +0 -15
  141. package/esm/index.js +0 -16
  142. package/esm/index.js.map +0 -1
  143. package/esm/magic-attribute-model.d.ts +0 -7
  144. package/esm/magic-attribute-model.js +0 -70
  145. package/esm/magic-attribute-model.js.map +0 -1
  146. package/esm/mock-database.d.ts +0 -22
  147. package/esm/mock-database.js +0 -34
  148. package/esm/mock-database.js.map +0 -1
  149. package/esm/model-hook.d.ts +0 -12
  150. package/esm/model-hook.js +0 -60
  151. package/esm/model-hook.js.map +0 -1
  152. package/esm/model.d.ts +0 -15
  153. package/esm/model.js +0 -80
  154. package/esm/model.js.map +0 -1
  155. package/esm/operators/array.d.ts +0 -26
  156. package/esm/operators/array.js +0 -105
  157. package/esm/operators/array.js.map +0 -1
  158. package/esm/operators/association.d.ts +0 -10
  159. package/esm/operators/association.js +0 -14
  160. package/esm/operators/association.js.map +0 -1
  161. package/esm/operators/date.d.ts +0 -34
  162. package/esm/operators/date.js +0 -35
  163. package/esm/operators/date.js.map +0 -1
  164. package/esm/operators/empty.d.ts +0 -28
  165. package/esm/operators/empty.js +0 -58
  166. package/esm/operators/empty.js.map +0 -1
  167. package/esm/operators/index.d.ts +0 -2
  168. package/esm/operators/index.js +0 -2
  169. package/esm/operators/index.js.map +0 -1
  170. package/esm/operators/ne.d.ts +0 -10
  171. package/esm/operators/ne.js +0 -12
  172. package/esm/operators/ne.js.map +0 -1
  173. package/esm/operators/notIn.d.ts +0 -10
  174. package/esm/operators/notIn.js +0 -12
  175. package/esm/operators/notIn.js.map +0 -1
  176. package/esm/operators/string.d.ts +0 -21
  177. package/esm/operators/string.js +0 -35
  178. package/esm/operators/string.js.map +0 -1
  179. package/esm/operators/utils.d.ts +0 -4
  180. package/esm/operators/utils.js +0 -11
  181. package/esm/operators/utils.js.map +0 -1
  182. package/esm/options-parser.d.ts +0 -31
  183. package/esm/options-parser.js +0 -225
  184. package/esm/options-parser.js.map +0 -1
  185. package/esm/playground.d.ts +0 -1
  186. package/esm/playground.js +0 -53
  187. package/esm/playground.js.map +0 -1
  188. package/esm/relation-repository/belongs-to-many-repository.d.ts +0 -36
  189. package/esm/relation-repository/belongs-to-many-repository.js +0 -199
  190. package/esm/relation-repository/belongs-to-many-repository.js.map +0 -1
  191. package/esm/relation-repository/belongs-to-repository.d.ts +0 -17
  192. package/esm/relation-repository/belongs-to-repository.js +0 -4
  193. package/esm/relation-repository/belongs-to-repository.js.map +0 -1
  194. package/esm/relation-repository/hasmany-repository.d.ts +0 -23
  195. package/esm/relation-repository/hasmany-repository.js +0 -125
  196. package/esm/relation-repository/hasmany-repository.js.map +0 -1
  197. package/esm/relation-repository/hasone-repository.d.ts +0 -17
  198. package/esm/relation-repository/hasone-repository.js +0 -4
  199. package/esm/relation-repository/hasone-repository.js.map +0 -1
  200. package/esm/relation-repository/multiple-relation-repository.d.ts +0 -23
  201. package/esm/relation-repository/multiple-relation-repository.js +0 -149
  202. package/esm/relation-repository/multiple-relation-repository.js.map +0 -1
  203. package/esm/relation-repository/relation-repository.d.ts +0 -32
  204. package/esm/relation-repository/relation-repository.js +0 -95
  205. package/esm/relation-repository/relation-repository.js.map +0 -1
  206. package/esm/relation-repository/single-relation-repository.d.ts +0 -23
  207. package/esm/relation-repository/single-relation-repository.js +0 -96
  208. package/esm/relation-repository/single-relation-repository.js.map +0 -1
  209. package/esm/relation-repository/types.d.ts +0 -7
  210. package/esm/relation-repository/types.js +0 -2
  211. package/esm/relation-repository/types.js.map +0 -1
  212. package/esm/repository.d.ts +0 -165
  213. package/esm/repository.js +0 -276
  214. package/esm/repository.js.map +0 -1
  215. package/esm/transaction-decorator.d.ts +0 -1
  216. package/esm/transaction-decorator.js +0 -63
  217. package/esm/transaction-decorator.js.map +0 -1
  218. package/esm/update-associations.d.ts +0 -60
  219. package/esm/update-associations.js +0 -362
  220. package/esm/update-associations.js.map +0 -1
  221. package/esm/update-guard.d.ts +0 -26
  222. package/esm/update-guard.js +0 -122
  223. package/esm/update-guard.js.map +0 -1
  224. package/lib/collection-importer.js.map +0 -1
  225. package/lib/collection.js.map +0 -1
  226. package/lib/database.js.map +0 -1
  227. package/lib/fields/array-field.js.map +0 -1
  228. package/lib/fields/belongs-to-field.js.map +0 -1
  229. package/lib/fields/belongs-to-many-field.js.map +0 -1
  230. package/lib/fields/boolean-field.js.map +0 -1
  231. package/lib/fields/context-field.js.map +0 -1
  232. package/lib/fields/date-field.js.map +0 -1
  233. package/lib/fields/field.js.map +0 -1
  234. package/lib/fields/has-inverse-field.js.map +0 -1
  235. package/lib/fields/has-many-field.js.map +0 -1
  236. package/lib/fields/has-one-field.js.map +0 -1
  237. package/lib/fields/index.js.map +0 -1
  238. package/lib/fields/json-field.js.map +0 -1
  239. package/lib/fields/number-field.js.map +0 -1
  240. package/lib/fields/password-field.js.map +0 -1
  241. package/lib/fields/radio-field.js.map +0 -1
  242. package/lib/fields/relation-field.js.map +0 -1
  243. package/lib/fields/sort-field.js.map +0 -1
  244. package/lib/fields/string-field.js.map +0 -1
  245. package/lib/fields/text-field.js.map +0 -1
  246. package/lib/fields/time-field.js.map +0 -1
  247. package/lib/fields/uid-field.js.map +0 -1
  248. package/lib/fields/uuid-field.js.map +0 -1
  249. package/lib/fields/virtual-field.js.map +0 -1
  250. package/lib/filter-parser.js.map +0 -1
  251. package/lib/index.js.map +0 -1
  252. package/lib/magic-attribute-model.js.map +0 -1
  253. package/lib/mock-database.js.map +0 -1
  254. package/lib/model-hook.js.map +0 -1
  255. package/lib/model.js.map +0 -1
  256. package/lib/operators/array.js.map +0 -1
  257. package/lib/operators/association.js.map +0 -1
  258. package/lib/operators/date.js.map +0 -1
  259. package/lib/operators/empty.js.map +0 -1
  260. package/lib/operators/index.js.map +0 -1
  261. package/lib/operators/ne.js.map +0 -1
  262. package/lib/operators/notIn.js.map +0 -1
  263. package/lib/operators/string.js.map +0 -1
  264. package/lib/operators/utils.js.map +0 -1
  265. package/lib/options-parser.js.map +0 -1
  266. package/lib/playground.js.map +0 -1
  267. package/lib/relation-repository/belongs-to-many-repository.js.map +0 -1
  268. package/lib/relation-repository/belongs-to-repository.js.map +0 -1
  269. package/lib/relation-repository/hasmany-repository.js.map +0 -1
  270. package/lib/relation-repository/hasone-repository.js.map +0 -1
  271. package/lib/relation-repository/multiple-relation-repository.js.map +0 -1
  272. package/lib/relation-repository/relation-repository.js.map +0 -1
  273. package/lib/relation-repository/single-relation-repository.js.map +0 -1
  274. package/lib/relation-repository/types.js.map +0 -1
  275. package/lib/repository.js.map +0 -1
  276. package/lib/transaction-decorator.js.map +0 -1
  277. package/lib/update-associations.js.map +0 -1
  278. package/lib/update-guard.js.map +0 -1
  279. package/tsconfig.build.json +0 -9
  280. package/tsconfig.json +0 -5
@@ -1,53 +1,81 @@
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
- Object.defineProperty(exports, "__esModule", { value: true });
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
12
6
  exports.RadioField = void 0;
13
- const sequelize_1 = require("sequelize");
14
- const field_1 = require("./field");
7
+
8
+ function _sequelize() {
9
+ const data = require("sequelize");
10
+
11
+ _sequelize = function _sequelize() {
12
+ return data;
13
+ };
14
+
15
+ return data;
16
+ }
17
+
18
+ var _field = require("./field");
19
+
20
+ 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); } }
21
+
22
+ 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); }); }; }
23
+
15
24
  /**
16
25
  * 暂时只支持全局,不支持批量
17
26
  */
18
- class RadioField extends field_1.Field {
19
- get dataType() {
20
- return sequelize_1.DataTypes.BOOLEAN;
21
- }
22
- init() {
23
- const { name } = this.options;
24
- this.listener = (model, { transaction }) => __awaiter(this, void 0, void 0, function* () {
25
- if (!model.changed(name)) {
26
- return;
27
- }
28
- const value = model.get(name);
29
- if (value) {
30
- const M = this.collection.model;
31
- yield M.update({ [name]: false }, {
32
- where: {
33
- [name]: true,
34
- },
35
- transaction,
36
- hooks: false,
37
- });
38
- }
39
- });
40
- }
41
- bind() {
42
- super.bind();
43
- this.on('beforeCreate', this.listener.bind(this));
44
- this.on('beforeUpdate', this.listener.bind(this));
45
- }
46
- unbind() {
47
- super.unbind();
48
- this.off('beforeCreate', this.listener.bind(this));
49
- this.off('beforeUpdate', this.listener.bind(this));
50
- }
27
+ class RadioField extends _field.Field {
28
+ get dataType() {
29
+ return _sequelize().DataTypes.BOOLEAN;
30
+ }
31
+
32
+ init() {
33
+ var _this = this;
34
+
35
+ const name = this.options.name;
36
+
37
+ this.listener = /*#__PURE__*/function () {
38
+ var _ref = _asyncToGenerator(function* (model, {
39
+ transaction
40
+ }) {
41
+ if (!model.changed(name)) {
42
+ return;
43
+ }
44
+
45
+ const value = model.get(name);
46
+
47
+ if (value) {
48
+ const M = _this.collection.model;
49
+ yield M.update({
50
+ [name]: false
51
+ }, {
52
+ where: {
53
+ [name]: true
54
+ },
55
+ transaction,
56
+ hooks: false
57
+ });
58
+ }
59
+ });
60
+
61
+ return function (_x, _x2) {
62
+ return _ref.apply(this, arguments);
63
+ };
64
+ }();
65
+ }
66
+
67
+ bind() {
68
+ super.bind();
69
+ this.on('beforeCreate', this.listener.bind(this));
70
+ this.on('beforeUpdate', this.listener.bind(this));
71
+ }
72
+
73
+ unbind() {
74
+ super.unbind();
75
+ this.off('beforeCreate', this.listener.bind(this));
76
+ this.off('beforeUpdate', this.listener.bind(this));
77
+ }
78
+
51
79
  }
52
- exports.RadioField = RadioField;
53
- //# sourceMappingURL=radio-field.js.map
80
+
81
+ exports.RadioField = RadioField;
@@ -1,31 +1,44 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
3
6
  exports.RelationField = void 0;
4
- const field_1 = require("./field");
5
- class RelationField extends field_1.Field {
6
- /**
7
- * target relation name
8
- */
9
- get target() {
10
- const { target, name } = this.options;
11
- return target || name;
12
- }
13
- get foreignKey() {
14
- return this.options.foreignKey;
15
- }
16
- get sourceKey() {
17
- return this.options.sourceKey || this.collection.model.primaryKeyAttribute;
18
- }
19
- get targetKey() {
20
- return this.options.targetKey || this.TargetModel.primaryKeyAttribute;
21
- }
22
- /**
23
- * get target model from database by it's name
24
- * @constructor
25
- */
26
- get TargetModel() {
27
- return this.context.database.sequelize.models[this.target];
28
- }
7
+
8
+ var _field = require("./field");
9
+
10
+ class RelationField extends _field.Field {
11
+ /**
12
+ * target relation name
13
+ */
14
+ get target() {
15
+ const _this$options = this.options,
16
+ target = _this$options.target,
17
+ name = _this$options.name;
18
+ return target || name;
19
+ }
20
+
21
+ get foreignKey() {
22
+ return this.options.foreignKey;
23
+ }
24
+
25
+ get sourceKey() {
26
+ return this.options.sourceKey || this.collection.model.primaryKeyAttribute;
27
+ }
28
+
29
+ get targetKey() {
30
+ return this.options.targetKey || this.TargetModel.primaryKeyAttribute;
31
+ }
32
+ /**
33
+ * get target model from database by it's name
34
+ * @constructor
35
+ */
36
+
37
+
38
+ get TargetModel() {
39
+ return this.context.database.sequelize.models[this.target];
40
+ }
41
+
29
42
  }
30
- exports.RelationField = RelationField;
31
- //# sourceMappingURL=relation-field.js.map
43
+
44
+ exports.RelationField = RelationField;
@@ -1,94 +1,170 @@
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
- Object.defineProperty(exports, "__esModule", { value: true });
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
12
6
  exports.SortField = void 0;
13
- const async_mutex_1 = require("async-mutex");
14
- const lodash_1 = require("lodash");
15
- const sequelize_1 = require("sequelize");
16
- const field_1 = require("./field");
17
- const sortFieldMutex = new async_mutex_1.Mutex();
18
- class SortField extends field_1.Field {
19
- get dataType() {
20
- return sequelize_1.DataTypes.INTEGER;
21
- }
22
- setSortValue(instance, options) {
23
- return __awaiter(this, void 0, void 0, function* () {
24
- const { name, scopeKey } = this.options;
25
- const { model } = this.context.collection;
26
- if ((0, lodash_1.isNumber)(instance.get(name)) && instance._previousDataValues[scopeKey] == instance[scopeKey]) {
27
- return;
28
- }
29
- const where = {};
30
- if (scopeKey) {
31
- const value = instance.get(scopeKey);
32
- if (value !== undefined && value !== null) {
33
- where[scopeKey] = value;
34
- }
35
- }
36
- yield sortFieldMutex.runExclusive(() => __awaiter(this, void 0, void 0, function* () {
37
- const max = yield model.max(name, Object.assign(Object.assign({}, options), { where }));
38
- const newValue = (max || 0) + 1;
39
- instance.set(name, newValue);
40
- }));
41
- });
42
- }
43
- onScopeChange(instance, options) {
44
- return __awaiter(this, void 0, void 0, function* () {
45
- const { scopeKey } = this.options;
46
- if (scopeKey && !instance.isNewRecord && instance._previousDataValues[scopeKey] != instance[scopeKey]) {
47
- yield this.setSortValue(instance, options);
48
- }
7
+
8
+ function _asyncMutex() {
9
+ const data = require("async-mutex");
10
+
11
+ _asyncMutex = function _asyncMutex() {
12
+ return data;
13
+ };
14
+
15
+ return data;
16
+ }
17
+
18
+ function _lodash() {
19
+ const data = require("lodash");
20
+
21
+ _lodash = function _lodash() {
22
+ return data;
23
+ };
24
+
25
+ return data;
26
+ }
27
+
28
+ function _sequelize() {
29
+ const data = require("sequelize");
30
+
31
+ _sequelize = function _sequelize() {
32
+ return data;
33
+ };
34
+
35
+ return data;
36
+ }
37
+
38
+ var _field = require("./field");
39
+
40
+ function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
41
+
42
+ 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); }
43
+
44
+ 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; }
45
+
46
+ 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; }
47
+
48
+ 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; }
49
+
50
+ 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; }
51
+
52
+ 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); } }
53
+
54
+ 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); }); }; }
55
+
56
+ const sortFieldMutex = new (_asyncMutex().Mutex)();
57
+
58
+ class SortField extends _field.Field {
59
+ get dataType() {
60
+ return _sequelize().DataTypes.INTEGER;
61
+ }
62
+
63
+ setSortValue(instance, options) {
64
+ var _this = this;
65
+
66
+ return _asyncToGenerator(function* () {
67
+ const _this$options = _this.options,
68
+ name = _this$options.name,
69
+ scopeKey = _this$options.scopeKey;
70
+ const model = _this.context.collection.model;
71
+
72
+ if ((0, _lodash().isNumber)(instance.get(name)) && instance._previousDataValues[scopeKey] == instance[scopeKey]) {
73
+ return;
74
+ }
75
+
76
+ const where = {};
77
+
78
+ if (scopeKey) {
79
+ const value = instance.get(scopeKey);
80
+
81
+ if (value !== undefined && value !== null) {
82
+ where[scopeKey] = value;
83
+ }
84
+ }
85
+
86
+ yield sortFieldMutex.runExclusive( /*#__PURE__*/_asyncToGenerator(function* () {
87
+ const max = yield model.max(name, _objectSpread(_objectSpread({}, options), {}, {
88
+ where
89
+ }));
90
+ const newValue = (max || 0) + 1;
91
+ instance.set(name, newValue);
92
+ }));
93
+ })();
94
+ }
95
+
96
+ onScopeChange(instance, options) {
97
+ var _this2 = this;
98
+
99
+ return _asyncToGenerator(function* () {
100
+ const scopeKey = _this2.options.scopeKey;
101
+
102
+ if (scopeKey && !instance.isNewRecord && instance._previousDataValues[scopeKey] != instance[scopeKey]) {
103
+ yield _this2.setSortValue(instance, options);
104
+ }
105
+ })();
106
+ }
107
+
108
+ initRecordsSortValue({
109
+ transaction
110
+ }) {
111
+ var _this3 = this;
112
+
113
+ return _asyncToGenerator(function* () {
114
+ const totalCount = yield _this3.collection.repository.count({
115
+ transaction
116
+ });
117
+ const emptyCount = yield _this3.collection.repository.count({
118
+ filter: {
119
+ [_this3.name]: null
120
+ },
121
+ transaction
122
+ });
123
+
124
+ if (emptyCount === totalCount && emptyCount > 0) {
125
+ const records = yield _this3.collection.repository.find({
126
+ order: [_this3.collection.model.primaryKeyAttribute],
127
+ transaction
49
128
  });
50
- }
51
- initRecordsSortValue({ transaction }) {
52
- return __awaiter(this, void 0, void 0, function* () {
53
- const totalCount = yield this.collection.repository.count({
54
- transaction,
55
- });
56
- const emptyCount = yield this.collection.repository.count({
57
- filter: {
58
- [this.name]: null,
59
- },
60
- transaction,
129
+ let start = 1;
130
+
131
+ var _iterator = _createForOfIteratorHelper(records),
132
+ _step;
133
+
134
+ try {
135
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
136
+ const record = _step.value;
137
+ yield record.update({
138
+ sort: start
139
+ }, {
140
+ transaction,
141
+ silent: true
61
142
  });
62
- if (emptyCount === totalCount && emptyCount > 0) {
63
- const records = yield this.collection.repository.find({
64
- order: [this.collection.model.primaryKeyAttribute],
65
- transaction,
66
- });
67
- let start = 1;
68
- for (const record of records) {
69
- yield record.update({
70
- sort: start,
71
- }, {
72
- transaction,
73
- silent: true,
74
- });
75
- start += 1;
76
- }
77
- }
78
- });
79
- }
80
- bind() {
81
- super.bind();
82
- this.on('afterSync', this.initRecordsSortValue.bind(this));
83
- this.on('beforeUpdate', this.onScopeChange.bind(this));
84
- this.on('beforeCreate', this.setSortValue.bind(this));
85
- }
86
- unbind() {
87
- super.unbind();
88
- this.off('beforeUpdate', this.onScopeChange.bind(this));
89
- this.off('beforeCreate', this.setSortValue.bind(this));
90
- this.off('afterSync', this.initRecordsSortValue.bind(this));
91
- }
143
+ start += 1;
144
+ }
145
+ } catch (err) {
146
+ _iterator.e(err);
147
+ } finally {
148
+ _iterator.f();
149
+ }
150
+ }
151
+ })();
152
+ }
153
+
154
+ bind() {
155
+ super.bind();
156
+ this.on('afterSync', this.initRecordsSortValue.bind(this));
157
+ this.on('beforeUpdate', this.onScopeChange.bind(this));
158
+ this.on('beforeCreate', this.setSortValue.bind(this));
159
+ }
160
+
161
+ unbind() {
162
+ super.unbind();
163
+ this.off('beforeUpdate', this.onScopeChange.bind(this));
164
+ this.off('beforeCreate', this.setSortValue.bind(this));
165
+ this.off('afterSync', this.initRecordsSortValue.bind(this));
166
+ }
167
+
92
168
  }
93
- exports.SortField = SortField;
94
- //# sourceMappingURL=sort-field.js.map
169
+
170
+ exports.SortField = SortField;
@@ -1,12 +1,27 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
3
6
  exports.StringField = void 0;
4
- const sequelize_1 = require("sequelize");
5
- const field_1 = require("./field");
6
- class StringField extends field_1.Field {
7
- get dataType() {
8
- return sequelize_1.DataTypes.STRING;
9
- }
7
+
8
+ function _sequelize() {
9
+ const data = require("sequelize");
10
+
11
+ _sequelize = function _sequelize() {
12
+ return data;
13
+ };
14
+
15
+ return data;
10
16
  }
11
- exports.StringField = StringField;
12
- //# sourceMappingURL=string-field.js.map
17
+
18
+ var _field = require("./field");
19
+
20
+ class StringField extends _field.Field {
21
+ get dataType() {
22
+ return _sequelize().DataTypes.STRING;
23
+ }
24
+
25
+ }
26
+
27
+ exports.StringField = StringField;
@@ -1,12 +1,27 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
3
6
  exports.TextField = void 0;
4
- const sequelize_1 = require("sequelize");
5
- const field_1 = require("./field");
6
- class TextField extends field_1.Field {
7
- get dataType() {
8
- return sequelize_1.DataTypes.TEXT;
9
- }
7
+
8
+ function _sequelize() {
9
+ const data = require("sequelize");
10
+
11
+ _sequelize = function _sequelize() {
12
+ return data;
13
+ };
14
+
15
+ return data;
10
16
  }
11
- exports.TextField = TextField;
12
- //# sourceMappingURL=text-field.js.map
17
+
18
+ var _field = require("./field");
19
+
20
+ class TextField extends _field.Field {
21
+ get dataType() {
22
+ return _sequelize().DataTypes.TEXT;
23
+ }
24
+
25
+ }
26
+
27
+ exports.TextField = TextField;
@@ -1,12 +1,27 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
3
6
  exports.TimeField = void 0;
4
- const sequelize_1 = require("sequelize");
5
- const field_1 = require("./field");
6
- class TimeField extends field_1.Field {
7
- get dataType() {
8
- return sequelize_1.DataTypes.TIME;
9
- }
7
+
8
+ function _sequelize() {
9
+ const data = require("sequelize");
10
+
11
+ _sequelize = function _sequelize() {
12
+ return data;
13
+ };
14
+
15
+ return data;
10
16
  }
11
- exports.TimeField = TimeField;
12
- //# sourceMappingURL=time-field.js.map
17
+
18
+ var _field = require("./field");
19
+
20
+ class TimeField extends _field.Field {
21
+ get dataType() {
22
+ return _sequelize().DataTypes.TIME;
23
+ }
24
+
25
+ }
26
+
27
+ exports.TimeField = TimeField;
@@ -1,31 +1,60 @@
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
- Object.defineProperty(exports, "__esModule", { value: true });
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
12
6
  exports.UidField = void 0;
13
- const utils_1 = require("@nocobase/utils");
14
- const sequelize_1 = require("sequelize");
15
- const field_1 = require("./field");
16
- class UidField extends field_1.Field {
17
- get dataType() {
18
- return sequelize_1.DataTypes.STRING;
19
- }
20
- init() {
21
- const { name, prefix = '' } = this.options;
22
- const { model } = this.context.collection;
23
- model.beforeCreate((instance) => __awaiter(this, void 0, void 0, function* () {
24
- if (!instance.get(name)) {
25
- instance.set(name, `${prefix}${(0, utils_1.uid)()}`);
26
- }
27
- }));
28
- }
7
+
8
+ function _utils() {
9
+ const data = require("@nocobase/utils");
10
+
11
+ _utils = function _utils() {
12
+ return data;
13
+ };
14
+
15
+ return data;
29
16
  }
30
- exports.UidField = UidField;
31
- //# sourceMappingURL=uid-field.js.map
17
+
18
+ function _sequelize() {
19
+ const data = require("sequelize");
20
+
21
+ _sequelize = function _sequelize() {
22
+ return data;
23
+ };
24
+
25
+ return data;
26
+ }
27
+
28
+ var _field = require("./field");
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
+ class UidField extends _field.Field {
35
+ get dataType() {
36
+ return _sequelize().DataTypes.STRING;
37
+ }
38
+
39
+ init() {
40
+ const _this$options = this.options,
41
+ name = _this$options.name,
42
+ _this$options$prefix = _this$options.prefix,
43
+ prefix = _this$options$prefix === void 0 ? '' : _this$options$prefix;
44
+ const model = this.context.collection.model;
45
+ model.beforeCreate( /*#__PURE__*/function () {
46
+ var _ref = _asyncToGenerator(function* (instance) {
47
+ if (!instance.get(name)) {
48
+ instance.set(name, `${prefix}${(0, _utils().uid)()}`);
49
+ }
50
+ });
51
+
52
+ return function (_x) {
53
+ return _ref.apply(this, arguments);
54
+ };
55
+ }());
56
+ }
57
+
58
+ }
59
+
60
+ exports.UidField = UidField;