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

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,107 +1,147 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const sequelize_1 = require("sequelize");
4
- const utils_1 = require("./utils");
5
- const getFieldName = (ctx) => {
6
- const fieldName = ctx.fieldName;
7
- return fieldName;
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
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 _utils = require("./utils");
19
+
20
+ const getFieldName = ctx => {
21
+ const fieldName = ctx.fieldName;
22
+ return fieldName;
8
23
  };
24
+
9
25
  const escape = (value, ctx) => {
10
- const sequelize = ctx.db.sequelize;
11
- return sequelize.escape(value);
26
+ const sequelize = ctx.db.sequelize;
27
+ return sequelize.escape(value);
12
28
  };
29
+
13
30
  const sqliteExistQuery = (value, ctx) => {
14
- const fieldName = getFieldName(ctx);
15
- const sqlArray = `(${value.map((v) => `'${v}'`).join(', ')})`;
16
- const subQuery = `exists (select * from json_each(${fieldName}) where json_each.value in ${sqlArray})`;
17
- return subQuery;
31
+ const fieldName = getFieldName(ctx);
32
+ const sqlArray = `(${value.map(v => `'${v}'`).join(', ')})`;
33
+ const subQuery = `exists (select * from json_each(${fieldName}) where json_each.value in ${sqlArray})`;
34
+ return subQuery;
18
35
  };
36
+
19
37
  const emptyQuery = (ctx, operator) => {
38
+ const fieldName = getFieldName(ctx);
39
+ let funcName = 'json_array_length';
40
+ let ifNull = 'IFNULL';
41
+
42
+ if ((0, _utils.isPg)(ctx)) {
43
+ funcName = 'jsonb_array_length';
44
+ ifNull = 'coalesce';
45
+ }
46
+
47
+ if ((0, _utils.isMySQL)(ctx)) {
48
+ funcName = 'json_length';
49
+ }
50
+
51
+ return `(select ${ifNull}(${funcName}(${fieldName}), 0) ${operator} 0)`;
52
+ };
53
+
54
+ var _default = {
55
+ $match(value, ctx) {
20
56
  const fieldName = getFieldName(ctx);
21
- let funcName = 'json_array_length';
22
- let ifNull = 'IFNULL';
23
- if ((0, utils_1.isPg)(ctx)) {
24
- funcName = 'jsonb_array_length';
25
- ifNull = 'coalesce';
57
+
58
+ if ((0, _utils.isPg)(ctx)) {
59
+ return {
60
+ [_sequelize().Op.contained]: value,
61
+ [_sequelize().Op.contains]: value
62
+ };
26
63
  }
27
- if ((0, utils_1.isMySQL)(ctx)) {
28
- funcName = 'json_length';
64
+
65
+ value = escape(JSON.stringify(value.sort()), ctx);
66
+
67
+ if ((0, _utils.isMySQL)(ctx)) {
68
+ return _sequelize().Sequelize.literal(`JSON_CONTAINS(${fieldName}, ${value}) AND JSON_CONTAINS(${value}, ${fieldName})`);
29
69
  }
30
- return `(select ${ifNull}(${funcName}(${fieldName}), 0) ${operator} 0)`;
31
- };
32
- exports.default = {
33
- $match(value, ctx) {
34
- const fieldName = getFieldName(ctx);
35
- if ((0, utils_1.isPg)(ctx)) {
36
- return {
37
- [sequelize_1.Op.contained]: value,
38
- [sequelize_1.Op.contains]: value,
39
- };
40
- }
41
- value = escape(JSON.stringify(value.sort()), ctx);
42
- if ((0, utils_1.isMySQL)(ctx)) {
43
- return sequelize_1.Sequelize.literal(`JSON_CONTAINS(${fieldName}, ${value}) AND JSON_CONTAINS(${value}, ${fieldName})`);
44
- }
45
- return {
46
- [sequelize_1.Op.eq]: sequelize_1.Sequelize.literal(`json(${value})`),
47
- };
48
- },
49
- $notMatch(value, ctx) {
50
- const fieldName = getFieldName(ctx);
51
- value = escape(JSON.stringify(value), ctx);
52
- if ((0, utils_1.isPg)(ctx)) {
53
- return sequelize_1.Sequelize.literal(`not (${fieldName} <@ ${value}::JSONB and ${fieldName} @> ${value}::JSONB)`);
54
- }
55
- if ((0, utils_1.isMySQL)(ctx)) {
56
- return sequelize_1.Sequelize.literal(`not (JSON_CONTAINS(${fieldName}, ${value}) AND JSON_CONTAINS(${value}, ${fieldName}))`);
57
- }
58
- return {
59
- [sequelize_1.Op.ne]: sequelize_1.Sequelize.literal(`json(${value})`),
60
- };
61
- },
62
- $anyOf(value, ctx) {
63
- const fieldName = getFieldName(ctx);
64
- if ((0, utils_1.isPg)(ctx)) {
65
- return sequelize_1.Sequelize.literal(`${fieldName} ?| ${escape(value.map((i) => `${i}`), ctx)}`);
66
- }
67
- if ((0, utils_1.isMySQL)(ctx)) {
68
- value = escape(JSON.stringify(value), ctx);
69
- return sequelize_1.Sequelize.literal(`JSON_OVERLAPS(${fieldName}, ${value})`);
70
- }
71
- const subQuery = sqliteExistQuery(value, ctx);
72
- return sequelize_1.Sequelize.literal(subQuery);
73
- },
74
- $noneOf(value, ctx) {
75
- let where;
76
- if ((0, utils_1.isPg)(ctx)) {
77
- const fieldName = getFieldName(ctx);
78
- // pg single quote
79
- where = sequelize_1.Sequelize.literal(`not (${fieldName} ?| ${escape(value.map((i) => `${i}`), ctx)})`);
80
- }
81
- else if ((0, utils_1.isMySQL)(ctx)) {
82
- const fieldName = getFieldName(ctx);
83
- value = escape(JSON.stringify(value), ctx);
84
- where = sequelize_1.Sequelize.literal(`NOT JSON_OVERLAPS(${fieldName}, ${value})`);
85
- }
86
- else {
87
- const subQuery = sqliteExistQuery(value, ctx);
88
- where = sequelize_1.Sequelize.literal(`not ${subQuery}`);
89
- }
90
- return {
91
- [sequelize_1.Op.or]: [where, { [sequelize_1.Op.is]: null }],
92
- };
93
- },
94
- $arrayEmpty(value, ctx) {
95
- const subQuery = emptyQuery(ctx, '=');
96
- return {
97
- [sequelize_1.Op.and]: [sequelize_1.Sequelize.literal(`${subQuery}`)],
98
- };
99
- },
100
- $arrayNotEmpty(value, ctx) {
101
- const subQuery = emptyQuery(ctx, '>');
102
- return {
103
- [sequelize_1.Op.and]: [sequelize_1.Sequelize.literal(`${subQuery}`)],
104
- };
105
- },
70
+
71
+ return {
72
+ [_sequelize().Op.eq]: _sequelize().Sequelize.literal(`json(${value})`)
73
+ };
74
+ },
75
+
76
+ $notMatch(value, ctx) {
77
+ const fieldName = getFieldName(ctx);
78
+ value = escape(JSON.stringify(value), ctx);
79
+
80
+ if ((0, _utils.isPg)(ctx)) {
81
+ return _sequelize().Sequelize.literal(`not (${fieldName} <@ ${value}::JSONB and ${fieldName} @> ${value}::JSONB)`);
82
+ }
83
+
84
+ if ((0, _utils.isMySQL)(ctx)) {
85
+ return _sequelize().Sequelize.literal(`not (JSON_CONTAINS(${fieldName}, ${value}) AND JSON_CONTAINS(${value}, ${fieldName}))`);
86
+ }
87
+
88
+ return {
89
+ [_sequelize().Op.ne]: _sequelize().Sequelize.literal(`json(${value})`)
90
+ };
91
+ },
92
+
93
+ $anyOf(value, ctx) {
94
+ const fieldName = getFieldName(ctx);
95
+
96
+ if ((0, _utils.isPg)(ctx)) {
97
+ return _sequelize().Sequelize.literal(`${fieldName} ?| ${escape(value.map(i => `${i}`), ctx)}`);
98
+ }
99
+
100
+ if ((0, _utils.isMySQL)(ctx)) {
101
+ value = escape(JSON.stringify(value), ctx);
102
+ return _sequelize().Sequelize.literal(`JSON_OVERLAPS(${fieldName}, ${value})`);
103
+ }
104
+
105
+ const subQuery = sqliteExistQuery(value, ctx);
106
+ return _sequelize().Sequelize.literal(subQuery);
107
+ },
108
+
109
+ $noneOf(value, ctx) {
110
+ let where;
111
+
112
+ if ((0, _utils.isPg)(ctx)) {
113
+ const fieldName = getFieldName(ctx); // pg single quote
114
+
115
+ where = _sequelize().Sequelize.literal(`not (${fieldName} ?| ${escape(value.map(i => `${i}`), ctx)})`);
116
+ } else if ((0, _utils.isMySQL)(ctx)) {
117
+ const fieldName = getFieldName(ctx);
118
+ value = escape(JSON.stringify(value), ctx);
119
+ where = _sequelize().Sequelize.literal(`NOT JSON_OVERLAPS(${fieldName}, ${value})`);
120
+ } else {
121
+ const subQuery = sqliteExistQuery(value, ctx);
122
+ where = _sequelize().Sequelize.literal(`not ${subQuery}`);
123
+ }
124
+
125
+ return {
126
+ [_sequelize().Op.or]: [where, {
127
+ [_sequelize().Op.is]: null
128
+ }]
129
+ };
130
+ },
131
+
132
+ $arrayEmpty(value, ctx) {
133
+ const subQuery = emptyQuery(ctx, '=');
134
+ return {
135
+ [_sequelize().Op.and]: [_sequelize().Sequelize.literal(`${subQuery}`)]
136
+ };
137
+ },
138
+
139
+ $arrayNotEmpty(value, ctx) {
140
+ const subQuery = emptyQuery(ctx, '>');
141
+ return {
142
+ [_sequelize().Op.and]: [_sequelize().Sequelize.literal(`${subQuery}`)]
143
+ };
144
+ }
145
+
106
146
  };
107
- //# sourceMappingURL=array.js.map
147
+ exports.default = _default;
@@ -1,16 +1,32 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const sequelize_1 = require("sequelize");
4
- exports.default = {
5
- $exists(value, ctx) {
6
- return {
7
- [sequelize_1.Op.not]: null,
8
- };
9
- },
10
- $notExists(value, ctx) {
11
- return {
12
- [sequelize_1.Op.is]: null,
13
- };
14
- },
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
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 _default = {
19
+ $exists(value, ctx) {
20
+ return {
21
+ [_sequelize().Op.not]: null
22
+ };
23
+ },
24
+
25
+ $notExists(value, ctx) {
26
+ return {
27
+ [_sequelize().Op.is]: null
28
+ };
29
+ }
30
+
15
31
  };
16
- //# sourceMappingURL=association.js.map
32
+ exports.default = _default;
@@ -0,0 +1,13 @@
1
+ import { Op } from 'sequelize';
2
+ declare const _default: {
3
+ $isFalsy(): {
4
+ [Op.or]: {
5
+ [Op.is]: any;
6
+ [Op.eq]: boolean;
7
+ };
8
+ };
9
+ $isTruly(): {
10
+ [Op.eq]: boolean;
11
+ };
12
+ };
13
+ export default _default;
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
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 _default = {
19
+ $isFalsy() {
20
+ return {
21
+ [_sequelize().Op.or]: {
22
+ [_sequelize().Op.is]: null,
23
+ [_sequelize().Op.eq]: false
24
+ }
25
+ };
26
+ },
27
+
28
+ $isTruly() {
29
+ return {
30
+ [_sequelize().Op.eq]: true
31
+ };
32
+ }
33
+
34
+ };
35
+ exports.default = _default;
@@ -1,40 +1,84 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const sequelize_1 = require("sequelize");
7
- const moment_1 = __importDefault(require("moment"));
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
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
+ function _moment() {
19
+ const data = _interopRequireDefault(require("moment"));
20
+
21
+ _moment = function _moment() {
22
+ return data;
23
+ };
24
+
25
+ return data;
26
+ }
27
+
28
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
29
+
8
30
  function stringToDate(value) {
9
- return (0, moment_1.default)(value).toDate();
31
+ return (0, _moment().default)(value).toDate();
10
32
  }
33
+
11
34
  function getNextDay(value) {
12
- return (0, moment_1.default)(value).add(1, 'd').toDate();
35
+ return (0, _moment().default)(value).add(1, 'd').toDate();
13
36
  }
14
- exports.default = {
15
- $dateOn(value) {
16
- return {
17
- [sequelize_1.Op.and]: [{ [sequelize_1.Op.gte]: stringToDate(value) }, { [sequelize_1.Op.lt]: getNextDay(value) }],
18
- };
19
- },
20
- $dateNotOn(value) {
21
- return {
22
- [sequelize_1.Op.or]: [{ [sequelize_1.Op.lt]: stringToDate(value) }, { [sequelize_1.Op.gte]: getNextDay(value) }],
23
- };
24
- },
25
- $dateBefore(value) {
26
- return { [sequelize_1.Op.lt]: stringToDate(value) };
27
- },
28
- $dateNotBefore(value) {
29
- return {
30
- [sequelize_1.Op.gte]: stringToDate(value),
31
- };
32
- },
33
- $dateAfter(value) {
34
- return { [sequelize_1.Op.gte]: getNextDay(value) };
35
- },
36
- $dateNotAfter(value) {
37
- return { [sequelize_1.Op.lt]: getNextDay(value) };
38
- },
37
+
38
+ var _default = {
39
+ $dateOn(value) {
40
+ return {
41
+ [_sequelize().Op.and]: [{
42
+ [_sequelize().Op.gte]: stringToDate(value)
43
+ }, {
44
+ [_sequelize().Op.lt]: getNextDay(value)
45
+ }]
46
+ };
47
+ },
48
+
49
+ $dateNotOn(value) {
50
+ return {
51
+ [_sequelize().Op.or]: [{
52
+ [_sequelize().Op.lt]: stringToDate(value)
53
+ }, {
54
+ [_sequelize().Op.gte]: getNextDay(value)
55
+ }]
56
+ };
57
+ },
58
+
59
+ $dateBefore(value) {
60
+ return {
61
+ [_sequelize().Op.lt]: stringToDate(value)
62
+ };
63
+ },
64
+
65
+ $dateNotBefore(value) {
66
+ return {
67
+ [_sequelize().Op.gte]: stringToDate(value)
68
+ };
69
+ },
70
+
71
+ $dateAfter(value) {
72
+ return {
73
+ [_sequelize().Op.gte]: getNextDay(value)
74
+ };
75
+ },
76
+
77
+ $dateNotAfter(value) {
78
+ return {
79
+ [_sequelize().Op.lt]: getNextDay(value)
80
+ };
81
+ }
82
+
39
83
  };
40
- //# sourceMappingURL=date.js.map
84
+ exports.default = _default;
@@ -1,82 +1,120 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
- }) : (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- o[k2] = m[k];
8
- }));
9
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
- Object.defineProperty(o, "default", { enumerable: true, value: v });
11
- }) : function(o, v) {
12
- o["default"] = v;
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
13
5
  });
