@nocobase/database 1.6.0-alpha.3 → 1.6.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/{relation-repository → belongs-to-array}/belongs-to-array-repository.d.ts +3 -1
- package/lib/{relation-repository → belongs-to-array}/belongs-to-array-repository.js +26 -3
- package/lib/collection.d.ts +4 -0
- package/lib/database.js +1 -0
- package/lib/dialects/mysql-dialect.d.ts +1 -0
- package/lib/dialects/mysql-dialect.js +5 -0
- package/lib/fields/belongs-to-many-field.js +4 -1
- package/lib/fields/unix-timestamp-field.js +7 -4
- package/lib/filter-match.js +3 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.js +2 -2
- package/lib/inherited-collection.js +3 -0
- package/lib/interfaces/datetime-interface.d.ts +23 -0
- package/lib/interfaces/datetime-interface.js +28 -4
- package/lib/interfaces/datetime-no-tz-interface.d.ts +8 -0
- package/lib/interfaces/datetime-no-tz-interface.js +10 -3
- package/lib/interfaces/to-many-interface.js +12 -2
- package/lib/operators/boolean.js +19 -6
- package/lib/operators/string.js +64 -36
- package/lib/relation-repository/hasmany-repository.d.ts +2 -1
- package/lib/relation-repository/multiple-relation-repository.d.ts +6 -10
- package/lib/relation-repository/multiple-relation-repository.js +7 -0
- package/lib/relation-repository/relation-repository.d.ts +5 -1
- package/lib/relation-repository/relation-repository.js +35 -1
- package/lib/relation-repository/single-relation-repository.d.ts +3 -10
- package/lib/relation-repository/single-relation-repository.js +3 -1
- package/lib/relation-repository/types.d.ts +77 -6
- package/lib/repository.d.ts +6 -6
- package/lib/repository.js +18 -48
- package/lib/update-associations.d.ts +5 -3
- package/lib/update-associations.js +15 -23
- package/lib/utils/filter-utils.d.ts +13 -0
- package/lib/utils/filter-utils.js +86 -0
- package/lib/utils.d.ts +3 -0
- package/lib/utils.js +18 -0
- package/package.json +4 -4
|
@@ -9,9 +9,10 @@
|
|
|
9
9
|
import { Transactionable } from 'sequelize/types';
|
|
10
10
|
import { Collection } from '../collection';
|
|
11
11
|
import { FindOptions } from '../repository';
|
|
12
|
-
import { MultipleRelationRepository } from '
|
|
12
|
+
import { MultipleRelationRepository } from '../relation-repository/multiple-relation-repository';
|
|
13
13
|
import Database from '../database';
|
|
14
14
|
import { Model } from '../model';
|
|
15
|
+
import { UpdateAssociationOptions } from '../update-associations';
|
|
15
16
|
export declare class BelongsToArrayAssociation {
|
|
16
17
|
db: Database;
|
|
17
18
|
associationType: string;
|
|
@@ -33,6 +34,7 @@ export declare class BelongsToArrayAssociation {
|
|
|
33
34
|
generateInclude(): {
|
|
34
35
|
on: import("sequelize/types/utils").Literal;
|
|
35
36
|
};
|
|
37
|
+
update(instance: Model, value: any, options?: UpdateAssociationOptions): Promise<void>;
|
|
36
38
|
}
|
|
37
39
|
export declare class BelongsToArrayRepository extends MultipleRelationRepository {
|
|
38
40
|
private belongsToArrayAssociation;
|
|
@@ -7,9 +7,11 @@
|
|
|
7
7
|
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
+
var __create = Object.create;
|
|
10
11
|
var __defProp = Object.defineProperty;
|
|
11
12
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
12
13
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
14
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
13
15
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
14
16
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
15
17
|
var __export = (target, all) => {
|
|
@@ -24,6 +26,14 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
24
26
|
}
|
|
25
27
|
return to;
|
|
26
28
|
};
|
|
29
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
30
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
31
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
32
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
33
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
34
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
35
|
+
mod
|
|
36
|
+
));
|
|
27
37
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
38
|
var __decorateClass = (decorators, target, key, kind) => {
|
|
29
39
|
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
@@ -39,9 +49,9 @@ __export(belongs_to_array_repository_exports, {
|
|
|
39
49
|
BelongsToArrayRepository: () => BelongsToArrayRepository
|
|
40
50
|
});
|
|
41
51
|
module.exports = __toCommonJS(belongs_to_array_repository_exports);
|
|
42
|
-
var import_lodash = require("lodash");
|
|
52
|
+
var import_lodash = __toESM(require("lodash"));
|
|
43
53
|
var import_transaction_decorator = require("../decorators/transaction-decorator");
|
|
44
|
-
var import_multiple_relation_repository = require("
|
|
54
|
+
var import_multiple_relation_repository = require("../relation-repository/multiple-relation-repository");
|
|
45
55
|
const transaction = (0, import_transaction_decorator.transactionWrapperBuilder)(function() {
|
|
46
56
|
return this.collection.model.sequelize.transaction();
|
|
47
57
|
});
|
|
@@ -83,6 +93,19 @@ const _BelongsToArrayAssociation = class _BelongsToArrayAssociation {
|
|
|
83
93
|
on: this.db.sequelize.literal(`${left}=any(${right})`)
|
|
84
94
|
};
|
|
85
95
|
}
|
|
96
|
+
async update(instance, value, options = {}) {
|
|
97
|
+
await instance.update(
|
|
98
|
+
{
|
|
99
|
+
[this.as]: value
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
values: {
|
|
103
|
+
[this.as]: value
|
|
104
|
+
},
|
|
105
|
+
transaction: options == null ? void 0 : options.transaction
|
|
106
|
+
}
|
|
107
|
+
);
|
|
108
|
+
}
|
|
86
109
|
};
|
|
87
110
|
__name(_BelongsToArrayAssociation, "BelongsToArrayAssociation");
|
|
88
111
|
let BelongsToArrayAssociation = _BelongsToArrayAssociation;
|
|
@@ -109,7 +132,7 @@ const _BelongsToArrayRepository = class _BelongsToArrayRepository extends import
|
|
|
109
132
|
addFilter[targetKey] = options.filterByTk;
|
|
110
133
|
}
|
|
111
134
|
const findOptions = {
|
|
112
|
-
...
|
|
135
|
+
...import_lodash.default.omit(options, ["filterByTk", "where", "values", "attributes"]),
|
|
113
136
|
filter: {
|
|
114
137
|
$and: [options.filter || {}, addFilter]
|
|
115
138
|
}
|
package/lib/collection.d.ts
CHANGED
|
@@ -29,17 +29,21 @@ export type DumpRules = BuiltInGroup | ({
|
|
|
29
29
|
} & BaseDumpRules) | ({
|
|
30
30
|
group: BuiltInGroup | string;
|
|
31
31
|
} & BaseDumpRules);
|
|
32
|
+
export type MigrationRule = 'overwrite' | 'skip' | 'upsert' | 'schema-only' | 'insert-ignore' | (string & {}) | null;
|
|
32
33
|
export interface CollectionOptions extends Omit<ModelOptions, 'name' | 'hooks'> {
|
|
33
34
|
name: string;
|
|
34
35
|
title?: string;
|
|
35
36
|
namespace?: string;
|
|
37
|
+
migrationRules?: MigrationRule[];
|
|
36
38
|
dumpRules?: DumpRules;
|
|
37
39
|
tableName?: string;
|
|
38
40
|
inherits?: string[] | string;
|
|
39
41
|
viewName?: string;
|
|
40
42
|
writableView?: boolean;
|
|
43
|
+
isThrough?: boolean;
|
|
41
44
|
filterTargetKey?: string | string[];
|
|
42
45
|
fields?: FieldOptions[];
|
|
46
|
+
fieldSort?: string[];
|
|
43
47
|
model?: string | ModelStatic<Model>;
|
|
44
48
|
repository?: string | RepositoryType;
|
|
45
49
|
sortable?: CollectionSortable;
|
package/lib/database.js
CHANGED
|
@@ -220,6 +220,7 @@ const _Database = class _Database extends import_events.EventEmitter {
|
|
|
220
220
|
autoGenId: false,
|
|
221
221
|
timestamps: false,
|
|
222
222
|
dumpRules: "required",
|
|
223
|
+
migrationRules: ["schema-only", "overwrite"],
|
|
223
224
|
origin: "@nocobase/database",
|
|
224
225
|
fields: [{ type: "string", name: "name", primaryKey: true }]
|
|
225
226
|
});
|
|
@@ -32,6 +32,7 @@ __export(mysql_dialect_exports, {
|
|
|
32
32
|
MysqlDialect: () => MysqlDialect
|
|
33
33
|
});
|
|
34
34
|
module.exports = __toCommonJS(mysql_dialect_exports);
|
|
35
|
+
var import_utils = require("@nocobase/utils");
|
|
35
36
|
var import_base_dialect = require("./base-dialect");
|
|
36
37
|
const _MysqlDialect = class _MysqlDialect extends import_base_dialect.BaseDialect {
|
|
37
38
|
getVersionGuard() {
|
|
@@ -44,6 +45,10 @@ const _MysqlDialect = class _MysqlDialect extends import_base_dialect.BaseDialec
|
|
|
44
45
|
version: ">=8.0.17"
|
|
45
46
|
};
|
|
46
47
|
}
|
|
48
|
+
getSequelizeOptions(options) {
|
|
49
|
+
import_utils.lodash.set(options, "dialectOptions.multipleStatements", true);
|
|
50
|
+
return options;
|
|
51
|
+
}
|
|
47
52
|
};
|
|
48
53
|
__name(_MysqlDialect, "MysqlDialect");
|
|
49
54
|
__publicField(_MysqlDialect, "dialectName", "mysql");
|
|
@@ -125,7 +125,10 @@ const _BelongsToManyField = class _BelongsToManyField extends import_relation_fi
|
|
|
125
125
|
Through = database.getCollection(through);
|
|
126
126
|
} else {
|
|
127
127
|
const throughCollectionOptions = {
|
|
128
|
-
name: through
|
|
128
|
+
name: through,
|
|
129
|
+
isThrough: true,
|
|
130
|
+
sourceCollectionName: this.collection.name,
|
|
131
|
+
targetCollectionName: this.target
|
|
129
132
|
};
|
|
130
133
|
if (this.collection.options.dumpRules) {
|
|
131
134
|
throughCollectionOptions["dumpRules"] = this.collection.options.dumpRules;
|
|
@@ -52,7 +52,7 @@ const _UnixTimestampField = class _UnixTimestampField extends import_date_field.
|
|
|
52
52
|
if (accuracy === "millisecond") {
|
|
53
53
|
rationalNumber = 1;
|
|
54
54
|
}
|
|
55
|
-
return Math.floor(new Date(val).getTime() / rationalNumber);
|
|
55
|
+
return Math.floor(typeof val === "number" ? val : new Date(val).getTime() / rationalNumber);
|
|
56
56
|
}
|
|
57
57
|
additionalSequelizeOptions() {
|
|
58
58
|
var _a, _b, _c, _d, _e;
|
|
@@ -71,16 +71,19 @@ const _UnixTimestampField = class _UnixTimestampField extends import_date_field.
|
|
|
71
71
|
return {
|
|
72
72
|
get() {
|
|
73
73
|
const value = this.getDataValue(name);
|
|
74
|
-
if (value
|
|
74
|
+
if (value == null) {
|
|
75
75
|
return value;
|
|
76
76
|
}
|
|
77
77
|
return new Date(value * rationalNumber);
|
|
78
78
|
},
|
|
79
79
|
set(value) {
|
|
80
|
-
if (value
|
|
80
|
+
if (value == null) {
|
|
81
81
|
this.setDataValue(name, value);
|
|
82
82
|
} else {
|
|
83
|
-
this.setDataValue(
|
|
83
|
+
this.setDataValue(
|
|
84
|
+
name,
|
|
85
|
+
Math.floor(typeof value === "number" ? value : new Date(value).getTime() / rationalNumber)
|
|
86
|
+
);
|
|
84
87
|
}
|
|
85
88
|
}
|
|
86
89
|
};
|
package/lib/filter-match.js
CHANGED
|
@@ -69,7 +69,9 @@ function filterMatch(model, where) {
|
|
|
69
69
|
$ne: /* @__PURE__ */ __name((value, condition) => value !== condition, "$ne"),
|
|
70
70
|
$in: /* @__PURE__ */ __name((value, condition) => condition.includes(value), "$in"),
|
|
71
71
|
$or: /* @__PURE__ */ __name((model2, conditions) => Object.values(conditions).some((condition) => filterMatch(model2, condition)), "$or"),
|
|
72
|
-
$and: /* @__PURE__ */ __name((model2, conditions) => Object.values(conditions).every((condition) => filterMatch(model2, condition)), "$and")
|
|
72
|
+
$and: /* @__PURE__ */ __name((model2, conditions) => Object.values(conditions).every((condition) => filterMatch(model2, condition)), "$and"),
|
|
73
|
+
// boolean
|
|
74
|
+
$isFalsy: /* @__PURE__ */ __name((value) => !value, "$isFalsy")
|
|
73
75
|
};
|
|
74
76
|
for (const [key, value] of Object.entries(where)) {
|
|
75
77
|
if (operatorFunctions[key] !== void 0) {
|
package/lib/index.d.ts
CHANGED
|
@@ -26,7 +26,7 @@ export * from './relation-repository/belongs-to-repository';
|
|
|
26
26
|
export * from './relation-repository/hasmany-repository';
|
|
27
27
|
export * from './relation-repository/multiple-relation-repository';
|
|
28
28
|
export * from './relation-repository/single-relation-repository';
|
|
29
|
-
export * from './
|
|
29
|
+
export * from './belongs-to-array/belongs-to-array-repository';
|
|
30
30
|
export * from './repository';
|
|
31
31
|
export * from './update-associations';
|
|
32
32
|
export { snakeCase } from './utils';
|
package/lib/index.js
CHANGED
|
@@ -81,7 +81,7 @@ __reExport(src_exports, require("./relation-repository/belongs-to-repository"),
|
|
|
81
81
|
__reExport(src_exports, require("./relation-repository/hasmany-repository"), module.exports);
|
|
82
82
|
__reExport(src_exports, require("./relation-repository/multiple-relation-repository"), module.exports);
|
|
83
83
|
__reExport(src_exports, require("./relation-repository/single-relation-repository"), module.exports);
|
|
84
|
-
__reExport(src_exports, require("./
|
|
84
|
+
__reExport(src_exports, require("./belongs-to-array/belongs-to-array-repository"), module.exports);
|
|
85
85
|
__reExport(src_exports, require("./repository"), module.exports);
|
|
86
86
|
__reExport(src_exports, require("./update-associations"), module.exports);
|
|
87
87
|
var import_utils = require("./utils");
|
|
@@ -133,7 +133,7 @@ __reExport(src_exports, require("./dialects"), module.exports);
|
|
|
133
133
|
...require("./relation-repository/hasmany-repository"),
|
|
134
134
|
...require("./relation-repository/multiple-relation-repository"),
|
|
135
135
|
...require("./relation-repository/single-relation-repository"),
|
|
136
|
-
...require("./
|
|
136
|
+
...require("./belongs-to-array/belongs-to-array-repository"),
|
|
137
137
|
...require("./repository"),
|
|
138
138
|
...require("./update-associations"),
|
|
139
139
|
...require("./value-parsers"),
|
|
@@ -81,6 +81,9 @@ const _InheritedCollection = class _InheritedCollection extends import_collectio
|
|
|
81
81
|
}
|
|
82
82
|
parentFields() {
|
|
83
83
|
const fields = /* @__PURE__ */ new Map();
|
|
84
|
+
if (!this.parents) {
|
|
85
|
+
return fields;
|
|
86
|
+
}
|
|
84
87
|
for (const parent of this.parents) {
|
|
85
88
|
if (parent.isInherited()) {
|
|
86
89
|
for (const [name, field] of parent.parentFields()) {
|
|
@@ -8,6 +8,29 @@
|
|
|
8
8
|
*/
|
|
9
9
|
import { BaseInterface } from './base-interface';
|
|
10
10
|
export declare class DatetimeInterface extends BaseInterface {
|
|
11
|
+
protected parseDateString(value: string): {
|
|
12
|
+
year: string;
|
|
13
|
+
month: string;
|
|
14
|
+
day: string;
|
|
15
|
+
hour: string;
|
|
16
|
+
minute: string;
|
|
17
|
+
second: string;
|
|
18
|
+
} | {
|
|
19
|
+
year: string;
|
|
20
|
+
month: string;
|
|
21
|
+
day: string;
|
|
22
|
+
hour?: undefined;
|
|
23
|
+
minute?: undefined;
|
|
24
|
+
second?: undefined;
|
|
25
|
+
};
|
|
26
|
+
protected formatDateTimeToISO(dateInfo: {
|
|
27
|
+
year: string;
|
|
28
|
+
month: string;
|
|
29
|
+
day: string;
|
|
30
|
+
hour?: string;
|
|
31
|
+
minute?: string;
|
|
32
|
+
second?: string;
|
|
33
|
+
}): string;
|
|
11
34
|
toValue(value: any, ctx?: any): Promise<any>;
|
|
12
35
|
toString(value: any, ctx?: any): any;
|
|
13
36
|
}
|
|
@@ -62,15 +62,39 @@ function resolveTimeZoneFromCtx(ctx) {
|
|
|
62
62
|
}
|
|
63
63
|
__name(resolveTimeZoneFromCtx, "resolveTimeZoneFromCtx");
|
|
64
64
|
const _DatetimeInterface = class _DatetimeInterface extends import_base_interface.BaseInterface {
|
|
65
|
+
parseDateString(value) {
|
|
66
|
+
const dateOnlyMatch = /^(\d{4})[-/]?(\d{2})[-/]?(\d{2})$/.exec(value);
|
|
67
|
+
const dateTimeMatch = /^(\d{4})(\d{2})(\d{2})\s+(\d{2}):(\d{2}):(\d{2})$/.exec(value);
|
|
68
|
+
if (dateTimeMatch) {
|
|
69
|
+
const [_, year, month, day, hour, minute, second] = dateTimeMatch;
|
|
70
|
+
return { year, month, day, hour, minute, second };
|
|
71
|
+
}
|
|
72
|
+
if (dateOnlyMatch) {
|
|
73
|
+
const [_, year, month, day] = dateOnlyMatch;
|
|
74
|
+
return { year, month, day };
|
|
75
|
+
}
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
formatDateTimeToISO(dateInfo) {
|
|
79
|
+
const { year, month, day, hour = "00", minute = "00", second = "00" } = dateInfo;
|
|
80
|
+
const m = (0, import_dayjs.default)(`${year}-${month}-${day} ${hour}:${minute}:${second}.000`);
|
|
81
|
+
return m.toISOString();
|
|
82
|
+
}
|
|
65
83
|
async toValue(value, ctx = {}) {
|
|
66
84
|
if (!value) {
|
|
67
85
|
return null;
|
|
68
86
|
}
|
|
87
|
+
if (typeof value === "number") {
|
|
88
|
+
const valueStr = value.toString();
|
|
89
|
+
const dateOnlyMatch = /^(\d{4})[-/]?(\d{2})[-/]?(\d{2})$/.exec(valueStr);
|
|
90
|
+
if (dateOnlyMatch) {
|
|
91
|
+
value = valueStr;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
69
94
|
if (typeof value === "string") {
|
|
70
|
-
const
|
|
71
|
-
if (
|
|
72
|
-
|
|
73
|
-
return m.toISOString();
|
|
95
|
+
const dateInfo = this.parseDateString(value);
|
|
96
|
+
if (dateInfo) {
|
|
97
|
+
return this.formatDateTimeToISO(dateInfo);
|
|
74
98
|
}
|
|
75
99
|
}
|
|
76
100
|
if (import_dayjs.default.isDayjs(value)) {
|
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
import { DatetimeInterface } from './datetime-interface';
|
|
2
2
|
export declare class DatetimeNoTzInterface extends DatetimeInterface {
|
|
3
|
+
protected formatDateTimeToString(dateInfo: {
|
|
4
|
+
year: string;
|
|
5
|
+
month: string;
|
|
6
|
+
day: string;
|
|
7
|
+
hour?: string;
|
|
8
|
+
minute?: string;
|
|
9
|
+
second?: string;
|
|
10
|
+
}): string;
|
|
3
11
|
toValue(value: any, ctx?: any): Promise<any>;
|
|
4
12
|
toString(value: any, ctx?: any): any;
|
|
5
13
|
}
|
|
@@ -55,14 +55,21 @@ function isNumeric(str) {
|
|
|
55
55
|
}
|
|
56
56
|
__name(isNumeric, "isNumeric");
|
|
57
57
|
const _DatetimeNoTzInterface = class _DatetimeNoTzInterface extends import_datetime_interface.DatetimeInterface {
|
|
58
|
+
formatDateTimeToString(dateInfo) {
|
|
59
|
+
const { year, month, day, hour, minute, second } = dateInfo;
|
|
60
|
+
if (hour !== void 0 && minute !== void 0 && second !== void 0) {
|
|
61
|
+
return `${year}-${month}-${day} ${hour}:${minute}:${second}`;
|
|
62
|
+
}
|
|
63
|
+
return `${year}-${month}-${day}`;
|
|
64
|
+
}
|
|
58
65
|
async toValue(value, ctx = {}) {
|
|
59
66
|
if (!value) {
|
|
60
67
|
return null;
|
|
61
68
|
}
|
|
62
69
|
if (typeof value === "string") {
|
|
63
|
-
const
|
|
64
|
-
if (
|
|
65
|
-
return
|
|
70
|
+
const dateInfo = this.parseDateString(value);
|
|
71
|
+
if (dateInfo) {
|
|
72
|
+
return this.formatDateTimeToString(dateInfo);
|
|
66
73
|
}
|
|
67
74
|
}
|
|
68
75
|
if (import_dayjs.default.isDayjs(value)) {
|
|
@@ -38,7 +38,7 @@ const _ToManyInterface = class _ToManyInterface extends import_base_interface.Ba
|
|
|
38
38
|
}
|
|
39
39
|
str = `${str}`.trim();
|
|
40
40
|
const items = str.split(",");
|
|
41
|
-
const { filterKey, targetCollection, transaction } = ctx;
|
|
41
|
+
const { filterKey, targetCollection, transaction, field } = ctx;
|
|
42
42
|
const targetInstances = await targetCollection.repository.find({
|
|
43
43
|
filter: {
|
|
44
44
|
[filterKey]: items
|
|
@@ -51,7 +51,17 @@ const _ToManyInterface = class _ToManyInterface extends import_base_interface.Ba
|
|
|
51
51
|
}
|
|
52
52
|
});
|
|
53
53
|
const primaryKeyAttribute = targetCollection.model.primaryKeyAttribute;
|
|
54
|
-
|
|
54
|
+
const targetKey = field.options.targetKey;
|
|
55
|
+
const values = targetInstances.map((targetInstance) => {
|
|
56
|
+
const result = {
|
|
57
|
+
[targetKey]: targetInstance[targetKey]
|
|
58
|
+
};
|
|
59
|
+
if (targetKey !== primaryKeyAttribute) {
|
|
60
|
+
result[primaryKeyAttribute] = targetInstance[primaryKeyAttribute];
|
|
61
|
+
}
|
|
62
|
+
return result;
|
|
63
|
+
});
|
|
64
|
+
return values;
|
|
55
65
|
}
|
|
56
66
|
};
|
|
57
67
|
__name(_ToManyInterface, "ToManyInterface");
|
package/lib/operators/boolean.js
CHANGED
|
@@ -31,17 +31,30 @@ __export(boolean_exports, {
|
|
|
31
31
|
module.exports = __toCommonJS(boolean_exports);
|
|
32
32
|
var import_sequelize = require("sequelize");
|
|
33
33
|
var boolean_default = {
|
|
34
|
-
$isFalsy() {
|
|
34
|
+
$isFalsy(value) {
|
|
35
|
+
if (value === true || value === "true") {
|
|
36
|
+
return {
|
|
37
|
+
[import_sequelize.Op.or]: {
|
|
38
|
+
[import_sequelize.Op.is]: null,
|
|
39
|
+
[import_sequelize.Op.eq]: false
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
return {
|
|
44
|
+
[import_sequelize.Op.eq]: true
|
|
45
|
+
};
|
|
46
|
+
},
|
|
47
|
+
$isTruly(value) {
|
|
48
|
+
if (value === true || value === "true") {
|
|
49
|
+
return {
|
|
50
|
+
[import_sequelize.Op.eq]: true
|
|
51
|
+
};
|
|
52
|
+
}
|
|
35
53
|
return {
|
|
36
54
|
[import_sequelize.Op.or]: {
|
|
37
55
|
[import_sequelize.Op.is]: null,
|
|
38
56
|
[import_sequelize.Op.eq]: false
|
|
39
57
|
}
|
|
40
58
|
};
|
|
41
|
-
},
|
|
42
|
-
$isTruly() {
|
|
43
|
-
return {
|
|
44
|
-
[import_sequelize.Op.eq]: true
|
|
45
|
-
};
|
|
46
59
|
}
|
|
47
60
|
};
|
package/lib/operators/string.js
CHANGED
|
@@ -36,6 +36,46 @@ function escapeLike(value) {
|
|
|
36
36
|
return value.replace(/[_%]/g, "\\$&");
|
|
37
37
|
}
|
|
38
38
|
__name(escapeLike, "escapeLike");
|
|
39
|
+
const getFieldName = /* @__PURE__ */ __name((ctx) => {
|
|
40
|
+
const fullNameSplit = ctx.fullName.split(".");
|
|
41
|
+
const fieldName = ctx.fieldName;
|
|
42
|
+
let columnName = fieldName;
|
|
43
|
+
const associationPath = [];
|
|
44
|
+
if (fullNameSplit.length > 1) {
|
|
45
|
+
for (let i = 0; i < fullNameSplit.length - 1; i++) {
|
|
46
|
+
associationPath.push(fullNameSplit[i]);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
const getModelFromAssociationPath = /* @__PURE__ */ __name(() => {
|
|
50
|
+
let model2 = ctx.model;
|
|
51
|
+
for (const association of associationPath) {
|
|
52
|
+
model2 = model2.associations[association].target;
|
|
53
|
+
}
|
|
54
|
+
return model2;
|
|
55
|
+
}, "getModelFromAssociationPath");
|
|
56
|
+
const model = getModelFromAssociationPath();
|
|
57
|
+
let columnPrefix = model.name;
|
|
58
|
+
if (model.rawAttributes[fieldName]) {
|
|
59
|
+
columnName = model.rawAttributes[fieldName].field || fieldName;
|
|
60
|
+
}
|
|
61
|
+
if (associationPath.length > 0) {
|
|
62
|
+
const association = associationPath.join("->");
|
|
63
|
+
columnPrefix = association;
|
|
64
|
+
}
|
|
65
|
+
columnName = `${columnPrefix}.${columnName}`;
|
|
66
|
+
return columnName;
|
|
67
|
+
}, "getFieldName");
|
|
68
|
+
function getFieldExpression(value, ctx, operator) {
|
|
69
|
+
if ((0, import_utils.isPg)(ctx)) {
|
|
70
|
+
const fieldName = getFieldName(ctx);
|
|
71
|
+
const queryInterface = ctx.db.sequelize.getQueryInterface();
|
|
72
|
+
const quotedField = queryInterface.quoteIdentifiers(fieldName);
|
|
73
|
+
return import_sequelize.Sequelize.literal(`CAST(${quotedField} AS TEXT) ${operator} ${ctx.db.sequelize.escape(value)}`);
|
|
74
|
+
}
|
|
75
|
+
const op = operator === "LIKE" ? import_sequelize.Op.like : operator === "NOT LIKE" ? import_sequelize.Op.notLike : operator === "ILIKE" ? import_sequelize.Op.like : operator === "NOT ILIKE" ? import_sequelize.Op.notLike : import_sequelize.Op.like;
|
|
76
|
+
return { [op]: value };
|
|
77
|
+
}
|
|
78
|
+
__name(getFieldExpression, "getFieldExpression");
|
|
39
79
|
var string_default = {
|
|
40
80
|
$includes(value, ctx) {
|
|
41
81
|
if (value === null) {
|
|
@@ -44,16 +84,14 @@ var string_default = {
|
|
|
44
84
|
};
|
|
45
85
|
}
|
|
46
86
|
if (Array.isArray(value)) {
|
|
47
|
-
const conditions = value.map(
|
|
48
|
-
|
|
49
|
-
|
|
87
|
+
const conditions = value.map(
|
|
88
|
+
(item) => getFieldExpression(`%${escapeLike(item)}%`, ctx, (0, import_utils.isPg)(ctx) ? "ILIKE" : "LIKE")
|
|
89
|
+
);
|
|
50
90
|
return {
|
|
51
91
|
[import_sequelize.Op.or]: conditions
|
|
52
92
|
};
|
|
53
93
|
}
|
|
54
|
-
return {
|
|
55
|
-
[(0, import_utils.isPg)(ctx) ? import_sequelize.Op.iLike : import_sequelize.Op.like]: `%${escapeLike(value)}%`
|
|
56
|
-
};
|
|
94
|
+
return getFieldExpression(`%${escapeLike(value)}%`, ctx, (0, import_utils.isPg)(ctx) ? "ILIKE" : "LIKE");
|
|
57
95
|
},
|
|
58
96
|
$notIncludes(value, ctx) {
|
|
59
97
|
if (value === null) {
|
|
@@ -62,67 +100,57 @@ var string_default = {
|
|
|
62
100
|
};
|
|
63
101
|
}
|
|
64
102
|
if (Array.isArray(value)) {
|
|
65
|
-
const conditions = value.map(
|
|
66
|
-
|
|
67
|
-
|
|
103
|
+
const conditions = value.map(
|
|
104
|
+
(item) => getFieldExpression(`%${escapeLike(item)}%`, ctx, (0, import_utils.isPg)(ctx) ? "NOT ILIKE" : "NOT LIKE")
|
|
105
|
+
);
|
|
68
106
|
return {
|
|
69
107
|
[import_sequelize.Op.and]: conditions
|
|
70
108
|
};
|
|
71
109
|
}
|
|
72
|
-
return {
|
|
73
|
-
[(0, import_utils.isPg)(ctx) ? import_sequelize.Op.notILike : import_sequelize.Op.notLike]: `%${escapeLike(value)}%`
|
|
74
|
-
};
|
|
110
|
+
return getFieldExpression(`%${escapeLike(value)}%`, ctx, (0, import_utils.isPg)(ctx) ? "NOT ILIKE" : "NOT LIKE");
|
|
75
111
|
},
|
|
76
112
|
$startsWith(value, ctx) {
|
|
77
113
|
if (Array.isArray(value)) {
|
|
78
|
-
const conditions = value.map(
|
|
79
|
-
|
|
80
|
-
|
|
114
|
+
const conditions = value.map(
|
|
115
|
+
(item) => getFieldExpression(`${escapeLike(item)}%`, ctx, (0, import_utils.isPg)(ctx) ? "ILIKE" : "LIKE")
|
|
116
|
+
);
|
|
81
117
|
return {
|
|
82
118
|
[import_sequelize.Op.or]: conditions
|
|
83
119
|
};
|
|
84
120
|
}
|
|
85
|
-
return {
|
|
86
|
-
[(0, import_utils.isPg)(ctx) ? import_sequelize.Op.iLike : import_sequelize.Op.like]: `${escapeLike(value)}%`
|
|
87
|
-
};
|
|
121
|
+
return getFieldExpression(`${escapeLike(value)}%`, ctx, (0, import_utils.isPg)(ctx) ? "ILIKE" : "LIKE");
|
|
88
122
|
},
|
|
89
123
|
$notStartsWith(value, ctx) {
|
|
90
124
|
if (Array.isArray(value)) {
|
|
91
|
-
const conditions = value.map(
|
|
92
|
-
|
|
93
|
-
|
|
125
|
+
const conditions = value.map(
|
|
126
|
+
(item) => getFieldExpression(`${escapeLike(item)}%`, ctx, (0, import_utils.isPg)(ctx) ? "NOT ILIKE" : "NOT LIKE")
|
|
127
|
+
);
|
|
94
128
|
return {
|
|
95
129
|
[import_sequelize.Op.and]: conditions
|
|
96
130
|
};
|
|
97
131
|
}
|
|
98
|
-
return {
|
|
99
|
-
[(0, import_utils.isPg)(ctx) ? import_sequelize.Op.notILike : import_sequelize.Op.notLike]: `${escapeLike(value)}%`
|
|
100
|
-
};
|
|
132
|
+
return getFieldExpression(`${escapeLike(value)}%`, ctx, (0, import_utils.isPg)(ctx) ? "NOT ILIKE" : "NOT LIKE");
|
|
101
133
|
},
|
|
102
134
|
$endWith(value, ctx) {
|
|
103
135
|
if (Array.isArray(value)) {
|
|
104
|
-
const conditions = value.map(
|
|
105
|
-
|
|
106
|
-
|
|
136
|
+
const conditions = value.map(
|
|
137
|
+
(item) => getFieldExpression(`%${escapeLike(item)}`, ctx, (0, import_utils.isPg)(ctx) ? "ILIKE" : "LIKE")
|
|
138
|
+
);
|
|
107
139
|
return {
|
|
108
140
|
[import_sequelize.Op.or]: conditions
|
|
109
141
|
};
|
|
110
142
|
}
|
|
111
|
-
return {
|
|
112
|
-
[(0, import_utils.isPg)(ctx) ? import_sequelize.Op.iLike : import_sequelize.Op.like]: `%${escapeLike(value)}`
|
|
113
|
-
};
|
|
143
|
+
return getFieldExpression(`%${escapeLike(value)}`, ctx, (0, import_utils.isPg)(ctx) ? "ILIKE" : "LIKE");
|
|
114
144
|
},
|
|
115
145
|
$notEndWith(value, ctx) {
|
|
116
146
|
if (Array.isArray(value)) {
|
|
117
|
-
const conditions = value.map(
|
|
118
|
-
|
|
119
|
-
|
|
147
|
+
const conditions = value.map(
|
|
148
|
+
(item) => getFieldExpression(`%${escapeLike(item)}`, ctx, (0, import_utils.isPg)(ctx) ? "NOT ILIKE" : "NOT LIKE")
|
|
149
|
+
);
|
|
120
150
|
return {
|
|
121
151
|
[import_sequelize.Op.and]: conditions
|
|
122
152
|
};
|
|
123
153
|
}
|
|
124
|
-
return {
|
|
125
|
-
[(0, import_utils.isPg)(ctx) ? import_sequelize.Op.notILike : import_sequelize.Op.notLike]: `%${escapeLike(value)}`
|
|
126
|
-
};
|
|
154
|
+
return getFieldExpression(`%${escapeLike(value)}`, ctx, (0, import_utils.isPg)(ctx) ? "NOT ILIKE" : "NOT LIKE");
|
|
127
155
|
}
|
|
128
156
|
};
|
|
@@ -7,7 +7,8 @@
|
|
|
7
7
|
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
8
|
*/
|
|
9
9
|
import { AggregateOptions, DestroyOptions, FindOptions, TargetKey, TK } from '../repository';
|
|
10
|
-
import {
|
|
10
|
+
import { MultipleRelationRepository } from './multiple-relation-repository';
|
|
11
|
+
import { AssociatedOptions } from './types';
|
|
11
12
|
export declare class HasManyRepository extends MultipleRelationRepository {
|
|
12
13
|
find(options?: FindOptions): Promise<any>;
|
|
13
14
|
aggregate(options: AggregateOptions): Promise<any>;
|
|
@@ -6,24 +6,20 @@
|
|
|
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 { MultiAssociationAccessors, Transaction
|
|
10
|
-
import { CommonFindOptions, CountOptions, DestroyOptions, Filter, FindOneOptions, FindOptions, TargetKey, TK, UpdateOptions } from '../repository';
|
|
9
|
+
import { MultiAssociationAccessors, Transaction } from 'sequelize';
|
|
11
10
|
import { RelationRepository } from './relation-repository';
|
|
12
|
-
|
|
13
|
-
export interface AssociatedOptions extends Transactionable {
|
|
14
|
-
tk?: TK;
|
|
15
|
-
}
|
|
11
|
+
import { AssociatedOptions, CountOptions, DestroyOptions, Filter, FindOptions, TargetKey, UpdateOptions, FirstOrCreateOptions } from './types';
|
|
16
12
|
export declare abstract class MultipleRelationRepository extends RelationRepository {
|
|
17
13
|
targetRepositoryFilterOptionsBySourceValue(): Promise<any>;
|
|
18
14
|
find(options?: FindOptions): Promise<any>;
|
|
19
|
-
findAndCount(options?:
|
|
15
|
+
findAndCount(options?: FindOptions): Promise<[any[], number]>;
|
|
20
16
|
count(options?: CountOptions): Promise<number>;
|
|
21
|
-
findOne(options?:
|
|
17
|
+
findOne(options?: FindOptions): Promise<any>;
|
|
22
18
|
remove(options: TargetKey | TargetKey[] | AssociatedOptions): Promise<void>;
|
|
23
19
|
update(options?: UpdateOptions): Promise<any>;
|
|
24
|
-
destroy(options?:
|
|
20
|
+
destroy(options?: TargetKey | DestroyOptions): Promise<boolean>;
|
|
25
21
|
protected destroyByFilter(filter: Filter, transaction?: Transaction): Promise<boolean>;
|
|
26
22
|
protected filterHasInclude(filter: Filter, options?: any): boolean;
|
|
27
23
|
protected accessors(): MultiAssociationAccessors;
|
|
24
|
+
updateOrCreate(options: FirstOrCreateOptions): Promise<any>;
|
|
28
25
|
}
|
|
29
|
-
export {};
|
|
@@ -191,6 +191,10 @@ const _MultipleRelationRepository = class _MultipleRelationRepository extends im
|
|
|
191
191
|
accessors() {
|
|
192
192
|
return super.accessors();
|
|
193
193
|
}
|
|
194
|
+
async updateOrCreate(options) {
|
|
195
|
+
const result = await super.updateOrCreate(options);
|
|
196
|
+
return Array.isArray(result) ? result[0] : result;
|
|
197
|
+
}
|
|
194
198
|
};
|
|
195
199
|
__name(_MultipleRelationRepository, "MultipleRelationRepository");
|
|
196
200
|
__decorateClass([
|
|
@@ -205,6 +209,9 @@ __decorateClass([
|
|
|
205
209
|
(0, import_relation_repository.transaction)(),
|
|
206
210
|
import_target_collection_decorator.default
|
|
207
211
|
], _MultipleRelationRepository.prototype, "update", 1);
|
|
212
|
+
__decorateClass([
|
|
213
|
+
(0, import_relation_repository.transaction)()
|
|
214
|
+
], _MultipleRelationRepository.prototype, "updateOrCreate", 1);
|
|
208
215
|
let MultipleRelationRepository = _MultipleRelationRepository;
|
|
209
216
|
// Annotate the CommonJS export names for ESM import in node:
|
|
210
217
|
0 && (module.exports = {
|