@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,448 +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 eager_loading_tree_exports = {};
39
- __export(eager_loading_tree_exports, {
40
- EagerLoadingTree: () => EagerLoadingTree
41
- });
42
- module.exports = __toCommonJS(eager_loading_tree_exports);
43
- var import_lodash = __toESM(require("lodash"));
44
- var import_sequelize = require("sequelize");
45
- var import_append_child_collection_name_after_repository_find = require("../listeners/append-child-collection-name-after-repository-find");
46
- var import_options_parser = require("../options-parser");
47
- var import_adjacency_list_repository = require("../repositories/tree-repository/adjacency-list-repository");
48
- const pushAttribute = /* @__PURE__ */ __name((node, attribute) => {
49
- if (import_lodash.default.isArray(node.attributes) && !node.attributes.includes(attribute)) {
50
- node.attributes.push(attribute);
51
- }
52
- }, "pushAttribute");
53
- const EagerLoadingNodeProto = {
54
- afterBuild(db) {
55
- const collection = db.modelCollection.get(this.model);
56
- if (collection && collection.isParent()) {
57
- if (!this.attributes) {
58
- this.attributes = {
59
- include: []
60
- };
61
- }
62
- import_options_parser.OptionsParser.appendInheritInspectAttribute(
63
- import_lodash.default.isArray(this.attributes) ? this.attributes : this.attributes.include,
64
- collection
65
- );
66
- this.inspectInheritAttribute = true;
67
- }
68
- }
69
- };
70
- const _EagerLoadingTree = class _EagerLoadingTree {
71
- root;
72
- db;
73
- rootQueryOptions = {};
74
- constructor(root) {
75
- this.root = root;
76
- }
77
- static buildFromSequelizeOptions(options) {
78
- const { model, rootAttributes, includeOption, db, rootQueryOptions } = options;
79
- const buildNode = /* @__PURE__ */ __name((node) => {
80
- Object.setPrototypeOf(node, EagerLoadingNodeProto);
81
- node.afterBuild(db);
82
- return node;
83
- }, "buildNode");
84
- const root = buildNode({
85
- model,
86
- association: null,
87
- rawAttributes: import_lodash.default.cloneDeep(rootAttributes),
88
- attributes: import_lodash.default.cloneDeep(rootAttributes),
89
- order: options.rootOrder,
90
- children: []
91
- });
92
- const traverseIncludeOption = /* @__PURE__ */ __name((includeOption2, eagerLoadingTreeParent) => {
93
- const includeOptions = import_lodash.default.castArray(includeOption2);
94
- if (includeOption2.length > 0) {
95
- const modelPrimaryKey = eagerLoadingTreeParent.model.primaryKeyAttribute;
96
- pushAttribute(eagerLoadingTreeParent, modelPrimaryKey);
97
- }
98
- for (const include of includeOptions) {
99
- if (include.fromFilter) {
100
- continue;
101
- }
102
- const association = import_lodash.default.isString(include.association) ? eagerLoadingTreeParent.model.associations[include.association] : include.association;
103
- if (!association) {
104
- throw new Error(
105
- `Association "${include.association}" not found in model "${eagerLoadingTreeParent.model.name}"`
106
- );
107
- }
108
- const associationType = association.associationType;
109
- const child = buildNode({
110
- model: association.target,
111
- association,
112
- rawAttributes: import_lodash.default.cloneDeep(include.attributes),
113
- attributes: import_lodash.default.cloneDeep(include.attributes),
114
- parent: eagerLoadingTreeParent,
115
- where: include.where,
116
- children: [],
117
- includeOption: include.options || {}
118
- });
119
- if (associationType == "HasOne" || associationType == "HasMany") {
120
- const { sourceKey, foreignKey } = association;
121
- pushAttribute(eagerLoadingTreeParent, sourceKey);
122
- pushAttribute(child, foreignKey);
123
- }
124
- if (associationType == "BelongsTo") {
125
- const { targetKey, foreignKey } = association;
126
- pushAttribute(eagerLoadingTreeParent, foreignKey);
127
- pushAttribute(child, targetKey);
128
- }
129
- if (associationType == "BelongsToMany") {
130
- const { sourceKey } = association;
131
- pushAttribute(eagerLoadingTreeParent, sourceKey);
132
- }
133
- eagerLoadingTreeParent.children.push(child);
134
- if (include.include) {
135
- traverseIncludeOption(include.include, child);
136
- }
137
- }
138
- }, "traverseIncludeOption");
139
- traverseIncludeOption(includeOption, root);
140
- const tree = new _EagerLoadingTree(root);
141
- tree.db = db;
142
- tree.rootQueryOptions = rootQueryOptions;
143
- return tree;
144
- }
145
- async load(transaction) {
146
- const result = {};
147
- const orderOption = /* @__PURE__ */ __name((association) => {
148
- const targetModel = association.target;
149
- const order = [];
150
- if (targetModel.primaryKeyAttribute && targetModel.rawAttributes[targetModel.primaryKeyAttribute].autoIncrement) {
151
- order.push([targetModel.primaryKeyAttribute, "ASC"]);
152
- }
153
- return order;
154
- }, "orderOption");
155
- const loadRecursive = /* @__PURE__ */ __name(async (node, ids = []) => {
156
- var _a;
157
- let instances = [];
158
- if (!node.parent) {
159
- const rootInclude = ((_a = this.rootQueryOptions) == null ? void 0 : _a.include) || node.includeOption;
160
- const includeForFilter = rootInclude.filter((include) => {
161
- var _a2, _b;
162
- return Object.keys(include.where || {}).length > 0 || ((_b = JSON.stringify((_a2 = this.rootQueryOptions) == null ? void 0 : _a2.filter)) == null ? void 0 : _b.includes(include.association));
163
- });
164
- const isBelongsToAssociationOnly = /* @__PURE__ */ __name((includes, model) => {
165
- for (const include of includes) {
166
- const association = model.associations[include.association];
167
- if (!association) {
168
- return false;
169
- }
170
- if (association.associationType != "BelongsTo") {
171
- return false;
172
- }
173
- if (!isBelongsToAssociationOnly(include.include || [], association.target)) {
174
- return false;
175
- }
176
- }
177
- return true;
178
- }, "isBelongsToAssociationOnly");
179
- const belongsToAssociationsOnly = isBelongsToAssociationOnly(includeForFilter, node.model);
180
- if (belongsToAssociationsOnly) {
181
- instances = await node.model.findAll({
182
- ...this.rootQueryOptions,
183
- attributes: node.attributes,
184
- distinct: true,
185
- include: includeForFilter,
186
- transaction
187
- });
188
- } else {
189
- const primaryKeyField = node.model.primaryKeyField || node.model.primaryKeyAttribute;
190
- if (!primaryKeyField) {
191
- throw new Error(`Model ${node.model.name} does not have primary key`);
192
- }
193
- const ids2 = (await node.model.findAll({
194
- ...this.rootQueryOptions,
195
- includeIgnoreAttributes: false,
196
- attributes: [primaryKeyField],
197
- group: `${node.model.name}.${primaryKeyField}`,
198
- transaction,
199
- include: includeForFilter
200
- })).map((row) => {
201
- return { row, pk: row[primaryKeyField] };
202
- });
203
- const findOptions = {
204
- where: { [primaryKeyField]: ids2.map((i) => i.pk) },
205
- attributes: node.attributes
206
- };
207
- if (node.order) {
208
- findOptions["order"] = node.order;
209
- }
210
- instances = await node.model.findAll({
211
- ...findOptions,
212
- transaction
213
- });
214
- }
215
- const associations = node.model.associations;
216
- for (const association of Object.keys(associations)) {
217
- for (const instance of instances) {
218
- delete instance[association];
219
- delete instance.dataValues[association];
220
- }
221
- }
222
- } else if (ids.length > 0) {
223
- const association = node.association;
224
- const associationType = association.associationType;
225
- let params = {};
226
- const otherFindOptions = import_lodash.default.pick(node.includeOption, ["sort"]) || {};
227
- const collection = this.db.modelCollection.get(node.model);
228
- if (collection && !import_lodash.default.isEmpty(otherFindOptions)) {
229
- const parser = new import_options_parser.OptionsParser(otherFindOptions, {
230
- collection
231
- });
232
- params = parser.toSequelizeParams();
233
- }
234
- if (associationType == "HasOne" || associationType == "HasMany") {
235
- const foreignKey = association.foreignKey;
236
- const foreignKeyValues = node.parent.instances.map((instance) => instance.get(association.sourceKey));
237
- let where = { [foreignKey]: foreignKeyValues };
238
- if (node.where) {
239
- where = {
240
- [import_sequelize.Op.and]: [where, node.where]
241
- };
242
- }
243
- const findOptions = {
244
- where,
245
- attributes: node.attributes,
246
- order: params.order || orderOption(association),
247
- transaction
248
- };
249
- instances = await node.model.findAll(findOptions);
250
- }
251
- if (associationType == "BelongsTo") {
252
- const foreignKey = association.foreignKey;
253
- const parentInstancesForeignKeyValues = node.parent.instances.map((instance) => instance.get(foreignKey));
254
- const collection2 = this.db.modelCollection.get(node.model);
255
- instances = await node.model.findAll({
256
- transaction,
257
- where: {
258
- [association.targetKey]: parentInstancesForeignKeyValues
259
- },
260
- attributes: node.attributes
261
- });
262
- if (node.includeOption.recursively && instances.length > 0) {
263
- const targetKey = association.targetKey;
264
- const sql = import_adjacency_list_repository.AdjacencyListRepository.queryParentSQL({
265
- db: this.db,
266
- collection: collection2,
267
- foreignKey,
268
- targetKey,
269
- nodeIds: instances.map((instance) => instance.get(targetKey))
270
- });
271
- const results = await this.db.sequelize.query(sql, {
272
- type: "SELECT",
273
- transaction
274
- });
275
- const parentInstances = await node.model.findAll({
276
- transaction,
277
- where: {
278
- [association.targetKey]: results.map((result2) => result2[targetKey])
279
- },
280
- attributes: node.attributes
281
- });
282
- const setInstanceParent = /* @__PURE__ */ __name((instance) => {
283
- const parentInstance = parentInstances.find(
284
- (parentInstance2) => parentInstance2.get(targetKey) == instance.get(foreignKey)
285
- );
286
- if (!parentInstance) {
287
- return;
288
- }
289
- setInstanceParent(parentInstance);
290
- instance[association.as] = instance.dataValues[association.as] = parentInstance;
291
- }, "setInstanceParent");
292
- for (const instance of instances) {
293
- setInstanceParent(instance);
294
- }
295
- }
296
- }
297
- if (associationType == "BelongsToMany") {
298
- const foreignKeyValues = node.parent.instances.map((instance) => instance.get(association.sourceKey));
299
- const hasOneOptions = {
300
- as: "_pivot_",
301
- foreignKey: association.otherKey,
302
- sourceKey: association.targetKey
303
- };
304
- if (association.through.scope) {
305
- hasOneOptions.scope = association.through.scope;
306
- }
307
- const pivotAssoc = new import_sequelize.HasOne(association.target, association.through.model, hasOneOptions);
308
- instances = await node.model.findAll({
309
- transaction,
310
- attributes: node.attributes,
311
- include: [
312
- {
313
- association: pivotAssoc,
314
- where: {
315
- [association.foreignKey]: foreignKeyValues
316
- }
317
- }
318
- ],
319
- order: params.order || orderOption(association)
320
- });
321
- }
322
- }
323
- node.instances = instances;
324
- for (const child of node.children) {
325
- const modelPrimaryKey = node.model.primaryKeyField || node.model.primaryKeyAttribute;
326
- const nodeIds = instances.map((instance) => instance.get(modelPrimaryKey));
327
- await loadRecursive(child, nodeIds);
328
- }
329
- if (!node.parent) {
330
- return;
331
- } else {
332
- const association = node.association;
333
- const associationType = association.associationType;
334
- const setParentAccessor = /* @__PURE__ */ __name((parentInstance) => {
335
- const key = association.as;
336
- const children = parentInstance.getDataValue(association.as);
337
- if (association.isSingleAssociation) {
338
- const isEmpty = !children;
339
- parentInstance[key] = parentInstance.dataValues[key] = isEmpty ? null : children;
340
- } else {
341
- const isEmpty = !children || children.length == 0;
342
- parentInstance[key] = parentInstance.dataValues[key] = isEmpty ? [] : children;
343
- }
344
- }, "setParentAccessor");
345
- if (associationType == "HasMany" || associationType == "HasOne") {
346
- const foreignKey = association.foreignKey;
347
- const sourceKey = association.sourceKey;
348
- for (const instance of node.instances) {
349
- const parentInstance = node.parent.instances.find(
350
- (parentInstance2) => parentInstance2.get(sourceKey) == instance.get(foreignKey)
351
- );
352
- if (parentInstance) {
353
- if (associationType == "HasMany") {
354
- const children = parentInstance.getDataValue(association.as);
355
- if (!children) {
356
- parentInstance.setDataValue(association.as, [instance]);
357
- } else {
358
- children.push(instance);
359
- }
360
- }
361
- if (associationType == "HasOne") {
362
- const key = association.options.realAs || association.as;
363
- parentInstance[key] = parentInstance.dataValues[key] = instance;
364
- }
365
- }
366
- }
367
- }
368
- if (associationType == "BelongsTo") {
369
- const foreignKey = association.foreignKey;
370
- const targetKey = association.targetKey;
371
- for (const instance of node.instances) {
372
- const parentInstances = node.parent.instances.filter(
373
- (parentInstance) => parentInstance.get(foreignKey) == instance.get(targetKey)
374
- );
375
- for (const parentInstance of parentInstances) {
376
- parentInstance.setDataValue(association.as, instance);
377
- }
378
- }
379
- }
380
- if (associationType == "BelongsToMany") {
381
- const sourceKey = association.sourceKey;
382
- const foreignKey = association.foreignKey;
383
- const as = association.oneFromTarget.as;
384
- for (const instance of node.instances) {
385
- instance[as] = instance.dataValues[as] = instance["_pivot_"];
386
- delete instance.dataValues["_pivot_"];
387
- delete instance["_pivot_"];
388
- const parentInstance = node.parent.instances.find(
389
- (parentInstance2) => parentInstance2.get(sourceKey) == instance.dataValues[as].get(foreignKey)
390
- );
391
- if (parentInstance) {
392
- const children = parentInstance.getDataValue(association.as);
393
- if (!children) {
394
- parentInstance.setDataValue(association.as, [instance]);
395
- } else {
396
- children.push(instance);
397
- }
398
- }
399
- }
400
- }
401
- for (const parent of node.parent.instances) {
402
- setParentAccessor(parent);
403
- }
404
- }
405
- }, "loadRecursive");
406
- await loadRecursive(this.root);
407
- const appendChildCollectionName = (0, import_append_child_collection_name_after_repository_find.appendChildCollectionNameAfterRepositoryFind)(this.db);
408
- const setInstanceAttributes = /* @__PURE__ */ __name((node) => {
409
- var _a;
410
- if (node.inspectInheritAttribute) {
411
- appendChildCollectionName({
412
- findOptions: {},
413
- data: node.instances,
414
- dataCollection: this.db.modelCollection.get(node.model)
415
- });
416
- }
417
- if (((_a = node.association) == null ? void 0 : _a.as) == "_pivot_") {
418
- return;
419
- }
420
- const nodeRawAttributes = node.rawAttributes || [];
421
- if (!import_lodash.default.isArray(nodeRawAttributes)) {
422
- return;
423
- }
424
- const nodeChildrenAs = node.children.map((child) => child.association.as);
425
- const includeAttributes = [...nodeRawAttributes, ...nodeChildrenAs];
426
- if (node.inspectInheritAttribute) {
427
- includeAttributes.push("__schemaName", "__tableName", "__collection");
428
- }
429
- for (const instance of node.instances) {
430
- instance.dataValues = import_lodash.default.pick(instance.dataValues, includeAttributes);
431
- }
432
- }, "setInstanceAttributes");
433
- const traverse = /* @__PURE__ */ __name((node) => {
434
- setInstanceAttributes(node);
435
- for (const child of node.children) {
436
- traverse(child);
437
- }
438
- }, "traverse");
439
- traverse(this.root);
440
- return result;
441
- }
442
- };
443
- __name(_EagerLoadingTree, "EagerLoadingTree");
444
- let EagerLoadingTree = _EagerLoadingTree;
445
- // Annotate the CommonJS export names for ESM import in node:
446
- 0 && (module.exports = {
447
- EagerLoadingTree
448
- });
@@ -1,11 +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
- export declare class IdentifierError extends Error {
10
- constructor(message: string);
11
- }
@@ -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
-
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 identifier_error_exports = {};
29
- __export(identifier_error_exports, {
30
- IdentifierError: () => IdentifierError
31
- });
32
- module.exports = __toCommonJS(identifier_error_exports);
33
- const _IdentifierError = class _IdentifierError extends Error {
34
- constructor(message) {
35
- super(message);
36
- this.name = "IdentifierError";
37
- }
38
- };
39
- __name(_IdentifierError, "IdentifierError");
40
- let IdentifierError = _IdentifierError;
41
- // Annotate the CommonJS export names for ESM import in node:
42
- 0 && (module.exports = {
43
- IdentifierError
44
- });
@@ -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
- export declare class ZeroColumnTableError extends Error {
10
- }
@@ -1,40 +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 zero_column_table_error_exports = {};
29
- __export(zero_column_table_error_exports, {
30
- ZeroColumnTableError: () => ZeroColumnTableError
31
- });
32
- module.exports = __toCommonJS(zero_column_table_error_exports);
33
- const _ZeroColumnTableError = class _ZeroColumnTableError extends Error {
34
- };
35
- __name(_ZeroColumnTableError, "ZeroColumnTableError");
36
- let ZeroColumnTableError = _ZeroColumnTableError;
37
- // Annotate the CommonJS export names for ESM import in node:
38
- 0 && (module.exports = {
39
- ZeroColumnTableError
40
- });
@@ -1,29 +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 Database from '../database';
10
- export type ReferencePriority = 'default' | 'user';
11
- export interface Reference {
12
- sourceCollectionName: string;
13
- sourceField: string;
14
- targetField: string;
15
- targetCollectionName: string;
16
- onDelete: string;
17
- priority: ReferencePriority;
18
- }
19
- export declare function buildReference(options: Partial<Reference>): Reference;
20
- declare class ReferencesMap {
21
- private db;
22
- protected map: Map<string, Reference[]>;
23
- constructor(db: Database);
24
- addReference(reference: Reference): void;
25
- getReferences(collectionName: any): Reference[];
26
- existReference(reference: Reference): Reference;
27
- removeReference(reference: Reference): void;
28
- }
29
- export default ReferencesMap;