14
- var __importStar = (this && this.__importStar) || function (mod) {
15
- if (mod && mod.__esModule) return mod;
16
- var result = {};
17
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
- __setModuleDefault(result, mod);
19
- return result;
20
- };
21
- var __importDefault = (this && this.__importDefault) || function (mod) {
22
- return (mod && mod.__esModule) ? mod : { "default": mod };
23
- };
24
- Object.defineProperty(exports, "__esModule", { value: true });
25
- const sequelize_1 = require("sequelize");
26
- const fields_1 = require("../fields");
27
- const array_1 = __importDefault(require("./array"));
28
- const lodash_1 = __importStar(require("lodash"));
29
- const findFilterFieldType = (ctx) => {
30
- const db = ctx.db;
31
- let path = ctx.path.split('.');
32
- // remove operators
33
- path.pop();
34
- const fieldName = path.pop();
35
- let model = ctx.model;
36
- const associationPath = path;
37
- for (const association of associationPath) {
38
- if (lodash_1.default.isNumber((0, lodash_1.parseInt)(association)) || association.startsWith('$')) {
39
- continue;
40
- }
41
- model = model.associations[association].target;
6
+ exports.default = void 0;
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 _fields = require("../fields");
19
+
20
+ var _array = _interopRequireDefault(require("./array"));
21
+
22
+ function _lodash() {
23
+ const data = _interopRequireWildcard(require("lodash"));
24
+
25
+ _lodash = function _lodash() {
26
+ return data;
27
+ };
28
+
29
+ return data;
30
+ }
31
+
32
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
33
+
34
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
35
+
36
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
37
+
38
+ 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; } } }; }
39
+
40
+ 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); }
41
+
42
+ 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; }
43
+
44
+ const findFilterFieldType = ctx => {
45
+ const db = ctx.db;
46
+ let path = ctx.path.split('.'); // remove operators
47
+
48
+ path.pop();
49
+ const fieldName = path.pop();
50
+ let model = ctx.model;
51
+ const associationPath = path;
52
+
53
+ var _iterator = _createForOfIteratorHelper(associationPath),
54
+ _step;
55
+
56
+ try {
57
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
58
+ const association = _step.value;
59
+
60
+ if (_lodash().default.isNumber((0, _lodash().parseInt)(association)) || association.startsWith('$')) {
61
+ continue;
62
+ }
63
+
64
+ model = model.associations[association].target;
42
65
  }
43
- const collection = db.modelCollection.get(model);
44
- return collection.getField(fieldName);
66
+ } catch (err) {
67
+ _iterator.e(err);
68
+ } finally {
69
+ _iterator.f();
70
+ }
71
+
72
+ const collection = db.modelCollection.get(model);
73
+ return collection.getField(fieldName);
45
74
  };
