@nocobase/database 2.0.0-alpha.3 → 2.0.0-alpha.31
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.d.ts +0 -3
- package/lib/collection.js +11 -27
- package/lib/database.d.ts +1 -0
- package/lib/database.js +15 -9
- package/lib/dialects/postgres-dialect.js +0 -3
- package/lib/eager-loading/eager-loading-tree.js +2 -1
- package/lib/index.d.ts +3 -1
- package/lib/index.js +8 -0
- package/lib/operators/in.d.ts +10 -0
- package/lib/operators/in.js +40 -0
- package/lib/operators/index.js +2 -0
- package/lib/relation-repository/belongs-to-many-repository.js +1 -2
- package/lib/relation-repository/relation-repository.js +1 -1
- package/lib/repository.js +2 -2
- package/lib/sync-runner.js +3 -0
- package/lib/update-associations.js +1 -6
- package/lib/utils/field-validation.d.ts +0 -45
- package/lib/utils/field-validation.js +2 -60
- package/lib/utils.d.ts +1 -0
- package/lib/utils.js +10 -0
- package/package.json +4 -4
package/lib/collection.d.ts
CHANGED
|
@@ -93,9 +93,6 @@ export declare class Collection<TModelAttributes extends {} = any, TCreationAttr
|
|
|
93
93
|
validate(options: {
|
|
94
94
|
values: Record<string, any> | Record<string, any>[];
|
|
95
95
|
operation: 'create' | 'update';
|
|
96
|
-
context: {
|
|
97
|
-
t: Function;
|
|
98
|
-
};
|
|
99
96
|
}): void;
|
|
100
97
|
isMultiFilterTargetKey(): boolean;
|
|
101
98
|
tableName(): any;
|
package/lib/collection.js
CHANGED
|
@@ -58,6 +58,7 @@ var import_model = require("./model");
|
|
|
58
58
|
var import_repository = require("./repository");
|
|
59
59
|
var import_utils = require("./utils");
|
|
60
60
|
var import_field_validation = require("./utils/field-validation");
|
|
61
|
+
var import_joi = __toESM(require("joi"));
|
|
61
62
|
function EnsureAtomicity(target, propertyKey, descriptor) {
|
|
62
63
|
const originalMethod = descriptor.value;
|
|
63
64
|
descriptor.value = function(...args) {
|
|
@@ -161,50 +162,33 @@ const _Collection = class _Collection extends import_events.EventEmitter {
|
|
|
161
162
|
}
|
|
162
163
|
}
|
|
163
164
|
validate(options) {
|
|
164
|
-
const { values: updateValues,
|
|
165
|
+
const { values: updateValues, operation } = options;
|
|
165
166
|
if (!updateValues) {
|
|
166
167
|
return;
|
|
167
168
|
}
|
|
168
169
|
const values = Array.isArray(updateValues) ? updateValues : [updateValues];
|
|
169
|
-
const { t } = context || { t: /* @__PURE__ */ __name((key, options2) => key, "t") };
|
|
170
|
-
const unwrapTplLabel = /* @__PURE__ */ __name((label) => {
|
|
171
|
-
if (typeof label !== "string") return label;
|
|
172
|
-
const m = label.match(/^[\s\t]*\{\{\s*t\(\s*(['"])(.*?)\1(?:\s*,[\s\S]*)?\)\s*\}\}[\s\t]*$/);
|
|
173
|
-
return m ? m[2] : label;
|
|
174
|
-
}, "unwrapTplLabel");
|
|
175
170
|
const helper = /* @__PURE__ */ __name((field, value) => {
|
|
176
|
-
var _a, _b
|
|
171
|
+
var _a, _b;
|
|
177
172
|
const val = value[field.name];
|
|
178
173
|
if (!field.options.validation) {
|
|
179
174
|
return;
|
|
180
175
|
}
|
|
181
|
-
const fieldLabel = unwrapTplLabel(((_a = field.options.uiSchema) == null ? void 0 : _a.title) || field.name);
|
|
182
176
|
if (field instanceof import_fields.RelationField) {
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
"#label": `${t("Collection", { ns: "client" })}: ${this.name}, ${t("Field", { ns: "client" })}: ${t(
|
|
190
|
-
fieldLabel,
|
|
191
|
-
{ ns: "client" }
|
|
192
|
-
)}`
|
|
193
|
-
})
|
|
194
|
-
);
|
|
177
|
+
const rules = ((_b = (_a = field.options) == null ? void 0 : _a.validation) == null ? void 0 : _b.rules) || [];
|
|
178
|
+
const required = rules.some((rule) => rule.name === "required");
|
|
179
|
+
if (required) {
|
|
180
|
+
const { error: error2 } = import_joi.default.any().empty(null).required().label(`${this.name}.${field.name}`).validate(val);
|
|
181
|
+
if (error2) {
|
|
182
|
+
throw error2;
|
|
195
183
|
}
|
|
196
184
|
}
|
|
197
185
|
return;
|
|
198
186
|
}
|
|
199
187
|
const joiSchema = (0, import_field_validation.buildJoiSchema)(field.options.validation, {
|
|
200
|
-
label: `${
|
|
201
|
-
ns: "client"
|
|
202
|
-
})}`,
|
|
188
|
+
label: `${this.name}.${field.name}`,
|
|
203
189
|
value: val
|
|
204
190
|
});
|
|
205
|
-
const { error } = joiSchema.validate(val
|
|
206
|
-
messages: (0, import_field_validation.getJoiErrorMessage)(t)
|
|
207
|
-
});
|
|
191
|
+
const { error } = joiSchema.validate(val);
|
|
208
192
|
if (error) {
|
|
209
193
|
throw error;
|
|
210
194
|
}
|
package/lib/database.d.ts
CHANGED
|
@@ -215,6 +215,7 @@ export declare class Database extends EventEmitter implements AsyncEmitter {
|
|
|
215
215
|
private registerCollectionType;
|
|
216
216
|
quoteIdentifier(identifier: string): string;
|
|
217
217
|
quoteTable(tableName: string): string;
|
|
218
|
+
private runSQLWithSchema;
|
|
218
219
|
runSQL(sql: string, options?: RunSQLOptions): Promise<any>;
|
|
219
220
|
}
|
|
220
221
|
export declare function extendCollection(collectionOptions: CollectionOptions, mergeOptions?: MergeOptions): {
|
package/lib/database.js
CHANGED
|
@@ -287,8 +287,8 @@ const _Database = class _Database extends import_events.EventEmitter {
|
|
|
287
287
|
*/
|
|
288
288
|
initListener() {
|
|
289
289
|
this.on("afterConnect", async (client) => {
|
|
290
|
-
if (this.
|
|
291
|
-
await client.query("SET search_path
|
|
290
|
+
if (this.isPostgresCompatibleDialect()) {
|
|
291
|
+
await client.query("SET search_path TO public");
|
|
292
292
|
}
|
|
293
293
|
});
|
|
294
294
|
this.on("beforeDefine", (model, options) => {
|
|
@@ -431,11 +431,7 @@ const _Database = class _Database extends import_events.EventEmitter {
|
|
|
431
431
|
*/
|
|
432
432
|
collection(options) {
|
|
433
433
|
options = import_lodash.default.cloneDeep(options);
|
|
434
|
-
|
|
435
|
-
if (this.options.underscored) {
|
|
436
|
-
options.underscored = true;
|
|
437
|
-
}
|
|
438
|
-
}
|
|
434
|
+
options.underscored = options.underscored ?? this.options.underscored;
|
|
439
435
|
this.logger.trace(`beforeDefineCollection: ${(0, import_safe_json_stringify.default)(options)}`, {
|
|
440
436
|
databaseInstanceId: this.instanceId
|
|
441
437
|
});
|
|
@@ -791,18 +787,28 @@ const _Database = class _Database extends import_events.EventEmitter {
|
|
|
791
787
|
quoteTable(tableName) {
|
|
792
788
|
return this.sequelize.getQueryInterface().quoteIdentifiers(tableName);
|
|
793
789
|
}
|
|
790
|
+
async runSQLWithSchema(finalSQL, bind, transaction) {
|
|
791
|
+
if (!this.options.schema || !this.isPostgresCompatibleDialect()) {
|
|
792
|
+
return this.sequelize.query(finalSQL, { bind, transaction });
|
|
793
|
+
}
|
|
794
|
+
const execute = /* @__PURE__ */ __name(async (t) => {
|
|
795
|
+
await this.sequelize.query(`SET LOCAL search_path TO ${this.options.schema}`, { transaction: t });
|
|
796
|
+
return this.sequelize.query(finalSQL, { bind, transaction: t });
|
|
797
|
+
}, "execute");
|
|
798
|
+
return transaction ? execute(transaction) : this.sequelize.transaction(execute);
|
|
799
|
+
}
|
|
794
800
|
async runSQL(sql, options = {}) {
|
|
795
801
|
const { filter, bind, type, transaction } = options;
|
|
796
802
|
let finalSQL = sql;
|
|
797
803
|
if (!finalSQL.replace(/\s+/g, " ").trim()) {
|
|
798
804
|
throw new Error("SQL cannot be empty");
|
|
799
805
|
}
|
|
806
|
+
const queryGenerator = this.sequelize.getQueryInterface().queryGenerator;
|
|
800
807
|
if (filter) {
|
|
801
808
|
let where = {};
|
|
802
809
|
const tmpCollection = new import_collection.Collection({ name: "tmp", underscored: false }, { database: this });
|
|
803
810
|
const r = tmpCollection.repository;
|
|
804
811
|
where = r.buildQueryOptions({ filter }).where;
|
|
805
|
-
const queryGenerator = this.sequelize.getQueryInterface().queryGenerator;
|
|
806
812
|
const wSQL = queryGenerator.getWhereConditions(where, null, null, { bindParam: true });
|
|
807
813
|
if (wSQL) {
|
|
808
814
|
let normalizedSQL = sql.replace(/\s+/g, " ").trim();
|
|
@@ -813,7 +819,7 @@ const _Database = class _Database extends import_events.EventEmitter {
|
|
|
813
819
|
}
|
|
814
820
|
}
|
|
815
821
|
this.logger.debug("runSQL", { finalSQL });
|
|
816
|
-
const result = await this.
|
|
822
|
+
const result = await this.runSQLWithSchema(finalSQL, bind, transaction);
|
|
817
823
|
let data = result[0];
|
|
818
824
|
if (type === "selectVar") {
|
|
819
825
|
if (Array.isArray(data)) {
|
|
@@ -52,9 +52,6 @@ const _PostgresDialect = class _PostgresDialect extends import_base_dialect.Base
|
|
|
52
52
|
if (!options.hooks["afterConnect"]) {
|
|
53
53
|
options.hooks["afterConnect"] = [];
|
|
54
54
|
}
|
|
55
|
-
options.hooks["afterConnect"].push(async (connection) => {
|
|
56
|
-
await connection.query("SET search_path TO public;");
|
|
57
|
-
});
|
|
58
55
|
return options;
|
|
59
56
|
}
|
|
60
57
|
getVersionGuard() {
|
|
@@ -215,7 +215,8 @@ const _EagerLoadingTree = class _EagerLoadingTree {
|
|
|
215
215
|
attributes: [primaryKeyField],
|
|
216
216
|
group: `${node.model.name}.${primaryKeyField}`,
|
|
217
217
|
transaction,
|
|
218
|
-
include: (0, import_utils.processIncludes)(includeForFilter, node.model)
|
|
218
|
+
include: (0, import_utils.processIncludes)(includeForFilter, node.model),
|
|
219
|
+
raw: true
|
|
219
220
|
})).map((row) => {
|
|
220
221
|
return { row, pk: row[primaryKeyField] };
|
|
221
222
|
});
|
package/lib/index.d.ts
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
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 { ValidationError as JoiValidationError } from 'joi';
|
|
10
11
|
export * from './belongs-to-array/belongs-to-array-repository';
|
|
11
12
|
export * from './collection';
|
|
12
13
|
export * from './collection-group-manager';
|
|
@@ -35,11 +36,12 @@ export * from './repository';
|
|
|
35
36
|
export * from './relation-repository/relation-repository';
|
|
36
37
|
export { default as sqlParser, SQLParserTypes } from './sql-parser';
|
|
37
38
|
export * from './update-associations';
|
|
38
|
-
export { snakeCase } from './utils';
|
|
39
|
+
export { snakeCase, extractTypeFromDefinition } from './utils';
|
|
39
40
|
export * from './value-parsers';
|
|
40
41
|
export * from './view-collection';
|
|
41
42
|
export { default as fieldTypeMap } from './view/field-type-map';
|
|
42
43
|
export * from './view/view-inference';
|
|
43
44
|
export * from './update-guard';
|
|
45
|
+
export { TableInfo } from './query-interface/query-interface';
|
|
44
46
|
export { default as operators } from './operators';
|
|
45
47
|
export { filterIncludes, mergeIncludes } from './utils/filter-include';
|
package/lib/index.js
CHANGED
|
@@ -44,15 +44,18 @@ __export(src_exports, {
|
|
|
44
44
|
HasManyCountAssociationsMixin: () => import_sequelize.HasManyCountAssociationsMixin,
|
|
45
45
|
HasManyCreateAssociationMixin: () => import_sequelize.HasManyCreateAssociationMixin,
|
|
46
46
|
HasManyGetAssociationsMixin: () => import_sequelize.HasManyGetAssociationsMixin,
|
|
47
|
+
JoiValidationError: () => import_joi.ValidationError,
|
|
47
48
|
ModelStatic: () => import_sequelize.ModelStatic,
|
|
48
49
|
Op: () => import_sequelize.Op,
|
|
49
50
|
SQLParserTypes: () => import_sql_parser.SQLParserTypes,
|
|
50
51
|
SyncOptions: () => import_sequelize.SyncOptions,
|
|
52
|
+
TableInfo: () => import_query_interface.TableInfo,
|
|
51
53
|
Transaction: () => import_sequelize.Transaction,
|
|
52
54
|
UniqueConstraintError: () => import_sequelize.UniqueConstraintError,
|
|
53
55
|
ValidationError: () => import_sequelize.ValidationError,
|
|
54
56
|
ValidationErrorItem: () => import_sequelize.ValidationErrorItem,
|
|
55
57
|
default: () => import_database.Database,
|
|
58
|
+
extractTypeFromDefinition: () => import_utils.extractTypeFromDefinition,
|
|
56
59
|
fieldTypeMap: () => import_field_type_map.default,
|
|
57
60
|
filterIncludes: () => import_filter_include.filterIncludes,
|
|
58
61
|
fn: () => import_sequelize.fn,
|
|
@@ -65,6 +68,7 @@ __export(src_exports, {
|
|
|
65
68
|
});
|
|
66
69
|
module.exports = __toCommonJS(src_exports);
|
|
67
70
|
var import_sequelize = require("sequelize");
|
|
71
|
+
var import_joi = require("joi");
|
|
68
72
|
__reExport(src_exports, require("./belongs-to-array/belongs-to-array-repository"), module.exports);
|
|
69
73
|
__reExport(src_exports, require("./collection"), module.exports);
|
|
70
74
|
__reExport(src_exports, require("./collection-group-manager"), module.exports);
|
|
@@ -99,6 +103,7 @@ __reExport(src_exports, require("./view-collection"), module.exports);
|
|
|
99
103
|
var import_field_type_map = __toESM(require("./view/field-type-map"));
|
|
100
104
|
__reExport(src_exports, require("./view/view-inference"), module.exports);
|
|
101
105
|
__reExport(src_exports, require("./update-guard"), module.exports);
|
|
106
|
+
var import_query_interface = require("./query-interface/query-interface");
|
|
102
107
|
var import_operators = __toESM(require("./operators"));
|
|
103
108
|
var import_filter_include = require("./utils/filter-include");
|
|
104
109
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -110,14 +115,17 @@ var import_filter_include = require("./utils/filter-include");
|
|
|
110
115
|
HasManyCountAssociationsMixin,
|
|
111
116
|
HasManyCreateAssociationMixin,
|
|
112
117
|
HasManyGetAssociationsMixin,
|
|
118
|
+
JoiValidationError,
|
|
113
119
|
ModelStatic,
|
|
114
120
|
Op,
|
|
115
121
|
SQLParserTypes,
|
|
116
122
|
SyncOptions,
|
|
123
|
+
TableInfo,
|
|
117
124
|
Transaction,
|
|
118
125
|
UniqueConstraintError,
|
|
119
126
|
ValidationError,
|
|
120
127
|
ValidationErrorItem,
|
|
128
|
+
extractTypeFromDefinition,
|
|
121
129
|
fieldTypeMap,
|
|
122
130
|
filterIncludes,
|
|
123
131
|
fn,
|
|
@@ -0,0 +1,10 @@
|
|
|
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;
|
|
@@ -0,0 +1,40 @@
|
|
|
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 __defProp = Object.defineProperty;
|
|
11
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
12
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
13
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
14
|
+
var __export = (target, all) => {
|
|
15
|
+
for (var name in all)
|
|
16
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
17
|
+
};
|
|
18
|
+
var __copyProps = (to, from, except, desc) => {
|
|
19
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
20
|
+
for (let key of __getOwnPropNames(from))
|
|
21
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
22
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
23
|
+
}
|
|
24
|
+
return to;
|
|
25
|
+
};
|
|
26
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
27
|
+
var in_exports = {};
|
|
28
|
+
__export(in_exports, {
|
|
29
|
+
default: () => in_default
|
|
30
|
+
});
|
|
31
|
+
module.exports = __toCommonJS(in_exports);
|
|
32
|
+
var import_lodash = require("lodash");
|
|
33
|
+
var import_sequelize = require("sequelize");
|
|
34
|
+
var in_default = {
|
|
35
|
+
$in(val, ctx) {
|
|
36
|
+
return {
|
|
37
|
+
[import_sequelize.Op.in]: val == null ? [] : (0, import_lodash.castArray)(val)
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
};
|
package/lib/operators/index.js
CHANGED
|
@@ -46,6 +46,7 @@ var import_empty = __toESM(require("./empty"));
|
|
|
46
46
|
var import_string = __toESM(require("./string"));
|
|
47
47
|
var import_eq = __toESM(require("./eq"));
|
|
48
48
|
var import_ne = __toESM(require("./ne"));
|
|
49
|
+
var import_in = __toESM(require("./in"));
|
|
49
50
|
var import_notIn = __toESM(require("./notIn"));
|
|
50
51
|
var import_boolean = __toESM(require("./boolean"));
|
|
51
52
|
var import_child_collection = __toESM(require("./child-collection"));
|
|
@@ -57,6 +58,7 @@ var operators_default = {
|
|
|
57
58
|
...import_string.default,
|
|
58
59
|
...import_eq.default,
|
|
59
60
|
...import_ne.default,
|
|
61
|
+
...import_in.default,
|
|
60
62
|
...import_notIn.default,
|
|
61
63
|
...import_boolean.default,
|
|
62
64
|
...import_child_collection.default
|
|
@@ -88,8 +88,7 @@ const _BelongsToManyRepository = class _BelongsToManyRepository extends import_m
|
|
|
88
88
|
};
|
|
89
89
|
this.collection.validate({
|
|
90
90
|
values,
|
|
91
|
-
operation: "create"
|
|
92
|
-
context: options.context
|
|
91
|
+
operation: "create"
|
|
93
92
|
});
|
|
94
93
|
const instance = await sourceModel[createAccessor](values, createOptions);
|
|
95
94
|
await (0, import_update_associations.updateAssociations)(instance, values, { ...options, transaction: transaction2 });
|
|
@@ -178,7 +178,7 @@ const _RelationRepository = class _RelationRepository {
|
|
|
178
178
|
const values = options.values;
|
|
179
179
|
const transaction2 = await this.getTransaction(options);
|
|
180
180
|
const sourceModel = await this.getSourceModel(transaction2);
|
|
181
|
-
this.collection.validate({ values,
|
|
181
|
+
this.collection.validate({ values, operation: "create" });
|
|
182
182
|
const instance = await sourceModel[createAccessor](guard.sanitize(options.values), { ...options, transaction: transaction2 });
|
|
183
183
|
await (0, import_update_associations.updateAssociations)(instance, values, { ...options, transaction: transaction2 });
|
|
184
184
|
if (options.hooks !== false) {
|
package/lib/repository.js
CHANGED
|
@@ -453,7 +453,7 @@ const _Repository = class _Repository {
|
|
|
453
453
|
underscored: this.collection.options.underscored
|
|
454
454
|
});
|
|
455
455
|
const values = this.model.callSetters(guard.sanitize(options.values || {}), options);
|
|
456
|
-
this.validate({ values,
|
|
456
|
+
this.validate({ values, operation: "create" });
|
|
457
457
|
const instance = await this.model.create(values, {
|
|
458
458
|
...options,
|
|
459
459
|
transaction: transaction2
|
|
@@ -498,7 +498,7 @@ const _Repository = class _Repository {
|
|
|
498
498
|
const transaction2 = await this.getTransaction(options);
|
|
499
499
|
const guard = import_update_guard.UpdateGuard.fromOptions(this.model, { ...options, underscored: this.collection.options.underscored });
|
|
500
500
|
const values = this.model.callSetters(guard.sanitize(options.values || {}), options);
|
|
501
|
-
this.validate({ values,
|
|
501
|
+
this.validate({ values, operation: "update" });
|
|
502
502
|
if (options.individualHooks === false) {
|
|
503
503
|
const { model: Model2 } = this.collection;
|
|
504
504
|
const primaryKeyField = Model2.primaryKeyField || Model2.primaryKeyAttribute;
|
package/lib/sync-runner.js
CHANGED
|
@@ -162,6 +162,9 @@ const _SyncRunner = class _SyncRunner {
|
|
|
162
162
|
}, "isJSONColumn");
|
|
163
163
|
for (const columnName in columns) {
|
|
164
164
|
const column = columns[columnName];
|
|
165
|
+
if (isJSONColumn(column) && this.database.inDialect("mysql")) {
|
|
166
|
+
continue;
|
|
167
|
+
}
|
|
165
168
|
const isPrimaryKey = /* @__PURE__ */ __name(() => {
|
|
166
169
|
const attribute = this.findAttributeByColumnName(columnName);
|
|
167
170
|
return attribute && attribute.primaryKey || column.primaryKey;
|
|
@@ -81,8 +81,7 @@ async function updateModelByValues(instance, values, options) {
|
|
|
81
81
|
}
|
|
82
82
|
instance.constructor.collection.validate({
|
|
83
83
|
values,
|
|
84
|
-
operation: "update"
|
|
85
|
-
context: options == null ? void 0 : options.context
|
|
84
|
+
operation: "update"
|
|
86
85
|
});
|
|
87
86
|
await instance.update(values, options);
|
|
88
87
|
await updateAssociations(instance, values, options);
|
|
@@ -273,7 +272,6 @@ async function updateSingleAssociation(model, key, value, options = {}) {
|
|
|
273
272
|
}
|
|
274
273
|
association.target.collection.validate({
|
|
275
274
|
values: value,
|
|
276
|
-
context: options.context,
|
|
277
275
|
operation: "create"
|
|
278
276
|
});
|
|
279
277
|
const instance = await model[createAccessor](value, { context, transaction });
|
|
@@ -368,7 +366,6 @@ async function updateMultipleAssociation(model, key, value, options = {}) {
|
|
|
368
366
|
if ((0, import_utils.isUndefinedOrNull)(item[targetKey])) {
|
|
369
367
|
association.target.collection.validate({
|
|
370
368
|
values: item,
|
|
371
|
-
context: options.context,
|
|
372
369
|
operation: "create"
|
|
373
370
|
});
|
|
374
371
|
const instance = await model[createAccessor](item, accessorOptions);
|
|
@@ -390,7 +387,6 @@ async function updateMultipleAssociation(model, key, value, options = {}) {
|
|
|
390
387
|
if (!instance) {
|
|
391
388
|
association.target.collection.validate({
|
|
392
389
|
values: item,
|
|
393
|
-
context: options.context,
|
|
394
390
|
operation: "create"
|
|
395
391
|
});
|
|
396
392
|
instance = await model[createAccessor](item, accessorOptions);
|
|
@@ -414,7 +410,6 @@ async function updateMultipleAssociation(model, key, value, options = {}) {
|
|
|
414
410
|
}
|
|
415
411
|
association.target.collection.validate({
|
|
416
412
|
values: item,
|
|
417
|
-
context: options.context,
|
|
418
413
|
operation: "update"
|
|
419
414
|
});
|
|
420
415
|
await instance.update(item, { ...options, transaction });
|
|
@@ -12,48 +12,3 @@ export declare function buildJoiSchema(validation: ValidationOptions, options: {
|
|
|
12
12
|
label?: string;
|
|
13
13
|
value: string;
|
|
14
14
|
}): AnySchema;
|
|
15
|
-
export declare function getJoiErrorMessage(t: Function): {
|
|
16
|
-
'string.base': any;
|
|
17
|
-
'string.empty': any;
|
|
18
|
-
'string.min': any;
|
|
19
|
-
'string.max': any;
|
|
20
|
-
'string.length': any;
|
|
21
|
-
'string.alphanum': any;
|
|
22
|
-
'string.token': any;
|
|
23
|
-
'string.regex': any;
|
|
24
|
-
'string.email': any;
|
|
25
|
-
'string.uri': any;
|
|
26
|
-
'string.uriCustomScheme': any;
|
|
27
|
-
'string.isoDate': any;
|
|
28
|
-
'string.guid': any;
|
|
29
|
-
'string.hex': any;
|
|
30
|
-
'string.hostname': any;
|
|
31
|
-
'string.lowercase': any;
|
|
32
|
-
'string.uppercase': any;
|
|
33
|
-
'string.trim': any;
|
|
34
|
-
'string.creditCard': any;
|
|
35
|
-
'string.pattern.base': any;
|
|
36
|
-
'string.pattern.name': any;
|
|
37
|
-
'string.pattern.invert.base': any;
|
|
38
|
-
'string.pattern.invert.name': any;
|
|
39
|
-
'any.required': any;
|
|
40
|
-
'number.base': any;
|
|
41
|
-
'number.min': any;
|
|
42
|
-
'number.max': any;
|
|
43
|
-
'number.less': any;
|
|
44
|
-
'number.greater': any;
|
|
45
|
-
'number.float': any;
|
|
46
|
-
'number.integer': any;
|
|
47
|
-
'number.negative': any;
|
|
48
|
-
'number.positive': any;
|
|
49
|
-
'number.precision': any;
|
|
50
|
-
'number.multiple': any;
|
|
51
|
-
'number.port': any;
|
|
52
|
-
'number.unsafe': any;
|
|
53
|
-
'date.base': any;
|
|
54
|
-
'date.format': any;
|
|
55
|
-
'date.greater': any;
|
|
56
|
-
'date.less': any;
|
|
57
|
-
'date.max': any;
|
|
58
|
-
'date.min': any;
|
|
59
|
-
};
|
|
@@ -37,8 +37,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
37
37
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
38
38
|
var field_validation_exports = {};
|
|
39
39
|
__export(field_validation_exports, {
|
|
40
|
-
buildJoiSchema: () => buildJoiSchema
|
|
41
|
-
getJoiErrorMessage: () => getJoiErrorMessage
|
|
40
|
+
buildJoiSchema: () => buildJoiSchema
|
|
42
41
|
});
|
|
43
42
|
module.exports = __toCommonJS(field_validation_exports);
|
|
44
43
|
var import_joi = __toESM(require("joi"));
|
|
@@ -80,64 +79,7 @@ function buildJoiSchema(validation, options) {
|
|
|
80
79
|
return schema;
|
|
81
80
|
}
|
|
82
81
|
__name(buildJoiSchema, "buildJoiSchema");
|
|
83
|
-
function getJoiErrorMessage(t) {
|
|
84
|
-
const tOptions = { ns: "client" };
|
|
85
|
-
const JoiErrorMessages = {
|
|
86
|
-
"string.base": t("{{#label}} must be a string", tOptions),
|
|
87
|
-
"string.empty": t("{{#label}} is not allowed to be empty", tOptions),
|
|
88
|
-
"string.min": t("{{#label}} length must be at least {{#limit}} characters long", tOptions),
|
|
89
|
-
"string.max": t("{{#label}} length must be less than or equal to {{#limit}} characters long", tOptions),
|
|
90
|
-
"string.length": t("{{#label}} length must be {{#limit}} characters long", tOptions),
|
|
91
|
-
"string.alphanum": t("{{#label}} must only contain alpha-numeric characters", tOptions),
|
|
92
|
-
"string.token": t("{{#label}} must only contain alpha-numeric and underscore characters", tOptions),
|
|
93
|
-
"string.regex": t("{{#label}} with value {{#value}} fails to match the required pattern", tOptions),
|
|
94
|
-
"string.email": t("{{#label}} email address doesn\u2019t meet the required format", tOptions),
|
|
95
|
-
"string.uri": t("{{#label}} must be a valid uri", tOptions),
|
|
96
|
-
"string.uriCustomScheme": t(
|
|
97
|
-
"{{#label}} must be a valid uri with a scheme matching the {{#scheme}} pattern",
|
|
98
|
-
tOptions
|
|
99
|
-
),
|
|
100
|
-
"string.isoDate": t("{{#label}} must be a valid ISO 8601 date", tOptions),
|
|
101
|
-
"string.guid": t("{{#label}} must be a valid UUID", tOptions),
|
|
102
|
-
"string.hex": t("{{#label}} must only contain hexadecimal characters", tOptions),
|
|
103
|
-
"string.hostname": t("{{#label}} must be a valid hostname", tOptions),
|
|
104
|
-
"string.lowercase": t("{{#label}} must only contain lowercase characters", tOptions),
|
|
105
|
-
"string.uppercase": t("{{#label}} must only contain uppercase characters", tOptions),
|
|
106
|
-
"string.trim": t("{{#label}} must not have leading or trailing whitespace", tOptions),
|
|
107
|
-
"string.creditCard": t("{{#label}} must be a credit card", tOptions),
|
|
108
|
-
"string.pattern.base": t('{{#label}} with value "{{#value}}" fails to match the required pattern', tOptions),
|
|
109
|
-
"string.pattern.name": t('{{#label}} with value "{{#value}}" fails to match the {{#name}} pattern', tOptions),
|
|
110
|
-
"string.pattern.invert.base": t('{{#label}} with value "{{#value}}" matches the inverted pattern', tOptions),
|
|
111
|
-
"string.pattern.invert.name": t(
|
|
112
|
-
'{{#label}} with value "{{#value}}" matches the inverted {{#name}} pattern',
|
|
113
|
-
tOptions
|
|
114
|
-
),
|
|
115
|
-
"any.required": t("{{#label}} is required", tOptions),
|
|
116
|
-
"number.base": t("{{#label}} must be a number", tOptions),
|
|
117
|
-
"number.min": t("{{#label}} must be greater than or equal to {{#limit}}", tOptions),
|
|
118
|
-
"number.max": t("{{#label}} must be less than or equal to {{#limit}}", tOptions),
|
|
119
|
-
"number.less": t("{{#label}} must be less than {{#limit}}", tOptions),
|
|
120
|
-
"number.greater": t("{{#label}} must be greater than {{#limit}}", tOptions),
|
|
121
|
-
"number.float": t("{{#label}} must be a float or double", tOptions),
|
|
122
|
-
"number.integer": t("{{#label}} must be an integer", tOptions),
|
|
123
|
-
"number.negative": t("{{#label}} must be a negative number", tOptions),
|
|
124
|
-
"number.positive": t("{{#label}} must be a positive number", tOptions),
|
|
125
|
-
"number.precision": t("{{#label}} must not have more than {{#limit}} decimal places", tOptions),
|
|
126
|
-
"number.multiple": t("{{#label}} must be a multiple of {{#multiple}}", tOptions),
|
|
127
|
-
"number.port": t("{{#label}} must be a valid port", tOptions),
|
|
128
|
-
"number.unsafe": t("{{#label}} must be a safe number", tOptions),
|
|
129
|
-
"date.base": t("{{#label}} must be a valid date", tOptions),
|
|
130
|
-
"date.format": t("{{#label}} must be in {{#format}} format", tOptions),
|
|
131
|
-
"date.greater": t("{{#label}} must be greater than {{#limit}}", tOptions),
|
|
132
|
-
"date.less": t("{{#label}} must be less than {{#limit}}", tOptions),
|
|
133
|
-
"date.max": t("{{#label}} must be less than or equal to {{#limit}}", tOptions),
|
|
134
|
-
"date.min": t("{{#label}} must be greater than or equal to {{#limit}}", tOptions)
|
|
135
|
-
};
|
|
136
|
-
return JoiErrorMessages;
|
|
137
|
-
}
|
|
138
|
-
__name(getJoiErrorMessage, "getJoiErrorMessage");
|
|
139
82
|
// Annotate the CommonJS export names for ESM import in node:
|
|
140
83
|
0 && (module.exports = {
|
|
141
|
-
buildJoiSchema
|
|
142
|
-
getJoiErrorMessage
|
|
84
|
+
buildJoiSchema
|
|
143
85
|
});
|
package/lib/utils.d.ts
CHANGED
|
@@ -16,4 +16,5 @@ export declare function percent2float(value: string): number;
|
|
|
16
16
|
export declare function isUndefinedOrNull(value: any): boolean;
|
|
17
17
|
export declare function isStringOrNumber(value: any): boolean;
|
|
18
18
|
export declare function getKeysByPrefix(keys: string[], prefix: string): string[];
|
|
19
|
+
export declare function extractTypeFromDefinition(rawType: string): string;
|
|
19
20
|
export declare function processIncludes(includes: any[], model: any, parentAs?: string): any[];
|
package/lib/utils.js
CHANGED
|
@@ -38,6 +38,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
38
38
|
var utils_exports = {};
|
|
39
39
|
__export(utils_exports, {
|
|
40
40
|
checkIdentifier: () => checkIdentifier,
|
|
41
|
+
extractTypeFromDefinition: () => extractTypeFromDefinition,
|
|
41
42
|
getKeysByPrefix: () => getKeysByPrefix,
|
|
42
43
|
getTableName: () => getTableName,
|
|
43
44
|
isStringOrNumber: () => isStringOrNumber,
|
|
@@ -141,6 +142,14 @@ function getKeysByPrefix(keys, prefix) {
|
|
|
141
142
|
return keys.filter((key) => key.startsWith(`${prefix}.`)).map((key) => key.substring(prefix.length + 1));
|
|
142
143
|
}
|
|
143
144
|
__name(getKeysByPrefix, "getKeysByPrefix");
|
|
145
|
+
function extractTypeFromDefinition(rawType) {
|
|
146
|
+
const leftParenIndex = rawType.indexOf("(");
|
|
147
|
+
if (leftParenIndex === -1) {
|
|
148
|
+
return rawType.toLowerCase();
|
|
149
|
+
}
|
|
150
|
+
return rawType.substring(0, leftParenIndex).toLowerCase().trim();
|
|
151
|
+
}
|
|
152
|
+
__name(extractTypeFromDefinition, "extractTypeFromDefinition");
|
|
144
153
|
function processIncludes(includes, model, parentAs = "") {
|
|
145
154
|
includes.forEach((include, index) => {
|
|
146
155
|
const association = model.associations[include.association];
|
|
@@ -164,6 +173,7 @@ __name(processIncludes, "processIncludes");
|
|
|
164
173
|
// Annotate the CommonJS export names for ESM import in node:
|
|
165
174
|
0 && (module.exports = {
|
|
166
175
|
checkIdentifier,
|
|
176
|
+
extractTypeFromDefinition,
|
|
167
177
|
getKeysByPrefix,
|
|
168
178
|
getTableName,
|
|
169
179
|
isStringOrNumber,
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nocobase/database",
|
|
3
|
-
"version": "2.0.0-alpha.
|
|
3
|
+
"version": "2.0.0-alpha.31",
|
|
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": "2.0.0-alpha.
|
|
10
|
-
"@nocobase/utils": "2.0.0-alpha.
|
|
9
|
+
"@nocobase/logger": "2.0.0-alpha.31",
|
|
10
|
+
"@nocobase/utils": "2.0.0-alpha.31",
|
|
11
11
|
"async-mutex": "^0.3.2",
|
|
12
12
|
"chalk": "^4.1.1",
|
|
13
13
|
"cron-parser": "4.4.0",
|
|
@@ -39,5 +39,5 @@
|
|
|
39
39
|
"url": "git+https://github.com/nocobase/nocobase.git",
|
|
40
40
|
"directory": "packages/database"
|
|
41
41
|
},
|
|
42
|
-
"gitHead": "
|
|
42
|
+
"gitHead": "1ccdc0a8af73f6c2e3e83df75741947a5a8c1984"
|
|
43
43
|
}
|