@nocobase/database 0.7.0-alpha.8 → 0.7.0-alpha.80

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 (298) hide show
  1. package/lib/collection-importer.js +101 -67
  2. package/lib/collection.js +339 -210
  3. package/lib/database.d.ts +4 -1
  4. package/lib/database.js +489 -275
  5. package/lib/fields/array-field.js +45 -25
  6. package/lib/fields/belongs-to-field.js +101 -54
  7. package/lib/fields/belongs-to-many-field.js +98 -53
  8. package/lib/fields/boolean-field.js +24 -9
  9. package/lib/fields/context-field.js +77 -42
  10. package/lib/fields/date-field.js +24 -9
  11. package/lib/fields/field.js +114 -75
  12. package/lib/fields/has-inverse-field.js +4 -2
  13. package/lib/fields/has-many-field.js +105 -56
  14. package/lib/fields/has-one-field.js +105 -54
  15. package/lib/fields/index.d.ts +3 -1
  16. package/lib/fields/index.js +277 -32
  17. package/lib/fields/json-field.js +36 -16
  18. package/lib/fields/number-field.js +53 -26
  19. package/lib/fields/password-field.js +120 -73
  20. package/lib/fields/radio-field.js +75 -47
  21. package/lib/fields/relation-field.js +41 -28
  22. package/lib/fields/sort-field.js +165 -89
  23. package/lib/fields/string-field.js +24 -9
  24. package/lib/fields/text-field.js +24 -9
  25. package/lib/fields/time-field.js +24 -9
  26. package/lib/fields/uid-field.js +57 -28
  27. package/lib/fields/uuid-field.d.ts +9 -0
  28. package/lib/fields/uuid-field.js +39 -0
  29. package/lib/fields/virtual-field.js +24 -9
  30. package/lib/filter-parser.js +288 -179
  31. package/lib/index.js +210 -29
  32. package/lib/magic-attribute-model.js +123 -71
  33. package/lib/mock-database.js +68 -34
  34. package/lib/model-hook.js +101 -60
  35. package/lib/model.js +116 -81
  36. package/lib/operators/array.js +136 -96
  37. package/lib/operators/association.js +30 -14
  38. package/lib/operators/boolean.d.ts +13 -0
  39. package/lib/operators/boolean.js +35 -0
  40. package/lib/operators/date.js +78 -34
  41. package/lib/operators/empty.js +113 -75
  42. package/lib/operators/index.js +15 -3
  43. package/lib/operators/ne.js +27 -12
  44. package/{esm/operators/ne.d.ts → lib/operators/notIn.d.ts} +2 -2
  45. package/lib/operators/notIn.js +29 -0
  46. package/lib/operators/string.js +56 -35
  47. package/lib/operators/utils.js +18 -10
  48. package/lib/options-parser.js +323 -215
  49. package/lib/playground.js +66 -53
  50. package/lib/relation-repository/belongs-to-many-repository.js +281 -198
  51. package/lib/relation-repository/belongs-to-repository.js +10 -6
  52. package/lib/relation-repository/hasmany-repository.js +168 -121
  53. package/lib/relation-repository/hasone-repository.js +10 -6
  54. package/lib/relation-repository/multiple-relation-repository.d.ts +3 -3
  55. package/lib/relation-repository/multiple-relation-repository.js +263 -148
  56. package/lib/relation-repository/relation-repository.d.ts +1 -1
  57. package/lib/relation-repository/relation-repository.js +155 -95
  58. package/lib/relation-repository/single-relation-repository.d.ts +6 -6
  59. package/lib/relation-repository/single-relation-repository.js +138 -99
  60. package/lib/relation-repository/types.js +4 -2
  61. package/lib/repository.d.ts +4 -7
  62. package/lib/repository.js +465 -291
  63. package/lib/transaction-decorator.js +80 -67
  64. package/lib/update-associations.d.ts +1 -2
  65. package/lib/update-associations.js +525 -321
  66. package/lib/update-guard.js +160 -117
  67. package/package.json +3 -8
  68. package/src/__tests__/fields/uuid-field.test.ts +30 -0
  69. package/src/__tests__/operator/notIn.test.ts +33 -0
  70. package/src/__tests__/option-parser.test.ts +20 -0
  71. package/src/database.ts +51 -4
  72. package/src/fields/index.ts +3 -0
  73. package/src/fields/password-field.ts +2 -0
  74. package/src/fields/uuid-field.ts +21 -0
  75. package/src/mock-database.ts +1 -1
  76. package/src/model-hook.ts +1 -1
  77. package/src/operators/boolean.ts +18 -0
  78. package/src/operators/index.ts +2 -0
  79. package/src/operators/notIn.ts +12 -0
  80. package/src/options-parser.ts +1 -1
  81. package/src/relation-repository/multiple-relation-repository.ts +8 -6
  82. package/src/relation-repository/relation-repository.ts +11 -6
  83. package/src/relation-repository/single-relation-repository.ts +6 -6
  84. package/src/repository.ts +4 -6
  85. package/src/update-associations.ts +1 -2
  86. package/esm/collection-importer.d.ts +0 -7
  87. package/esm/collection-importer.js +0 -49
  88. package/esm/collection-importer.js.map +0 -1
  89. package/esm/collection.d.ts +0 -73
  90. package/esm/collection.js +0 -224
  91. package/esm/collection.js.map +0 -1
  92. package/esm/database.d.ts +0 -101
  93. package/esm/database.js +0 -275
  94. package/esm/database.js.map +0 -1
  95. package/esm/fields/array-field.d.ts +0 -11
  96. package/esm/fields/array-field.js +0 -26
  97. package/esm/fields/array-field.js.map +0 -1
  98. package/esm/fields/belongs-to-field.d.ts +0 -12
  99. package/esm/fields/belongs-to-field.js +0 -57
  100. package/esm/fields/belongs-to-field.js.map +0 -1
  101. package/esm/fields/belongs-to-many-field.d.ts +0 -11
  102. package/esm/fields/belongs-to-many-field.js +0 -55
  103. package/esm/fields/belongs-to-many-field.js.map +0 -1
  104. package/esm/fields/boolean-field.d.ts +0 -8
  105. package/esm/fields/boolean-field.js +0 -8
  106. package/esm/fields/boolean-field.js.map +0 -1
  107. package/esm/fields/context-field.d.ts +0 -13
  108. package/esm/fields/context-field.js +0 -43
  109. package/esm/fields/context-field.js.map +0 -1
  110. package/esm/fields/date-field.d.ts +0 -8
  111. package/esm/fields/date-field.js +0 -8
  112. package/esm/fields/date-field.js.map +0 -1
  113. package/esm/fields/field.d.ts +0 -37
  114. package/esm/fields/field.js +0 -74
  115. package/esm/fields/field.js.map +0 -1
  116. package/esm/fields/has-inverse-field.d.ts +0 -4
  117. package/esm/fields/has-inverse-field.js +0 -2
  118. package/esm/fields/has-inverse-field.js.map +0 -1
  119. package/esm/fields/has-many-field.d.ts +0 -64
  120. package/esm/fields/has-many-field.js +0 -58
  121. package/esm/fields/has-many-field.js.map +0 -1
  122. package/esm/fields/has-one-field.d.ts +0 -64
  123. package/esm/fields/has-one-field.js +0 -57
  124. package/esm/fields/has-one-field.js.map +0 -1
  125. package/esm/fields/index.d.ts +0 -40
  126. package/esm/fields/index.js +0 -21
  127. package/esm/fields/index.js.map +0 -1
  128. package/esm/fields/json-field.d.ts +0 -14
  129. package/esm/fields/json-field.js +0 -17
  130. package/esm/fields/json-field.js.map +0 -1
  131. package/esm/fields/number-field.d.ts +0 -32
  132. package/esm/fields/number-field.js +0 -28
  133. package/esm/fields/number-field.js.map +0 -1
  134. package/esm/fields/password-field.d.ts +0 -21
  135. package/esm/fields/password-field.js +0 -71
  136. package/esm/fields/password-field.js.map +0 -1
  137. package/esm/fields/radio-field.d.ts +0 -14
  138. package/esm/fields/radio-field.js +0 -49
  139. package/esm/fields/radio-field.js.map +0 -1
  140. package/esm/fields/relation-field.d.ts +0 -20
  141. package/esm/fields/relation-field.js +0 -27
  142. package/esm/fields/relation-field.js.map +0 -1
  143. package/esm/fields/sort-field.d.ts +0 -16
  144. package/esm/fields/sort-field.js +0 -90
  145. package/esm/fields/sort-field.js.map +0 -1
  146. package/esm/fields/string-field.d.ts +0 -8
  147. package/esm/fields/string-field.js +0 -8
  148. package/esm/fields/string-field.js.map +0 -1
  149. package/esm/fields/text-field.d.ts +0 -8
  150. package/esm/fields/text-field.js +0 -8
  151. package/esm/fields/text-field.js.map +0 -1
  152. package/esm/fields/time-field.d.ts +0 -8
  153. package/esm/fields/time-field.js +0 -8
  154. package/esm/fields/time-field.js.map +0 -1
  155. package/esm/fields/uid-field.d.ts +0 -10
  156. package/esm/fields/uid-field.js +0 -27
  157. package/esm/fields/uid-field.js.map +0 -1
  158. package/esm/fields/virtual-field.d.ts +0 -8
  159. package/esm/fields/virtual-field.js +0 -8
  160. package/esm/fields/virtual-field.js.map +0 -1
  161. package/esm/filter-parser.d.ts +0 -27
  162. package/esm/filter-parser.js +0 -185
  163. package/esm/filter-parser.js.map +0 -1
  164. package/esm/index.d.ts +0 -15
  165. package/esm/index.js +0 -16
  166. package/esm/index.js.map +0 -1
  167. package/esm/magic-attribute-model.d.ts +0 -7
  168. package/esm/magic-attribute-model.js +0 -70
  169. package/esm/magic-attribute-model.js.map +0 -1
  170. package/esm/mock-database.d.ts +0 -22
  171. package/esm/mock-database.js +0 -34
  172. package/esm/mock-database.js.map +0 -1
  173. package/esm/model-hook.d.ts +0 -12
  174. package/esm/model-hook.js +0 -61
  175. package/esm/model-hook.js.map +0 -1
  176. package/esm/model.d.ts +0 -15
  177. package/esm/model.js +0 -80
  178. package/esm/model.js.map +0 -1
  179. package/esm/operators/array.d.ts +0 -26
  180. package/esm/operators/array.js +0 -105
  181. package/esm/operators/array.js.map +0 -1
  182. package/esm/operators/association.d.ts +0 -10
  183. package/esm/operators/association.js +0 -14
  184. package/esm/operators/association.js.map +0 -1
  185. package/esm/operators/date.d.ts +0 -34
  186. package/esm/operators/date.js +0 -35
  187. package/esm/operators/date.js.map +0 -1
  188. package/esm/operators/empty.d.ts +0 -28
  189. package/esm/operators/empty.js +0 -58
  190. package/esm/operators/empty.js.map +0 -1
  191. package/esm/operators/index.d.ts +0 -2
  192. package/esm/operators/index.js +0 -2
  193. package/esm/operators/index.js.map +0 -1
  194. package/esm/operators/ne.js +0 -12
  195. package/esm/operators/ne.js.map +0 -1
  196. package/esm/operators/string.d.ts +0 -21
  197. package/esm/operators/string.js +0 -35
  198. package/esm/operators/string.js.map +0 -1
  199. package/esm/operators/utils.d.ts +0 -4
  200. package/esm/operators/utils.js +0 -11
  201. package/esm/operators/utils.js.map +0 -1
  202. package/esm/options-parser.d.ts +0 -31
  203. package/esm/options-parser.js +0 -225
  204. package/esm/options-parser.js.map +0 -1
  205. package/esm/playground.d.ts +0 -1
  206. package/esm/playground.js +0 -53
  207. package/esm/playground.js.map +0 -1
  208. package/esm/relation-repository/belongs-to-many-repository.d.ts +0 -36
  209. package/esm/relation-repository/belongs-to-many-repository.js +0 -199
  210. package/esm/relation-repository/belongs-to-many-repository.js.map +0 -1
  211. package/esm/relation-repository/belongs-to-repository.d.ts +0 -17
  212. package/esm/relation-repository/belongs-to-repository.js +0 -4
  213. package/esm/relation-repository/belongs-to-repository.js.map +0 -1
  214. package/esm/relation-repository/hasmany-repository.d.ts +0 -23
  215. package/esm/relation-repository/hasmany-repository.js +0 -125
  216. package/esm/relation-repository/hasmany-repository.js.map +0 -1
  217. package/esm/relation-repository/hasone-repository.d.ts +0 -17
  218. package/esm/relation-repository/hasone-repository.js +0 -4
  219. package/esm/relation-repository/hasone-repository.js.map +0 -1
  220. package/esm/relation-repository/multiple-relation-repository.d.ts +0 -23
  221. package/esm/relation-repository/multiple-relation-repository.js +0 -149
  222. package/esm/relation-repository/multiple-relation-repository.js.map +0 -1
  223. package/esm/relation-repository/relation-repository.d.ts +0 -32
  224. package/esm/relation-repository/relation-repository.js +0 -93
  225. package/esm/relation-repository/relation-repository.js.map +0 -1
  226. package/esm/relation-repository/single-relation-repository.d.ts +0 -23
  227. package/esm/relation-repository/single-relation-repository.js +0 -96
  228. package/esm/relation-repository/single-relation-repository.js.map +0 -1
  229. package/esm/relation-repository/types.d.ts +0 -7
  230. package/esm/relation-repository/types.js +0 -2
  231. package/esm/relation-repository/types.js.map +0 -1
  232. package/esm/repository.d.ts +0 -165
  233. package/esm/repository.js +0 -276
  234. package/esm/repository.js.map +0 -1
  235. package/esm/transaction-decorator.d.ts +0 -1
  236. package/esm/transaction-decorator.js +0 -63
  237. package/esm/transaction-decorator.js.map +0 -1
  238. package/esm/update-associations.d.ts +0 -60
  239. package/esm/update-associations.js +0 -362
  240. package/esm/update-associations.js.map +0 -1
  241. package/esm/update-guard.d.ts +0 -26
  242. package/esm/update-guard.js +0 -122
  243. package/esm/update-guard.js.map +0 -1
  244. package/lib/collection-importer.js.map +0 -1
  245. package/lib/collection.js.map +0 -1
  246. package/lib/database.js.map +0 -1
  247. package/lib/fields/array-field.js.map +0 -1
  248. package/lib/fields/belongs-to-field.js.map +0 -1
  249. package/lib/fields/belongs-to-many-field.js.map +0 -1
  250. package/lib/fields/boolean-field.js.map +0 -1
  251. package/lib/fields/context-field.js.map +0 -1
  252. package/lib/fields/date-field.js.map +0 -1
  253. package/lib/fields/field.js.map +0 -1
  254. package/lib/fields/has-inverse-field.js.map +0 -1
  255. package/lib/fields/has-many-field.js.map +0 -1
  256. package/lib/fields/has-one-field.js.map +0 -1
  257. package/lib/fields/index.js.map +0 -1
  258. package/lib/fields/json-field.js.map +0 -1
  259. package/lib/fields/number-field.js.map +0 -1
  260. package/lib/fields/password-field.js.map +0 -1
  261. package/lib/fields/radio-field.js.map +0 -1
  262. package/lib/fields/relation-field.js.map +0 -1
  263. package/lib/fields/sort-field.js.map +0 -1
  264. package/lib/fields/string-field.js.map +0 -1
  265. package/lib/fields/text-field.js.map +0 -1
  266. package/lib/fields/time-field.js.map +0 -1
  267. package/lib/fields/uid-field.js.map +0 -1
  268. package/lib/fields/virtual-field.js.map +0 -1
  269. package/lib/filter-parser.js.map +0 -1
  270. package/lib/index.js.map +0 -1
  271. package/lib/magic-attribute-model.js.map +0 -1
  272. package/lib/mock-database.js.map +0 -1
  273. package/lib/model-hook.js.map +0 -1
  274. package/lib/model.js.map +0 -1
  275. package/lib/operators/array.js.map +0 -1
  276. package/lib/operators/association.js.map +0 -1
  277. package/lib/operators/date.js.map +0 -1
  278. package/lib/operators/empty.js.map +0 -1
  279. package/lib/operators/index.js.map +0 -1
  280. package/lib/operators/ne.js.map +0 -1
  281. package/lib/operators/string.js.map +0 -1
  282. package/lib/operators/utils.js.map +0 -1
  283. package/lib/options-parser.js.map +0 -1
  284. package/lib/playground.js.map +0 -1
  285. package/lib/relation-repository/belongs-to-many-repository.js.map +0 -1
  286. package/lib/relation-repository/belongs-to-repository.js.map +0 -1
  287. package/lib/relation-repository/hasmany-repository.js.map +0 -1
  288. package/lib/relation-repository/hasone-repository.js.map +0 -1
  289. package/lib/relation-repository/multiple-relation-repository.js.map +0 -1
  290. package/lib/relation-repository/relation-repository.js.map +0 -1
  291. package/lib/relation-repository/single-relation-repository.js.map +0 -1
  292. package/lib/relation-repository/types.js.map +0 -1
  293. package/lib/repository.js.map +0 -1
  294. package/lib/transaction-decorator.js.map +0 -1
  295. package/lib/update-associations.js.map +0 -1
  296. package/lib/update-guard.js.map +0 -1
  297. package/tsconfig.build.json +0 -9
  298. package/tsconfig.json +0 -5