46
- exports.default = {
47
- $empty(_, ctx) {
48
- const field = findFilterFieldType(ctx);
49
- if (field instanceof fields_1.StringField) {
50
- return {
51
- [sequelize_1.Op.or]: {
52
- [sequelize_1.Op.is]: null,
53
- [sequelize_1.Op.eq]: '',
54
- },
55
- };
56
- }
57
- if (field instanceof fields_1.ArrayField) {
58
- return array_1.default.$arrayEmpty(_, ctx);
59
- }
60
- return {
61
- [sequelize_1.Op.is]: null,
62
- };
63
- },
64
- $notEmpty(_, ctx) {
65
- const field = findFilterFieldType(ctx);
66
- if (field instanceof fields_1.StringField) {
67
- return {
68
- [sequelize_1.Op.and]: {
69
- [sequelize_1.Op.not]: null,
70
- [sequelize_1.Op.ne]: '',
71
- },
72
- };
75
+
76
+ var _default = {
77
+ $empty(_, ctx) {
78
+ const field = findFilterFieldType(ctx);
79
+
80
+ if (field instanceof _fields.StringField) {
81
+ return {
82
+ [_sequelize().Op.or]: {
83
+ [_sequelize().Op.is]: null,
84
+ [_sequelize().Op.eq]: ''
73
85
  }
74
- if (field instanceof fields_1.ArrayField) {
75
- return array_1.default.$arrayNotEmpty(_, ctx);
86
+ };
87
+ }
88
+
89
+ if (field instanceof _fields.ArrayField) {
90
+ return _array.default.$arrayEmpty(_, ctx);
91
+ }
92
+
93
+ return {
94
+ [_sequelize().Op.is]: null
95
+ };
96
+ },
97
+
98
+ $notEmpty(_, ctx) {
99
+ const field = findFilterFieldType(ctx);
100
+
101
+ if (field instanceof _fields.StringField) {
102
+ return {
103
+ [_sequelize().Op.and]: {
104
+ [_sequelize().Op.not]: null,
105
+ [_sequelize().Op.ne]: ''
76
106
  }
77
- return {
78
- [sequelize_1.Op.not]: null,
79
- };
80
- },
107
+ };
108
+ }
109
+
110
+ if (field instanceof _fields.ArrayField) {
111
+ return _array.default.$arrayNotEmpty(_, ctx);
112
+ }
113
+
114
+ return {
115
+ [_sequelize().Op.not]: null
116
+ };
117
+ }
118
+
81
119
  };
82
- //# sourceMappingURL=empty.js.map
120
+ exports.default = _default;