@nocobase/database 0.7.0-alpha.9 → 0.7.1-alpha.6

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 (325) hide show
  1. package/lib/collection-importer.js +85 -68
  2. package/lib/collection.d.ts +6 -2
  3. package/lib/collection.js +371 -210
  4. package/lib/database.d.ts +23 -4
  5. package/lib/database.js +599 -273
  6. package/lib/fields/array-field.js +45 -25
  7. package/lib/fields/belongs-to-field.js +101 -54
  8. package/lib/fields/belongs-to-many-field.js +98 -53
  9. package/lib/fields/boolean-field.js +24 -9
  10. package/lib/fields/context-field.js +77 -45
  11. package/lib/fields/date-field.js +24 -9
  12. package/lib/fields/field.d.ts +4 -1
  13. package/lib/fields/field.js +231 -75
  14. package/lib/fields/formula-field.d.ts +19 -0
  15. package/lib/fields/formula-field.js +184 -0
  16. package/lib/fields/has-inverse-field.js +4 -2
  17. package/lib/fields/has-many-field.js +105 -56
  18. package/lib/fields/has-one-field.js +105 -54
  19. package/lib/fields/index.d.ts +5 -1
  20. package/lib/fields/index.js +290 -32
  21. package/lib/fields/json-field.js +36 -16
  22. package/lib/fields/number-field.js +53 -26
  23. package/lib/fields/password-field.js +120 -73
  24. package/lib/fields/radio-field.js +75 -47
  25. package/lib/fields/relation-field.js +41 -28
  26. package/lib/fields/sort-field.js +165 -89
  27. package/lib/fields/string-field.js +24 -9
  28. package/lib/fields/text-field.js +24 -9
  29. package/lib/fields/time-field.js +24 -9
  30. package/lib/fields/uid-field.js +57 -28
  31. package/lib/fields/uuid-field.d.ts +9 -0
  32. package/lib/fields/uuid-field.js +39 -0
  33. package/lib/fields/virtual-field.js +24 -9
  34. package/lib/filter-parser.js +288 -179
  35. package/lib/index.d.ts +1 -0
  36. package/lib/index.js +224 -29
  37. package/lib/magic-attribute-model.js +123 -71
  38. package/lib/migration.d.ts +35 -0
  39. package/lib/migration.js +90 -0
  40. package/lib/mock-database.d.ts +1 -0
  41. package/lib/mock-database.js +69 -34
  42. package/lib/model-hook.d.ts +5 -5
  43. package/lib/model-hook.js +109 -60
  44. package/lib/model.js +116 -81
  45. package/lib/operators/array.js +136 -96
  46. package/lib/operators/association.js +30 -14
  47. package/lib/operators/boolean.d.ts +13 -0
  48. package/lib/operators/boolean.js +35 -0
  49. package/lib/operators/date.js +78 -34
  50. package/lib/operators/empty.js +113 -75
  51. package/lib/operators/index.js +15 -3
  52. package/lib/operators/ne.js +27 -12
  53. package/{esm/operators/ne.d.ts → lib/operators/notIn.d.ts} +2 -2
  54. package/lib/operators/notIn.js +29 -0
  55. package/lib/operators/string.js +56 -35
  56. package/lib/operators/utils.js +18 -10
  57. package/lib/options-parser.js +345 -215
  58. package/lib/playground.js +66 -53
  59. package/lib/relation-repository/belongs-to-many-repository.js +281 -198
  60. package/lib/relation-repository/belongs-to-repository.js +10 -6
  61. package/lib/relation-repository/hasmany-repository.js +168 -121
  62. package/lib/relation-repository/hasone-repository.js +10 -6
  63. package/lib/relation-repository/multiple-relation-repository.d.ts +3 -3
  64. package/lib/relation-repository/multiple-relation-repository.js +263 -148
  65. package/lib/relation-repository/relation-repository.d.ts +1 -1
  66. package/lib/relation-repository/relation-repository.js +163 -93
  67. package/lib/relation-repository/single-relation-repository.d.ts +6 -6
  68. package/lib/relation-repository/single-relation-repository.js +145 -99
  69. package/lib/relation-repository/types.js +4 -2
  70. package/lib/repository.d.ts +4 -7
  71. package/lib/repository.js +473 -291
  72. package/lib/transaction-decorator.js +80 -67
  73. package/lib/update-associations.d.ts +1 -2
  74. package/lib/update-associations.js +525 -321
  75. package/lib/update-guard.js +160 -117
  76. package/package.json +9 -9
  77. package/src/__tests__/collection.test.ts +27 -0
  78. package/src/__tests__/database.test.ts +47 -0
  79. package/src/__tests__/fields/formula-field.test.ts +69 -0
  80. package/src/__tests__/fields/uuid-field.test.ts +30 -0
  81. package/src/__tests__/fixtures/migrations/m1.ts +7 -0
  82. package/src/__tests__/fixtures/migrations/m2.ts +7 -0
  83. package/src/__tests__/hooks/afterCreateWithAssociations.test.ts +33 -0
  84. package/src/__tests__/migrator.test.ts +70 -0
  85. package/src/__tests__/model-hook.test.ts +54 -0
  86. package/src/__tests__/operator/notIn.test.ts +33 -0
  87. package/src/__tests__/option-parser.test.ts +30 -6
  88. package/src/__tests__/relation-repository/belongs-to-many-repository.test.ts +1 -1
  89. package/src/__tests__/sequelize-hooks.test.ts +69 -0
  90. package/src/__tests__/sort.test.ts +51 -0
  91. package/src/__tests__/update-associations.test.ts +3 -3
  92. package/src/collection-importer.ts +12 -20
  93. package/src/collection.ts +26 -2
  94. package/src/database.ts +144 -14
  95. package/src/fields/field.ts +88 -1
  96. package/src/fields/formula-field.ts +106 -0
  97. package/src/fields/index.ts +6 -0
  98. package/src/fields/password-field.ts +2 -0
  99. package/src/fields/uuid-field.ts +21 -0
  100. package/src/index.ts +1 -0
  101. package/src/migration.ts +76 -0
  102. package/src/mock-database.ts +2 -1
  103. package/src/model-hook.ts +26 -22
  104. package/src/operators/boolean.ts +18 -0
  105. package/src/operators/index.ts +2 -0
  106. package/src/operators/notIn.ts +12 -0
  107. package/src/options-parser.ts +14 -10
  108. package/src/relation-repository/multiple-relation-repository.ts +14 -6
  109. package/src/relation-repository/relation-repository.ts +12 -6
  110. package/src/relation-repository/single-relation-repository.ts +11 -7
  111. package/src/repository.ts +20 -10
  112. package/src/update-associations.ts +2 -3
  113. package/esm/collection-importer.d.ts +0 -7
  114. package/esm/collection-importer.js +0 -49
  115. package/esm/collection-importer.js.map +0 -1
  116. package/esm/collection.d.ts +0 -73
  117. package/esm/collection.js +0 -224
  118. package/esm/collection.js.map +0 -1
  119. package/esm/database.d.ts +0 -101
  120. package/esm/database.js +0 -275
  121. package/esm/database.js.map +0 -1
  122. package/esm/fields/array-field.d.ts +0 -11
  123. package/esm/fields/array-field.js +0 -26
  124. package/esm/fields/array-field.js.map +0 -1
  125. package/esm/fields/belongs-to-field.d.ts +0 -12
  126. package/esm/fields/belongs-to-field.js +0 -57
  127. package/esm/fields/belongs-to-field.js.map +0 -1
  128. package/esm/fields/belongs-to-many-field.d.ts +0 -11
  129. package/esm/fields/belongs-to-many-field.js +0 -55
  130. package/esm/fields/belongs-to-many-field.js.map +0 -1
  131. package/esm/fields/boolean-field.d.ts +0 -8
  132. package/esm/fields/boolean-field.js +0 -8
  133. package/esm/fields/boolean-field.js.map +0 -1
  134. package/esm/fields/context-field.d.ts +0 -13
  135. package/esm/fields/context-field.js +0 -43
  136. package/esm/fields/context-field.js.map +0 -1
  137. package/esm/fields/date-field.d.ts +0 -8
  138. package/esm/fields/date-field.js +0 -8
  139. package/esm/fields/date-field.js.map +0 -1
  140. package/esm/fields/field.d.ts +0 -37
  141. package/esm/fields/field.js +0 -74
  142. package/esm/fields/field.js.map +0 -1
  143. package/esm/fields/has-inverse-field.d.ts +0 -4
  144. package/esm/fields/has-inverse-field.js +0 -2
  145. package/esm/fields/has-inverse-field.js.map +0 -1
  146. package/esm/fields/has-many-field.d.ts +0 -64
  147. package/esm/fields/has-many-field.js +0 -58
  148. package/esm/fields/has-many-field.js.map +0 -1
  149. package/esm/fields/has-one-field.d.ts +0 -64
  150. package/esm/fields/has-one-field.js +0 -57
  151. package/esm/fields/has-one-field.js.map +0 -1
  152. package/esm/fields/index.d.ts +0 -40
  153. package/esm/fields/index.js +0 -21
  154. package/esm/fields/index.js.map +0 -1
  155. package/esm/fields/json-field.d.ts +0 -14
  156. package/esm/fields/json-field.js +0 -17
  157. package/esm/fields/json-field.js.map +0 -1
  158. package/esm/fields/number-field.d.ts +0 -32
  159. package/esm/fields/number-field.js +0 -28
  160. package/esm/fields/number-field.js.map +0 -1
  161. package/esm/fields/password-field.d.ts +0 -21
  162. package/esm/fields/password-field.js +0 -71
  163. package/esm/fields/password-field.js.map +0 -1
  164. package/esm/fields/radio-field.d.ts +0 -14
  165. package/esm/fields/radio-field.js +0 -49
  166. package/esm/fields/radio-field.js.map +0 -1
  167. package/esm/fields/relation-field.d.ts +0 -20
  168. package/esm/fields/relation-field.js +0 -27
  169. package/esm/fields/relation-field.js.map +0 -1
  170. package/esm/fields/sort-field.d.ts +0 -16
  171. package/esm/fields/sort-field.js +0 -90
  172. package/esm/fields/sort-field.js.map +0 -1
  173. package/esm/fields/string-field.d.ts +0 -8
  174. package/esm/fields/string-field.js +0 -8
  175. package/esm/fields/string-field.js.map +0 -1
  176. package/esm/fields/text-field.d.ts +0 -8
  177. package/esm/fields/text-field.js +0 -8
  178. package/esm/fields/text-field.js.map +0 -1
  179. package/esm/fields/time-field.d.ts +0 -8
  180. package/esm/fields/time-field.js +0 -8
  181. package/esm/fields/time-field.js.map +0 -1
  182. package/esm/fields/uid-field.d.ts +0 -10
  183. package/esm/fields/uid-field.js +0 -27
  184. package/esm/fields/uid-field.js.map +0 -1
  185. package/esm/fields/virtual-field.d.ts +0 -8
  186. package/esm/fields/virtual-field.js +0 -8
  187. package/esm/fields/virtual-field.js.map +0 -1
  188. package/esm/filter-parser.d.ts +0 -27
  189. package/esm/filter-parser.js +0 -185
  190. package/esm/filter-parser.js.map +0 -1
  191. package/esm/index.d.ts +0 -15
  192. package/esm/index.js +0 -16
  193. package/esm/index.js.map +0 -1
  194. package/esm/magic-attribute-model.d.ts +0 -7
  195. package/esm/magic-attribute-model.js +0 -70
  196. package/esm/magic-attribute-model.js.map +0 -1
  197. package/esm/mock-database.d.ts +0 -22
  198. package/esm/mock-database.js +0 -34
  199. package/esm/mock-database.js.map +0 -1
  200. package/esm/model-hook.d.ts +0 -12
  201. package/esm/model-hook.js +0 -61
  202. package/esm/model-hook.js.map +0 -1
  203. package/esm/model.d.ts +0 -15
  204. package/esm/model.js +0 -80
  205. package/esm/model.js.map +0 -1
  206. package/esm/operators/array.d.ts +0 -26
  207. package/esm/operators/array.js +0 -105
  208. package/esm/operators/array.js.map +0 -1
  209. package/esm/operators/association.d.ts +0 -10
  210. package/esm/operators/association.js +0 -14
  211. package/esm/operators/association.js.map +0 -1
  212. package/esm/operators/date.d.ts +0 -34
  213. package/esm/operators/date.js +0 -35
  214. package/esm/operators/date.js.map +0 -1
  215. package/esm/operators/empty.d.ts +0 -28
  216. package/esm/operators/empty.js +0 -58
  217. package/esm/operators/empty.js.map +0 -1
  218. package/esm/operators/index.d.ts +0 -2
  219. package/esm/operators/index.js +0 -2
  220. package/esm/operators/index.js.map +0 -1
  221. package/esm/operators/ne.js +0 -12
  222. package/esm/operators/ne.js.map +0 -1
  223. package/esm/operators/string.d.ts +0 -21
  224. package/esm/operators/string.js +0 -35
  225. package/esm/operators/string.js.map +0 -1
  226. package/esm/operators/utils.d.ts +0 -4
  227. package/esm/operators/utils.js +0 -11
  228. package/esm/operators/utils.js.map +0 -1
  229. package/esm/options-parser.d.ts +0 -31
  230. package/esm/options-parser.js +0 -225
  231. package/esm/options-parser.js.map +0 -1
  232. package/esm/playground.d.ts +0 -1
  233. package/esm/playground.js +0 -53
  234. package/esm/playground.js.map +0 -1
  235. package/esm/relation-repository/belongs-to-many-repository.d.ts +0 -36
  236. package/esm/relation-repository/belongs-to-many-repository.js +0 -199
  237. package/esm/relation-repository/belongs-to-many-repository.js.map +0 -1
  238. package/esm/relation-repository/belongs-to-repository.d.ts +0 -17
  239. package/esm/relation-repository/belongs-to-repository.js +0 -4
  240. package/esm/relation-repository/belongs-to-repository.js.map +0 -1
  241. package/esm/relation-repository/hasmany-repository.d.ts +0 -23
  242. package/esm/relation-repository/hasmany-repository.js +0 -125
  243. package/esm/relation-repository/hasmany-repository.js.map +0 -1
  244. package/esm/relation-repository/hasone-repository.d.ts +0 -17
  245. package/esm/relation-repository/hasone-repository.js +0 -4
  246. package/esm/relation-repository/hasone-repository.js.map +0 -1
  247. package/esm/relation-repository/multiple-relation-repository.d.ts +0 -23
  248. package/esm/relation-repository/multiple-relation-repository.js +0 -149
  249. package/esm/relation-repository/multiple-relation-repository.js.map +0 -1
  250. package/esm/relation-repository/relation-repository.d.ts +0 -32
  251. package/esm/relation-repository/relation-repository.js +0 -93
  252. package/esm/relation-repository/relation-repository.js.map +0 -1
  253. package/esm/relation-repository/single-relation-repository.d.ts +0 -23
  254. package/esm/relation-repository/single-relation-repository.js +0 -96
  255. package/esm/relation-repository/single-relation-repository.js.map +0 -1
  256. package/esm/relation-repository/types.d.ts +0 -7
  257. package/esm/relation-repository/types.js +0 -2
  258. package/esm/relation-repository/types.js.map +0 -1
  259. package/esm/repository.d.ts +0 -165
  260. package/esm/repository.js +0 -276
  261. package/esm/repository.js.map +0 -1
  262. package/esm/transaction-decorator.d.ts +0 -1
  263. package/esm/transaction-decorator.js +0 -63
  264. package/esm/transaction-decorator.js.map +0 -1
  265. package/esm/update-associations.d.ts +0 -60
  266. package/esm/update-associations.js +0 -362
  267. package/esm/update-associations.js.map +0 -1
  268. package/esm/update-guard.d.ts +0 -26
  269. package/esm/update-guard.js +0 -122
  270. package/esm/update-guard.js.map +0 -1
  271. package/lib/collection-importer.js.map +0 -1
  272. package/lib/collection.js.map +0 -1
  273. package/lib/database.js.map +0 -1
  274. package/lib/fields/array-field.js.map +0 -1
  275. package/lib/fields/belongs-to-field.js.map +0 -1
  276. package/lib/fields/belongs-to-many-field.js.map +0 -1
  277. package/lib/fields/boolean-field.js.map +0 -1
  278. package/lib/fields/context-field.js.map +0 -1
  279. package/lib/fields/date-field.js.map +0 -1
  280. package/lib/fields/field.js.map +0 -1
  281. package/lib/fields/has-inverse-field.js.map +0 -1
  282. package/lib/fields/has-many-field.js.map +0 -1
  283. package/lib/fields/has-one-field.js.map +0 -1
  284. package/lib/fields/index.js.map +0 -1
  285. package/lib/fields/json-field.js.map +0 -1
  286. package/lib/fields/number-field.js.map +0 -1
  287. package/lib/fields/password-field.js.map +0 -1
  288. package/lib/fields/radio-field.js.map +0 -1
  289. package/lib/fields/relation-field.js.map +0 -1
  290. package/lib/fields/sort-field.js.map +0 -1
  291. package/lib/fields/string-field.js.map +0 -1
  292. package/lib/fields/text-field.js.map +0 -1
  293. package/lib/fields/time-field.js.map +0 -1
  294. package/lib/fields/uid-field.js.map +0 -1
  295. package/lib/fields/virtual-field.js.map +0 -1
  296. package/lib/filter-parser.js.map +0 -1
  297. package/lib/index.js.map +0 -1
  298. package/lib/magic-attribute-model.js.map +0 -1
  299. package/lib/mock-database.js.map +0 -1
  300. package/lib/model-hook.js.map +0 -1
  301. package/lib/model.js.map +0 -1
  302. package/lib/operators/array.js.map +0 -1
  303. package/lib/operators/association.js.map +0 -1
  304. package/lib/operators/date.js.map +0 -1
  305. package/lib/operators/empty.js.map +0 -1
  306. package/lib/operators/index.js.map +0 -1
  307. package/lib/operators/ne.js.map +0 -1
  308. package/lib/operators/string.js.map +0 -1
  309. package/lib/operators/utils.js.map +0 -1
  310. package/lib/options-parser.js.map +0 -1
  311. package/lib/playground.js.map +0 -1
  312. package/lib/relation-repository/belongs-to-many-repository.js.map +0 -1
  313. package/lib/relation-repository/belongs-to-repository.js.map +0 -1
  314. package/lib/relation-repository/hasmany-repository.js.map +0 -1
  315. package/lib/relation-repository/hasone-repository.js.map +0 -1
  316. package/lib/relation-repository/multiple-relation-repository.js.map +0 -1
  317. package/lib/relation-repository/relation-repository.js.map +0 -1
  318. package/lib/relation-repository/single-relation-repository.js.map +0 -1
  319. package/lib/relation-repository/types.js.map +0 -1
  320. package/lib/repository.js.map +0 -1
  321. package/lib/transaction-decorator.js.map +0 -1
  322. package/lib/update-associations.js.map +0 -1
  323. package/lib/update-guard.js.map +0 -1
  324. package/tsconfig.build.json +0 -9
  325. package/tsconfig.json +0 -5