@@ -1,81 +1,120 @@
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.Field = void 0;
16
- const lodash_1 = __importDefault(require("lodash"));
7
+
8
+ function _lodash() {
9
+ const data = _interopRequireDefault(require("lodash"));
10
+
11
+ _lodash = function _lodash() {
12
+ return data;
13
+ };
14
+
15
+ return data;
16
+ }
17
+
18
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19
+
20
+ 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; }
21
+
22
+ 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; }
23
+
24
+ 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; }
25
+
26
+ 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); } }
27
+
28
+ 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); }); }; }
29
+
17
30
  class Field {
18
- constructor(options, context) {
19
- this.context = context;
20
- this.database = context.database;
21
- this.collection = context.collection;
22
- this.options = options || {};
23
- this.init();
24
- }
25
- get name() {
26
- return this.options.name;
27
- }
28
- get type() {
29
- return this.options.type;
30
- }
31
- get dataType() {
32
- return this.options.dataType;
33
- }
34
- // TODO
35
- sync(syncOptions) {
36
- return __awaiter(this, void 0, void 0, function* () {
37
- yield this.collection.sync(Object.assign(Object.assign({}, syncOptions), { force: false, alter: {
38
- drop: false,
39
- } }));
40
- });
41
- }
42
- init() {
43
- // code
44
- }
45
- on(eventName, listener) {
46
- this.database.on(`${this.collection.name}.${eventName}`, listener);
47
- return this;
48
- }
49
- off(eventName, listener) {
50
- this.database.off(`${this.collection.name}.${eventName}`, listener);
51
- return this;
52
- }
53
- get(name) {
54
- return this.options[name];
55
- }
56
- merge(obj) {
57
- Object.assign(this.options, obj);
58
- }
59
- bind() {
60
- const { model } = this.context.collection;
61
- model.rawAttributes[this.name] = this.toSequelize();
62
- // @ts-ignore
63
- model.refreshAttributes();
64
- }
65
- unbind() {
66
- const { model } = this.context.collection;
67
- model.removeAttribute(this.name);
68
- }
69
- toSequelize() {
70
- const opts = lodash_1.default.omit(this.options, ['name']);
71
- if (this.dataType) {
72
- Object.assign(opts, { type: this.dataType });
31
+ get name() {
32
+ return this.options.name;
33
+ }
34
+
35
+ get type() {
36
+ return this.options.type;
37
+ }
38
+
39
+ get dataType() {
40
+ return this.options.dataType;
41
+ }
42
+
43
+ constructor(options, context) {
44
+ this.options = void 0;
45
+ this.context = void 0;
46
+ this.database = void 0;
47
+ this.collection = void 0;
48
+ this.context = context;
49
+ this.database = context.database;
50
+ this.collection = context.collection;
51
+ this.options = options || {};
52
+ this.init();
53
+ } // TODO
54
+
55
+
56
+ sync(syncOptions) {
57
+ var _this = this;
58
+
59
+ return _asyncToGenerator(function* () {
60
+ yield _this.collection.sync(_objectSpread(_objectSpread({}, syncOptions), {}, {
61
+ force: false,
62
+ alter: {
63
+ drop: false
73
64
  }
74
- return opts;
75
- }
76
- isSqlite() {
77
- return this.database.sequelize.getDialect() === 'sqlite';
65
+ }));
66
+ })();
67
+ }
68
+
69
+ init() {// code
70
+ }
71
+
72
+ on(eventName, listener) {
73
+ this.database.on(`${this.collection.name}.${eventName}`, listener);
74
+ return this;
75
+ }
76
+
77
+ off(eventName, listener) {
78
+ this.database.off(`${this.collection.name}.${eventName}`, listener);
79
+ return this;
80
+ }
81
+
82
+ get(name) {
83
+ return this.options[name];
84
+ }
85
+
86
+ merge(obj) {
87
+ Object.assign(this.options, obj);
88
+ }
89
+
90
+ bind() {
91
+ const model = this.context.collection.model;
92
+ model.rawAttributes[this.name] = this.toSequelize(); // @ts-ignore
93
+
94
+ model.refreshAttributes();
95
+ }
96
+
97
+ unbind() {
98
+ const model = this.context.collection.model;
99
+ model.removeAttribute(this.name);
100
+ }
101
+
102
+ toSequelize() {
103
+ const opts = _lodash().default.omit(this.options, ['name']);
104
+
105
+ if (this.dataType) {
106
+ Object.assign(opts, {
107
+ type: this.dataType
108
+ });
78
109
  }
110
+
111
+ return opts;
112
+ }
113
+
114
+ isSqlite() {
115
+ return this.database.sequelize.getDialect() === 'sqlite';
116
+ }
117
+
79
118
  }
80
- exports.Field = Field;
81
- //# sourceMappingURL=field.js.map
119
+
120
+ exports.Field = Field;
@@ -1,3 +1,5 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=has-inverse-field.js.map
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
@@ -1,62 +1,111 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
3
6
  exports.HasManyField = void 0;
4
- const lodash_1 = require("lodash");
5
- const sequelize_1 = require("sequelize");
6
- const relation_field_1 = require("./relation-field");
7
- class HasManyField extends relation_field_1.RelationField {
8
- get foreignKey() {
9
- if (this.options.foreignKey) {
10
- return this.options.foreignKey;
11
- }
12
- const { model } = this.context.collection;
13
- return sequelize_1.Utils.camelize([model.options.name.singular, this.sourceKey || model.primaryKeyAttribute].join('_'));
7
+
8
+ function _lodash() {
9
+ const data = require("lodash");
10
+
11
+ _lodash = function _lodash() {
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 _relationField = require("./relation-field");
29
+
30
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
31
+
32
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
33
+
34
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
35
+
36
+ class HasManyField extends _relationField.RelationField {
37
+ get foreignKey() {
38
+ if (this.options.foreignKey) {
39
+ return this.options.foreignKey;
14
40
  }
15
- bind() {
16
- const { database, collection } = this.context;
17
- const Target = this.TargetModel;
18
- if (!Target) {
19
- database.addPendingField(this);
20
- return false;
21
- }
22
- if (collection.model.associations[this.name]) {
23
- delete collection.model.associations[this.name];
24
- }
25
- const association = collection.model.hasMany(Target, Object.assign({ as: this.name, foreignKey: this.foreignKey }, (0, lodash_1.omit)(this.options, ['name', 'type', 'target'])));
26
- // inverse relation
27
- // this.TargetModel.belongsTo(collection.model);
28
- // 建立关系之后从 pending 列表中删除
29
- database.removePendingField(this);
30
- if (!this.options.foreignKey) {
31
- this.options.foreignKey = association.foreignKey;
32
- }
33
- if (!this.options.sourceKey) {
34
- // @ts-ignore
35
- this.options.sourceKey = association.sourceKey;
36
- }
37
- return true;
41
+
42
+ const model = this.context.collection.model;
43
+ return _sequelize().Utils.camelize([model.options.name.singular, this.sourceKey || model.primaryKeyAttribute].join('_'));
44
+ }
45
+
46
+ bind() {
47
+ const _this$context = this.context,
48
+ database = _this$context.database,
49
+ collection = _this$context.collection;
50
+ const Target = this.TargetModel;
51
+
52
+ if (!Target) {
53
+ database.addPendingField(this);
54
+ return false;
38
55
  }
39
- unbind() {
40
- const { database, collection } = this.context;
41
- // 如果关系字段还没建立就删除了,也同步删除待建立关联的关系字段
42
- database.removePendingField(this);
43
- // 如果关系表内没有显式的创建外键字段,删除关系时,外键也删除掉
44
- const tcoll = database.collections.get(this.target);
45
- const foreignKey = this.options.foreignKey;
46
- const field = tcoll.findField((field) => {
47
- if (field.name === foreignKey) {
48
- return true;
49
- }
50
- return field.type === 'belongsTo' && field.foreignKey === foreignKey;
51
- });
52
- if (!field) {
53
- tcoll.model.removeAttribute(foreignKey);
54
- }
55
- // 删掉 model 的关联字段
56
- delete collection.model.associations[this.name];
57
- // @ts-ignore
58
- collection.model.refreshAttributes();
56
+
57
+ if (collection.model.associations[this.name]) {
58
+ delete collection.model.associations[this.name];
59
59
  }
60
+
61
+ const association = collection.model.hasMany(Target, _objectSpread({
62
+ as: this.name,
63
+ foreignKey: this.foreignKey
64
+ }, (0, _lodash().omit)(this.options, ['name', 'type', 'target']))); // inverse relation
65
+ // this.TargetModel.belongsTo(collection.model);
66
+ // 建立关系之后从 pending 列表中删除
67
+
68
+ database.removePendingField(this);
69
+
70
+ if (!this.options.foreignKey) {
71
+ this.options.foreignKey = association.foreignKey;
72
+ }
73
+
74
+ if (!this.options.sourceKey) {
75
+ // @ts-ignore
76
+ this.options.sourceKey = association.sourceKey;
77
+ }
78
+
79
+ return true;
80
+ }
81
+
82
+ unbind() {
83
+ const _this$context2 = this.context,
84
+ database = _this$context2.database,
85
+ collection = _this$context2.collection; // 如果关系字段还没建立就删除了,也同步删除待建立关联的关系字段
86
+
87
+ database.removePendingField(this); // 如果关系表内没有显式的创建外键字段,删除关系时,外键也删除掉
88
+
89
+ const tcoll = database.collections.get(this.target);
90
+ const foreignKey = this.options.foreignKey;
91
+ const field = tcoll.findField(field => {
92
+ if (field.name === foreignKey) {
93
+ return true;
94
+ }
95
+
96
+ return field.type === 'belongsTo' && field.foreignKey === foreignKey;
97
+ });
98
+
99
+ if (!field) {
100
+ tcoll.model.removeAttribute(foreignKey);
101
+ } // 删掉 model 的关联字段
102
+
103
+
104
+ delete collection.model.associations[this.name]; // @ts-ignore
105
+
106
+ collection.model.refreshAttributes();
107
+ }
108
+
60
109
  }
61
- exports.HasManyField = HasManyField;
62
- //# sourceMappingURL=has-many-field.js.map
110
+
111
+ exports.HasManyField = HasManyField;
@@ -1,61 +1,112 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
3
6
  exports.HasOneField = void 0;
4
- const lodash_1 = require("lodash");
5
- const sequelize_1 = require("sequelize");
6
- const relation_field_1 = require("./relation-field");
7
- class HasOneField extends relation_field_1.RelationField {
8
- get target() {
9
- const { target, name } = this.options;
10
- return target || sequelize_1.Utils.pluralize(name);
7
+
8
+ function _lodash() {
9
+ const data = require("lodash");
10
+
11
+ _lodash = function _lodash() {
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 _relationField = require("./relation-field");
29
+
30
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
31
+
32
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
33
+
34
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
35
+
36
+ class HasOneField extends _relationField.RelationField {
37
+ get target() {
38
+ const _this$options = this.options,
39
+ target = _this$options.target,
40
+ name = _this$options.name;
41
+ return target || _sequelize().Utils.pluralize(name);
42
+ }
43
+
44
+ get foreignKey() {
45
+ if (this.options.foreignKey) {
46
+ return this.options.foreignKey;
11
47
  }
12
- get foreignKey() {
13
- if (this.options.foreignKey) {
14
- return this.options.foreignKey;
15
- }
16
- const { model } = this.context.collection;
17
- return sequelize_1.Utils.camelize([model.options.name.singular, model.primaryKeyAttribute].join('_'));
48
+
49
+ const model = this.context.collection.model;
50
+ return _sequelize().Utils.camelize([model.options.name.singular, model.primaryKeyAttribute].join('_'));
51
+ }
52
+
53
+ bind() {
54
+ const _this$context = this.context,
55
+ database = _this$context.database,
56
+ collection = _this$context.collection;
57
+ const Target = this.TargetModel;
58
+
59
+ if (!Target) {
60
+ database.addPendingField(this);
61
+ return false;
18
62
  }
19
- bind() {
20
- const { database, collection } = this.context;
21
- const Target = this.TargetModel;
22
- if (!Target) {
23
- database.addPendingField(this);
24
- return false;
25
- }
26
- const association = collection.model.hasOne(Target, Object.assign({ as: this.name, foreignKey: this.foreignKey }, (0, lodash_1.omit)(this.options, ['name', 'type', 'target'])));
27
- // 建立关系之后从 pending 列表中删除
28
- database.removePendingField(this);
29
- if (!this.options.foreignKey) {
30
- this.options.foreignKey = association.foreignKey;
31
- }
32
- if (!this.options.sourceKey) {
33
- // @ts-ignore
34
- this.options.sourceKey = association.sourceKey;
35
- }
36
- return true;
63
+
64
+ const association = collection.model.hasOne(Target, _objectSpread({
65
+ as: this.name,
66
+ foreignKey: this.foreignKey
67
+ }, (0, _lodash().omit)(this.options, ['name', 'type', 'target']))); // 建立关系之后从 pending 列表中删除
68
+
69
+ database.removePendingField(this);
70
+
71
+ if (!this.options.foreignKey) {
72
+ this.options.foreignKey = association.foreignKey;
37
73
  }
38
- unbind() {
39
- const { database, collection } = this.context;
40
- // 如果关系字段还没建立就删除了,也同步删除待建立关联的关系字段
41
- database.removePendingField(this);
42
- // 如果关系表内没有显式的创建外键字段,删除关系时,外键也删除掉
43
- const tcoll = database.collections.get(this.target);
44
- const foreignKey = this.options.foreignKey;
45
- const field = tcoll.findField((field) => {
46
- if (field.name === foreignKey) {
47
- return true;
48
- }
49
- return field.type === 'belongsTo' && field.foreignKey === foreignKey;
50
- });
51
- if (!field) {
52
- tcoll.model.removeAttribute(foreignKey);
53
- }
54
- // 删掉 model 的关联字段
55
- delete collection.model.associations[this.name];
56
- // @ts-ignore
57
- collection.model.refreshAttributes();
74
+
75
+ if (!this.options.sourceKey) {
76
+ // @ts-ignore
77
+ this.options.sourceKey = association.sourceKey;
58
78
  }
79
+
80
+ return true;
81
+ }
82
+
83
+ unbind() {
84
+ const _this$context2 = this.context,
85
+ database = _this$context2.database,
86
+ collection = _this$context2.collection; // 如果关系字段还没建立就删除了,也同步删除待建立关联的关系字段
87
+
88
+ database.removePendingField(this); // 如果关系表内没有显式的创建外键字段,删除关系时,外键也删除掉
89
+
90
+ const tcoll = database.collections.get(this.target);
91
+ const foreignKey = this.options.foreignKey;
92
+ const field = tcoll.findField(field => {
93
+ if (field.name === foreignKey) {
94
+ return true;
95
+ }
96
+
97
+ return field.type === 'belongsTo' && field.foreignKey === foreignKey;
98
+ });
99
+
100
+ if (!field) {
101
+ tcoll.model.removeAttribute(foreignKey);
102
+ } // 删掉 model 的关联字段
103
+
104
+
105
+ delete collection.model.associations[this.name]; // @ts-ignore
106
+
107
+ collection.model.refreshAttributes();
108
+ }
109
+
59
110
  }
60
- exports.HasOneField = HasOneField;
61
- //# sourceMappingURL=has-one-field.js.map
111
+
112
+ exports.HasOneField = HasOneField;
@@ -16,6 +16,7 @@ import { StringFieldOptions } from './string-field';
16
16
  import { TextFieldOptions } from './text-field';
17
17
  import { TimeFieldOptions } from './time-field';
18
18
  import { UidFieldOptions } from './uid-field';
19
+ import { UUIDFieldOptions } from './uuid-field';
19
20
  import { VirtualFieldOptions } from './virtual-field';
20
21
  export * from './array-field';
21
22
  export * from './belongs-to-field';
@@ -36,5 +37,6 @@ export * from './string-field';
36
37
  export * from './text-field';
37
38
  export * from './time-field';
38
39
  export * from './uid-field';
40
+ export * from './uuid-field';
39
41
  export * from './virtual-field';
40
- export declare type FieldOptions = BaseFieldOptions | StringFieldOptions | IntegerFieldOptions | FloatFieldOptions | DecimalFieldOptions | DoubleFieldOptions | RealFieldOptions | JsonFieldOptions | JsonbFieldOptions | BooleanFieldOptions | RadioFieldOptions | SortFieldOptions | TextFieldOptions | VirtualFieldOptions | ArrayFieldOptions | TimeFieldOptions | DateFieldOptions | UidFieldOptions | PasswordFieldOptions | ContextFieldOptions | BelongsToFieldOptions | HasOneFieldOptions | HasManyFieldOptions | BelongsToManyFieldOptions;
42
+ export declare type FieldOptions = BaseFieldOptions | StringFieldOptions | IntegerFieldOptions | FloatFieldOptions | DecimalFieldOptions | DoubleFieldOptions | RealFieldOptions | JsonFieldOptions | JsonbFieldOptions | BooleanFieldOptions | RadioFieldOptions | SortFieldOptions | TextFieldOptions | VirtualFieldOptions | ArrayFieldOptions | TimeFieldOptions | DateFieldOptions | UidFieldOptions | UUIDFieldOptions | PasswordFieldOptions | ContextFieldOptions | BelongsToFieldOptions | HasOneFieldOptions | HasManyFieldOptions | BelongsToManyFieldOptions;