@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,147 +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 inherited_collection_exports = {};
39
- __export(inherited_collection_exports, {
40
- InheritedCollection: () => InheritedCollection
41
- });
42
- module.exports = __toCommonJS(inherited_collection_exports);
43
- var import_lodash = __toESM(require("lodash"));
44
- var import_collection = require("./collection");
45
- const _InheritedCollection = class _InheritedCollection extends import_collection.Collection {
46
- parents;
47
- constructor(options, context) {
48
- if (!options.inherits) {
49
- throw new Error("InheritedCollection must have inherits option");
50
- }
51
- options.inherits = import_lodash.default.castArray(options.inherits);
52
- super(options, context);
53
- try {
54
- this.bindParents();
55
- } catch (err) {
56
- if (err instanceof ParentCollectionNotFound) {
57
- const listener = /* @__PURE__ */ __name((collection) => {
58
- if (options.inherits.includes(collection.name) && options.inherits.every((name) => this.db.collections.has(name))) {
59
- this.bindParents();
60
- this.db.removeListener("afterDefineCollection", listener);
61
- }
62
- }, "listener");
63
- this.db.addListener("afterDefineCollection", listener);
64
- } else {
65
- throw err;
66
- }
67
- }
68
- }
69
- getParents() {
70
- return this.parents;
71
- }
72
- getFlatParents() {
73
- const parents = [];
74
- for (const parent of this.parents) {
75
- if (parent.isInherited()) {
76
- parents.push(...parent.getFlatParents());
77
- }
78
- parents.push(parent);
79
- }
80
- return parents;
81
- }
82
- parentFields() {
83
- const fields = /* @__PURE__ */ new Map();
84
- for (const parent of this.parents) {
85
- if (parent.isInherited()) {
86
- for (const [name, field] of parent.parentFields()) {
87
- fields.set(name, field.options);
88
- }
89
- }
90
- const parentFields = parent.fields;
91
- for (const [name, field] of parentFields) {
92
- fields.set(name, field.options);
93
- }
94
- }
95
- return fields;
96
- }
97
- parentAttributes() {
98
- const attributes = {};
99
- for (const parent of this.parents) {
100
- if (parent.isInherited()) {
101
- Object.assign(attributes, parent.parentAttributes());
102
- }
103
- const parentAttributes = parent.model.tableAttributes;
104
- Object.assign(attributes, parentAttributes);
105
- }
106
- return attributes;
107
- }
108
- isInherited() {
109
- return true;
110
- }
111
- bindParents() {
112
- this.setParents(this.options.inherits);
113
- this.setParentFields();
114
- this.setFields(this.options.fields, false);
115
- this.db.inheritanceMap.setInheritance(this.name, this.options.inherits);
116
- }
117
- setParents(inherits) {
118
- this.parents = import_lodash.default.castArray(inherits).map((name) => {
119
- const existCollection = this.db.collections.get(name);
120
- if (!existCollection) {
121
- throw new ParentCollectionNotFound(name);
122
- }
123
- return existCollection;
124
- });
125
- }
126
- setParentFields() {
127
- for (const [name, fieldOptions] of this.parentFields()) {
128
- this.setField(name, {
129
- ...fieldOptions,
130
- inherit: true
131
- });
132
- }
133
- }
134
- };
135
- __name(_InheritedCollection, "InheritedCollection");
136
- let InheritedCollection = _InheritedCollection;
137
- const _ParentCollectionNotFound = class _ParentCollectionNotFound extends Error {
138
- constructor(name) {
139
- super(`parent collection ${name} not found`);
140
- }
141
- };
142
- __name(_ParentCollectionNotFound, "ParentCollectionNotFound");
143
- let ParentCollectionNotFound = _ParentCollectionNotFound;
144
- // Annotate the CommonJS export names for ESM import in node:
145
- 0 && (module.exports = {
146
- InheritedCollection
147
- });
@@ -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
- declare class TableNode {
10
- name: string;
11
- parents: Set<TableNode>;
12
- children: Set<TableNode>;
13
- constructor(name: string);
14
- }
15
- export default class InheritanceMap {
16
- nodes: Map<string, TableNode>;
17
- removeNode(name: string): void;
18
- getOrCreateNode(name: string): TableNode;
19
- getNode(name: string): TableNode;
20
- setInheritance(name: string, inherits: string | string[]): void;
21
- isParentNode(name: string): boolean;
22
- getChildren(name: string, options?: {
23
- deep: boolean;
24
- }): Set<string>;
25
- getParents(name: string, options?: {
26
- deep: boolean;
27
- }): Set<string>;
28
- }
29
- export {};
@@ -1,125 +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 inherited_map_exports = {};
39
- __export(inherited_map_exports, {
40
- default: () => InheritanceMap
41
- });
42
- module.exports = __toCommonJS(inherited_map_exports);
43
- var import_lodash = __toESM(require("lodash"));
44
- const _TableNode = class _TableNode {
45
- name;
46
- parents;
47
- children;
48
- constructor(name) {
49
- this.name = name;
50
- this.parents = /* @__PURE__ */ new Set();
51
- this.children = /* @__PURE__ */ new Set();
52
- }
53
- };
54
- __name(_TableNode, "TableNode");
55
- let TableNode = _TableNode;
56
- const _InheritanceMap = class _InheritanceMap {
57
- nodes = /* @__PURE__ */ new Map();
58
- removeNode(name) {
59
- const node = this.nodes.get(name);
60
- if (!node)
61
- return;
62
- for (const parent of node.parents) {
63
- parent.children.delete(node);
64
- }
65
- for (const child of node.children) {
66
- child.parents.delete(node);
67
- }
68
- this.nodes.delete(name);
69
- }
70
- getOrCreateNode(name) {
71
- if (!this.nodes.has(name)) {
72
- this.nodes.set(name, new TableNode(name));
73
- }
74
- return this.getNode(name);
75
- }
76
- getNode(name) {
77
- return this.nodes.get(name);
78
- }
79
- setInheritance(name, inherits) {
80
- const node = this.getOrCreateNode(name);
81
- const parents = import_lodash.default.castArray(inherits).map((name2) => this.getOrCreateNode(name2));
82
- node.parents = new Set(parents);
83
- for (const parent of parents) {
84
- parent.children.add(node);
85
- }
86
- }
87
- isParentNode(name) {
88
- const node = this.getNode(name);
89
- return node && node.children.size > 0;
90
- }
91
- getChildren(name, options = { deep: true }) {
92
- const results = /* @__PURE__ */ new Set();
93
- const node = this.getNode(name);
94
- if (!node)
95
- return results;
96
- for (const child of node.children) {
97
- results.add(child.name);
98
- if (!options.deep) {
99
- continue;
100
- }
101
- for (const grandchild of this.getChildren(child.name)) {
102
- results.add(grandchild);
103
- }
104
- }
105
- return results;
106
- }
107
- getParents(name, options = { deep: true }) {
108
- const results = /* @__PURE__ */ new Set();
109
- const node = this.getNode(name);
110
- if (!node)
111
- return results;
112
- for (const parent of node.parents) {
113
- results.add(parent.name);
114
- if (!options.deep) {
115
- continue;
116
- }
117
- for (const grandparent of this.getParents(parent.name)) {
118
- results.add(grandparent);
119
- }
120
- }
121
- return results;
122
- }
123
- };
124
- __name(_InheritanceMap, "InheritanceMap");
125
- let InheritanceMap = _InheritanceMap;
@@ -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
- export declare class InheritedSyncRunner {
10
- static syncInheritModel(model: any, options: any): Promise<void>;
11
- static createTable(tableName: any, attributes: any, options: any, model: any, parents: any): Promise<any>;
12
- }
@@ -1,184 +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 inherited_sync_runner_exports = {};
39
- __export(inherited_sync_runner_exports, {
40
- InheritedSyncRunner: () => InheritedSyncRunner
41
- });
42
- module.exports = __toCommonJS(inherited_sync_runner_exports);
43
- var import_lodash = __toESM(require("lodash"));
44
- const _InheritedSyncRunner = class _InheritedSyncRunner {
45
- static async syncInheritModel(model, options) {
46
- const { transaction } = options;
47
- const inheritedCollection = model.collection;
48
- const db = inheritedCollection.context.database;
49
- const dialect = db.sequelize.getDialect();
50
- const queryInterface = db.sequelize.getQueryInterface();
51
- if (dialect != "postgres") {
52
- throw new Error("Inherit model is only supported on postgres");
53
- }
54
- const parents = inheritedCollection.parents;
55
- if (!parents) {
56
- throw new Error(
57
- `Inherit model ${inheritedCollection.name} can't be created without parents, parents option is ${import_lodash.default.castArray(inheritedCollection.options.inherits).join(", ")}`
58
- );
59
- }
60
- for (const parent of parents) {
61
- if (Object.keys(parent.model.rawAttributes).length === 0) {
62
- throw new Error(
63
- `can't inherit from collection ${parent.options.name} because it has no attributes, please define at least one attribute in parent collection`
64
- );
65
- }
66
- }
67
- const tableName = inheritedCollection.getTableNameWithSchema();
68
- const attributes = model.tableAttributes;
69
- const childAttributes = import_lodash.default.pickBy(attributes, (value) => {
70
- return !value.inherit;
71
- });
72
- if (!await inheritedCollection.existsInDb({
73
- transaction
74
- })) {
75
- let maxSequenceVal = 0;
76
- let maxSequenceName;
77
- if (childAttributes.id && childAttributes.id.autoIncrement) {
78
- for (const parent of parents) {
79
- const sequenceNameResult = await queryInterface.sequelize.query(
80
- `SELECT column_default
81
- FROM information_schema.columns
82
- WHERE table_name = '${parent.model.tableName}'
83
- and table_schema = '${parent.collectionSchema()}'
84
- and "column_name" = 'id';`,
85
- {
86
- transaction
87
- }
88
- );
89
- if (!sequenceNameResult[0].length) {
90
- continue;
91
- }
92
- const columnDefault = sequenceNameResult[0][0]["column_default"];
93
- if (!columnDefault) {
94
- throw new Error(`Can't find sequence name of parent collection ${parent.options.name}`);
95
- }
96
- const regex = new RegExp(/nextval\('(.*)'::regclass\)/);
97
- const match = regex.exec(columnDefault);
98
- const sequenceName = match[1];
99
- const sequenceCurrentValResult = await queryInterface.sequelize.query(
100
- `select last_value
101
- from ${sequenceName}`,
102
- {
103
- transaction
104
- }
105
- );
106
- const sequenceCurrentVal = parseInt(sequenceCurrentValResult[0][0]["last_value"]);
107
- if (sequenceCurrentVal > maxSequenceVal) {
108
- maxSequenceName = sequenceName;
109
- maxSequenceVal = sequenceCurrentVal;
110
- }
111
- }
112
- }
113
- await this.createTable(tableName, childAttributes, options, model, parents);
114
- if (maxSequenceName) {
115
- const parentsDeep = Array.from(db.inheritanceMap.getParents(inheritedCollection.name)).map(
116
- (parent) => db.getCollection(parent).getTableNameWithSchema()
117
- );
118
- const sequenceTables = [...parentsDeep, tableName];
119
- for (const sequenceTable of sequenceTables) {
120
- const tableName2 = sequenceTable.tableName;
121
- const schemaName = sequenceTable.schema;
122
- const idColumnSql = `SELECT column_name
123
- FROM information_schema.columns
124
- WHERE table_name = '${tableName2}'
125
- and column_name = 'id'
126
- and table_schema = '${schemaName}';
127
- `;
128
- const idColumnQuery = await queryInterface.sequelize.query(idColumnSql, {
129
- transaction
130
- });
131
- if (idColumnQuery[0].length == 0) {
132
- continue;
133
- }
134
- await queryInterface.sequelize.query(
135
- `alter table ${db.utils.quoteTable(sequenceTable)}
136
- alter column id set default nextval('${maxSequenceName}')`,
137
- {
138
- transaction
139
- }
140
- );
141
- }
142
- }
143
- }
144
- if (options.alter) {
145
- const columns = await queryInterface.describeTable(tableName, options);
146
- for (const attribute in childAttributes) {
147
- const columnName = childAttributes[attribute].field;
148
- if (!columns[columnName]) {
149
- await queryInterface.addColumn(tableName, columnName, childAttributes[columnName], options);
150
- }
151
- }
152
- }
153
- }
154
- static async createTable(tableName, attributes, options, model, parents) {
155
- let sql = "";
156
- options = { ...options };
157
- if (options && options.uniqueKeys) {
158
- import_lodash.default.forOwn(options.uniqueKeys, (uniqueKey) => {
159
- if (uniqueKey.customIndex === void 0) {
160
- uniqueKey.customIndex = true;
161
- }
162
- });
163
- }
164
- if (model) {
165
- options.uniqueKeys = options.uniqueKeys || model.uniqueKeys;
166
- }
167
- const queryGenerator = model.queryGenerator;
168
- attributes = import_lodash.default.mapValues(attributes, (attribute) => model.sequelize.normalizeAttribute(attribute));
169
- attributes = queryGenerator.attributesToSQL(attributes, { table: tableName, context: "createTable" });
170
- sql = `${queryGenerator.createTableQuery(tableName, attributes, options)}`.replace(
171
- ";",
172
- ` INHERITS (${parents.map((t) => {
173
- return t.getTableNameWithSchema();
174
- }).join(", ")});`
175
- );
176
- return await model.sequelize.query(sql, options);
177
- }
178
- };
179
- __name(_InheritedSyncRunner, "InheritedSyncRunner");
180
- let InheritedSyncRunner = _InheritedSyncRunner;
181
- // Annotate the CommonJS export names for ESM import in node:
182
- 0 && (module.exports = {
183
- InheritedSyncRunner
184
- });
@@ -1,17 +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
- import { BaseInterface } from './interfaces/base-interface';
11
- export declare class InterfaceManager {
12
- private db;
13
- interfaceTypes: Map<string, new (options: any) => BaseInterface>;
14
- constructor(db: Database);
15
- registerInterfaceType(name: any, iface: any): void;
16
- getInterfaceType(name: any): new (options: any) => BaseInterface;
17
- }
@@ -1,50 +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 interface_manager_exports = {};
29
- __export(interface_manager_exports, {
30
- InterfaceManager: () => InterfaceManager
31
- });
32
- module.exports = __toCommonJS(interface_manager_exports);
33
- const _InterfaceManager = class _InterfaceManager {
34
- constructor(db) {
35
- this.db = db;
36
- }
37
- interfaceTypes = /* @__PURE__ */ new Map();
38
- registerInterfaceType(name, iface) {
39
- this.interfaceTypes.set(name, iface);
40
- }
41
- getInterfaceType(name) {
42
- return this.interfaceTypes.get(name);
43
- }
44
- };
45
- __name(_InterfaceManager, "InterfaceManager");
46
- let InterfaceManager = _InterfaceManager;
47
- // Annotate the CommonJS export names for ESM import in node:
48
- 0 && (module.exports = {
49
- InterfaceManager
50
- });
@@ -1,33 +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 abstract class BaseInterface {
10
- options: any;
11
- constructor(options?: any);
12
- /**
13
- * cast value to string
14
- * @param value
15
- * @param ctx
16
- */
17
- toString(value: any, ctx?: any): any;
18
- /**
19
- * parse string to value
20
- * @param str
21
- * @param ctx
22
- */
23
- toValue(str: any, ctx?: any): Promise<any>;
24
- /**
25
- * cast value to array
26
- * eg: 'a,b,c' => ['a', 'b', 'c']
27
- * eg: ['a', 'b', 'c'] => ['a', 'b', 'c']
28
- * @param value
29
- * @param splitter
30
- */
31
- castArray(value: any, splitter?: string): any[];
32
- trim(value: any): any;
33
- }
@@ -1,80 +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 base_interface_exports = {};
29
- __export(base_interface_exports, {
30
- BaseInterface: () => BaseInterface
31
- });
32
- module.exports = __toCommonJS(base_interface_exports);
33
- const _BaseInterface = class _BaseInterface {
34
- constructor(options = {}) {
35
- this.options = options;
36
- }
37
- /**
38
- * cast value to string
39
- * @param value
40
- * @param ctx
41
- */
42
- toString(value, ctx) {
43
- return value;
44
- }
45
- /**
46
- * parse string to value
47
- * @param str
48
- * @param ctx
49
- */
50
- async toValue(str, ctx) {
51
- return str;
52
- }
53
- /**
54
- * cast value to array
55
- * eg: 'a,b,c' => ['a', 'b', 'c']
56
- * eg: ['a', 'b', 'c'] => ['a', 'b', 'c']
57
- * @param value
58
- * @param splitter
59
- */
60
- castArray(value, splitter) {
61
- let values = [];
62
- if (!value) {
63
- values = [];
64
- } else if (typeof value === "string") {
65
- values = value.split(splitter || /,|,|、/);
66
- } else if (Array.isArray(value)) {
67
- values = value;
68
- }
69
- return values.map((v) => this.trim(v)).filter(Boolean);
70
- }
71
- trim(value) {
72
- return typeof value === "string" ? value.trim() : value;
73
- }
74
- };
75
- __name(_BaseInterface, "BaseInterface");
76
- let BaseInterface = _BaseInterface;
77
- // Annotate the CommonJS export names for ESM import in node:
78
- 0 && (module.exports = {
79
- BaseInterface
80
- });