@@ -1,22 +1,42 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
3
6
  exports.JsonbField = exports.JsonField = void 0;
4
- const sequelize_1 = require("sequelize");
5
- const field_1 = require("./field");
6
- class JsonField extends field_1.Field {
7
- get dataType() {
8
- return sequelize_1.DataTypes.JSON;
9
- }
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
+ class JsonField extends _field.Field {
21
+ get dataType() {
22
+ return _sequelize().DataTypes.JSON;
23
+ }
24
+
10
25
  }
26
+
11
27
  exports.JsonField = JsonField;
12
- class JsonbField extends field_1.Field {
13
- get dataType() {
14
- const dialect = this.context.database.sequelize.getDialect();
15
- if (dialect === 'postgres') {
16
- return sequelize_1.DataTypes.JSONB;
17
- }
18
- return sequelize_1.DataTypes.JSON;
28
+
29
+ class JsonbField extends _field.Field {
30
+ get dataType() {
31
+ const dialect = this.context.database.sequelize.getDialect();
32
+
33
+ if (dialect === 'postgres') {
34
+ return _sequelize().DataTypes.JSONB;
19
35
  }
36
+
37
+ return _sequelize().DataTypes.JSON;
38
+ }
39
+
20
40
  }
21
- exports.JsonbField = JsonbField;
22
- //# sourceMappingURL=json-field.js.map
41
+
42
+ exports.JsonbField = JsonbField;
@@ -1,36 +1,63 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DecimalField = exports.RealField = exports.DoubleField = exports.FloatField = exports.IntegerField = void 0;
4
- const sequelize_1 = require("sequelize");
5
- const field_1 = require("./field");
6
- class IntegerField extends field_1.Field {
7
- get dataType() {
8
- return sequelize_1.DataTypes.INTEGER;
9
- }
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.RealField = exports.IntegerField = exports.FloatField = exports.DoubleField = exports.DecimalField = void 0;
7
+
8
+ function _sequelize() {
9
+ const data = require("sequelize");
10
+
11
+ _sequelize = function _sequelize() {
12
+ return data;
13
+ };
14
+
15
+ return data;
10
16
  }
17
+
18
+ var _field = require("./field");
19
+
20
+ class IntegerField extends _field.Field {
21
+ get dataType() {
22
+ return _sequelize().DataTypes.INTEGER;
23
+ }
24
+
25
+ }
26
+
11
27
  exports.IntegerField = IntegerField;
12
- class FloatField extends field_1.Field {
13
- get dataType() {
14
- return sequelize_1.DataTypes.FLOAT;
15
- }
28
+
29
+ class FloatField extends _field.Field {
30
+ get dataType() {
31
+ return _sequelize().DataTypes.FLOAT;
32
+ }
33
+
16
34
  }
35
+
17
36
  exports.FloatField = FloatField;
18
- class DoubleField extends field_1.Field {
19
- get dataType() {
20
- return sequelize_1.DataTypes.DOUBLE;
21
- }
37
+
38
+ class DoubleField extends _field.Field {
39
+ get dataType() {
40
+ return _sequelize().DataTypes.DOUBLE;
41
+ }
42
+
22
43
  }
44
+
23
45
  exports.DoubleField = DoubleField;
24
- class RealField extends field_1.Field {
25
- get dataType() {
26
- return sequelize_1.DataTypes.REAL;
27
- }
46
+
47
+ class RealField extends _field.Field {
48
+ get dataType() {
49
+ return _sequelize().DataTypes.REAL;
50
+ }
51
+
28
52
  }
53
+
29
54
  exports.RealField = RealField;
30
- class DecimalField extends field_1.Field {
31
- get dataType() {
32
- return sequelize_1.DataTypes.DECIMAL;
33
- }
55
+
56
+ class DecimalField extends _field.Field {
57
+ get dataType() {
58
+ return _sequelize().DataTypes.DECIMAL;
59
+ }
60
+
34
61
  }
35
- exports.DecimalField = DecimalField;
36
- //# sourceMappingURL=number-field.js.map
62
+
63
+ exports.DecimalField = DecimalField;
@@ -1,78 +1,125 @@
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 });
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
15
6
  exports.PasswordField = void 0;
16
- const crypto_1 = __importDefault(require("crypto"));
17
- const sequelize_1 = require("sequelize");
18
- const field_1 = require("./field");
19
- class PasswordField extends field_1.Field {
20
- get dataType() {
21
- return sequelize_1.DataTypes.STRING;
22
- }
23
- verify(password, hash) {
24
- return __awaiter(this, void 0, void 0, function* () {
25
- const { length = 64, randomBytesSize = 8 } = this.options;
26
- return new Promise((resolve, reject) => {
27
- const salt = hash.substring(0, randomBytesSize * 2);
28
- const key = hash.substring(randomBytesSize * 2);
29
- crypto_1.default.scrypt(password, salt, length / 2 - randomBytesSize, (err, derivedKey) => {
30
- if (err)
31
- reject(err);
32
- resolve(key == derivedKey.toString('hex'));
33
- });
34
- });
35
- });
36
- }
37
- hash(password) {
38
- return __awaiter(this, void 0, void 0, function* () {
39
- const { length = 64, randomBytesSize = 8 } = this.options;
40
- return new Promise((resolve, reject) => {
41
- const salt = crypto_1.default.randomBytes(randomBytesSize).toString('hex');
42
- crypto_1.default.scrypt(password, salt, length / 2 - randomBytesSize, (err, derivedKey) => {
43
- if (err)
44
- reject(err);
45
- resolve(salt + derivedKey.toString('hex'));
46
- });
47
- });
7
+
8
+ function _crypto() {
9
+ const data = _interopRequireDefault(require("crypto"));
10
+
11
+ _crypto = function _crypto() {
12
+ return data;
13
+ };
14
+
15
+ return data;
16
+ }
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 _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
31
+
32
+ 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); } }
33
+
34
+ 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); }); }; }
35
+
36
+ class PasswordField extends _field.Field {
37
+ get dataType() {
38
+ return _sequelize().DataTypes.STRING;
39
+ }
40
+
41
+ verify(password, hash) {
42
+ var _this = this;
43
+
44
+ return _asyncToGenerator(function* () {
45
+ password = password || '';
46
+ hash = hash || '';
47
+ const _this$options = _this.options,
48
+ _this$options$length = _this$options.length,
49
+ length = _this$options$length === void 0 ? 64 : _this$options$length,
50
+ _this$options$randomB = _this$options.randomBytesSize,
51
+ randomBytesSize = _this$options$randomB === void 0 ? 8 : _this$options$randomB;
52
+ return new Promise((resolve, reject) => {
53
+ const salt = hash.substring(0, randomBytesSize * 2);
54
+ const key = hash.substring(randomBytesSize * 2);
55
+
56
+ _crypto().default.scrypt(password, salt, length / 2 - randomBytesSize, (err, derivedKey) => {
57
+ if (err) reject(err);
58
+ resolve(key == derivedKey.toString('hex'));
48
59
  });
49
- }
50
- init() {
51
- const { name } = this.options;
52
- this.listener = (model) => __awaiter(this, void 0, void 0, function* () {
53
- if (!model.changed(name)) {
54
- return;
55
- }
56
- const value = model.get(name);
57
- if (value) {
58
- const hash = yield this.hash(value);
59
- model.set(name, hash);
60
- }
61
- else {
62
- model.set(name, null);
63
- }
60
+ });
61
+ })();
62
+ }
63
+
64
+ hash(password) {
65
+ var _this2 = this;
66
+
67
+ return _asyncToGenerator(function* () {
68
+ const _this2$options = _this2.options,
69
+ _this2$options$length = _this2$options.length,
70
+ length = _this2$options$length === void 0 ? 64 : _this2$options$length,
71
+ _this2$options$random = _this2$options.randomBytesSize,
72
+ randomBytesSize = _this2$options$random === void 0 ? 8 : _this2$options$random;
73
+ return new Promise((resolve, reject) => {
74
+ const salt = _crypto().default.randomBytes(randomBytesSize).toString('hex');
75
+
76
+ _crypto().default.scrypt(password, salt, length / 2 - randomBytesSize, (err, derivedKey) => {
77
+ if (err) reject(err);
78
+ resolve(salt + derivedKey.toString('hex'));
64
79
  });
65
- }
66
- bind() {
67
- super.bind();
68
- this.on('beforeCreate', this.listener);
69
- this.on('beforeUpdate', this.listener);
70
- }
71
- unbind() {
72
- super.unbind();
73
- this.off('beforeCreate', this.listener);
74
- this.off('beforeUpdate', this.listener);
75
- }
80
+ });
81
+ })();
82
+ }
83
+
84
+ init() {
85
+ var _this3 = this;
86
+
87
+ const name = this.options.name;
88
+
89
+ this.listener = /*#__PURE__*/function () {
90
+ var _ref = _asyncToGenerator(function* (model) {
91
+ if (!model.changed(name)) {
92
+ return;
93
+ }
94
+
95
+ const value = model.get(name);
96
+
97
+ if (value) {
98
+ const hash = yield _this3.hash(value);
99
+ model.set(name, hash);
100
+ } else {
101
+ model.set(name, null);
102
+ }
103
+ });
104
+
105
+ return function (_x) {
106
+ return _ref.apply(this, arguments);
107
+ };
108
+ }();
109
+ }
110
+
111
+ bind() {
112
+ super.bind();
113
+ this.on('beforeCreate', this.listener);
114
+ this.on('beforeUpdate', this.listener);
115
+ }
116
+
117
+ unbind() {
118
+ super.unbind();
119
+ this.off('beforeCreate', this.listener);
120
+ this.off('beforeUpdate', this.listener);
121
+ }
122
+
76
123
  }
77
- exports.PasswordField = PasswordField;
78
- //# sourceMappingURL=password-field.js.map
124
+
125
+ exports.PasswordField = PasswordField;
@@ -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;