@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,136 +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 mock_database_exports = {};
39
- __export(mock_database_exports, {
40
- MockDatabase: () => MockDatabase,
41
- getConfigByEnv: () => getConfigByEnv,
42
- mockDatabase: () => mockDatabase
43
- });
44
- module.exports = __toCommonJS(mock_database_exports);
45
- var import_utils = require("@nocobase/utils");
46
- var import_nanoid = require("nanoid");
47
- var import_node_fetch = __toESM(require("node-fetch"));
48
- var import_path = __toESM(require("path"));
49
- var import_database = require("./database");
50
- /* istanbul ignore file -- @preserve */
51
- const _MockDatabase = class _MockDatabase extends import_database.Database {
52
- constructor(options) {
53
- super({
54
- storage: ":memory:",
55
- dialect: "sqlite",
56
- ...options
57
- });
58
- }
59
- };
60
- __name(_MockDatabase, "MockDatabase");
61
- let MockDatabase = _MockDatabase;
62
- function getConfigByEnv() {
63
- const options = {
64
- username: process.env.DB_USER,
65
- password: process.env.DB_PASSWORD,
66
- database: process.env.DB_DATABASE,
67
- host: process.env.DB_HOST,
68
- port: process.env.DB_PORT,
69
- dialect: process.env.DB_DIALECT || "sqlite",
70
- logging: process.env.DB_LOGGING === "on" ? customLogger : false,
71
- storage: process.env.DB_STORAGE,
72
- define: {
73
- charset: "utf8mb4",
74
- collate: "utf8mb4_unicode_ci"
75
- },
76
- timezone: process.env.DB_TIMEZONE,
77
- underscored: process.env.DB_UNDERSCORED === "true",
78
- schema: process.env.DB_SCHEMA !== "public" ? process.env.DB_SCHEMA : void 0,
79
- dialectOptions: {}
80
- };
81
- if (process.env.DB_DIALECT == "postgres") {
82
- options.dialectOptions["application_name"] = "nocobase.main";
83
- }
84
- return options;
85
- }
86
- __name(getConfigByEnv, "getConfigByEnv");
87
- function customLogger(queryString, queryObject) {
88
- console.log(queryString);
89
- if (queryObject == null ? void 0 : queryObject.bind) {
90
- console.log(queryObject.bind);
91
- }
92
- }
93
- __name(customLogger, "customLogger");
94
- function mockDatabase(options = {}) {
95
- const dbOptions = (0, import_utils.merge)(getConfigByEnv(), options);
96
- if (process.env["DB_TEST_PREFIX"]) {
97
- let configKey = "database";
98
- if (dbOptions.dialect === "sqlite") {
99
- configKey = "storage";
100
- } else {
101
- configKey = "database";
102
- }
103
- const shouldChange = /* @__PURE__ */ __name(() => {
104
- if (dbOptions.dialect === "sqlite") {
105
- return !dbOptions[configKey].includes(process.env["DB_TEST_PREFIX"]);
106
- }
107
- return !dbOptions[configKey].startsWith(process.env["DB_TEST_PREFIX"]);
108
- }, "shouldChange");
109
- if (dbOptions[configKey] && shouldChange()) {
110
- const nanoid = (0, import_nanoid.customAlphabet)("1234567890abcdefghijklmnopqrstuvwxyz", 10);
111
- const instanceId = `d_${nanoid()}`;
112
- const databaseName = `${process.env["DB_TEST_PREFIX"]}_${instanceId}`;
113
- if (dbOptions.dialect === "sqlite") {
114
- dbOptions.storage = import_path.default.resolve(import_path.default.dirname(dbOptions.storage), databaseName);
115
- } else {
116
- dbOptions.database = databaseName;
117
- }
118
- }
119
- if (process.env["DB_TEST_DISTRIBUTOR_PORT"]) {
120
- dbOptions.hooks = dbOptions.hooks || {};
121
- dbOptions.hooks.beforeConnect = async (config) => {
122
- const url = `http://127.0.0.1:${process.env["DB_TEST_DISTRIBUTOR_PORT"]}/acquire?via=${db.instanceId}&name=${config.database}`;
123
- await (0, import_node_fetch.default)(url);
124
- };
125
- }
126
- }
127
- const db = new MockDatabase(dbOptions);
128
- return db;
129
- }
130
- __name(mockDatabase, "mockDatabase");
131
- // Annotate the CommonJS export names for ESM import in node:
132
- 0 && (module.exports = {
133
- MockDatabase,
134
- getConfigByEnv,
135
- mockDatabase
136
- });
@@ -1,20 +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 { SequelizeHooks } from 'sequelize/types/hooks';
10
- import Database from './database';
11
- export declare class ModelHook {
12
- database: Database;
13
- boundEvents: Set<string>;
14
- constructor(database: Database);
15
- match(event: string | symbol): keyof SequelizeHooks | null;
16
- findModelName(hookArgs: any): any;
17
- bindEvent(type: any): void;
18
- hasBoundEvent(type: any): boolean;
19
- buildSequelizeHook(type: any): (...args: any[]) => Promise<void>;
20
- }
package/lib/model-hook.js DELETED
@@ -1,96 +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 model_hook_exports = {};
39
- __export(model_hook_exports, {
40
- ModelHook: () => ModelHook
41
- });
42
- module.exports = __toCommonJS(model_hook_exports);
43
- var import_lodash = __toESM(require("lodash"));
44
- const { hooks } = require("sequelize/lib/hooks");
45
- const _ModelHook = class _ModelHook {
46
- database;
47
- boundEvents = /* @__PURE__ */ new Set();
48
- constructor(database) {
49
- this.database = database;
50
- }
51
- match(event) {
52
- if (!import_lodash.default.isString(event)) {
53
- return null;
54
- }
55
- const type = event.split(".").pop();
56
- return type in hooks ? type : null;
57
- }
58
- findModelName(hookArgs) {
59
- for (const arg of hookArgs) {
60
- if (arg == null ? void 0 : arg._previousDataValues) {
61
- return arg.constructor.name;
62
- }
63
- if (import_lodash.default.isPlainObject(arg)) {
64
- if (arg["model"]) {
65
- return arg["model"].name;
66
- }
67
- const modelName = arg["modelName"];
68
- if (this.database.sequelize.isDefined(modelName)) {
69
- return modelName;
70
- }
71
- }
72
- }
73
- return null;
74
- }
75
- bindEvent(type) {
76
- this.boundEvents.add(type);
77
- }
78
- hasBoundEvent(type) {
79
- return this.boundEvents.has(type);
80
- }
81
- buildSequelizeHook(type) {
82
- return async (...args) => {
83
- const modelName = this.findModelName(args);
84
- if (modelName) {
85
- await this.database.emitAsync(`${modelName}.${type}`, ...args);
86
- }
87
- await this.database.emitAsync(type, ...args);
88
- };
89
- }
90
- };
91
- __name(_ModelHook, "ModelHook");
92
- let ModelHook = _ModelHook;
93
- // Annotate the CommonJS export names for ESM import in node:
94
- 0 && (module.exports = {
95
- ModelHook
96
- });
package/lib/model.d.ts DELETED
@@ -1,32 +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 as SequelizeModel } from 'sequelize';
10
- import { Collection } from './collection';
11
- import { Database } from './database';
12
- interface IModel {
13
- [key: string]: any;
14
- }
15
- export declare class Model<TModelAttributes extends {} = any, TCreationAttributes extends {} = TModelAttributes> extends SequelizeModel<TModelAttributes, TCreationAttributes> implements IModel {
16
- static database: Database;
17
- static collection: Collection;
18
- [key: string]: any;
19
- protected _changedWithAssociations: Set<unknown>;
20
- protected _previousDataValuesWithAssociations: {};
21
- get db(): Database;
22
- static sync(options: any): Promise<any>;
23
- toChangedWithAssociations(): void;
24
- changedWithAssociations(key?: string, value?: any): boolean | unknown[] | this;
25
- clearChangedWithAssociations(): void;
26
- toJSON<T extends TModelAttributes>(): T;
27
- private hiddenObjKey;
28
- private handleBigInt;
29
- private sortAssociations;
30
- private sortArray;
31
- }
32
- export {};
package/lib/model.js DELETED
@@ -1,179 +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 model_exports = {};
44
- __export(model_exports, {
45
- Model: () => Model
46
- });
47
- module.exports = __toCommonJS(model_exports);
48
- var import_lodash = __toESM(require("lodash"));
49
- var import_sequelize = require("sequelize");
50
- var import_sync_runner = require("./sync-runner");
51
- const _ = import_lodash.default;
52
- const _Model = class _Model extends import_sequelize.Model {
53
- _changedWithAssociations = /* @__PURE__ */ new Set();
54
- _previousDataValuesWithAssociations = {};
55
- get db() {
56
- return this.constructor.database;
57
- }
58
- static async sync(options) {
59
- const runner = new import_sync_runner.SyncRunner(this);
60
- return runner.runSync(options);
61
- }
62
- // TODO
63
- toChangedWithAssociations() {
64
- this._changedWithAssociations = /* @__PURE__ */ new Set([...this._changedWithAssociations, ...this._changed]);
65
- this._previousDataValuesWithAssociations = this._previousDataValues;
66
- }
67
- changedWithAssociations(key, value) {
68
- if (key === void 0) {
69
- if (this._changedWithAssociations.size > 0) {
70
- return Array.from(this._changedWithAssociations);
71
- }
72
- return false;
73
- }
74
- if (value === true) {
75
- this._changedWithAssociations.add(key);
76
- return this;
77
- }
78
- if (value === false) {
79
- this._changedWithAssociations.delete(key);
80
- return this;
81
- }
82
- return this._changedWithAssociations.has(key);
83
- }
84
- clearChangedWithAssociations() {
85
- this._changedWithAssociations = /* @__PURE__ */ new Set();
86
- }
87
- toJSON() {
88
- const handleObj = /* @__PURE__ */ __name((obj, options) => {
89
- const handles = [
90
- (data) => {
91
- if (data instanceof _Model) {
92
- return data.toJSON();
93
- }
94
- return data;
95
- },
96
- this.hiddenObjKey,
97
- this.handleBigInt
98
- ];
99
- return handles.reduce((carry, fn) => fn.apply(this, [carry, options]), obj);
100
- }, "handleObj");
101
- const handleArray = /* @__PURE__ */ __name((arrayOfObj, options) => {
102
- const handles = [this.sortAssociations];
103
- return handles.reduce((carry, fn) => fn.apply(this, [carry, options]), arrayOfObj || []);
104
- }, "handleArray");
105
- const opts = {
106
- model: this.constructor,
107
- collection: this.constructor.collection,
108
- db: this.constructor.database
109
- };
110
- const traverseJSON = /* @__PURE__ */ __name((data, options) => {
111
- const { model, db, collection } = options;
112
- data = handleObj(data, options);
113
- const result = {};
114
- for (const key of Object.keys(data)) {
115
- if (model.hasAlias(key)) {
116
- const association = model.associations[key];
117
- const opts2 = {
118
- model: association.target,
119
- collection: db.getCollection(association.target.name),
120
- db,
121
- key,
122
- field: collection.getField(key)
123
- };
124
- if (["HasMany", "BelongsToMany"].includes(association.associationType)) {
125
- result[key] = handleArray(data[key], opts2).map((item) => traverseJSON(item, opts2));
126
- } else {
127
- result[key] = data[key] ? traverseJSON(data[key], opts2) : null;
128
- }
129
- } else {
130
- result[key] = data[key];
131
- }
132
- }
133
- return result;
134
- }, "traverseJSON");
135
- return traverseJSON(super.toJSON(), opts);
136
- }
137
- hiddenObjKey(obj, options) {
138
- const hiddenFields = Array.from(options.collection.fields.values()).filter((field) => field.options.hidden).map((field) => field.options.name);
139
- return import_lodash.default.omit(obj, hiddenFields);
140
- }
141
- handleBigInt(obj, options) {
142
- if (!options.db.inDialect("mariadb")) {
143
- return obj;
144
- }
145
- const bigIntKeys = Object.keys(options.model.rawAttributes).filter((key) => {
146
- return options.model.rawAttributes[key].type.constructor.name === "BIGINT";
147
- });
148
- for (const key of bigIntKeys) {
149
- if (obj[key] !== null && obj[key] !== void 0 && typeof obj[key] !== "string" && typeof obj[key] !== "number") {
150
- obj[key] = obj[key].toString();
151
- }
152
- }
153
- return obj;
154
- }
155
- sortAssociations(data, { field }) {
156
- const sortBy = field.options.sortBy;
157
- return sortBy ? this.sortArray(data, sortBy) : data;
158
- }
159
- sortArray(data, sortBy) {
160
- if (!import_lodash.default.isArray(sortBy)) {
161
- sortBy = [sortBy];
162
- }
163
- const orderItems = [];
164
- const orderDirections = [];
165
- sortBy.forEach((sortItem) => {
166
- orderDirections.push(sortItem.startsWith("-") ? "desc" : "asc");
167
- orderItems.push(sortItem.replace("-", ""));
168
- });
169
- return import_lodash.default.orderBy(data, orderItems, orderDirections);
170
- }
171
- };
172
- __name(_Model, "Model");
173
- __publicField(_Model, "database");
174
- __publicField(_Model, "collection");
175
- let Model = _Model;
176
- // Annotate the CommonJS export names for ESM import in node:
177
- 0 && (module.exports = {
178
- Model
179
- });
@@ -1,10 +0,0 @@
1
- /**
2
- * This file is part of the NocoBase (R) project.
3
- * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
- * Authors: NocoBase Team.
5
- *
6
- * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
- * For more information, please refer to: https://www.nocobase.com/agreement.
8
- */
9
- declare const _default: Record<string, any>;
10
- export default _default;
@@ -1,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 __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 array_exports = {};
39
- __export(array_exports, {
40
- default: () => array_default
41
- });
42
- module.exports = __toCommonJS(array_exports);
43
- var import_lodash = __toESM(require("lodash"));
44
- var import_sequelize = require("sequelize");
45
- var import_utils = require("./utils");
46
- const getFieldName = /* @__PURE__ */ __name((ctx) => {
47
- const fullNameSplit = ctx.fullName.split(".");
48
- const fieldName = ctx.fieldName;
49
- let columnName = fieldName;
50
- const associationPath = [];
51
- if (fullNameSplit.length > 1) {
52
- for (let i = 0; i < fullNameSplit.length - 1; i++) {
53
- associationPath.push(fullNameSplit[i]);
54
- }
55
- }
56
- const getModelFromAssociationPath = /* @__PURE__ */ __name(() => {
57
- let model2 = ctx.model;
58
- for (const association of associationPath) {
59
- model2 = model2.associations[association].target;
60
- }
61
- return model2;
62
- }, "getModelFromAssociationPath");
63
- const model = getModelFromAssociationPath();
64
- let columnPrefix = model.name;
65
- if (model.rawAttributes[fieldName]) {
66
- columnName = model.rawAttributes[fieldName].field || fieldName;
67
- }
68
- if (associationPath.length > 0) {
69
- const association = associationPath.join("->");
70
- columnPrefix = association;
71
- }
72
- columnName = `${columnPrefix}.${columnName}`;
73
- return columnName;
74
- }, "getFieldName");
75
- const escape = /* @__PURE__ */ __name((value, ctx) => {
76
- const sequelize = ctx.db.sequelize;
77
- return sequelize.escape(value);
78
- }, "escape");
79
- const getQueryInterface = /* @__PURE__ */ __name((ctx) => {
80
- const sequelize = ctx.db.sequelize;
81
- return sequelize.getQueryInterface();
82
- }, "getQueryInterface");
83
- const sqliteExistQuery = /* @__PURE__ */ __name((value, ctx) => {
84
- const fieldName = getFieldName(ctx);
85
- const queryInterface = getQueryInterface(ctx);
86
- const name = queryInterface.quoteIdentifiers(fieldName);
87
- const sqlArray = `(${value.map((v) => `'${v}'`).join(", ")})`;
88
- const subQuery = `exists (select * from json_each(${name}) where json_each.value in ${sqlArray})`;
89
- return subQuery;
90
- }, "sqliteExistQuery");
91
- const emptyQuery = /* @__PURE__ */ __name((ctx, operator) => {
92
- const fieldName = getFieldName(ctx);
93
- let funcName = "json_array_length";
94
- let ifNull = "IFNULL";
95
- if ((0, import_utils.isPg)(ctx)) {
96
- funcName = "jsonb_array_length";
97
- ifNull = "coalesce";
98
- }
99
- if ((0, import_utils.isMySQL)(ctx)) {
100
- funcName = "json_length";
101
- }
102
- const queryInterface = getQueryInterface(ctx);
103
- return `(select ${ifNull}(${funcName}(${queryInterface.quoteIdentifiers(fieldName)}), 0) ${operator} 0)`;
104
- }, "emptyQuery");
105
- var array_default = {
106
- $match(value, ctx) {
107
- const queryInterface = getQueryInterface(ctx);
108
- const fieldName = getFieldName(ctx);
109
- if ((0, import_utils.isPg)(ctx)) {
110
- const name = queryInterface.quoteIdentifiers(fieldName);
111
- const queryValue = escape(JSON.stringify(value), ctx);
112
- return import_sequelize.Sequelize.literal(`${name} @> ${queryValue}::JSONB AND ${name} <@ ${queryValue}::JSONB`);
113
- }
114
- value = escape(JSON.stringify(value.sort()), ctx);
115
- if ((0, import_utils.isMySQL)(ctx)) {
116
- const name = queryInterface.quoteIdentifiers(fieldName);
117
- return import_sequelize.Sequelize.literal(`JSON_CONTAINS(${name}, ${value}) AND JSON_CONTAINS(${value}, ${name})`);
118
- }
119
- return {
120
- [import_sequelize.Op.eq]: import_sequelize.Sequelize.literal(`json(${value})`)
121
- };
122
- },
123
- $notMatch(value, ctx) {
124
- const queryInterface = getQueryInterface(ctx);
125
- value = escape(JSON.stringify(value), ctx);
126
- if ((0, import_utils.isPg)(ctx)) {
127
- const name = queryInterface.quoteIdentifiers(getFieldName(ctx));
128
- return import_sequelize.Sequelize.literal(`not (${name} <@ ${value}::JSONB and ${name} @> ${value}::JSONB)`);
129
- }
130
- if ((0, import_utils.isMySQL)(ctx)) {
131
- const name = queryInterface.quoteIdentifiers(getFieldName(ctx));
132
- return import_sequelize.Sequelize.literal(`not (JSON_CONTAINS(${name}, ${value}) AND JSON_CONTAINS(${value}, ${name}))`);
133
- }
134
- return {
135
- [import_sequelize.Op.ne]: import_sequelize.Sequelize.literal(`json(${value})`)
136
- };
137
- },
138
- $anyOf(value, ctx) {
139
- const fieldName = getFieldName(ctx);
140
- value = import_lodash.default.castArray(value);
141
- const queryInterface = getQueryInterface(ctx);
142
- if ((0, import_utils.isPg)(ctx)) {
143
- const name = queryInterface.quoteIdentifiers(getFieldName(ctx));
144
- return import_sequelize.Sequelize.literal(
145
- `${name} ?| ${escape(
146
- value.map((i) => `${i}`),
147
- ctx
148
- )}`
149
- );
150
- }
151
- if ((0, import_utils.isMySQL)(ctx)) {
152
- value = escape(JSON.stringify(value), ctx);
153
- const name = queryInterface.quoteIdentifiers(getFieldName(ctx));
154
- return import_sequelize.Sequelize.literal(`JSON_OVERLAPS(${name}, ${value})`);
155
- }
156
- const subQuery = sqliteExistQuery(value, ctx);
157
- return import_sequelize.Sequelize.literal(subQuery);
158
- },
159
- $noneOf(value, ctx) {
160
- let where;
161
- value = import_lodash.default.castArray(value);
162
- const queryInterface = getQueryInterface(ctx);
163
- if ((0, import_utils.isPg)(ctx)) {
164
- const name = queryInterface.quoteIdentifiers(getFieldName(ctx));
165
- where = import_sequelize.Sequelize.literal(
166
- `not (${name} ?| ${escape(
167
- value.map((i) => `${i}`),
168
- ctx
169
- )})`
170
- );
171
- } else if ((0, import_utils.isMySQL)(ctx)) {
172
- const fieldName = getFieldName(ctx);
173
- value = escape(JSON.stringify(value), ctx);
174
- const name = queryInterface.quoteIdentifiers(getFieldName(ctx));
175
- where = import_sequelize.Sequelize.literal(`NOT JSON_OVERLAPS(${name}, ${value})`);
176
- } else {
177
- const subQuery = sqliteExistQuery(value, ctx);
178
- where = import_sequelize.Sequelize.literal(`not ${subQuery}`);
179
- }
180
- return {
181
- [import_sequelize.Op.or]: [where, { [import_sequelize.Op.is]: null }]
182
- };
183
- },
184
- $arrayEmpty(value, ctx) {
185
- const subQuery = emptyQuery(ctx, "=");
186
- return {
187
- [import_sequelize.Op.and]: [import_sequelize.Sequelize.literal(`${subQuery}`)]
188
- };
189
- },
190
- $arrayNotEmpty(value, ctx) {
191
- const subQuery = emptyQuery(ctx, ">");
192
- return {
193
- [import_sequelize.Op.and]: [import_sequelize.Sequelize.literal(`${subQuery}`)]
194
- };
195
- }
196
- };
@@ -1,10 +0,0 @@
1
- /**
2
- * This file is part of the NocoBase (R) project.
3
- * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
- * Authors: NocoBase Team.
5
- *
6
- * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
- * For more information, please refer to: https://www.nocobase.com/agreement.
8
- */
9
- declare const _default: Record<string, any>;
10
- export default _default;