@nocobase/database 1.2.3-alpha → 1.2.5-alpha
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 +1 -0
- package/lib/database.d.ts +1 -1
- package/lib/database.js +10 -10
- package/lib/fields/sort-field.d.ts +1 -3
- package/lib/fields/sort-field.js +2 -1
- package/lib/interfaces/multiple-select-interface.js +8 -1
- package/lib/interfaces/select-interface.js +11 -1
- package/lib/interfaces/to-many-interface.js +5 -0
- package/lib/interfaces/to-one-interface.js +7 -4
- package/lib/model-hook.js +3 -8
- package/lib/view/field-type-map.d.ts +4 -0
- package/lib/view/field-type-map.js +2 -0
- package/package.json +4 -4
package/lib/collection.js
CHANGED
|
@@ -173,6 +173,7 @@ const _Collection = class _Collection extends import_events.EventEmitter {
|
|
|
173
173
|
this.model = class extends M {
|
|
174
174
|
};
|
|
175
175
|
this.model.init(null, this.sequelizeModelOptions());
|
|
176
|
+
this.model.options.modelName = this.options.name;
|
|
176
177
|
if (!autoGenId) {
|
|
177
178
|
this.model.removeAttribute("id");
|
|
178
179
|
}
|
package/lib/database.d.ts
CHANGED
|
@@ -23,6 +23,7 @@ import { ArrayFieldRepository } from './field-repository/array-field-repository'
|
|
|
23
23
|
import * as FieldTypes from './fields';
|
|
24
24
|
import { Field, FieldContext, RelationField } from './fields';
|
|
25
25
|
import InheritanceMap from './inherited-map';
|
|
26
|
+
import { InterfaceManager } from './interface-manager';
|
|
26
27
|
import { MigrationItem, Migrations } from './migration';
|
|
27
28
|
import { Model } from './model';
|
|
28
29
|
import { ModelHook } from './model-hook';
|
|
@@ -31,7 +32,6 @@ import { RelationRepository } from './relation-repository/relation-repository';
|
|
|
31
32
|
import { Repository } from './repository';
|
|
32
33
|
import { AfterDefineCollectionListener, BeforeDefineCollectionListener, CreateListener, CreateWithAssociationsListener, DatabaseAfterDefineCollectionEventType, DatabaseAfterRemoveCollectionEventType, DatabaseBeforeDefineCollectionEventType, DatabaseBeforeRemoveCollectionEventType, DestroyListener, EventType, ModelCreateEventTypes, ModelCreateWithAssociationsEventTypes, ModelDestroyEventTypes, ModelSaveEventTypes, ModelSaveWithAssociationsEventTypes, ModelUpdateEventTypes, ModelUpdateWithAssociationsEventTypes, ModelValidateEventTypes, RemoveCollectionListener, SaveListener, SaveWithAssociationsListener, SyncListener, UpdateListener, UpdateWithAssociationsListener, ValidateListener } from './types';
|
|
33
34
|
import { BaseValueParser } from './value-parsers';
|
|
34
|
-
import { InterfaceManager } from './interface-manager';
|
|
35
35
|
export type MergeOptions = merge.Options;
|
|
36
36
|
export interface PendingOptions {
|
|
37
37
|
field: RelationField;
|
package/lib/database.js
CHANGED
|
@@ -52,9 +52,9 @@ var import_events = require("events");
|
|
|
52
52
|
var import_exponential_backoff = require("exponential-backoff");
|
|
53
53
|
var import_glob = __toESM(require("glob"));
|
|
54
54
|
var import_lodash = __toESM(require("lodash"));
|
|
55
|
-
var import_safe_json_stringify = __toESM(require("safe-json-stringify"));
|
|
56
55
|
var import_nanoid = require("nanoid");
|
|
57
56
|
var import_path = require("path");
|
|
57
|
+
var import_safe_json_stringify = __toESM(require("safe-json-stringify"));
|
|
58
58
|
var import_semver = __toESM(require("semver"));
|
|
59
59
|
var import_sequelize = require("sequelize");
|
|
60
60
|
var import_umzug = require("umzug");
|
|
@@ -68,16 +68,16 @@ var FieldTypes = __toESM(require("./fields"));
|
|
|
68
68
|
var import_helpers = require("./helpers");
|
|
69
69
|
var import_inherited_collection = require("./inherited-collection");
|
|
70
70
|
var import_inherited_map = __toESM(require("./inherited-map"));
|
|
71
|
+
var import_interface_manager = require("./interface-manager");
|
|
72
|
+
var import_utils2 = require("./interfaces/utils");
|
|
71
73
|
var import_listeners = require("./listeners");
|
|
72
74
|
var import_migration = require("./migration");
|
|
73
75
|
var import_model_hook = require("./model-hook");
|
|
74
76
|
var import_operators = __toESM(require("./operators"));
|
|
75
77
|
var import_query_interface_builder = __toESM(require("./query-interface/query-interface-builder"));
|
|
76
|
-
var
|
|
78
|
+
var import_utils3 = require("./utils");
|
|
77
79
|
var import_value_parsers = require("./value-parsers");
|
|
78
80
|
var import_view_collection = require("./view-collection");
|
|
79
|
-
var import_interface_manager = require("./interface-manager");
|
|
80
|
-
var import_utils3 = require("./interfaces/utils");
|
|
81
81
|
const DialectVersionAccessors = {
|
|
82
82
|
sqlite: {
|
|
83
83
|
sql: "select sqlite_version() as version",
|
|
@@ -207,7 +207,7 @@ const _Database = class _Database extends import_events.EventEmitter {
|
|
|
207
207
|
[key]: field
|
|
208
208
|
});
|
|
209
209
|
}
|
|
210
|
-
(0,
|
|
210
|
+
(0, import_utils2.registerInterfaces)(this);
|
|
211
211
|
(0, import_value_parsers.registerFieldValueParsers)(this);
|
|
212
212
|
this.initOperators();
|
|
213
213
|
const migratorOptions = this.options.migrator || {};
|
|
@@ -246,7 +246,7 @@ const _Database = class _Database extends import_events.EventEmitter {
|
|
|
246
246
|
})
|
|
247
247
|
});
|
|
248
248
|
this.initListener();
|
|
249
|
-
(0,
|
|
249
|
+
(0, import_utils3.patchSequelizeQueryInterface)(this);
|
|
250
250
|
this.registerCollectionType();
|
|
251
251
|
}
|
|
252
252
|
_instanceId;
|
|
@@ -363,13 +363,13 @@ const _Database = class _Database extends import_events.EventEmitter {
|
|
|
363
363
|
}
|
|
364
364
|
if (options.underscored) {
|
|
365
365
|
if (import_lodash.default.get(options, "sortable.scopeKey")) {
|
|
366
|
-
options.sortable.scopeKey = (0,
|
|
366
|
+
options.sortable.scopeKey = (0, import_utils3.snakeCase)(options.sortable.scopeKey);
|
|
367
367
|
}
|
|
368
368
|
if (import_lodash.default.get(options, "indexes")) {
|
|
369
369
|
options.indexes = options.indexes.map((index) => {
|
|
370
370
|
if (index.fields) {
|
|
371
371
|
index.fields = index.fields.map((field) => {
|
|
372
|
-
return (0,
|
|
372
|
+
return (0, import_utils3.snakeCase)(field);
|
|
373
373
|
});
|
|
374
374
|
}
|
|
375
375
|
return index;
|
|
@@ -573,7 +573,7 @@ const _Database = class _Database extends import_events.EventEmitter {
|
|
|
573
573
|
}
|
|
574
574
|
const { collection } = context;
|
|
575
575
|
if (options.field && collection.options.underscored && !collection.isView()) {
|
|
576
|
-
options.field = (0,
|
|
576
|
+
options.field = (0, import_utils3.snakeCase)(options.field);
|
|
577
577
|
}
|
|
578
578
|
if (Object.prototype.hasOwnProperty.call(options, "defaultValue") && options.defaultValue === null) {
|
|
579
579
|
delete options.defaultValue;
|
|
@@ -626,7 +626,7 @@ const _Database = class _Database extends import_events.EventEmitter {
|
|
|
626
626
|
}
|
|
627
627
|
/* istanbul ignore next -- @preserve */
|
|
628
628
|
async auth(options = {}) {
|
|
629
|
-
const { retry =
|
|
629
|
+
const { retry = 9, ...others } = options;
|
|
630
630
|
const startingDelay = 50;
|
|
631
631
|
const timeMultiple = 2;
|
|
632
632
|
let attemptNumber = 1;
|
|
@@ -12,9 +12,7 @@ export declare class SortField extends Field {
|
|
|
12
12
|
get dataType(): DataTypes.BigIntDataTypeConstructor;
|
|
13
13
|
setSortValue: (instance: any, options: any) => Promise<void>;
|
|
14
14
|
onScopeChange: (instance: any, options: any) => Promise<void>;
|
|
15
|
-
initRecordsSortValue: (
|
|
16
|
-
transaction: any;
|
|
17
|
-
}) => Promise<void>;
|
|
15
|
+
initRecordsSortValue: (options: any) => Promise<void>;
|
|
18
16
|
bind(): void;
|
|
19
17
|
unbind(): void;
|
|
20
18
|
}
|
package/lib/fields/sort-field.js
CHANGED
|
@@ -64,7 +64,8 @@ const _SortField = class _SortField extends import_field.Field {
|
|
|
64
64
|
await this.setSortValue(instance, options);
|
|
65
65
|
}
|
|
66
66
|
};
|
|
67
|
-
initRecordsSortValue = async (
|
|
67
|
+
initRecordsSortValue = async (options) => {
|
|
68
|
+
const { transaction } = options;
|
|
68
69
|
const orderField = (() => {
|
|
69
70
|
const model = this.collection.model;
|
|
70
71
|
if (model.primaryKeyAttribute) {
|
|
@@ -49,7 +49,14 @@ const _MultipleSelectInterface = class _MultipleSelectInterface extends import_b
|
|
|
49
49
|
const enumConfig = ((_a = this.options.uiSchema) == null ? void 0 : _a.enum) || [];
|
|
50
50
|
return items.map((item) => {
|
|
51
51
|
const option = enumConfig.find((option2) => option2.label === item);
|
|
52
|
-
|
|
52
|
+
if (option) {
|
|
53
|
+
return option.value;
|
|
54
|
+
}
|
|
55
|
+
const valueOption = enumConfig.find((option2) => option2.value === item);
|
|
56
|
+
if (valueOption) {
|
|
57
|
+
return valueOption.value;
|
|
58
|
+
}
|
|
59
|
+
throw new Error(`"${item}" is not a valid option in ${ctx.field.name} field.`);
|
|
53
60
|
});
|
|
54
61
|
}
|
|
55
62
|
toString(value, ctx) {
|
|
@@ -34,9 +34,19 @@ var import_base_interface = require("./base-interface");
|
|
|
34
34
|
const _SelectInterface = class _SelectInterface extends import_base_interface.BaseInterface {
|
|
35
35
|
async toValue(str, ctx) {
|
|
36
36
|
var _a;
|
|
37
|
+
if (!str) {
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
37
40
|
const enumConfig = ((_a = this.options.uiSchema) == null ? void 0 : _a.enum) || [];
|
|
38
41
|
const option = enumConfig.find((item) => item.label === str);
|
|
39
|
-
|
|
42
|
+
if (option) {
|
|
43
|
+
return option.value;
|
|
44
|
+
}
|
|
45
|
+
const valueOption = enumConfig.find((item) => item.value === str);
|
|
46
|
+
if (valueOption) {
|
|
47
|
+
return valueOption.value;
|
|
48
|
+
}
|
|
49
|
+
throw new Error(`"${str}" is not a valid option in ${ctx.field.name} field.`);
|
|
40
50
|
}
|
|
41
51
|
toString(value, ctx) {
|
|
42
52
|
var _a;
|
|
@@ -44,6 +44,11 @@ const _ToManyInterface = class _ToManyInterface extends import_base_interface.Ba
|
|
|
44
44
|
},
|
|
45
45
|
transaction
|
|
46
46
|
});
|
|
47
|
+
items.forEach((item) => {
|
|
48
|
+
if (!targetInstances.find((targetInstance) => targetInstance[filterKey] === item)) {
|
|
49
|
+
throw new Error(`"${item}" not found in ${targetCollection.model.name} ${filterKey}`);
|
|
50
|
+
}
|
|
51
|
+
});
|
|
47
52
|
const primaryKeyAttribute = targetCollection.model.primaryKeyAttribute;
|
|
48
53
|
return targetInstances.map((targetInstance) => targetInstance[primaryKeyAttribute]);
|
|
49
54
|
}
|
|
@@ -36,6 +36,9 @@ const _ToOneInterface = class _ToOneInterface extends import_base_interface.Base
|
|
|
36
36
|
return value;
|
|
37
37
|
}
|
|
38
38
|
async toValue(str, ctx) {
|
|
39
|
+
if (!str) {
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
39
42
|
const { filterKey, targetCollection, transaction } = ctx;
|
|
40
43
|
const targetInstance = await targetCollection.repository.findOne({
|
|
41
44
|
filter: {
|
|
@@ -43,11 +46,11 @@ const _ToOneInterface = class _ToOneInterface extends import_base_interface.Base
|
|
|
43
46
|
},
|
|
44
47
|
transaction
|
|
45
48
|
});
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
return targetInstance[primaryKeyAttribute];
|
|
49
|
+
if (!targetInstance) {
|
|
50
|
+
throw new Error(`"${str}" not found in ${targetCollection.model.name} ${filterKey}`);
|
|
49
51
|
}
|
|
50
|
-
|
|
52
|
+
const primaryKeyAttribute = targetCollection.model.primaryKeyAttribute;
|
|
53
|
+
return targetInstance[primaryKeyAttribute];
|
|
51
54
|
}
|
|
52
55
|
};
|
|
53
56
|
__name(_ToOneInterface, "ToOneInterface");
|
package/lib/model-hook.js
CHANGED
|
@@ -56,7 +56,6 @@ const _ModelHook = class _ModelHook {
|
|
|
56
56
|
return type in hooks ? type : null;
|
|
57
57
|
}
|
|
58
58
|
findModelName(hookArgs) {
|
|
59
|
-
var _a, _b;
|
|
60
59
|
for (const arg of hookArgs) {
|
|
61
60
|
if (arg == null ? void 0 : arg._previousDataValues) {
|
|
62
61
|
return arg.constructor.name;
|
|
@@ -65,13 +64,9 @@ const _ModelHook = class _ModelHook {
|
|
|
65
64
|
if (arg["model"]) {
|
|
66
65
|
return arg["model"].name;
|
|
67
66
|
}
|
|
68
|
-
const
|
|
69
|
-
if (this.database.sequelize.isDefined(
|
|
70
|
-
return
|
|
71
|
-
}
|
|
72
|
-
const singular = (_b = arg == null ? void 0 : arg.name) == null ? void 0 : _b.singular;
|
|
73
|
-
if (this.database.sequelize.isDefined(singular)) {
|
|
74
|
-
return singular;
|
|
67
|
+
const modelName = arg["modelName"];
|
|
68
|
+
if (this.database.sequelize.isDefined(modelName)) {
|
|
69
|
+
return modelName;
|
|
75
70
|
}
|
|
76
71
|
}
|
|
77
72
|
}
|
|
@@ -46,7 +46,9 @@ declare const _default: {
|
|
|
46
46
|
varchar: string[];
|
|
47
47
|
date: string;
|
|
48
48
|
time: string;
|
|
49
|
+
tinytext: string;
|
|
49
50
|
text: string;
|
|
51
|
+
mediumtext: string;
|
|
50
52
|
longtext: string;
|
|
51
53
|
int: string[];
|
|
52
54
|
'int unsigned': string[];
|
|
@@ -85,7 +87,9 @@ declare const _default: {
|
|
|
85
87
|
varchar: string[];
|
|
86
88
|
date: string;
|
|
87
89
|
time: string;
|
|
90
|
+
tinytext: string;
|
|
88
91
|
text: string;
|
|
92
|
+
mediumtext: string;
|
|
89
93
|
longtext: string;
|
|
90
94
|
int: string[];
|
|
91
95
|
'int unsigned': string[];
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nocobase/database",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.5-alpha",
|
|
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.2.
|
|
10
|
-
"@nocobase/utils": "1.2.
|
|
9
|
+
"@nocobase/logger": "1.2.5-alpha",
|
|
10
|
+
"@nocobase/utils": "1.2.5-alpha",
|
|
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": "ca7baa2d4dffe0e2c02f676b96ff841f3ee31e7e"
|
|
42
42
|
}
|