@nocobase/database 1.2.13-alpha → 1.3.0-alpha.20240710084543

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 (247) hide show
  1. package/package.json +4 -4
  2. package/lib/collection-factory.d.ts +0 -25
  3. package/lib/collection-factory.js +0 -61
  4. package/lib/collection-group-manager.d.ts +0 -34
  5. package/lib/collection-group-manager.js +0 -66
  6. package/lib/collection-importer.d.ts +0 -15
  7. package/lib/collection-importer.js +0 -83
  8. package/lib/collection.d.ts +0 -145
  9. package/lib/collection.js +0 -663
  10. package/lib/database-utils/index.d.ts +0 -16
  11. package/lib/database-utils/index.js +0 -75
  12. package/lib/database.d.ts +0 -228
  13. package/lib/database.js +0 -795
  14. package/lib/decorators/must-have-filter-decorator.d.ts +0 -10
  15. package/lib/decorators/must-have-filter-decorator.js +0 -48
  16. package/lib/decorators/target-collection-decorator.d.ts +0 -10
  17. package/lib/decorators/target-collection-decorator.js +0 -56
  18. package/lib/decorators/transaction-decorator.d.ts +0 -9
  19. package/lib/decorators/transaction-decorator.js +0 -95
  20. package/lib/eager-loading/eager-loading-tree.d.ts +0 -39
  21. package/lib/eager-loading/eager-loading-tree.js +0 -448
  22. package/lib/errors/identifier-error.d.ts +0 -11
  23. package/lib/errors/identifier-error.js +0 -44
  24. package/lib/errors/zero-column-table-error.d.ts +0 -10
  25. package/lib/errors/zero-column-table-error.js +0 -40
  26. package/lib/features/references-map.d.ts +0 -29
  27. package/lib/features/references-map.js +0 -120
  28. package/lib/features/referential-integrity-check.d.ts +0 -16
  29. package/lib/features/referential-integrity-check.js +0 -86
  30. package/lib/field-repository/array-field-repository.d.ts +0 -36
  31. package/lib/field-repository/array-field-repository.js +0 -179
  32. package/lib/fields/array-field.d.ts +0 -19
  33. package/lib/fields/array-field.js +0 -66
  34. package/lib/fields/belongs-to-field.d.ts +0 -25
  35. package/lib/fields/belongs-to-field.js +0 -166
  36. package/lib/fields/belongs-to-many-field.d.ts +0 -28
  37. package/lib/fields/belongs-to-many-field.js +0 -196
  38. package/lib/fields/boolean-field.d.ts +0 -16
  39. package/lib/fields/boolean-field.js +0 -45
  40. package/lib/fields/context-field.d.ts +0 -22
  41. package/lib/fields/context-field.js +0 -79
  42. package/lib/fields/date-field.d.ts +0 -21
  43. package/lib/fields/date-field.js +0 -73
  44. package/lib/fields/field.d.ts +0 -52
  45. package/lib/fields/field.js +0 -168
  46. package/lib/fields/has-inverse-field.d.ts +0 -12
  47. package/lib/fields/has-inverse-field.js +0 -24
  48. package/lib/fields/has-many-field.d.ts +0 -76
  49. package/lib/fields/has-many-field.js +0 -165
  50. package/lib/fields/has-one-field.d.ts +0 -76
  51. package/lib/fields/has-one-field.js +0 -159
  52. package/lib/fields/index.d.ts +0 -54
  53. package/lib/fields/index.js +0 -74
  54. package/lib/fields/json-field.d.ts +0 -22
  55. package/lib/fields/json-field.js +0 -63
  56. package/lib/fields/nanoid-field.d.ts +0 -22
  57. package/lib/fields/nanoid-field.js +0 -65
  58. package/lib/fields/number-field.d.ts +0 -49
  59. package/lib/fields/number-field.js +0 -94
  60. package/lib/fields/password-field.d.ts +0 -29
  61. package/lib/fields/password-field.js +0 -106
  62. package/lib/fields/radio-field.d.ts +0 -24
  63. package/lib/fields/radio-field.js +0 -75
  64. package/lib/fields/relation-field.d.ts +0 -31
  65. package/lib/fields/relation-field.js +0 -94
  66. package/lib/fields/set-field.d.ts +0 -18
  67. package/lib/fields/set-field.js +0 -55
  68. package/lib/fields/sort-field.d.ts +0 -22
  69. package/lib/fields/sort-field.js +0 -197
  70. package/lib/fields/string-field.d.ts +0 -16
  71. package/lib/fields/string-field.js +0 -45
  72. package/lib/fields/text-field.d.ts +0 -18
  73. package/lib/fields/text-field.js +0 -53
  74. package/lib/fields/time-field.d.ts +0 -16
  75. package/lib/fields/time-field.js +0 -45
  76. package/lib/fields/uid-field.d.ts +0 -21
  77. package/lib/fields/uid-field.js +0 -72
  78. package/lib/fields/uuid-field.d.ts +0 -20
  79. package/lib/fields/uuid-field.js +0 -63
  80. package/lib/fields/virtual-field.d.ts +0 -16
  81. package/lib/fields/virtual-field.js +0 -45
  82. package/lib/filter-match.d.ts +0 -9
  83. package/lib/filter-match.js +0 -75
  84. package/lib/filter-parser.d.ts +0 -29
  85. package/lib/filter-parser.js +0 -238
  86. package/lib/helpers.d.ts +0 -11
  87. package/lib/helpers.js +0 -182
  88. package/lib/index.d.ts +0 -37
  89. package/lib/index.js +0 -138
  90. package/lib/inherited-collection.d.ts +0 -22
  91. package/lib/inherited-collection.js +0 -147
  92. package/lib/inherited-map.d.ts +0 -29
  93. package/lib/inherited-map.js +0 -125
  94. package/lib/inherited-sync-runner.d.ts +0 -12
  95. package/lib/inherited-sync-runner.js +0 -184
  96. package/lib/interface-manager.d.ts +0 -17
  97. package/lib/interface-manager.js +0 -50
  98. package/lib/interfaces/base-interface.d.ts +0 -33
  99. package/lib/interfaces/base-interface.js +0 -80
  100. package/lib/interfaces/boolean-interface.d.ts +0 -13
  101. package/lib/interfaces/boolean-interface.js +0 -70
  102. package/lib/interfaces/checkboxes-interface.d.ts +0 -11
  103. package/lib/interfaces/checkboxes-interface.js +0 -41
  104. package/lib/interfaces/datetime-interface.d.ts +0 -13
  105. package/lib/interfaces/datetime-interface.js +0 -108
  106. package/lib/interfaces/index.d.ts +0 -14
  107. package/lib/interfaces/index.js +0 -40
  108. package/lib/interfaces/integer-interface.d.ts +0 -12
  109. package/lib/interfaces/integer-interface.js +0 -44
  110. package/lib/interfaces/json-interface.d.ts +0 -13
  111. package/lib/interfaces/json-interface.js +0 -47
  112. package/lib/interfaces/many-to-many-interface.d.ts +0 -11
  113. package/lib/interfaces/many-to-many-interface.js +0 -41
  114. package/lib/interfaces/many-to-one-interface.d.ts +0 -11
  115. package/lib/interfaces/many-to-one-interface.js +0 -41
  116. package/lib/interfaces/multiple-select-interface.d.ts +0 -13
  117. package/lib/interfaces/multiple-select-interface.js +0 -76
  118. package/lib/interfaces/number-interface.d.ts +0 -15
  119. package/lib/interfaces/number-interface.js +0 -72
  120. package/lib/interfaces/one-belongs-to-one-interface.d.ts +0 -11
  121. package/lib/interfaces/one-belongs-to-one-interface.js +0 -41
  122. package/lib/interfaces/one-has-one-interface.d.ts +0 -11
  123. package/lib/interfaces/one-has-one-interface.js +0 -41
  124. package/lib/interfaces/one-to-many-interface.d.ts +0 -11
  125. package/lib/interfaces/one-to-many-interface.js +0 -41
  126. package/lib/interfaces/percent-interface.d.ts +0 -13
  127. package/lib/interfaces/percent-interface.js +0 -55
  128. package/lib/interfaces/select-interface.d.ts +0 -13
  129. package/lib/interfaces/select-interface.js +0 -63
  130. package/lib/interfaces/to-many-interface.d.ts +0 -12
  131. package/lib/interfaces/to-many-interface.js +0 -61
  132. package/lib/interfaces/to-one-interface.d.ts +0 -13
  133. package/lib/interfaces/to-one-interface.js +0 -61
  134. package/lib/interfaces/utils.d.ts +0 -10
  135. package/lib/interfaces/utils.js +0 -72
  136. package/lib/listeners/adjacency-list.d.ts +0 -10
  137. package/lib/listeners/adjacency-list.js +0 -51
  138. package/lib/listeners/append-child-collection-name-after-repository-find.d.ts +0 -14
  139. package/lib/listeners/append-child-collection-name-after-repository-find.js +0 -75
  140. package/lib/listeners/index.d.ts +0 -10
  141. package/lib/listeners/index.js +0 -42
  142. package/lib/magic-attribute-model.d.ts +0 -16
  143. package/lib/magic-attribute-model.js +0 -213
  144. package/lib/migration.d.ts +0 -43
  145. package/lib/migration.js +0 -112
  146. package/lib/mock-database.d.ts +0 -33
  147. package/lib/mock-database.js +0 -136
  148. package/lib/model-hook.d.ts +0 -20
  149. package/lib/model-hook.js +0 -96
  150. package/lib/model.d.ts +0 -32
  151. package/lib/model.js +0 -179
  152. package/lib/operators/array.d.ts +0 -10
  153. package/lib/operators/array.js +0 -196
  154. package/lib/operators/association.d.ts +0 -10
  155. package/lib/operators/association.js +0 -44
  156. package/lib/operators/boolean.d.ts +0 -10
  157. package/lib/operators/boolean.js +0 -47
  158. package/lib/operators/child-collection.d.ts +0 -10
  159. package/lib/operators/child-collection.js +0 -77
  160. package/lib/operators/date.d.ts +0 -10
  161. package/lib/operators/date.js +0 -149
  162. package/lib/operators/empty.d.ts +0 -13
  163. package/lib/operators/empty.js +0 -102
  164. package/lib/operators/eq.d.ts +0 -10
  165. package/lib/operators/eq.js +0 -44
  166. package/lib/operators/index.d.ts +0 -13
  167. package/lib/operators/index.js +0 -63
  168. package/lib/operators/ne.d.ts +0 -10
  169. package/lib/operators/ne.js +0 -49
  170. package/lib/operators/notIn.d.ts +0 -10
  171. package/lib/operators/notIn.js +0 -42
  172. package/lib/operators/string.d.ts +0 -10
  173. package/lib/operators/string.js +0 -118
  174. package/lib/operators/utils.d.ts +0 -12
  175. package/lib/operators/utils.js +0 -53
  176. package/lib/options-parser.d.ts +0 -45
  177. package/lib/options-parser.js +0 -350
  178. package/lib/query-interface/mysql-query-interface.d.ts +0 -44
  179. package/lib/query-interface/mysql-query-interface.js +0 -134
  180. package/lib/query-interface/postgres-query-interface.d.ts +0 -41
  181. package/lib/query-interface/postgres-query-interface.js +0 -207
  182. package/lib/query-interface/query-interface-builder.d.ts +0 -10
  183. package/lib/query-interface/query-interface-builder.js +0 -55
  184. package/lib/query-interface/query-interface.d.ts +0 -52
  185. package/lib/query-interface/query-interface.js +0 -59
  186. package/lib/query-interface/sqlite-query-interface.d.ts +0 -44
  187. package/lib/query-interface/sqlite-query-interface.js +0 -141
  188. package/lib/relation-repository/belongs-to-many-repository.d.ts +0 -28
  189. package/lib/relation-repository/belongs-to-many-repository.js +0 -248
  190. package/lib/relation-repository/belongs-to-repository.d.ts +0 -17
  191. package/lib/relation-repository/belongs-to-repository.js +0 -51
  192. package/lib/relation-repository/hasmany-repository.d.ts +0 -21
  193. package/lib/relation-repository/hasmany-repository.js +0 -158
  194. package/lib/relation-repository/hasone-repository.d.ts +0 -17
  195. package/lib/relation-repository/hasone-repository.js +0 -51
  196. package/lib/relation-repository/multiple-relation-repository.d.ts +0 -27
  197. package/lib/relation-repository/multiple-relation-repository.js +0 -200
  198. package/lib/relation-repository/relation-repository.d.ts +0 -38
  199. package/lib/relation-repository/relation-repository.js +0 -175
  200. package/lib/relation-repository/single-relation-repository.d.ts +0 -36
  201. package/lib/relation-repository/single-relation-repository.js +0 -151
  202. package/lib/relation-repository/types.d.ts +0 -15
  203. package/lib/relation-repository/types.js +0 -24
  204. package/lib/repositories/tree-repository/adjacency-list-repository.d.ts +0 -26
  205. package/lib/repositories/tree-repository/adjacency-list-repository.js +0 -192
  206. package/lib/repositories/view-repository.d.ts +0 -11
  207. package/lib/repositories/view-repository.js +0 -41
  208. package/lib/repository.d.ts +0 -214
  209. package/lib/repository.js +0 -609
  210. package/lib/sql-parser/index.d.ts +0 -13
  211. package/lib/sql-parser/index.js +0 -33
  212. package/lib/sync-runner.d.ts +0 -41
  213. package/lib/sync-runner.js +0 -335
  214. package/lib/types.d.ts +0 -57
  215. package/lib/types.js +0 -24
  216. package/lib/update-associations.d.ts +0 -68
  217. package/lib/update-associations.js +0 -429
  218. package/lib/update-guard.d.ts +0 -36
  219. package/lib/update-guard.js +0 -212
  220. package/lib/utils.d.ts +0 -15
  221. package/lib/utils.js +0 -136
  222. package/lib/value-parsers/array-value-parser.d.ts +0 -16
  223. package/lib/value-parsers/array-value-parser.js +0 -67
  224. package/lib/value-parsers/base-value-parser.d.ts +0 -20
  225. package/lib/value-parsers/base-value-parser.js +0 -72
  226. package/lib/value-parsers/boolean-value-parser.d.ts +0 -12
  227. package/lib/value-parsers/boolean-value-parser.js +0 -61
  228. package/lib/value-parsers/date-value-parser.d.ts +0 -13
  229. package/lib/value-parsers/date-value-parser.js +0 -99
  230. package/lib/value-parsers/index.d.ts +0 -20
  231. package/lib/value-parsers/index.js +0 -87
  232. package/lib/value-parsers/json-value-parser.d.ts +0 -12
  233. package/lib/value-parsers/json-value-parser.js +0 -56
  234. package/lib/value-parsers/number-value-parser.d.ts +0 -12
  235. package/lib/value-parsers/number-value-parser.js +0 -67
  236. package/lib/value-parsers/string-value-parser.d.ts +0 -16
  237. package/lib/value-parsers/string-value-parser.js +0 -73
  238. package/lib/value-parsers/to-many-value-parser.d.ts +0 -21
  239. package/lib/value-parsers/to-many-value-parser.js +0 -117
  240. package/lib/value-parsers/to-one-value-parser.d.ts +0 -12
  241. package/lib/value-parsers/to-one-value-parser.js +0 -57
  242. package/lib/view/field-type-map.d.ts +0 -109
  243. package/lib/view/field-type-map.js +0 -101
  244. package/lib/view/view-inference.d.ts +0 -40
  245. package/lib/view/view-inference.js +0 -157
  246. package/lib/view-collection.d.ts +0 -14
  247. package/lib/view-collection.js +0 -54
