@nocobase/database 1.2.12-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,166 +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 __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
17
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
18
- var __export = (target, all) => {
19
- for (var name in all)
20
- __defProp(target, name, { get: all[name], enumerable: true });
21
- };
22
- var __copyProps = (to, from, except, desc) => {
23
- if (from && typeof from === "object" || typeof from === "function") {
24
- for (let key of __getOwnPropNames(from))
25
- if (!__hasOwnProp.call(to, key) && key !== except)
26
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
27
- }
28
- return to;
29
- };
30
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
31
- // If the importer is in node compatibility mode or this is not an ESM
32
- // file that has been converted to a CommonJS file using a Babel-
33
- // compatible transform (i.e. "__esModule" has not been set), then set
34
- // "default" to the CommonJS "module.exports" for node compatibility.
35
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
36
- mod
37
- ));
38
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
39
- var __publicField = (obj, key, value) => {
40
- __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
41
- return value;
42
- };
43
- var belongs_to_field_exports = {};
44
- __export(belongs_to_field_exports, {
45
- BelongsToField: () => BelongsToField
46
- });
47
- module.exports = __toCommonJS(belongs_to_field_exports);
48
- var import_lodash = __toESM(require("lodash"));
49
- var import_sequelize = require("sequelize");
50
- var import_references_map = require("../features/references-map");
51
- var import_utils = require("../utils");
52
- var import_relation_field = require("./relation-field");
53
- const _BelongsToField = class _BelongsToField extends import_relation_field.RelationField {
54
- get dataType() {
55
- return "BelongsTo";
56
- }
57
- get target() {
58
- const { target, name } = this.options;
59
- return target || import_sequelize.Utils.pluralize(name);
60
- }
61
- static toReference(db, association, onDelete, priority = "default") {
62
- const targetKey = association.targetKey;
63
- return (0, import_references_map.buildReference)({
64
- sourceCollectionName: db.modelCollection.get(association.source).name,
65
- sourceField: association.foreignKey,
66
- targetField: targetKey,
67
- targetCollectionName: db.modelCollection.get(association.target).name,
68
- onDelete,
69
- priority
70
- });
71
- }
72
- reference(association) {
73
- return _BelongsToField.toReference(
74
- this.database,
75
- association,
76
- this.options.onDelete,
77
- this.options.onDelete ? "user" : "default"
78
- );
79
- }
80
- checkAssociationKeys() {
81
- let { foreignKey, targetKey } = this.options;
82
- if (!targetKey) {
83
- targetKey = this.TargetModel.primaryKeyAttribute;
84
- }
85
- if (!foreignKey) {
86
- foreignKey = import_lodash.default.camelCase(`${this.name}_${targetKey}`);
87
- }
88
- const targetKeyAttribute = this.TargetModel.rawAttributes[targetKey];
89
- const foreignKeyAttribute = this.collection.model.rawAttributes[foreignKey];
90
- if (!foreignKeyAttribute || !targetKeyAttribute) {
91
- return;
92
- }
93
- const foreignKeyType = foreignKeyAttribute.type.constructor.toString();
94
- const targetKeyType = targetKeyAttribute.type.constructor.toString();
95
- if (!this.keyPairsTypeMatched(foreignKeyType, targetKeyType)) {
96
- throw new Error(
97
- `Foreign key "${foreignKey}" type "${foreignKeyType}" does not match target key "${targetKey}" type "${targetKeyType}" in belongs to relation "${this.name}" of collection "${this.collection.name}"`
98
- );
99
- }
100
- }
101
- bind() {
102
- const { database, collection } = this.context;
103
- const Target = this.TargetModel;
104
- if (!Target) {
105
- database.addPendingField(this);
106
- return false;
107
- }
108
- this.checkAssociationKeys();
109
- if (collection.model.associations[this.name]) {
110
- delete collection.model.associations[this.name];
111
- }
112
- const association = collection.model.belongsTo(Target, {
113
- as: this.name,
114
- constraints: false,
115
- ...(0, import_lodash.omit)(this.options, ["name", "type", "target", "onDelete"])
116
- });
117
- database.removePendingField(this);
118
- if (!this.options.foreignKey) {
119
- this.options.foreignKey = association.foreignKey;
120
- }
121
- if (!this.options.targetKey) {
122
- this.options.targetKey = association.targetKey;
123
- }
124
- try {
125
- (0, import_utils.checkIdentifier)(this.options.foreignKey);
126
- } catch (error) {
127
- this.unbind();
128
- throw error;
129
- }
130
- if (!this.options.sourceKey) {
131
- this.options.sourceKey = association.sourceKey;
132
- }
133
- this.collection.addIndex([this.options.foreignKey]);
134
- const reference = this.reference(association);
135
- this.database.referenceMap.addReference(reference);
136
- return true;
137
- }
138
- unbind() {
139
- const { database, collection } = this.context;
140
- database.removePendingField(this);
141
- const tcoll = database.collections.get(this.target);
142
- const foreignKey = this.options.foreignKey;
143
- const field1 = collection.getField(foreignKey);
144
- const field2 = tcoll ? tcoll.findField((field) => {
145
- return field.type === "hasMany" && field.foreignKey === foreignKey;
146
- }) : null;
147
- if (!field1 && !field2) {
148
- collection.model.removeAttribute(foreignKey);
149
- }
150
- const association = collection.model.associations[this.name];
151
- if (association && !this.options.inherit) {
152
- const reference = this.reference(association);
153
- this.database.referenceMap.removeReference(reference);
154
- }
155
- this.clearAccessors();
156
- delete collection.model.associations[this.name];
157
- collection.model.refreshAttributes();
158
- }
159
- };
160
- __name(_BelongsToField, "BelongsToField");
161
- __publicField(_BelongsToField, "type", "belongsTo");
162
- let BelongsToField = _BelongsToField;
163
- // Annotate the CommonJS export names for ESM import in node:
164
- 0 && (module.exports = {
165
- BelongsToField
166
- });
@@ -1,28 +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 { AssociationScope, BelongsToManyOptions as SequelizeBelongsToManyOptions } from 'sequelize';
10
- import { Reference } from '../features/references-map';
11
- import { MultipleRelationFieldOptions, RelationField } from './relation-field';
12
- export declare class BelongsToManyField extends RelationField {
13
- get dataType(): string;
14
- get through(): any;
15
- get otherKey(): any;
16
- references(association: any): Reference[];
17
- checkAssociationKeys(database: any): void;
18
- bind(): boolean;
19
- unbind(): void;
20
- }
21
- export interface BelongsToManyFieldOptions extends MultipleRelationFieldOptions, Omit<SequelizeBelongsToManyOptions, 'through'> {
22
- type: 'belongsToMany';
23
- target?: string;
24
- through?: string;
25
- throughScope?: AssociationScope;
26
- throughUnique?: boolean;
27
- throughParanoid?: boolean;
28
- }
@@ -1,196 +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 belongs_to_many_field_exports = {};
29
- __export(belongs_to_many_field_exports, {
30
- BelongsToManyField: () => BelongsToManyField
31
- });
32
- module.exports = __toCommonJS(belongs_to_many_field_exports);
33
- var import_lodash = require("lodash");
34
- var import_sequelize = require("sequelize");
35
- var import_utils = require("../utils");
36
- var import_belongs_to_field = require("./belongs-to-field");
37
- var import_relation_field = require("./relation-field");
38
- const _BelongsToManyField = class _BelongsToManyField extends import_relation_field.RelationField {
39
- get dataType() {
40
- return "BelongsToMany";
41
- }
42
- get through() {
43
- return this.options.through || import_sequelize.Utils.camelize(
44
- [this.context.collection.model.name, this.target].map((name) => name.toLowerCase()).sort().join("_")
45
- );
46
- }
47
- get otherKey() {
48
- return this.options.otherKey;
49
- }
50
- references(association) {
51
- const db = this.context.database;
52
- const onDelete = this.options.onDelete || "CASCADE";
53
- const priority = this.options.onDelete ? "user" : "default";
54
- const targetAssociation = association.toTarget;
55
- if (association.targetKey) {
56
- targetAssociation.targetKey = association.targetKey;
57
- }
58
- const sourceAssociation = association.toSource;
59
- if (association.sourceKey) {
60
- sourceAssociation.targetKey = association.sourceKey;
61
- }
62
- return [
63
- import_belongs_to_field.BelongsToField.toReference(db, targetAssociation, onDelete, priority),
64
- import_belongs_to_field.BelongsToField.toReference(db, sourceAssociation, onDelete, priority)
65
- ];
66
- }
67
- checkAssociationKeys(database) {
68
- let { foreignKey, sourceKey, otherKey, targetKey } = this.options;
69
- const through = this.through;
70
- const throughCollection = database.getCollection(through);
71
- if (!throughCollection) {
72
- return;
73
- }
74
- if (!sourceKey) {
75
- sourceKey = this.collection.model.primaryKeyAttribute;
76
- }
77
- if (!foreignKey) {
78
- foreignKey = import_sequelize.Utils.camelize([import_sequelize.Utils.singularize(this.collection.model.name), sourceKey].join("_"));
79
- }
80
- if (!targetKey) {
81
- targetKey = this.TargetModel.primaryKeyAttribute;
82
- }
83
- if (!otherKey) {
84
- otherKey = import_sequelize.Utils.camelize([import_sequelize.Utils.singularize(this.TargetModel.name), targetKey].join("_"));
85
- }
86
- const foreignKeyAttribute = throughCollection.model.rawAttributes[foreignKey];
87
- const otherKeyAttribute = throughCollection.model.rawAttributes[otherKey];
88
- const sourceKeyAttribute = this.collection.model.rawAttributes[sourceKey];
89
- const targetKeyAttribute = this.TargetModel.rawAttributes[targetKey];
90
- if (!foreignKeyAttribute || !otherKeyAttribute || !sourceKeyAttribute || !targetKeyAttribute) {
91
- return;
92
- }
93
- const foreignKeyType = foreignKeyAttribute.type.constructor.toString();
94
- const otherKeyType = otherKeyAttribute.type.constructor.toString();
95
- const sourceKeyType = sourceKeyAttribute.type.constructor.toString();
96
- const targetKeyType = targetKeyAttribute.type.constructor.toString();
97
- if (!this.keyPairsTypeMatched(foreignKeyType, sourceKeyType)) {
98
- throw new Error(
99
- `Foreign key "${foreignKey}" type "${foreignKeyType}" does not match source key "${sourceKey}" type "${sourceKeyType}" in belongs to many relation "${this.name}" of collection "${this.collection.name}"`
100
- );
101
- }
102
- if (!this.keyPairsTypeMatched(otherKeyType, targetKeyType)) {
103
- throw new Error(
104
- `Other key "${otherKey}" type "${otherKeyType}" does not match target key "${targetKey}" type "${targetKeyType}" in belongs to many relation "${this.name}" of collection "${this.collection.name}"`
105
- );
106
- }
107
- }
108
- bind() {
109
- const { database, collection } = this.context;
110
- const Target = this.TargetModel;
111
- if (!Target) {
112
- database.addPendingField(this);
113
- return false;
114
- }
115
- if (!this.collection.model.primaryKeyAttribute) {
116
- throw new Error(`Collection model ${this.collection.model.name} has no primary key attribute`);
117
- }
118
- if (!Target.primaryKeyAttribute) {
119
- throw new Error(`Target model ${Target.name} has no primary key attribute`);
120
- }
121
- this.checkAssociationKeys(database);
122
- const through = this.through;
123
- let Through;
124
- if (database.hasCollection(through)) {
125
- Through = database.getCollection(through);
126
- } else {
127
- const throughCollectionOptions = {
128
- name: through
129
- };
130
- if (this.collection.options.dumpRules) {
131
- throughCollectionOptions["dumpRules"] = this.collection.options.dumpRules;
132
- }
133
- if (this.collection.collectionSchema()) {
134
- throughCollectionOptions["schema"] = this.collection.collectionSchema();
135
- }
136
- Through = database.collection(throughCollectionOptions);
137
- Object.defineProperty(Through.model, "isThrough", { value: true });
138
- }
139
- const belongsToManyOptions = {
140
- constraints: false,
141
- ...(0, import_lodash.omit)(this.options, ["name", "type", "target"]),
142
- as: this.name,
143
- through: {
144
- model: Through.model,
145
- scope: this.options.throughScope,
146
- paranoid: this.options.throughParanoid,
147
- unique: this.options.throughUnique
148
- }
149
- };
150
- const association = collection.model.belongsToMany(Target, belongsToManyOptions);
151
- database.removePendingField(this);
152
- if (!this.options.foreignKey) {
153
- this.options.foreignKey = association.foreignKey;
154
- }
155
- if (!this.options.sourceKey) {
156
- this.options.sourceKey = association.sourceKey;
157
- }
158
- if (!this.options.otherKey) {
159
- this.options.otherKey = association.otherKey;
160
- }
161
- if (!this.options.targetKey) {
162
- this.options.targetKey = association.targetKey;
163
- }
164
- try {
165
- (0, import_utils.checkIdentifier)(this.options.foreignKey);
166
- (0, import_utils.checkIdentifier)(this.options.otherKey);
167
- } catch (error) {
168
- this.unbind();
169
- throw error;
170
- }
171
- if (!this.options.through) {
172
- this.options.through = this.through;
173
- }
174
- Through.addIndex([this.options.foreignKey]);
175
- Through.addIndex([this.options.otherKey]);
176
- this.references(association).forEach((reference) => this.database.referenceMap.addReference(reference));
177
- return true;
178
- }
179
- unbind() {
180
- const { database, collection } = this.context;
181
- const Through = database.getCollection(this.through);
182
- database.removePendingField(this);
183
- const association = collection.model.associations[this.name];
184
- if (association && !this.options.inherit) {
185
- this.references(association).forEach((reference) => this.database.referenceMap.removeReference(reference));
186
- }
187
- this.clearAccessors();
188
- delete collection.model.associations[this.name];
189
- }
190
- };
191
- __name(_BelongsToManyField, "BelongsToManyField");
192
- let BelongsToManyField = _BelongsToManyField;
193
- // Annotate the CommonJS export names for ESM import in node:
194
- 0 && (module.exports = {
195
- BelongsToManyField
196
- });
@@ -1,16 +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 { DataTypes } from 'sequelize';
10
- import { BaseColumnFieldOptions, Field } from './field';
11
- export declare class BooleanField extends Field {
12
- get dataType(): DataTypes.AbstractDataTypeConstructor;
13
- }
14
- export interface BooleanFieldOptions extends BaseColumnFieldOptions {
15
- type: 'boolean';
16
- }
@@ -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
-
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 boolean_field_exports = {};
29
- __export(boolean_field_exports, {
30
- BooleanField: () => BooleanField
31
- });
32
- module.exports = __toCommonJS(boolean_field_exports);
33
- var import_sequelize = require("sequelize");
34
- var import_field = require("./field");
35
- const _BooleanField = class _BooleanField extends import_field.Field {
36
- get dataType() {
37
- return import_sequelize.DataTypes.BOOLEAN;
38
- }
39
- };
40
- __name(_BooleanField, "BooleanField");
41
- let BooleanField = _BooleanField;
42
- // Annotate the CommonJS export names for ESM import in node:
43
- 0 && (module.exports = {
44
- BooleanField
45
- });
@@ -1,22 +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 { Model } from '../model';
10
- import { BaseColumnFieldOptions, Field } from './field';
11
- export declare class ContextField extends Field {
12
- get dataType(): any;
13
- listener: (model: Model, options: any) => Promise<void>;
14
- bind(): void;
15
- unbind(): void;
16
- }
17
- export interface ContextFieldOptions extends BaseColumnFieldOptions {
18
- type: 'context';
19
- dataIndex: string;
20
- dataType?: string;
21
- createOnly?: boolean;
22
- }
@@ -1,79 +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 context_field_exports = {};
39
- __export(context_field_exports, {
40
- ContextField: () => ContextField
41
- });
42
- module.exports = __toCommonJS(context_field_exports);
43
- var import_lodash = __toESM(require("lodash"));
44
- var import_sequelize = require("sequelize");
45
- var import_field = require("./field");
46
- const _ContextField = class _ContextField extends import_field.Field {
47
- get dataType() {
48
- const type = this.options.dataType || "string";
49
- return import_sequelize.DataTypes[type.toUpperCase()] || import_sequelize.DataTypes.STRING;
50
- }
51
- listener = async (model, options) => {
52
- const { name, dataIndex } = this.options;
53
- const { context } = options;
54
- model.set(name, import_lodash.default.get(context, dataIndex));
55
- model.changed(name, true);
56
- };
57
- bind() {
58
- super.bind();
59
- const { createOnly } = this.options;
60
- this.on("beforeCreate", this.listener);
61
- if (!createOnly) {
62
- this.on("beforeUpdate", this.listener);
63
- }
64
- }
65
- unbind() {
66
- super.unbind();
67
- const { createOnly } = this.options;
68
- this.off("beforeCreate", this.listener);
69
- if (!createOnly) {
70
- this.off("beforeUpdate", this.listener);
71
- }
72
- }
73
- };
74
- __name(_ContextField, "ContextField");
75
- let ContextField = _ContextField;
76
- // Annotate the CommonJS export names for ESM import in node:
77
- 0 && (module.exports = {
78
- ContextField
79
- });
@@ -1,21 +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 { DataTypes } from 'sequelize';
10
- import { BaseColumnFieldOptions, Field } from './field';
11
- export declare class DateField extends Field {
12
- get dataType(): DataTypes.DateDataType;
13
- get timezone(): string;
14
- getProps(): any;
15
- isDateOnly(): boolean;
16
- isGMT(): any;
17
- bind(): void;
18
- }
19
- export interface DateFieldOptions extends BaseColumnFieldOptions {
20
- type: 'date';
21
- }
@@ -1,73 +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 date_field_exports = {};
29
- __export(date_field_exports, {
30
- DateField: () => DateField
31
- });
32
- module.exports = __toCommonJS(date_field_exports);
33
- var import_sequelize = require("sequelize");
34
- var import_field = require("./field");
35
- const _DateField = class _DateField extends import_field.Field {
36
- get dataType() {
37
- return import_sequelize.DataTypes.DATE(3);
38
- }
39
- get timezone() {
40
- return this.isGMT() ? "+00:00" : null;
41
- }
42
- getProps() {
43
- var _a, _b;
44
- return ((_b = (_a = this.options) == null ? void 0 : _a.uiSchema) == null ? void 0 : _b["x-component-props"]) || {};
45
- }
46
- isDateOnly() {
47
- const props = this.getProps();
48
- return !props.showTime;
49
- }
50
- isGMT() {
51
- const props = this.getProps();
52
- return props.gmt;
53
- }
54
- bind() {
55
- super.bind();
56
- if (this.options.interface === "createdAt") {
57
- const { model } = this.context.collection;
58
- model._timestampAttributes.createdAt = this.name;
59
- model.refreshAttributes();
60
- }
61
- if (this.options.interface === "updatedAt") {
62
- const { model } = this.context.collection;
63
- model._timestampAttributes.updatedAt = this.name;
64
- model.refreshAttributes();
65
- }
66
- }
67
- };
68
- __name(_DateField, "DateField");
69
- let DateField = _DateField;
70
- // Annotate the CommonJS export names for ESM import in node:
71
- 0 && (module.exports = {
72
- DateField
73
- });