@nocobase/database 1.2.33-alpha → 1.2.35-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 -2
- package/lib/database-utils/index.js +1 -2
- package/lib/database.js +11 -11
- package/lib/field-repository/array-field-repository.js +1 -2
- package/lib/fields/array-field.js +2 -2
- package/lib/fields/belongs-to-field.js +1 -4
- package/lib/fields/context-field.js +2 -2
- package/lib/fields/password-field.js +2 -4
- package/lib/fields/radio-field.js +2 -2
- package/lib/fields/set-field.js +2 -2
- package/lib/fields/sort-field.js +6 -6
- package/lib/filter-match.js +10 -10
- package/lib/helpers.js +12 -17
- package/lib/inherited-collection.js +15 -4
- package/lib/inherited-map.js +3 -6
- package/lib/interfaces/datetime-interface.js +2 -4
- package/lib/magic-attribute-model.js +1 -2
- package/lib/model.js +1 -4
- package/lib/operators/child-collection.js +1 -2
- package/lib/options-parser.js +3 -6
- package/lib/query-interface/mysql-query-interface.js +1 -1
- package/lib/query-interface/query-interface.js +1 -2
- package/lib/relation-repository/belongs-to-many-repository.js +3 -4
- package/lib/relation-repository/hasmany-repository.js +1 -2
- package/lib/relation-repository/multiple-relation-repository.js +2 -4
- package/lib/relation-repository/relation-repository.js +1 -2
- package/lib/relation-repository/single-relation-repository.js +2 -4
- package/lib/repository.js +1 -2
- package/lib/sync-runner.d.ts +1 -1
- package/lib/sync-runner.js +13 -19
- package/lib/value-parsers/date-value-parser.js +2 -4
- package/lib/view/view-inference.js +2 -4
- package/package.json +4 -4
package/lib/collection.js
CHANGED
|
@@ -40,8 +40,7 @@ var __decorateClass = (decorators, target, key, kind) => {
|
|
|
40
40
|
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
41
41
|
if (decorator = decorators[i])
|
|
42
42
|
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
43
|
-
if (kind && result)
|
|
44
|
-
__defProp(target, key, result);
|
|
43
|
+
if (kind && result) __defProp(target, key, result);
|
|
45
44
|
return result;
|
|
46
45
|
};
|
|
47
46
|
var collection_exports = {};
|
|
@@ -46,8 +46,7 @@ const _DatabaseUtils = class _DatabaseUtils {
|
|
|
46
46
|
this.db = db;
|
|
47
47
|
}
|
|
48
48
|
addSchema(tableName, schema) {
|
|
49
|
-
if (!this.db.inDialect("postgres"))
|
|
50
|
-
return tableName;
|
|
49
|
+
if (!this.db.inDialect("postgres")) return tableName;
|
|
51
50
|
if (this.db.options.schema && !schema) {
|
|
52
51
|
schema = this.db.options.schema;
|
|
53
52
|
}
|
package/lib/database.js
CHANGED
|
@@ -80,28 +80,28 @@ var import_view_collection = require("./view-collection");
|
|
|
80
80
|
const DialectVersionAccessors = {
|
|
81
81
|
sqlite: {
|
|
82
82
|
sql: "select sqlite_version() as version",
|
|
83
|
-
get: (v) => v
|
|
83
|
+
get: /* @__PURE__ */ __name((v) => v, "get")
|
|
84
84
|
},
|
|
85
85
|
mysql: {
|
|
86
86
|
sql: "select version() as version",
|
|
87
|
-
get: (v) => {
|
|
87
|
+
get: /* @__PURE__ */ __name((v) => {
|
|
88
88
|
const m = /([\d+.]+)/.exec(v);
|
|
89
89
|
return m[0];
|
|
90
|
-
}
|
|
90
|
+
}, "get")
|
|
91
91
|
},
|
|
92
92
|
mariadb: {
|
|
93
93
|
sql: "select version() as version",
|
|
94
|
-
get: (v) => {
|
|
94
|
+
get: /* @__PURE__ */ __name((v) => {
|
|
95
95
|
const m = /([\d+.]+)/.exec(v);
|
|
96
96
|
return m[0];
|
|
97
|
-
}
|
|
97
|
+
}, "get")
|
|
98
98
|
},
|
|
99
99
|
postgres: {
|
|
100
100
|
sql: "select version() as version",
|
|
101
|
-
get: (v) => {
|
|
101
|
+
get: /* @__PURE__ */ __name((v) => {
|
|
102
102
|
const m = /([\d+.]+)/.exec(v);
|
|
103
103
|
return import_semver.default.minVersion(m[0]).version;
|
|
104
|
-
}
|
|
104
|
+
}, "get")
|
|
105
105
|
}
|
|
106
106
|
};
|
|
107
107
|
const _Database = class _Database extends import_events.EventEmitter {
|
|
@@ -738,14 +738,14 @@ const _Database = class _Database extends import_events.EventEmitter {
|
|
|
738
738
|
}
|
|
739
739
|
registerCollectionType() {
|
|
740
740
|
this.collectionFactory.registerCollectionType(import_inherited_collection.InheritedCollection, {
|
|
741
|
-
condition: (options) => {
|
|
741
|
+
condition: /* @__PURE__ */ __name((options) => {
|
|
742
742
|
return options.inherits && import_lodash.default.castArray(options.inherits).length > 0;
|
|
743
|
-
}
|
|
743
|
+
}, "condition")
|
|
744
744
|
});
|
|
745
745
|
this.collectionFactory.registerCollectionType(import_view_collection.ViewCollection, {
|
|
746
|
-
condition: (options) => {
|
|
746
|
+
condition: /* @__PURE__ */ __name((options) => {
|
|
747
747
|
return options.viewName || options.view;
|
|
748
|
-
},
|
|
748
|
+
}, "condition"),
|
|
749
749
|
async onSync() {
|
|
750
750
|
return;
|
|
751
751
|
},
|
|
@@ -40,8 +40,7 @@ var __decorateClass = (decorators, target, key, kind) => {
|
|
|
40
40
|
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
41
41
|
if (decorator = decorators[i])
|
|
42
42
|
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
43
|
-
if (kind && result)
|
|
44
|
-
__defProp(target, key, result);
|
|
43
|
+
if (kind && result) __defProp(target, key, result);
|
|
45
44
|
return result;
|
|
46
45
|
};
|
|
47
46
|
var array_field_repository_exports = {};
|
|
@@ -39,7 +39,7 @@ const _ArrayField = class _ArrayField extends import_field.Field {
|
|
|
39
39
|
}
|
|
40
40
|
return import_sequelize.DataTypes.JSON;
|
|
41
41
|
}
|
|
42
|
-
sortValue = (model) => {
|
|
42
|
+
sortValue = /* @__PURE__ */ __name((model) => {
|
|
43
43
|
let oldValue = model.get(this.options.name);
|
|
44
44
|
if (oldValue) {
|
|
45
45
|
if (typeof oldValue === "string") {
|
|
@@ -48,7 +48,7 @@ const _ArrayField = class _ArrayField extends import_field.Field {
|
|
|
48
48
|
const newValue = oldValue.sort();
|
|
49
49
|
model.set(this.options.name, newValue);
|
|
50
50
|
}
|
|
51
|
-
};
|
|
51
|
+
}, "sortValue");
|
|
52
52
|
bind() {
|
|
53
53
|
super.bind();
|
|
54
54
|
this.on("beforeSave", this.sortValue);
|
|
@@ -36,10 +36,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
36
36
|
mod
|
|
37
37
|
));
|
|
38
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
|
-
};
|
|
39
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
43
40
|
var belongs_to_field_exports = {};
|
|
44
41
|
__export(belongs_to_field_exports, {
|
|
45
42
|
BelongsToField: () => BelongsToField
|
|
@@ -48,12 +48,12 @@ const _ContextField = class _ContextField extends import_field.Field {
|
|
|
48
48
|
const type = this.options.dataType || "string";
|
|
49
49
|
return import_sequelize.DataTypes[type.toUpperCase()] || import_sequelize.DataTypes.STRING;
|
|
50
50
|
}
|
|
51
|
-
listener = async (model, options) => {
|
|
51
|
+
listener = /* @__PURE__ */ __name(async (model, options) => {
|
|
52
52
|
const { name, dataIndex } = this.options;
|
|
53
53
|
const { context } = options;
|
|
54
54
|
model.set(name, import_lodash.default.get(context, dataIndex));
|
|
55
55
|
model.changed(name, true);
|
|
56
|
-
};
|
|
56
|
+
}, "listener");
|
|
57
57
|
bind() {
|
|
58
58
|
super.bind();
|
|
59
59
|
const { createOnly } = this.options;
|
|
@@ -55,8 +55,7 @@ const _PasswordField = class _PasswordField extends import_field.Field {
|
|
|
55
55
|
const salt = hash.substring(0, randomBytesSize * 2);
|
|
56
56
|
const key = hash.substring(randomBytesSize * 2);
|
|
57
57
|
import_crypto.default.scrypt(password, salt, length / 2 - randomBytesSize, (err, derivedKey) => {
|
|
58
|
-
if (err)
|
|
59
|
-
reject(err);
|
|
58
|
+
if (err) reject(err);
|
|
60
59
|
resolve(key == derivedKey.toString("hex"));
|
|
61
60
|
});
|
|
62
61
|
});
|
|
@@ -66,8 +65,7 @@ const _PasswordField = class _PasswordField extends import_field.Field {
|
|
|
66
65
|
return new Promise((resolve, reject) => {
|
|
67
66
|
const salt = import_crypto.default.randomBytes(randomBytesSize).toString("hex");
|
|
68
67
|
import_crypto.default.scrypt(password, salt, length / 2 - randomBytesSize, (err, derivedKey) => {
|
|
69
|
-
if (err)
|
|
70
|
-
reject(err);
|
|
68
|
+
if (err) reject(err);
|
|
71
69
|
resolve(salt + derivedKey.toString("hex"));
|
|
72
70
|
});
|
|
73
71
|
});
|
|
@@ -36,7 +36,7 @@ const _RadioField = class _RadioField extends import_field.Field {
|
|
|
36
36
|
get dataType() {
|
|
37
37
|
return import_sequelize.DataTypes.BOOLEAN;
|
|
38
38
|
}
|
|
39
|
-
listener = async (model, { transaction }) => {
|
|
39
|
+
listener = /* @__PURE__ */ __name(async (model, { transaction }) => {
|
|
40
40
|
const { name } = this.options;
|
|
41
41
|
if (!model.changed(name)) {
|
|
42
42
|
return;
|
|
@@ -55,7 +55,7 @@ const _RadioField = class _RadioField extends import_field.Field {
|
|
|
55
55
|
}
|
|
56
56
|
);
|
|
57
57
|
}
|
|
58
|
-
};
|
|
58
|
+
}, "listener");
|
|
59
59
|
bind() {
|
|
60
60
|
super.bind();
|
|
61
61
|
this.on("beforeCreate", this.listener);
|
package/lib/fields/set-field.js
CHANGED
|
@@ -32,12 +32,12 @@ __export(set_field_exports, {
|
|
|
32
32
|
module.exports = __toCommonJS(set_field_exports);
|
|
33
33
|
var import_array_field = require("./array-field");
|
|
34
34
|
const _SetField = class _SetField extends import_array_field.ArrayField {
|
|
35
|
-
beforeSave = (model) => {
|
|
35
|
+
beforeSave = /* @__PURE__ */ __name((model) => {
|
|
36
36
|
const oldValue = model.get(this.options.name);
|
|
37
37
|
if (oldValue) {
|
|
38
38
|
model.set(this.options.name, [...new Set(oldValue)]);
|
|
39
39
|
}
|
|
40
|
-
};
|
|
40
|
+
}, "beforeSave");
|
|
41
41
|
bind() {
|
|
42
42
|
super.bind();
|
|
43
43
|
this.on("beforeSave", this.beforeSave);
|
package/lib/fields/sort-field.js
CHANGED
|
@@ -39,7 +39,7 @@ const _SortField = class _SortField extends import_field.Field {
|
|
|
39
39
|
get dataType() {
|
|
40
40
|
return import_sequelize.DataTypes.BIGINT;
|
|
41
41
|
}
|
|
42
|
-
setSortValue = async (instance, options) => {
|
|
42
|
+
setSortValue = /* @__PURE__ */ __name(async (instance, options) => {
|
|
43
43
|
const { name, scopeKey } = this.options;
|
|
44
44
|
const { model } = this.context.collection;
|
|
45
45
|
if ((0, import_lodash.isNumber)(instance.get(name)) && instance._previousDataValues[scopeKey] == instance[scopeKey]) {
|
|
@@ -57,14 +57,14 @@ const _SortField = class _SortField extends import_field.Field {
|
|
|
57
57
|
const newValue = (max || 0) + 1;
|
|
58
58
|
instance.set(name, newValue);
|
|
59
59
|
});
|
|
60
|
-
};
|
|
61
|
-
onScopeChange = async (instance, options) => {
|
|
60
|
+
}, "setSortValue");
|
|
61
|
+
onScopeChange = /* @__PURE__ */ __name(async (instance, options) => {
|
|
62
62
|
const { scopeKey } = this.options;
|
|
63
63
|
if (scopeKey && !instance.isNewRecord && instance._previousDataValues[scopeKey] != instance[scopeKey]) {
|
|
64
64
|
await this.setSortValue(instance, options);
|
|
65
65
|
}
|
|
66
|
-
};
|
|
67
|
-
initRecordsSortValue = async (options) => {
|
|
66
|
+
}, "onScopeChange");
|
|
67
|
+
initRecordsSortValue = /* @__PURE__ */ __name(async (options) => {
|
|
68
68
|
const { transaction } = options;
|
|
69
69
|
const orderField = (() => {
|
|
70
70
|
const model = this.collection.model;
|
|
@@ -175,7 +175,7 @@ const _SortField = class _SortField extends import_field.Field {
|
|
|
175
175
|
} else if (await needInit()) {
|
|
176
176
|
await doInit();
|
|
177
177
|
}
|
|
178
|
-
};
|
|
178
|
+
}, "initRecordsSortValue");
|
|
179
179
|
bind() {
|
|
180
180
|
super.bind();
|
|
181
181
|
this.on("afterSync", this.initRecordsSortValue);
|
package/lib/filter-match.js
CHANGED
|
@@ -36,16 +36,16 @@ function filterMatch(model, where) {
|
|
|
36
36
|
where = import_mathjs.filter;
|
|
37
37
|
}
|
|
38
38
|
const operatorFunctions = {
|
|
39
|
-
$eq: (value, condition) => value === condition,
|
|
40
|
-
$not: (value, condition) => !filterMatch(model, condition),
|
|
41
|
-
$gt: (value, condition) => value > condition,
|
|
42
|
-
$gte: (value, condition) => value >= condition,
|
|
43
|
-
$lt: (value, condition) => value < condition,
|
|
44
|
-
$lte: (value, condition) => value <= condition,
|
|
45
|
-
$ne: (value, condition) => value !== condition,
|
|
46
|
-
$in: (value, condition) => condition.includes(value),
|
|
47
|
-
$or: (model2, conditions) => Object.values(conditions).some((condition) => filterMatch(model2, condition)),
|
|
48
|
-
$and: (model2, conditions) => Object.values(conditions).every((condition) => filterMatch(model2, condition))
|
|
39
|
+
$eq: /* @__PURE__ */ __name((value, condition) => value === condition, "$eq"),
|
|
40
|
+
$not: /* @__PURE__ */ __name((value, condition) => !filterMatch(model, condition), "$not"),
|
|
41
|
+
$gt: /* @__PURE__ */ __name((value, condition) => value > condition, "$gt"),
|
|
42
|
+
$gte: /* @__PURE__ */ __name((value, condition) => value >= condition, "$gte"),
|
|
43
|
+
$lt: /* @__PURE__ */ __name((value, condition) => value < condition, "$lt"),
|
|
44
|
+
$lte: /* @__PURE__ */ __name((value, condition) => value <= condition, "$lte"),
|
|
45
|
+
$ne: /* @__PURE__ */ __name((value, condition) => value !== condition, "$ne"),
|
|
46
|
+
$in: /* @__PURE__ */ __name((value, condition) => condition.includes(value), "$in"),
|
|
47
|
+
$or: /* @__PURE__ */ __name((model2, conditions) => Object.values(conditions).some((condition) => filterMatch(model2, condition)), "$or"),
|
|
48
|
+
$and: /* @__PURE__ */ __name((model2, conditions) => Object.values(conditions).every((condition) => filterMatch(model2, condition)), "$and")
|
|
49
49
|
};
|
|
50
50
|
for (const [key, value] of Object.entries(where)) {
|
|
51
51
|
if (operatorFunctions[key] !== void 0) {
|
package/lib/helpers.js
CHANGED
|
@@ -82,16 +82,11 @@ function extractSSLOptionsFromEnv() {
|
|
|
82
82
|
getValueOrFileContent("DB_DIALECT_OPTIONS_SSL_REJECT_UNAUTHORIZED")
|
|
83
83
|
]).then(([mode, ca, key, cert, rejectUnauthorized]) => {
|
|
84
84
|
const sslOptions = {};
|
|
85
|
-
if (mode)
|
|
86
|
-
|
|
87
|
-
if (
|
|
88
|
-
|
|
89
|
-
if (
|
|
90
|
-
sslOptions["key"] = key;
|
|
91
|
-
if (cert)
|
|
92
|
-
sslOptions["cert"] = cert;
|
|
93
|
-
if (rejectUnauthorized)
|
|
94
|
-
sslOptions["rejectUnauthorized"] = rejectUnauthorized === "true";
|
|
85
|
+
if (mode) sslOptions["mode"] = mode;
|
|
86
|
+
if (ca) sslOptions["ca"] = ca;
|
|
87
|
+
if (key) sslOptions["key"] = key;
|
|
88
|
+
if (cert) sslOptions["cert"] = cert;
|
|
89
|
+
if (rejectUnauthorized) sslOptions["rejectUnauthorized"] = rejectUnauthorized === "true";
|
|
95
90
|
return sslOptions;
|
|
96
91
|
});
|
|
97
92
|
}
|
|
@@ -129,31 +124,31 @@ __name(customLogger, "customLogger");
|
|
|
129
124
|
const dialectVersionAccessors = {
|
|
130
125
|
sqlite: {
|
|
131
126
|
sql: "select sqlite_version() as version",
|
|
132
|
-
get: (v) => v,
|
|
127
|
+
get: /* @__PURE__ */ __name((v) => v, "get"),
|
|
133
128
|
version: "3.x"
|
|
134
129
|
},
|
|
135
130
|
mysql: {
|
|
136
131
|
sql: "select version() as version",
|
|
137
|
-
get: (v) => {
|
|
132
|
+
get: /* @__PURE__ */ __name((v) => {
|
|
138
133
|
const m = /([\d+.]+)/.exec(v);
|
|
139
134
|
return m[0];
|
|
140
|
-
},
|
|
135
|
+
}, "get"),
|
|
141
136
|
version: ">=8.0.17"
|
|
142
137
|
},
|
|
143
138
|
mariadb: {
|
|
144
139
|
sql: "select version() as version",
|
|
145
|
-
get: (v) => {
|
|
140
|
+
get: /* @__PURE__ */ __name((v) => {
|
|
146
141
|
const m = /([\d+.]+)/.exec(v);
|
|
147
142
|
return m[0];
|
|
148
|
-
},
|
|
143
|
+
}, "get"),
|
|
149
144
|
version: ">=10.9"
|
|
150
145
|
},
|
|
151
146
|
postgres: {
|
|
152
147
|
sql: "select version() as version",
|
|
153
|
-
get: (v) => {
|
|
148
|
+
get: /* @__PURE__ */ __name((v) => {
|
|
154
149
|
const m = /([\d+.]+)/.exec(v);
|
|
155
150
|
return import_semver.default.minVersion(m[0]).version;
|
|
156
|
-
},
|
|
151
|
+
}, "get"),
|
|
157
152
|
version: ">=10"
|
|
158
153
|
}
|
|
159
154
|
};
|
|
@@ -84,12 +84,12 @@ const _InheritedCollection = class _InheritedCollection extends import_collectio
|
|
|
84
84
|
for (const parent of this.parents) {
|
|
85
85
|
if (parent.isInherited()) {
|
|
86
86
|
for (const [name, field] of parent.parentFields()) {
|
|
87
|
-
fields.set(name, field
|
|
87
|
+
fields.set(name, field);
|
|
88
88
|
}
|
|
89
89
|
}
|
|
90
90
|
const parentFields = parent.fields;
|
|
91
91
|
for (const [name, field] of parentFields) {
|
|
92
|
-
fields.set(name, field
|
|
92
|
+
fields.set(name, field);
|
|
93
93
|
}
|
|
94
94
|
}
|
|
95
95
|
return fields;
|
|
@@ -124,9 +124,20 @@ const _InheritedCollection = class _InheritedCollection extends import_collectio
|
|
|
124
124
|
});
|
|
125
125
|
}
|
|
126
126
|
setParentFields() {
|
|
127
|
-
|
|
127
|
+
const delayFields = /* @__PURE__ */ new Map();
|
|
128
|
+
for (const [name, field] of this.parentFields()) {
|
|
129
|
+
if (field.isRelationField()) {
|
|
130
|
+
delayFields.set(name, field);
|
|
131
|
+
continue;
|
|
132
|
+
}
|
|
133
|
+
this.setField(name, {
|
|
134
|
+
...field.options,
|
|
135
|
+
inherit: true
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
for (const [name, field] of delayFields) {
|
|
128
139
|
this.setField(name, {
|
|
129
|
-
...
|
|
140
|
+
...field.options,
|
|
130
141
|
inherit: true
|
|
131
142
|
});
|
|
132
143
|
}
|
package/lib/inherited-map.js
CHANGED
|
@@ -57,8 +57,7 @@ const _InheritanceMap = class _InheritanceMap {
|
|
|
57
57
|
nodes = /* @__PURE__ */ new Map();
|
|
58
58
|
removeNode(name) {
|
|
59
59
|
const node = this.nodes.get(name);
|
|
60
|
-
if (!node)
|
|
61
|
-
return;
|
|
60
|
+
if (!node) return;
|
|
62
61
|
for (const parent of node.parents) {
|
|
63
62
|
parent.children.delete(node);
|
|
64
63
|
}
|
|
@@ -91,8 +90,7 @@ const _InheritanceMap = class _InheritanceMap {
|
|
|
91
90
|
getChildren(name, options = { deep: true }) {
|
|
92
91
|
const results = /* @__PURE__ */ new Set();
|
|
93
92
|
const node = this.getNode(name);
|
|
94
|
-
if (!node)
|
|
95
|
-
return results;
|
|
93
|
+
if (!node) return results;
|
|
96
94
|
for (const child of node.children) {
|
|
97
95
|
results.add(child.name);
|
|
98
96
|
if (!options.deep) {
|
|
@@ -107,8 +105,7 @@ const _InheritanceMap = class _InheritanceMap {
|
|
|
107
105
|
getParents(name, options = { deep: true }) {
|
|
108
106
|
const results = /* @__PURE__ */ new Set();
|
|
109
107
|
const node = this.getNode(name);
|
|
110
|
-
if (!node)
|
|
111
|
-
return results;
|
|
108
|
+
if (!node) return results;
|
|
112
109
|
for (const parent of node.parents) {
|
|
113
110
|
results.add(parent.name);
|
|
114
111
|
if (!options.deep) {
|
|
@@ -49,10 +49,8 @@ function isDate(v) {
|
|
|
49
49
|
}
|
|
50
50
|
__name(isDate, "isDate");
|
|
51
51
|
function isNumeric(str) {
|
|
52
|
-
if (typeof str === "number")
|
|
53
|
-
|
|
54
|
-
if (typeof str != "string")
|
|
55
|
-
return false;
|
|
52
|
+
if (typeof str === "number") return true;
|
|
53
|
+
if (typeof str != "string") return false;
|
|
56
54
|
return !isNaN(str) && !isNaN(parseFloat(str));
|
|
57
55
|
}
|
|
58
56
|
__name(isNumeric, "isNumeric");
|
package/lib/model.js
CHANGED
|
@@ -36,10 +36,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
36
36
|
mod
|
|
37
37
|
));
|
|
38
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
|
-
};
|
|
39
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
43
40
|
var model_exports = {};
|
|
44
41
|
__export(model_exports, {
|
|
45
42
|
Model: () => Model
|
|
@@ -49,8 +49,7 @@ const mapVal = /* @__PURE__ */ __name((values, db) => values.map((v) => {
|
|
|
49
49
|
const filterItems = /* @__PURE__ */ __name((values, db) => {
|
|
50
50
|
return import_lodash.default.castArray(values).map((v) => {
|
|
51
51
|
const collection = db.getCollection(v);
|
|
52
|
-
if (!collection)
|
|
53
|
-
return null;
|
|
52
|
+
if (!collection) return null;
|
|
54
53
|
return `'${collection.tableNameAsString()}'::regclass`;
|
|
55
54
|
}).filter(Boolean);
|
|
56
55
|
}, "filterItems");
|
package/lib/options-parser.js
CHANGED
|
@@ -194,8 +194,7 @@ const _OptionsParser = class _OptionsParser {
|
|
|
194
194
|
if (this.isAssociationPath(exceptKey)) {
|
|
195
195
|
except.push(exceptKey);
|
|
196
196
|
} else {
|
|
197
|
-
if (Array.isArray(attributes))
|
|
198
|
-
continue;
|
|
197
|
+
if (Array.isArray(attributes)) continue;
|
|
199
198
|
attributes.exclude.push(exceptKey);
|
|
200
199
|
}
|
|
201
200
|
}
|
|
@@ -206,8 +205,7 @@ const _OptionsParser = class _OptionsParser {
|
|
|
206
205
|
};
|
|
207
206
|
}
|
|
208
207
|
parseExcept(except, filterParams) {
|
|
209
|
-
if (!except)
|
|
210
|
-
return filterParams;
|
|
208
|
+
if (!except) return filterParams;
|
|
211
209
|
const setExcept = /* @__PURE__ */ __name((queryParams, except2) => {
|
|
212
210
|
const exceptPath = except2.split(".");
|
|
213
211
|
const association = exceptPath[0];
|
|
@@ -247,8 +245,7 @@ const _OptionsParser = class _OptionsParser {
|
|
|
247
245
|
return obj;
|
|
248
246
|
}
|
|
249
247
|
parseAppends(appends, filterParams) {
|
|
250
|
-
if (!appends)
|
|
251
|
-
return filterParams;
|
|
248
|
+
if (!appends) return filterParams;
|
|
252
249
|
appends = import_lodash.default.sortBy(appends, (append) => append.split(".").length);
|
|
253
250
|
const setInclude = /* @__PURE__ */ __name((model, queryParams, append) => {
|
|
254
251
|
var _a;
|
|
@@ -100,7 +100,7 @@ const _MysqlQueryInterface = class _MysqlQueryInterface extends import_query_int
|
|
|
100
100
|
}
|
|
101
101
|
async showTableDefinition(tableInfo) {
|
|
102
102
|
const { tableName } = tableInfo;
|
|
103
|
-
const sql = `SHOW CREATE TABLE ${tableName}`;
|
|
103
|
+
const sql = `SHOW CREATE TABLE ${this.db.utils.quoteTable(tableName)}`;
|
|
104
104
|
const results = await this.db.sequelize.query(sql, { type: "SELECT" });
|
|
105
105
|
return results[0]["Create Table"];
|
|
106
106
|
}
|
|
@@ -37,8 +37,7 @@ const _QueryInterface = class _QueryInterface {
|
|
|
37
37
|
}
|
|
38
38
|
sequelizeQueryInterface;
|
|
39
39
|
async dropAll(options) {
|
|
40
|
-
if (options.drop !== true)
|
|
41
|
-
return;
|
|
40
|
+
if (options.drop !== true) return;
|
|
42
41
|
const views = await this.listViews();
|
|
43
42
|
for (const view of views) {
|
|
44
43
|
let removeSql;
|
|
@@ -40,8 +40,7 @@ var __decorateClass = (decorators, target, key, kind) => {
|
|
|
40
40
|
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
41
41
|
if (decorator = decorators[i])
|
|
42
42
|
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
43
|
-
if (kind && result)
|
|
44
|
-
__defProp(target, key, result);
|
|
43
|
+
if (kind && result) __defProp(target, key, result);
|
|
45
44
|
return result;
|
|
46
45
|
};
|
|
47
46
|
var belongs_to_many_repository_exports = {};
|
|
@@ -61,7 +60,7 @@ const _BelongsToManyRepository = class _BelongsToManyRepository extends import_m
|
|
|
61
60
|
const association = this.association;
|
|
62
61
|
return await targetRepository.aggregate({
|
|
63
62
|
...options,
|
|
64
|
-
optionsTransformer: (modelOptions) => {
|
|
63
|
+
optionsTransformer: /* @__PURE__ */ __name((modelOptions) => {
|
|
65
64
|
modelOptions.include = modelOptions.include || [];
|
|
66
65
|
const throughWhere = {};
|
|
67
66
|
throughWhere[association.foreignKey] = sourceModel.get(association.sourceKey);
|
|
@@ -71,7 +70,7 @@ const _BelongsToManyRepository = class _BelongsToManyRepository extends import_m
|
|
|
71
70
|
attributes: [],
|
|
72
71
|
where: throughWhere
|
|
73
72
|
});
|
|
74
|
-
}
|
|
73
|
+
}, "optionsTransformer")
|
|
75
74
|
});
|
|
76
75
|
}
|
|
77
76
|
async create(options) {
|
|
@@ -30,8 +30,7 @@ var __decorateClass = (decorators, target, key, kind) => {
|
|
|
30
30
|
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
31
31
|
if (decorator = decorators[i])
|
|
32
32
|
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
33
|
-
if (kind && result)
|
|
34
|
-
__defProp(target, key, result);
|
|
33
|
+
if (kind && result) __defProp(target, key, result);
|
|
35
34
|
return result;
|
|
36
35
|
};
|
|
37
36
|
var hasmany_repository_exports = {};
|
|
@@ -40,8 +40,7 @@ var __decorateClass = (decorators, target, key, kind) => {
|
|
|
40
40
|
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
41
41
|
if (decorator = decorators[i])
|
|
42
42
|
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
43
|
-
if (kind && result)
|
|
44
|
-
__defProp(target, key, result);
|
|
43
|
+
if (kind && result) __defProp(target, key, result);
|
|
45
44
|
return result;
|
|
46
45
|
};
|
|
47
46
|
var multiple_relation_repository_exports = {};
|
|
@@ -94,8 +93,7 @@ const _MultipleRelationRepository = class _MultipleRelationRepository extends im
|
|
|
94
93
|
async count(options) {
|
|
95
94
|
const transaction2 = await this.getTransaction(options);
|
|
96
95
|
const sourceModel = await this.getSourceModel(transaction2);
|
|
97
|
-
if (!sourceModel)
|
|
98
|
-
return 0;
|
|
96
|
+
if (!sourceModel) return 0;
|
|
99
97
|
const queryOptions = this.buildQueryOptions(options);
|
|
100
98
|
const count = await sourceModel[this.accessors().get]({
|
|
101
99
|
where: queryOptions.where,
|
|
@@ -40,8 +40,7 @@ var __decorateClass = (decorators, target, key, kind) => {
|
|
|
40
40
|
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
41
41
|
if (decorator = decorators[i])
|
|
42
42
|
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
43
|
-
if (kind && result)
|
|
44
|
-
__defProp(target, key, result);
|
|
43
|
+
if (kind && result) __defProp(target, key, result);
|
|
45
44
|
return result;
|
|
46
45
|
};
|
|
47
46
|
var relation_repository_exports = {};
|
|
@@ -40,8 +40,7 @@ var __decorateClass = (decorators, target, key, kind) => {
|
|
|
40
40
|
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
41
41
|
if (decorator = decorators[i])
|
|
42
42
|
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
43
|
-
if (kind && result)
|
|
44
|
-
__defProp(target, key, result);
|
|
43
|
+
if (kind && result) __defProp(target, key, result);
|
|
45
44
|
return result;
|
|
46
45
|
};
|
|
47
46
|
var single_relation_repository_exports = {};
|
|
@@ -71,8 +70,7 @@ const _SingleRelationRepository = class _SingleRelationRepository extends import
|
|
|
71
70
|
async find(options) {
|
|
72
71
|
const targetRepository = this.targetCollection.repository;
|
|
73
72
|
const sourceModel = await this.getSourceModel(await this.getTransaction(options));
|
|
74
|
-
if (!sourceModel)
|
|
75
|
-
return null;
|
|
73
|
+
if (!sourceModel) return null;
|
|
76
74
|
const addFilter = await this.filterOptions(sourceModel);
|
|
77
75
|
const findOptions = {
|
|
78
76
|
...options,
|
package/lib/repository.js
CHANGED
|
@@ -40,8 +40,7 @@ var __decorateClass = (decorators, target, key, kind) => {
|
|
|
40
40
|
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
41
41
|
if (decorator = decorators[i])
|
|
42
42
|
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
43
|
-
if (kind && result)
|
|
44
|
-
__defProp(target, key, result);
|
|
43
|
+
if (kind && result) __defProp(target, key, result);
|
|
45
44
|
return result;
|
|
46
45
|
};
|
|
47
46
|
var repository_exports = {};
|
package/lib/sync-runner.d.ts
CHANGED
|
@@ -6,8 +6,8 @@
|
|
|
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 { Model } from './model';
|
|
10
9
|
import { Model as SequelizeModel } from 'sequelize';
|
|
10
|
+
import { Model } from './model';
|
|
11
11
|
export declare class SyncRunner {
|
|
12
12
|
private model;
|
|
13
13
|
private readonly collection;
|
package/lib/sync-runner.js
CHANGED
|
@@ -30,10 +30,10 @@ __export(sync_runner_exports, {
|
|
|
30
30
|
SyncRunner: () => SyncRunner
|
|
31
31
|
});
|
|
32
32
|
module.exports = __toCommonJS(sync_runner_exports);
|
|
33
|
-
var
|
|
33
|
+
var import_utils = require("@nocobase/utils");
|
|
34
34
|
var import_sequelize = require("sequelize");
|
|
35
35
|
var import_zero_column_table_error = require("./errors/zero-column-table-error");
|
|
36
|
-
var
|
|
36
|
+
var import_inherited_sync_runner = require("./inherited-sync-runner");
|
|
37
37
|
const _SyncRunner = class _SyncRunner {
|
|
38
38
|
constructor(model) {
|
|
39
39
|
this.model = model;
|
|
@@ -78,14 +78,14 @@ const _SyncRunner = class _SyncRunner {
|
|
|
78
78
|
}
|
|
79
79
|
throw e;
|
|
80
80
|
}
|
|
81
|
+
let beforeColumns;
|
|
81
82
|
try {
|
|
82
|
-
|
|
83
|
+
beforeColumns = await this.queryInterface.describeTable(this.tableName, options);
|
|
84
|
+
} catch (error) {
|
|
85
|
+
}
|
|
86
|
+
if (beforeColumns) {
|
|
83
87
|
await this.handlePrimaryKeyBeforeSync(beforeColumns, options);
|
|
84
88
|
await this.handleUniqueFieldBeforeSync(beforeColumns, options);
|
|
85
|
-
} catch (e) {
|
|
86
|
-
if (!e.message.includes("No description found")) {
|
|
87
|
-
throw e;
|
|
88
|
-
}
|
|
89
89
|
}
|
|
90
90
|
const syncResult = await this.performSync(options);
|
|
91
91
|
const columns = await this.queryInterface.describeTable(this.tableName, options);
|
|
@@ -166,19 +166,14 @@ const _SyncRunner = class _SyncRunner {
|
|
|
166
166
|
const attribute = this.findAttributeByColumnName(columnName);
|
|
167
167
|
return attribute && attribute.primaryKey || column.primaryKey;
|
|
168
168
|
}, "isPrimaryKey");
|
|
169
|
-
if (isPrimaryKey())
|
|
170
|
-
|
|
171
|
-
if (await this.isParentColumn(columnName, options))
|
|
172
|
-
continue;
|
|
169
|
+
if (isPrimaryKey()) continue;
|
|
170
|
+
if (await this.isParentColumn(columnName, options)) continue;
|
|
173
171
|
const currentAttribute = this.findAttributeByColumnName(columnName);
|
|
174
|
-
if (!currentAttribute)
|
|
175
|
-
continue;
|
|
172
|
+
if (!currentAttribute) continue;
|
|
176
173
|
const attributeDefaultValue = (0, import_utils.isPlainObject)(currentAttribute.defaultValue) && isJSONColumn(column) ? JSON.stringify(currentAttribute.defaultValue) : currentAttribute.defaultValue;
|
|
177
174
|
const columnDefaultValue = columns[columnName].defaultValue;
|
|
178
|
-
if (columnDefaultValue === null && attributeDefaultValue === void 0)
|
|
179
|
-
|
|
180
|
-
if (columnDefaultValue === "NULL" && attributeDefaultValue === null)
|
|
181
|
-
continue;
|
|
175
|
+
if (columnDefaultValue === null && attributeDefaultValue === void 0) continue;
|
|
176
|
+
if (columnDefaultValue === "NULL" && attributeDefaultValue === null) continue;
|
|
182
177
|
if (columnDefaultValue != attributeDefaultValue) {
|
|
183
178
|
const changeAttribute = {
|
|
184
179
|
...currentAttribute,
|
|
@@ -215,8 +210,7 @@ const _SyncRunner = class _SyncRunner {
|
|
|
215
210
|
});
|
|
216
211
|
for (const existUniqueIndex of existsUniqueIndexes) {
|
|
217
212
|
const isSingleField = existUniqueIndex.fields.length == 1;
|
|
218
|
-
if (!isSingleField)
|
|
219
|
-
continue;
|
|
213
|
+
if (!isSingleField) continue;
|
|
220
214
|
const columnName = existUniqueIndex.fields[0].attribute;
|
|
221
215
|
const currentAttribute = this.findAttributeByColumnName(columnName);
|
|
222
216
|
if (!currentAttribute || !currentAttribute.unique && !currentAttribute.primaryKey) {
|
|
@@ -45,10 +45,8 @@ var import_dayjs = __toESM(require("dayjs"));
|
|
|
45
45
|
var import_excel_date_to_js = require("excel-date-to-js");
|
|
46
46
|
var import_base_value_parser = require("./base-value-parser");
|
|
47
47
|
function isNumeric(str) {
|
|
48
|
-
if (typeof str === "number")
|
|
49
|
-
|
|
50
|
-
if (typeof str != "string")
|
|
51
|
-
return false;
|
|
48
|
+
if (typeof str === "number") return true;
|
|
49
|
+
if (typeof str != "string") return false;
|
|
52
50
|
return !isNaN(str) && !isNaN(parseFloat(str));
|
|
53
51
|
}
|
|
54
52
|
__name(isNumeric, "isNumeric");
|
|
@@ -69,8 +69,7 @@ const _ViewFieldInference = class _ViewFieldInference {
|
|
|
69
69
|
`${usage.table_schema ? `${usage.table_schema}.` : ""}${usage.table_name}`
|
|
70
70
|
);
|
|
71
71
|
const collectionField = (() => {
|
|
72
|
-
if (!collection)
|
|
73
|
-
return false;
|
|
72
|
+
if (!collection) return false;
|
|
74
73
|
const fieldAttribute = Object.values(collection.model.rawAttributes).find(
|
|
75
74
|
(field) => field.field === usage.column_name
|
|
76
75
|
);
|
|
@@ -81,8 +80,7 @@ const _ViewFieldInference = class _ViewFieldInference {
|
|
|
81
80
|
return collection.getField(fieldName);
|
|
82
81
|
})();
|
|
83
82
|
const belongsToAssociationField = (() => {
|
|
84
|
-
if (!collection)
|
|
85
|
-
return false;
|
|
83
|
+
if (!collection) return false;
|
|
86
84
|
const field = Object.values(collection.model.rawAttributes).find(
|
|
87
85
|
(field2) => field2.field === usage.column_name
|
|
88
86
|
);
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nocobase/database",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.35-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.35-alpha",
|
|
10
|
+
"@nocobase/utils": "1.2.35-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": "37a4edc27153f9346b3b08c25a407fb57c78b68e"
|
|
42
42
|
}
|