@nocobase/database 1.8.0-beta.9 → 1.9.0-alpha.1
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/database.d.ts +1 -0
- package/lib/fields/password-field.js +15 -10
- package/lib/fields/uid-field.js +15 -10
- package/lib/helpers.js +25 -1
- package/lib/operators/date.js +4 -1
- package/lib/operators/eq.js +14 -1
- package/package.json +4 -4
package/lib/database.d.ts
CHANGED
|
@@ -72,27 +72,32 @@ const _PasswordField = class _PasswordField extends import_field.Field {
|
|
|
72
72
|
}
|
|
73
73
|
init() {
|
|
74
74
|
const { name } = this.options;
|
|
75
|
-
this.listener = async (
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
const
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
75
|
+
this.listener = async (instances) => {
|
|
76
|
+
instances = Array.isArray(instances) ? instances : [instances];
|
|
77
|
+
for (const instance of instances) {
|
|
78
|
+
if (!instance.changed(name)) {
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
const value = instance.get(name);
|
|
82
|
+
if (value) {
|
|
83
|
+
const hash = await this.hash(value);
|
|
84
|
+
instance.set(name, hash);
|
|
85
|
+
} else {
|
|
86
|
+
instance.set(name, instance.previous(name));
|
|
87
|
+
}
|
|
85
88
|
}
|
|
86
89
|
};
|
|
87
90
|
}
|
|
88
91
|
bind() {
|
|
89
92
|
super.bind();
|
|
90
93
|
this.on("beforeCreate", this.listener);
|
|
94
|
+
this.on("beforeBulkCreate", this.listener);
|
|
91
95
|
this.on("beforeUpdate", this.listener);
|
|
92
96
|
}
|
|
93
97
|
unbind() {
|
|
94
98
|
super.unbind();
|
|
95
99
|
this.off("beforeCreate", this.listener);
|
|
100
|
+
this.off("beforeBulkCreate", this.listener);
|
|
96
101
|
this.off("beforeUpdate", this.listener);
|
|
97
102
|
}
|
|
98
103
|
};
|
package/lib/fields/uid-field.js
CHANGED
|
@@ -40,16 +40,19 @@ const _UidField = class _UidField extends import_field.Field {
|
|
|
40
40
|
init() {
|
|
41
41
|
const { name, prefix = "", pattern } = this.options;
|
|
42
42
|
const re = new RegExp(pattern || "^[A-Za-z0-9_][A-Za-z0-9_-]*$");
|
|
43
|
-
this.listener = async (
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
instance.
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
43
|
+
this.listener = async (instances) => {
|
|
44
|
+
instances = Array.isArray(instances) ? instances : [instances];
|
|
45
|
+
for (const instance of instances) {
|
|
46
|
+
const value = instance.get(name);
|
|
47
|
+
if (!value) {
|
|
48
|
+
instance.set(name, `${prefix}${(0, import_utils.uid)()}`);
|
|
49
|
+
} else if (re.test(value)) {
|
|
50
|
+
instance.set(name, value);
|
|
51
|
+
} else {
|
|
52
|
+
throw new Error(
|
|
53
|
+
`${this.collection.name}.${this.options.name} can only include A-Z, a-z, 0-9, _-*$, '${value}' is invalid`
|
|
54
|
+
);
|
|
55
|
+
}
|
|
53
56
|
}
|
|
54
57
|
};
|
|
55
58
|
}
|
|
@@ -57,11 +60,13 @@ const _UidField = class _UidField extends import_field.Field {
|
|
|
57
60
|
super.bind();
|
|
58
61
|
this.on("beforeCreate", this.listener);
|
|
59
62
|
this.on("beforeUpdate", this.listener);
|
|
63
|
+
this.on("beforeBulkCreate", this.listener);
|
|
60
64
|
}
|
|
61
65
|
unbind() {
|
|
62
66
|
super.unbind();
|
|
63
67
|
this.off("beforeCreate", this.listener);
|
|
64
68
|
this.off("beforeUpdate", this.listener);
|
|
69
|
+
this.off("beforeBulkCreate", this.listener);
|
|
65
70
|
}
|
|
66
71
|
};
|
|
67
72
|
__name(_UidField, "UidField");
|
package/lib/helpers.js
CHANGED
|
@@ -96,6 +96,29 @@ function extractSSLOptionsFromEnv() {
|
|
|
96
96
|
});
|
|
97
97
|
}
|
|
98
98
|
__name(extractSSLOptionsFromEnv, "extractSSLOptionsFromEnv");
|
|
99
|
+
function getPoolOptions() {
|
|
100
|
+
const options = {};
|
|
101
|
+
if (process.env.DB_POOL_MAX) {
|
|
102
|
+
options.max = Number.parseInt(process.env.DB_POOL_MAX, 10);
|
|
103
|
+
}
|
|
104
|
+
if (process.env.DB_POOL_MIN) {
|
|
105
|
+
options.min = Number.parseInt(process.env.DB_POOL_MIN, 10);
|
|
106
|
+
}
|
|
107
|
+
if (process.env.DB_POOL_IDLE) {
|
|
108
|
+
options.idle = Number.parseInt(process.env.DB_POOL_IDLE, 10);
|
|
109
|
+
}
|
|
110
|
+
if (process.env.DB_POOL_ACQUIRE) {
|
|
111
|
+
options.acquire = Number.parseInt(process.env.DB_POOL_ACQUIRE, 10);
|
|
112
|
+
}
|
|
113
|
+
if (process.env.DB_POOL_EVICT) {
|
|
114
|
+
options.evict = Number.parseInt(process.env.DB_POOL_EVICT, 10);
|
|
115
|
+
}
|
|
116
|
+
if (process.env.DB_POOL_MAX_USES) {
|
|
117
|
+
options.maxUses = Number.parseInt(process.env.DB_POOL_MAX_USES, 10) || Number.POSITIVE_INFINITY;
|
|
118
|
+
}
|
|
119
|
+
return options;
|
|
120
|
+
}
|
|
121
|
+
__name(getPoolOptions, "getPoolOptions");
|
|
99
122
|
async function parseDatabaseOptionsFromEnv() {
|
|
100
123
|
const databaseOptions = {
|
|
101
124
|
logging: process.env.DB_LOGGING == "on" ? customLogger : false,
|
|
@@ -109,7 +132,8 @@ async function parseDatabaseOptionsFromEnv() {
|
|
|
109
132
|
timezone: process.env.DB_TIMEZONE,
|
|
110
133
|
tablePrefix: process.env.DB_TABLE_PREFIX,
|
|
111
134
|
schema: process.env.DB_SCHEMA,
|
|
112
|
-
underscored: process.env.DB_UNDERSCORED === "true"
|
|
135
|
+
underscored: process.env.DB_UNDERSCORED === "true",
|
|
136
|
+
pool: getPoolOptions()
|
|
113
137
|
};
|
|
114
138
|
const sslOptions = await extractSSLOptionsFromEnv();
|
|
115
139
|
if (Object.keys(sslOptions).length) {
|
package/lib/operators/date.js
CHANGED
|
@@ -61,7 +61,7 @@ const toDate = /* @__PURE__ */ __name((date, options = {}) => {
|
|
|
61
61
|
val = (0, import_moment.default)(val).utcOffset("+00:00").format("YYYY-MM-DD HH:mm:ss");
|
|
62
62
|
}
|
|
63
63
|
if (field.constructor.name === "DateOnlyField") {
|
|
64
|
-
val =
|
|
64
|
+
val = import_moment.default.utc(val).format("YYYY-MM-DD HH:mm:ss");
|
|
65
65
|
}
|
|
66
66
|
const eventObj = {
|
|
67
67
|
val,
|
|
@@ -95,6 +95,9 @@ var date_default = {
|
|
|
95
95
|
};
|
|
96
96
|
}
|
|
97
97
|
if (Array.isArray(r)) {
|
|
98
|
+
console.log(11111111, {
|
|
99
|
+
[import_sequelize.Op.and]: [{ [import_sequelize.Op.gte]: toDate(r[0], { ctx }) }, { [import_sequelize.Op.lt]: toDate(r[1], { ctx }) }]
|
|
100
|
+
});
|
|
98
101
|
return {
|
|
99
102
|
[import_sequelize.Op.and]: [{ [import_sequelize.Op.gte]: toDate(r[0], { ctx }) }, { [import_sequelize.Op.lt]: toDate(r[1], { ctx }) }]
|
|
100
103
|
};
|
package/lib/operators/eq.js
CHANGED
|
@@ -31,7 +31,20 @@ __export(eq_exports, {
|
|
|
31
31
|
module.exports = __toCommonJS(eq_exports);
|
|
32
32
|
var import_sequelize = require("sequelize");
|
|
33
33
|
var eq_default = {
|
|
34
|
-
$eq(val) {
|
|
34
|
+
$eq(val, ctx) {
|
|
35
|
+
if (ctx == null ? void 0 : ctx.fieldPath) {
|
|
36
|
+
const field = ctx.db.getFieldByPath(ctx.fieldPath);
|
|
37
|
+
if ((field == null ? void 0 : field.type) === "string" && typeof val !== "string") {
|
|
38
|
+
if (Array.isArray(val)) {
|
|
39
|
+
return {
|
|
40
|
+
[import_sequelize.Op.in]: val.map((v) => String(v))
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
return {
|
|
44
|
+
[import_sequelize.Op.eq]: String(val)
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
}
|
|
35
48
|
if (Array.isArray(val)) {
|
|
36
49
|
return {
|
|
37
50
|
[import_sequelize.Op.in]: val
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nocobase/database",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.9.0-alpha.1",
|
|
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.
|
|
10
|
-
"@nocobase/utils": "1.
|
|
9
|
+
"@nocobase/logger": "1.9.0-alpha.1",
|
|
10
|
+
"@nocobase/utils": "1.9.0-alpha.1",
|
|
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": "71ebde8a27da3c5c4d64194571804eeab6e95ce0"
|
|
42
42
|
}
|