@@ -1,42 +0,0 @@
1
- /**
2
- * This file is part of the NocoBase (R) project.
3
- * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
- * Authors: NocoBase Team.
5
- *
6
- * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
- * For more information, please refer to: https://www.nocobase.com/agreement.
8
- */
9
-
10
- var __defProp = Object.defineProperty;
11
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
12
- var __getOwnPropNames = Object.getOwnPropertyNames;
13
- var __hasOwnProp = Object.prototype.hasOwnProperty;
14
- var __export = (target, all) => {
15
- for (var name in all)
16
- __defProp(target, name, { get: all[name], enumerable: true });
17
- };
18
- var __copyProps = (to, from, except, desc) => {
19
- if (from && typeof from === "object" || typeof from === "function") {
20
- for (let key of __getOwnPropNames(from))
21
- if (!__hasOwnProp.call(to, key) && key !== except)
22
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
23
- }
24
- return to;
25
- };
26
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
27
- var notIn_exports = {};
28
- __export(notIn_exports, {
29
- default: () => notIn_default
30
- });
31
- module.exports = __toCommonJS(notIn_exports);
32
- var import_sequelize = require("sequelize");
33
- var notIn_default = {
34
- $notIn(val, ctx) {
35
- return {
36
- [import_sequelize.Op.or]: {
37
- [import_sequelize.Op.notIn]: val,
38
- [import_sequelize.Op.is]: null
39
- }
40
- };
41
- }
42
- };
@@ -1,10 +0,0 @@
1
- /**
2
- * This file is part of the NocoBase (R) project.
3
- * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
- * Authors: NocoBase Team.
5
- *
6
- * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
- * For more information, please refer to: https://www.nocobase.com/agreement.
8
- */
9
- declare const _default: Record<string, any>;
10
- export default _default;
@@ -1,118 +0,0 @@
1
- /**
2
- * This file is part of the NocoBase (R) project.
3
- * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
- * Authors: NocoBase Team.
5
- *
6
- * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
- * For more information, please refer to: https://www.nocobase.com/agreement.
8
- */
9
-
10
- var __defProp = Object.defineProperty;
11
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
12
- var __getOwnPropNames = Object.getOwnPropertyNames;
13
- var __hasOwnProp = Object.prototype.hasOwnProperty;
14
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
15
- var __export = (target, all) => {
16
- for (var name in all)
17
- __defProp(target, name, { get: all[name], enumerable: true });
18
- };
19
- var __copyProps = (to, from, except, desc) => {
20
- if (from && typeof from === "object" || typeof from === "function") {
21
- for (let key of __getOwnPropNames(from))
22
- if (!__hasOwnProp.call(to, key) && key !== except)
23
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
24
- }
25
- return to;
26
- };
27
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
- var string_exports = {};
29
- __export(string_exports, {
30
- default: () => string_default
31
- });
32
- module.exports = __toCommonJS(string_exports);
33
- var import_sequelize = require("sequelize");
34
- var import_utils = require("./utils");
35
- function escapeLike(value) {
36
- return value.replace(/[_%]/g, "\\$&");
37
- }
38
- __name(escapeLike, "escapeLike");
39
- var string_default = {
40
- $includes(value, ctx) {
41
- if (Array.isArray(value)) {
42
- const conditions = value.map((item) => ({
43
- [(0, import_utils.isPg)(ctx) ? import_sequelize.Op.iLike : import_sequelize.Op.like]: `%${escapeLike(item)}%`
44
- }));
45
- return {
46
- [import_sequelize.Op.or]: conditions
47
- };
48
- }
49
- return {
50
- [(0, import_utils.isPg)(ctx) ? import_sequelize.Op.iLike : import_sequelize.Op.like]: `%${escapeLike(value)}%`
51
- };
52
- },
53
- $notIncludes(value, ctx) {
54
- if (Array.isArray(value)) {
55
- const conditions = value.map((item) => ({
56
- [(0, import_utils.isPg)(ctx) ? import_sequelize.Op.notILike : import_sequelize.Op.notLike]: `%${escapeLike(item)}%`
57
- }));
58
- return {
59
- [import_sequelize.Op.and]: conditions
60
- };
61
- }
62
- return {
63
- [(0, import_utils.isPg)(ctx) ? import_sequelize.Op.notILike : import_sequelize.Op.notLike]: `%${escapeLike(value)}%`
64
- };
65
- },
66
- $startsWith(value, ctx) {
67
- if (Array.isArray(value)) {
68
- const conditions = value.map((item) => ({
69
- [(0, import_utils.isPg)(ctx) ? import_sequelize.Op.iLike : import_sequelize.Op.like]: `${escapeLike(item)}%`
70
- }));
71
- return {
72
- [import_sequelize.Op.or]: conditions
73
- };
74
- }
75
- return {
76
- [(0, import_utils.isPg)(ctx) ? import_sequelize.Op.iLike : import_sequelize.Op.like]: `${escapeLike(value)}%`
77
- };
78
- },
79
- $notStartsWith(value, ctx) {
80
- if (Array.isArray(value)) {
81
- const conditions = value.map((item) => ({
82
- [(0, import_utils.isPg)(ctx) ? import_sequelize.Op.notILike : import_sequelize.Op.notLike]: `${escapeLike(item)}%`
83
- }));
84
- return {
85
- [import_sequelize.Op.and]: conditions
86
- };
87
- }
88
- return {
89
- [(0, import_utils.isPg)(ctx) ? import_sequelize.Op.notILike : import_sequelize.Op.notLike]: `${escapeLike(value)}%`
90
- };
91
- },
92
- $endWith(value, ctx) {
93
- if (Array.isArray(value)) {
94
- const conditions = value.map((item) => ({
95
- [(0, import_utils.isPg)(ctx) ? import_sequelize.Op.iLike : import_sequelize.Op.like]: `%${escapeLike(item)}`
96
- }));
97
- return {
98
- [import_sequelize.Op.or]: conditions
99
- };
100
- }
101
- return {
102
- [(0, import_utils.isPg)(ctx) ? import_sequelize.Op.iLike : import_sequelize.Op.like]: `%${escapeLike(value)}`
103
- };
104
- },
105
- $notEndWith(value, ctx) {
106
- if (Array.isArray(value)) {
107
- const conditions = value.map((item) => ({
108
- [(0, import_utils.isPg)(ctx) ? import_sequelize.Op.notILike : import_sequelize.Op.notLike]: `%${escapeLike(item)}`
109
- }));
110
- return {
111
- [import_sequelize.Op.and]: conditions
112
- };
113
- }
114
- return {
115
- [(0, import_utils.isPg)(ctx) ? import_sequelize.Op.notILike : import_sequelize.Op.notLike]: `%${escapeLike(value)}`
116
- };
117
- }
118
- };
@@ -1,12 +0,0 @@
1
- /**
2
- * This file is part of the NocoBase (R) project.
3
- * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
- * Authors: NocoBase Team.
5
- *
6
- * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
- * For more information, please refer to: https://www.nocobase.com/agreement.
8
- */
9
- declare const getDialect: (ctx: any) => any;
10
- declare const isPg: (ctx: any) => boolean;
11
- declare const isMySQL: (ctx: any) => boolean;
12
- export { getDialect, isPg, isMySQL };
@@ -1,53 +0,0 @@
1
- /**
2
- * This file is part of the NocoBase (R) project.
3
- * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
- * Authors: NocoBase Team.
5
- *
6
- * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
- * For more information, please refer to: https://www.nocobase.com/agreement.
8
- */
9
-
10
- var __defProp = Object.defineProperty;
11
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
12
- var __getOwnPropNames = Object.getOwnPropertyNames;
13
- var __hasOwnProp = Object.prototype.hasOwnProperty;
14
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
15
- var __export = (target, all) => {
16
- for (var name in all)
17
- __defProp(target, name, { get: all[name], enumerable: true });
18
- };
19
- var __copyProps = (to, from, except, desc) => {
20
- if (from && typeof from === "object" || typeof from === "function") {
21
- for (let key of __getOwnPropNames(from))
22
- if (!__hasOwnProp.call(to, key) && key !== except)
23
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
24
- }
25
- return to;
26
- };
27
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
- var utils_exports = {};
29
- __export(utils_exports, {
30
- getDialect: () => getDialect,
31
- isMySQL: () => isMySQL,
32
- isPg: () => isPg
33
- });
34
- module.exports = __toCommonJS(utils_exports);
35
- const getDialect = /* @__PURE__ */ __name((ctx) => {
36
- return ctx.db.sequelize.getDialect();
37
- }, "getDialect");
38
- const isPg = /* @__PURE__ */ __name((ctx) => {
39
- return getDialect(ctx) === "postgres";
40
- }, "isPg");
41
- const isMySQL = /* @__PURE__ */ __name((ctx) => {
42
- return getDialect(ctx) === "mysql" || getDialect(ctx) === "mariadb";
43
- }, "isMySQL");
44
- const getQueryInterface = /* @__PURE__ */ __name((ctx) => {
45
- const sequelize = ctx.db.sequelize;
46
- return sequelize.getQueryInterface();
47
- }, "getQueryInterface");
48
- // Annotate the CommonJS export names for ESM import in node:
49
- 0 && (module.exports = {
50
- getDialect,
51
- isMySQL,
52
- isPg
53
- });
@@ -1,45 +0,0 @@
1
- /**
2
- * This file is part of the NocoBase (R) project.
3
- * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
- * Authors: NocoBase Team.
5
- *
6
- * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
- * For more information, please refer to: https://www.nocobase.com/agreement.
8
- */
9
- import { ModelStatic } from 'sequelize';
10
- import { Collection } from './collection';
11
- import { Database } from './database';
12
- import FilterParser from './filter-parser';
13
- import { Appends, Except, FindOptions } from './repository';
14
- interface OptionsParserContext {
15
- collection: Collection;
16
- targetKey?: string;
17
- }
18
- export declare class OptionsParser {
19
- options: FindOptions;
20
- database: Database;
21
- collection: Collection;
22
- model: ModelStatic<any>;
23
- filterParser: FilterParser;
24
- context: OptionsParserContext;
25
- constructor(options: FindOptions, context: OptionsParserContext);
26
- static appendInheritInspectAttribute(include: any, collection: any): any;
27
- isAssociation(key: string): boolean;
28
- isAssociationPath(path: string): boolean;
29
- toSequelizeParams(): any;
30
- /**
31
- * parser sort options
32
- * @param filterParams
33
- * @protected
34
- */
35
- protected parseSort(filterParams: any): any;
36
- protected parseFields(filterParams: any): any;
37
- protected parseExcept(except: Except, filterParams: any): any;
38
- protected parseAppendWithOptions(append: string): {
39
- name: string;
40
- options?: object;
41
- raw?: string;
42
- };
43
- protected parseAppends(appends: Appends, filterParams: any): any;
44
- }
45
- export {};
@@ -1,350 +0,0 @@
1
- /**
2
- * This file is part of the NocoBase (R) project.
3
- * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
- * Authors: NocoBase Team.
5
- *
6
- * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
- * For more information, please refer to: https://www.nocobase.com/agreement.
8
- */
9
-
10
- var __create = Object.create;
11
- var __defProp = Object.defineProperty;
12
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
13
- var __getOwnPropNames = Object.getOwnPropertyNames;
14
- var __getProtoOf = Object.getPrototypeOf;
15
- var __hasOwnProp = Object.prototype.hasOwnProperty;
16
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
17
- var __export = (target, all) => {
18
- for (var name in all)
19
- __defProp(target, name, { get: all[name], enumerable: true });
20
- };
21
- var __copyProps = (to, from, except, desc) => {
22
- if (from && typeof from === "object" || typeof from === "function") {
23
- for (let key of __getOwnPropNames(from))
24
- if (!__hasOwnProp.call(to, key) && key !== except)
25
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
26
- }
27
- return to;
28
- };
29
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
30
- // If the importer is in node compatibility mode or this is not an ESM
31
- // file that has been converted to a CommonJS file using a Babel-
32
- // compatible transform (i.e. "__esModule" has not been set), then set
33
- // "default" to the CommonJS "module.exports" for node compatibility.
34
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
35
- mod
36
- ));
37
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
38
- var options_parser_exports = {};
39
- __export(options_parser_exports, {
40
- OptionsParser: () => OptionsParser
41
- });
42
- module.exports = __toCommonJS(options_parser_exports);
43
- var import_lodash = __toESM(require("lodash"));
44
- var import_sequelize = require("sequelize");
45
- var import_filter_parser = __toESM(require("./filter-parser"));
46
- var import_qs = __toESM(require("qs"));
47
- const debug = require("debug")("noco-database");
48
- const _OptionsParser = class _OptionsParser {
49
- options;
50
- database;
51
- collection;
52
- model;
53
- filterParser;
54
- context;
55
- constructor(options, context) {
56
- const { collection } = context;
57
- this.collection = collection;
58
- this.model = collection.model;
59
- this.options = options;
60
- this.database = collection.context.database;
61
- this.filterParser = new import_filter_parser.default(options == null ? void 0 : options.filter, {
62
- collection,
63
- app: {
64
- ctx: options == null ? void 0 : options.context
65
- }
66
- });
67
- this.context = context;
68
- }
69
- static appendInheritInspectAttribute(include, collection) {
70
- if (include.find((item) => (item == null ? void 0 : item[1]) === "__tableName")) {
71
- return;
72
- }
73
- include.push([
74
- import_sequelize.Sequelize.literal(`(select relname from pg_class where pg_class.oid = "${collection.name}".tableoid)`),
75
- "__tableName"
76
- ]);
77
- include.push([
78
- import_sequelize.Sequelize.literal(`
79
- (SELECT n.nspname
80
- FROM pg_class c
81
- JOIN pg_namespace n ON n.oid = c.relnamespace
82
- WHERE c.oid = "${collection.name}".tableoid)
83
- `),
84
- "__schemaName"
85
- ]);
86
- }
87
- isAssociation(key) {
88
- return this.model.associations[key] !== void 0;
89
- }
90
- isAssociationPath(path) {
91
- return this.isAssociation(path.split(".")[0]);
92
- }
93
- toSequelizeParams() {
94
- var _a, _b;
95
- const queryParams = this.filterParser.toSequelizeParams();
96
- if ((_a = this.options) == null ? void 0 : _a.filterByTk) {
97
- queryParams.where = {
98
- [import_sequelize.Op.and]: [
99
- queryParams.where,
100
- {
101
- [this.context.targetKey || this.collection.filterTargetKey]: this.options.filterByTk
102
- }
103
- ]
104
- };
105
- }
106
- if ((_b = this.options) == null ? void 0 : _b.include) {
107
- if (!queryParams.include) {
108
- queryParams.include = [];
109
- }
110
- queryParams.include.push(...import_lodash.default.castArray(this.options.include));
111
- }
112
- return this.parseSort(this.parseFields(queryParams));
113
- }
114
- /**
115
- * parser sort options
116
- * @param filterParams
117
- * @protected
118
- */
119
- parseSort(filterParams) {
120
- var _a, _b;
121
- let sort = ((_a = this.options) == null ? void 0 : _a.sort) || [];
122
- if (typeof sort === "string") {
123
- sort = sort.split(",");
124
- }
125
- const primaryKeyField = this.model.primaryKeyAttribute;
126
- if (primaryKeyField && !((_b = this.options) == null ? void 0 : _b.group)) {
127
- if (!sort.includes(primaryKeyField)) {
128
- sort.push(primaryKeyField);
129
- }
130
- }
131
- const orderParams = [];
132
- for (const sortKey of sort) {
133
- let direction = sortKey.startsWith("-") ? "DESC" : "ASC";
134
- const sortField = sortKey.startsWith("-") ? sortKey.replace("-", "").split(".") : sortKey.split(".");
135
- if (this.database.inDialect("postgres", "sqlite")) {
136
- direction = `${direction} NULLS LAST`;
137
- }
138
- if (sortField.length > 1) {
139
- let associationModel = this.model;
140
- for (let i = 0; i < sortField.length - 1; i++) {
141
- const associationKey = sortField[i];
142
- sortField[i] = associationModel.associations[associationKey].target;
143
- associationModel = sortField[i];
144
- }
145
- } else {
146
- const rawField = this.model.rawAttributes[sortField[0]];
147
- sortField[0] = (rawField == null ? void 0 : rawField.field) || sortField[0];
148
- }
149
- sortField.push(direction);
150
- if (this.database.isMySQLCompatibleDialect()) {
151
- orderParams.push([import_sequelize.Sequelize.fn("ISNULL", import_sequelize.Sequelize.col(`${this.model.name}.${sortField[0]}`))]);
152
- }
153
- orderParams.push(sortField);
154
- }
155
- if (orderParams.length > 0) {
156
- return {
157
- order: orderParams,
158
- ...filterParams
159
- };
160
- }
161
- return filterParams;
162
- }
163
- parseFields(filterParams) {
164
- var _a, _b, _c, _d;
165
- const appends = ((_a = this.options) == null ? void 0 : _a.appends) || [];
166
- const except = [];
167
- if ((_b = this.options) == null ? void 0 : _b.attributes) {
168
- return {
169
- attributes: this.options.attributes
170
- };
171
- }
172
- let attributes = {
173
- include: [],
174
- exclude: []
175
- };
176
- if (this.collection.isParent()) {
177
- _OptionsParser.appendInheritInspectAttribute(attributes.include, this.collection);
178
- }
179
- if ((_c = this.options) == null ? void 0 : _c.fields) {
180
- attributes = [];
181
- if (this.collection.isParent()) {
182
- _OptionsParser.appendInheritInspectAttribute(attributes, this.collection);
183
- }
184
- for (const field of this.options.fields) {
185
- if (this.isAssociationPath(field)) {
186
- appends.push(field);
187
- } else {
188
- attributes.push(field);
189
- }
190
- }
191
- }
192
- if ((_d = this.options) == null ? void 0 : _d.except) {
193
- for (const exceptKey of this.options.except) {
194
- if (this.isAssociationPath(exceptKey)) {
195
- except.push(exceptKey);
196
- } else {
197
- if (Array.isArray(attributes))
198
- continue;
199
- attributes.exclude.push(exceptKey);
200
- }
201
- }
202
- }
203
- return {
204
- attributes,
205
- ...this.parseExcept(except, this.parseAppends(appends, filterParams))
206
- };
207
- }
208
- parseExcept(except, filterParams) {
209
- if (!except)
210
- return filterParams;
211
- const setExcept = /* @__PURE__ */ __name((queryParams, except2) => {
212
- const exceptPath = except2.split(".");
213
- const association = exceptPath[0];
214
- const lastLevel = exceptPath.length <= 2;
215
- const existIncludeIndex = queryParams["include"].findIndex((include) => include["association"] == association);
216
- if (existIncludeIndex == -1) {
217
- return;
218
- }
219
- if (lastLevel) {
220
- if (Array.isArray(queryParams["include"][existIncludeIndex]["attributes"])) {
221
- return;
222
- } else {
223
- if (!queryParams["include"][existIncludeIndex]["attributes"]["exclude"]) {
224
- queryParams["include"][existIncludeIndex]["attributes"]["exclude"] = [];
225
- }
226
- queryParams["include"][existIncludeIndex]["attributes"]["exclude"].push(exceptPath[1]);
227
- }
228
- } else {
229
- setExcept(queryParams["include"][existIncludeIndex], exceptPath.filter((_, index) => index !== 0).join("."));
230
- }
231
- }, "setExcept");
232
- for (const exceptKey of except) {
233
- setExcept(filterParams, exceptKey);
234
- }
235
- return filterParams;
236
- }
237
- parseAppendWithOptions(append) {
238
- const parts = append.split("(");
239
- const obj = {
240
- name: parts[0]
241
- };
242
- if (parts.length > 1) {
243
- const optionsStr = parts[1].replace(")", "");
244
- obj.options = import_qs.default.parse(optionsStr);
245
- obj.raw = `(${optionsStr})`;
246
- }
247
- return obj;
248
- }
249
- parseAppends(appends, filterParams) {
250
- if (!appends)
251
- return filterParams;
252
- appends = import_lodash.default.sortBy(appends, (append) => append.split(".").length);
253
- const setInclude = /* @__PURE__ */ __name((model, queryParams, append) => {
254
- var _a;
255
- const appendWithOptions = this.parseAppendWithOptions(append);
256
- append = appendWithOptions.name;
257
- const appendFields = append.split(".");
258
- const appendAssociation = appendFields[0];
259
- const associations = model.associations;
260
- let lastLevel = false;
261
- if (appendFields.length == 1) {
262
- lastLevel = true;
263
- }
264
- if (appendFields.length == 2) {
265
- const association = associations[appendFields[0]];
266
- if (!association) {
267
- throw new Error(`association ${appendFields[0]} in ${model.name} not found`);
268
- }
269
- const associationModel = associations[appendFields[0]].target;
270
- if (associationModel.rawAttributes[appendFields[1]]) {
271
- lastLevel = true;
272
- }
273
- }
274
- if (queryParams["include"] == void 0) {
275
- queryParams["include"] = [];
276
- }
277
- let existIncludeIndex = queryParams["include"].findIndex(
278
- (include) => include["association"] == appendAssociation
279
- );
280
- if (existIncludeIndex != -1) {
281
- delete queryParams["include"][existIncludeIndex]["fromFilter"];
282
- if (Array.isArray(queryParams["include"][existIncludeIndex]["attributes"]) && queryParams["include"][existIncludeIndex]["attributes"].length == 0) {
283
- queryParams["include"][existIncludeIndex]["attributes"] = {
284
- include: []
285
- };
286
- }
287
- }
288
- if (lastLevel && existIncludeIndex != -1 && ((_a = import_lodash.default.get(queryParams, ["include", existIncludeIndex, "attributes", "include"])) == null ? void 0 : _a.length) == 0) {
289
- return;
290
- }
291
- if (existIncludeIndex == -1) {
292
- queryParams["include"].push({
293
- association: appendAssociation,
294
- options: appendWithOptions.options || {}
295
- });
296
- existIncludeIndex = queryParams["include"].length - 1;
297
- }
298
- if (lastLevel) {
299
- let attributes = queryParams["include"][existIncludeIndex]["attributes"] || {
300
- include: []
301
- // all fields are output by default
302
- };
303
- if (appendFields.length == 2) {
304
- if (!Array.isArray(attributes)) {
305
- attributes = [];
306
- }
307
- const attributeName = appendFields[1];
308
- attributes.push(attributeName);
309
- } else {
310
- if (Array.isArray(attributes) && attributes.length == 0) {
311
- attributes = {
312
- include: []
313
- };
314
- }
315
- }
316
- queryParams["include"][existIncludeIndex] = {
317
- ...queryParams["include"][existIncludeIndex],
318
- attributes
319
- };
320
- } else {
321
- const existInclude = queryParams["include"][existIncludeIndex];
322
- if (existInclude.attributes && Array.isArray(existInclude.attributes) && existInclude.attributes.length == 0) {
323
- existInclude.attributes = {
324
- include: []
325
- };
326
- }
327
- let nextAppend = appendFields.filter((_, index) => index !== 0).join(".");
328
- if (appendWithOptions.raw) {
329
- nextAppend += appendWithOptions.raw;
330
- }
331
- setInclude(
332
- model.associations[queryParams["include"][existIncludeIndex].association].target,
333
- queryParams["include"][existIncludeIndex],
334
- nextAppend
335
- );
336
- }
337
- }, "setInclude");
338
- for (const append of appends) {
339
- setInclude(this.model, filterParams, append);
340
- }
341
- debug("filter params: %o", filterParams);
342
- return filterParams;
343
- }
344
- };
345
- __name(_OptionsParser, "OptionsParser");
346
- let OptionsParser = _OptionsParser;
347
- // Annotate the CommonJS export names for ESM import in node:
348
- 0 && (module.exports = {
349
- OptionsParser
350
- });
@@ -1,44 +0,0 @@
1
- /**
2
- * This file is part of the NocoBase (R) project.
3
- * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
- * Authors: NocoBase Team.
5
- *
6
- * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
- * For more information, please refer to: https://www.nocobase.com/agreement.
8
- */
9
- import { Transaction, Transactionable } from 'sequelize';
10
- import { Collection } from '../collection';
11
- import QueryInterface, { TableInfo } from './query-interface';
12
- export default class MysqlQueryInterface extends QueryInterface {
13
- constructor(db: any);
14
- collectionTableExists(collection: Collection, options?: Transactionable): Promise<boolean>;
15
- listViews(): Promise<[unknown[], unknown]>;
16
- viewColumnUsage(options: {
17
- viewName: string;
18
- schema?: string;
19
- }): Promise<{
20
- [view_column_name: string]: {
21
- column_name: string;
22
- table_name: string;
23
- table_schema?: string;
24
- };
25
- }>;
26
- parseSQL(sql: string): any;
27
- viewDef(viewName: string): Promise<string>;
28
- showTableDefinition(tableInfo: TableInfo): Promise<any>;
29
- getAutoIncrementInfo(options: {
30
- tableInfo: TableInfo;
31
- fieldName: string;
32
- transaction: Transaction;
33
- }): Promise<{
34
- seqName?: string;
35
- currentVal: number;
36
- }>;
37
- setAutoIncrementVal(options: {
38
- tableInfo: TableInfo;
39
- columnName: string;
40
- seqName?: string;
41
- currentVal: number;
42
- transaction?: Transaction;
43
- }): Promise<void>;
44
- }