@nocobase/database 1.7.0-alpha.3 → 1.7.0-alpha.4
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.
- package/lib/collection.js +13 -2
- package/lib/index.d.ts +7 -6
- package/lib/index.js +13 -11
- package/lib/mock-database.d.ts +2 -1
- package/lib/mock-database.js +14 -2
- package/lib/relation-repository/belongs-to-many-repository.js +1 -1
- package/package.json +4 -4
package/lib/collection.js
CHANGED
|
@@ -287,9 +287,20 @@ const _Collection = class _Collection extends import_events.EventEmitter {
|
|
|
287
287
|
if (!field) {
|
|
288
288
|
return;
|
|
289
289
|
}
|
|
290
|
-
if (options.type
|
|
291
|
-
|
|
290
|
+
if (options.type === field.type) {
|
|
291
|
+
return;
|
|
292
|
+
}
|
|
293
|
+
const isContextTypeMatch = /* @__PURE__ */ __name((data, dataType) => {
|
|
294
|
+
var _a, _b;
|
|
295
|
+
return [(_a = data.dataType) == null ? void 0 : _a.key, (_b = data.type) == null ? void 0 : _b.toUpperCase()].includes(dataType == null ? void 0 : dataType.toUpperCase());
|
|
296
|
+
}, "isContextTypeMatch");
|
|
297
|
+
if (options.type === "context" && isContextTypeMatch(field, options.dataType)) {
|
|
298
|
+
return;
|
|
299
|
+
}
|
|
300
|
+
if (field.type === "context" && isContextTypeMatch(options, field.dataType.key)) {
|
|
301
|
+
return;
|
|
292
302
|
}
|
|
303
|
+
throw new Error(`fields with same column must be of the same type ${JSON.stringify(options)}`);
|
|
293
304
|
}
|
|
294
305
|
/**
|
|
295
306
|
* @internal
|
package/lib/index.d.ts
CHANGED
|
@@ -7,16 +7,20 @@
|
|
|
7
7
|
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
8
|
*/
|
|
9
9
|
export { BaseError, BelongsToGetAssociationMixin, DataTypes, fn, HasManyCountAssociationsMixin, HasManyCreateAssociationMixin, HasManyGetAssociationsMixin, literal, ModelStatic, Op, SyncOptions, Transaction, UniqueConstraintError, ValidationError, ValidationErrorItem, where, } from 'sequelize';
|
|
10
|
+
export * from './belongs-to-array/belongs-to-array-repository';
|
|
10
11
|
export * from './collection';
|
|
11
12
|
export * from './collection-group-manager';
|
|
12
13
|
export * from './collection-importer';
|
|
13
14
|
export * from './database';
|
|
14
15
|
export { Database as default } from './database';
|
|
16
|
+
export * from './dialects';
|
|
15
17
|
export * from './field-repository/array-field-repository';
|
|
16
18
|
export * from './fields';
|
|
17
19
|
export * from './filter-match';
|
|
18
20
|
export { default as FilterParser } from './filter-parser';
|
|
21
|
+
export * from './helpers';
|
|
19
22
|
export * from './inherited-collection';
|
|
23
|
+
export * from './interfaces';
|
|
20
24
|
export * from './magic-attribute-model';
|
|
21
25
|
export * from './migration';
|
|
22
26
|
export * from './mock-database';
|
|
@@ -24,17 +28,14 @@ export * from './model';
|
|
|
24
28
|
export * from './relation-repository/belongs-to-many-repository';
|
|
25
29
|
export * from './relation-repository/belongs-to-repository';
|
|
26
30
|
export * from './relation-repository/hasmany-repository';
|
|
31
|
+
export * from './relation-repository/hasone-repository';
|
|
27
32
|
export * from './relation-repository/multiple-relation-repository';
|
|
28
33
|
export * from './relation-repository/single-relation-repository';
|
|
29
|
-
export * from './belongs-to-array/belongs-to-array-repository';
|
|
30
34
|
export * from './repository';
|
|
35
|
+
export { default as sqlParser, SQLParserTypes } from './sql-parser';
|
|
31
36
|
export * from './update-associations';
|
|
32
37
|
export { snakeCase } from './utils';
|
|
33
38
|
export * from './value-parsers';
|
|
34
39
|
export * from './view-collection';
|
|
35
|
-
export * from './view/view-inference';
|
|
36
|
-
export * from './helpers';
|
|
37
|
-
export { default as sqlParser, SQLParserTypes } from './sql-parser';
|
|
38
|
-
export * from './interfaces';
|
|
39
40
|
export { default as fieldTypeMap } from './view/field-type-map';
|
|
40
|
-
export * from './
|
|
41
|
+
export * from './view/view-inference';
|
package/lib/index.js
CHANGED
|
@@ -62,16 +62,20 @@ __export(src_exports, {
|
|
|
62
62
|
});
|
|
63
63
|
module.exports = __toCommonJS(src_exports);
|
|
64
64
|
var import_sequelize = require("sequelize");
|
|
65
|
+
__reExport(src_exports, require("./belongs-to-array/belongs-to-array-repository"), module.exports);
|
|
65
66
|
__reExport(src_exports, require("./collection"), module.exports);
|
|
66
67
|
__reExport(src_exports, require("./collection-group-manager"), module.exports);
|
|
67
68
|
__reExport(src_exports, require("./collection-importer"), module.exports);
|
|
68
69
|
__reExport(src_exports, require("./database"), module.exports);
|
|
69
70
|
var import_database = require("./database");
|
|
71
|
+
__reExport(src_exports, require("./dialects"), module.exports);
|
|
70
72
|
__reExport(src_exports, require("./field-repository/array-field-repository"), module.exports);
|
|
71
73
|
__reExport(src_exports, require("./fields"), module.exports);
|
|
72
74
|
__reExport(src_exports, require("./filter-match"), module.exports);
|
|
73
75
|
var import_filter_parser = __toESM(require("./filter-parser"));
|
|
76
|
+
__reExport(src_exports, require("./helpers"), module.exports);
|
|
74
77
|
__reExport(src_exports, require("./inherited-collection"), module.exports);
|
|
78
|
+
__reExport(src_exports, require("./interfaces"), module.exports);
|
|
75
79
|
__reExport(src_exports, require("./magic-attribute-model"), module.exports);
|
|
76
80
|
__reExport(src_exports, require("./migration"), module.exports);
|
|
77
81
|
__reExport(src_exports, require("./mock-database"), module.exports);
|
|
@@ -79,20 +83,17 @@ __reExport(src_exports, require("./model"), module.exports);
|
|
|
79
83
|
__reExport(src_exports, require("./relation-repository/belongs-to-many-repository"), module.exports);
|
|
80
84
|
__reExport(src_exports, require("./relation-repository/belongs-to-repository"), module.exports);
|
|
81
85
|
__reExport(src_exports, require("./relation-repository/hasmany-repository"), module.exports);
|
|
86
|
+
__reExport(src_exports, require("./relation-repository/hasone-repository"), module.exports);
|
|
82
87
|
__reExport(src_exports, require("./relation-repository/multiple-relation-repository"), module.exports);
|
|
83
88
|
__reExport(src_exports, require("./relation-repository/single-relation-repository"), module.exports);
|
|
84
|
-
__reExport(src_exports, require("./belongs-to-array/belongs-to-array-repository"), module.exports);
|
|
85
89
|
__reExport(src_exports, require("./repository"), module.exports);
|
|
90
|
+
var import_sql_parser = __toESM(require("./sql-parser"));
|
|
86
91
|
__reExport(src_exports, require("./update-associations"), module.exports);
|
|
87
92
|
var import_utils = require("./utils");
|
|
88
93
|
__reExport(src_exports, require("./value-parsers"), module.exports);
|
|
89
94
|
__reExport(src_exports, require("./view-collection"), module.exports);
|
|
90
|
-
__reExport(src_exports, require("./view/view-inference"), module.exports);
|
|
91
|
-
__reExport(src_exports, require("./helpers"), module.exports);
|
|
92
|
-
var import_sql_parser = __toESM(require("./sql-parser"));
|
|
93
|
-
__reExport(src_exports, require("./interfaces"), module.exports);
|
|
94
95
|
var import_field_type_map = __toESM(require("./view/field-type-map"));
|
|
95
|
-
__reExport(src_exports, require("./
|
|
96
|
+
__reExport(src_exports, require("./view/view-inference"), module.exports);
|
|
96
97
|
// Annotate the CommonJS export names for ESM import in node:
|
|
97
98
|
0 && (module.exports = {
|
|
98
99
|
BaseError,
|
|
@@ -116,14 +117,18 @@ __reExport(src_exports, require("./dialects"), module.exports);
|
|
|
116
117
|
snakeCase,
|
|
117
118
|
sqlParser,
|
|
118
119
|
where,
|
|
120
|
+
...require("./belongs-to-array/belongs-to-array-repository"),
|
|
119
121
|
...require("./collection"),
|
|
120
122
|
...require("./collection-group-manager"),
|
|
121
123
|
...require("./collection-importer"),
|
|
122
124
|
...require("./database"),
|
|
125
|
+
...require("./dialects"),
|
|
123
126
|
...require("./field-repository/array-field-repository"),
|
|
124
127
|
...require("./fields"),
|
|
125
128
|
...require("./filter-match"),
|
|
129
|
+
...require("./helpers"),
|
|
126
130
|
...require("./inherited-collection"),
|
|
131
|
+
...require("./interfaces"),
|
|
127
132
|
...require("./magic-attribute-model"),
|
|
128
133
|
...require("./migration"),
|
|
129
134
|
...require("./mock-database"),
|
|
@@ -131,15 +136,12 @@ __reExport(src_exports, require("./dialects"), module.exports);
|
|
|
131
136
|
...require("./relation-repository/belongs-to-many-repository"),
|
|
132
137
|
...require("./relation-repository/belongs-to-repository"),
|
|
133
138
|
...require("./relation-repository/hasmany-repository"),
|
|
139
|
+
...require("./relation-repository/hasone-repository"),
|
|
134
140
|
...require("./relation-repository/multiple-relation-repository"),
|
|
135
141
|
...require("./relation-repository/single-relation-repository"),
|
|
136
|
-
...require("./belongs-to-array/belongs-to-array-repository"),
|
|
137
142
|
...require("./repository"),
|
|
138
143
|
...require("./update-associations"),
|
|
139
144
|
...require("./value-parsers"),
|
|
140
145
|
...require("./view-collection"),
|
|
141
|
-
...require("./view/view-inference")
|
|
142
|
-
...require("./helpers"),
|
|
143
|
-
...require("./interfaces"),
|
|
144
|
-
...require("./dialects")
|
|
146
|
+
...require("./view/view-inference")
|
|
145
147
|
});
|
package/lib/mock-database.d.ts
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
7
|
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
8
|
*/
|
|
9
|
-
import { Database, IDatabaseOptions } from '
|
|
9
|
+
import { Database, IDatabaseOptions } from '@nocobase/database';
|
|
10
10
|
export declare class MockDatabase extends Database {
|
|
11
11
|
constructor(options: IDatabaseOptions);
|
|
12
12
|
}
|
|
@@ -29,5 +29,6 @@ export declare function getConfigByEnv(): {
|
|
|
29
29
|
dialectOptions: {};
|
|
30
30
|
};
|
|
31
31
|
declare function customLogger(queryString: any, queryObject: any): void;
|
|
32
|
+
export declare function createMockDatabase(options?: IDatabaseOptions): Promise<MockDatabase>;
|
|
32
33
|
export declare function mockDatabase(options?: IDatabaseOptions): MockDatabase;
|
|
33
34
|
export {};
|
package/lib/mock-database.js
CHANGED
|
@@ -38,15 +38,16 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
38
38
|
var mock_database_exports = {};
|
|
39
39
|
__export(mock_database_exports, {
|
|
40
40
|
MockDatabase: () => MockDatabase,
|
|
41
|
+
createMockDatabase: () => createMockDatabase,
|
|
41
42
|
getConfigByEnv: () => getConfigByEnv,
|
|
42
43
|
mockDatabase: () => mockDatabase
|
|
43
44
|
});
|
|
44
45
|
module.exports = __toCommonJS(mock_database_exports);
|
|
46
|
+
var import_database = require("@nocobase/database");
|
|
45
47
|
var import_utils = require("@nocobase/utils");
|
|
46
48
|
var import_nanoid = require("nanoid");
|
|
47
49
|
var import_node_fetch = __toESM(require("node-fetch"));
|
|
48
50
|
var import_path = __toESM(require("path"));
|
|
49
|
-
var import_database = require("./database");
|
|
50
51
|
/* istanbul ignore file -- @preserve */
|
|
51
52
|
const _MockDatabase = class _MockDatabase extends import_database.Database {
|
|
52
53
|
constructor(options) {
|
|
@@ -91,8 +92,18 @@ function customLogger(queryString, queryObject) {
|
|
|
91
92
|
}
|
|
92
93
|
}
|
|
93
94
|
__name(customLogger, "customLogger");
|
|
95
|
+
async function createMockDatabase(options = {}) {
|
|
96
|
+
try {
|
|
97
|
+
const { runPluginStaticImports } = await import("@nocobase/server");
|
|
98
|
+
await runPluginStaticImports();
|
|
99
|
+
} catch (error) {
|
|
100
|
+
}
|
|
101
|
+
return mockDatabase(options);
|
|
102
|
+
}
|
|
103
|
+
__name(createMockDatabase, "createMockDatabase");
|
|
94
104
|
function mockDatabase(options = {}) {
|
|
95
105
|
const dbOptions = (0, import_utils.merge)(getConfigByEnv(), options);
|
|
106
|
+
let db;
|
|
96
107
|
if (process.env["DB_TEST_PREFIX"]) {
|
|
97
108
|
let configKey = "database";
|
|
98
109
|
if (dbOptions.dialect === "sqlite") {
|
|
@@ -124,13 +135,14 @@ function mockDatabase(options = {}) {
|
|
|
124
135
|
};
|
|
125
136
|
}
|
|
126
137
|
}
|
|
127
|
-
|
|
138
|
+
db = new MockDatabase(dbOptions);
|
|
128
139
|
return db;
|
|
129
140
|
}
|
|
130
141
|
__name(mockDatabase, "mockDatabase");
|
|
131
142
|
// Annotate the CommonJS export names for ESM import in node:
|
|
132
143
|
0 && (module.exports = {
|
|
133
144
|
MockDatabase,
|
|
145
|
+
createMockDatabase,
|
|
134
146
|
getConfigByEnv,
|
|
135
147
|
mockDatabase
|
|
136
148
|
});
|
|
@@ -56,7 +56,7 @@ var import_relation_repository = require("./relation-repository");
|
|
|
56
56
|
const _BelongsToManyRepository = class _BelongsToManyRepository extends import_multiple_relation_repository.MultipleRelationRepository {
|
|
57
57
|
async aggregate(options) {
|
|
58
58
|
const targetRepository = this.targetCollection.repository;
|
|
59
|
-
const sourceModel = await this.getSourceModel();
|
|
59
|
+
const sourceModel = await this.getSourceModel(await this.getTransaction(options));
|
|
60
60
|
const association = this.association;
|
|
61
61
|
return await targetRepository.aggregate({
|
|
62
62
|
...options,
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nocobase/database",
|
|
3
|
-
"version": "1.7.0-alpha.
|
|
3
|
+
"version": "1.7.0-alpha.4",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"types": "./lib/index.d.ts",
|
|
7
7
|
"license": "AGPL-3.0",
|
|
8
8
|
"dependencies": {
|
|
9
|
-
"@nocobase/logger": "1.7.0-alpha.
|
|
10
|
-
"@nocobase/utils": "1.7.0-alpha.
|
|
9
|
+
"@nocobase/logger": "1.7.0-alpha.4",
|
|
10
|
+
"@nocobase/utils": "1.7.0-alpha.4",
|
|
11
11
|
"async-mutex": "^0.3.2",
|
|
12
12
|
"chalk": "^4.1.1",
|
|
13
13
|
"cron-parser": "4.4.0",
|
|
@@ -38,5 +38,5 @@
|
|
|
38
38
|
"url": "git+https://github.com/nocobase/nocobase.git",
|
|
39
39
|
"directory": "packages/database"
|
|
40
40
|
},
|
|
41
|
-
"gitHead": "
|
|
41
|
+
"gitHead": "e31c3136901b10ec7cbe4bbc8a22dc4cc7481f93"
|
|
42
42
|
}
|