@nocobase/database 1.7.0-beta.8 → 1.8.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/belongs-to-array/belongs-to-array-repository.d.ts +2 -2
- package/lib/belongs-to-array/belongs-to-array-repository.js +6 -7
- package/lib/cursor-builder.d.ts +38 -0
- package/lib/cursor-builder.js +307 -0
- package/lib/dialects/mariadb-dialect.d.ts +2 -0
- package/lib/dialects/mariadb-dialect.js +4 -0
- package/lib/eager-loading/eager-loading-tree.js +20 -10
- package/lib/fields/array-field.d.ts +1 -1
- package/lib/fields/array-field.js +12 -7
- package/lib/fields/date-field.js +14 -9
- package/lib/fields/datetime-no-tz-field.d.ts +1 -1
- package/lib/fields/datetime-no-tz-field.js +24 -18
- package/lib/fields/encryption-field/encryption-field.js +2 -0
- package/lib/fields/nanoid-field.js +12 -5
- package/lib/fields/set-field.d.ts +1 -1
- package/lib/fields/set-field.js +9 -4
- package/lib/fields/string-field.d.ts +4 -0
- package/lib/fields/string-field.js +18 -0
- package/lib/fields/text-field.d.ts +4 -0
- package/lib/fields/text-field.js +18 -0
- package/lib/fields/uuid-field.js +11 -4
- package/lib/index.d.ts +1 -0
- package/lib/index.js +3 -1
- package/lib/interfaces/index.d.ts +1 -0
- package/lib/interfaces/index.js +3 -1
- package/lib/interfaces/input-interface.d.ts +13 -0
- package/lib/interfaces/input-interface.js +64 -0
- package/lib/interfaces/time-interface.d.ts +13 -0
- package/lib/interfaces/time-interface.js +65 -0
- package/lib/interfaces/utils.js +4 -1
- package/lib/options-parser.d.ts +3 -1
- package/lib/options-parser.js +3 -2
- package/lib/query-interface/mysql-query-interface.d.ts +1 -0
- package/lib/query-interface/mysql-query-interface.js +3 -0
- package/lib/query-interface/postgres-query-interface.d.ts +1 -0
- package/lib/query-interface/postgres-query-interface.js +3 -0
- package/lib/query-interface/query-interface.d.ts +1 -0
- package/lib/query-interface/query-interface.js +4 -0
- package/lib/query-interface/sqlite-query-interface.d.ts +1 -0
- package/lib/query-interface/sqlite-query-interface.js +3 -0
- package/lib/relation-repository/hasmany-repository.js +7 -1
- package/lib/relation-repository/multiple-relation-repository.d.ts +4 -1
- package/lib/relation-repository/multiple-relation-repository.js +2 -2
- package/lib/repository.d.ts +21 -0
- package/lib/repository.js +30 -4
- package/lib/view-collection.js +1 -1
- package/package.json +6 -6
|
@@ -40,21 +40,28 @@ const _NanoidField = class _NanoidField extends import_field.Field {
|
|
|
40
40
|
}
|
|
41
41
|
init() {
|
|
42
42
|
const { name, size, customAlphabet: customAlphabetOptions, autoFill } = this.options;
|
|
43
|
-
this.listener = async (
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
const
|
|
47
|
-
|
|
43
|
+
this.listener = async (instances) => {
|
|
44
|
+
instances = Array.isArray(instances) ? instances : [instances];
|
|
45
|
+
for (const instance of instances) {
|
|
46
|
+
const value = instance.get(name);
|
|
47
|
+
if (!value && autoFill !== false) {
|
|
48
|
+
const nanoIdFunc = customAlphabetOptions ? (0, import_nanoid.customAlphabet)(customAlphabetOptions) : import_nanoid.nanoid;
|
|
49
|
+
instance.set(name, nanoIdFunc(size || DEFAULT_SIZE));
|
|
50
|
+
}
|
|
48
51
|
}
|
|
49
52
|
};
|
|
50
53
|
}
|
|
51
54
|
bind() {
|
|
52
55
|
super.bind();
|
|
53
56
|
this.on("beforeValidate", this.listener);
|
|
57
|
+
this.on("beforeBulkCreate", this.listener);
|
|
58
|
+
this.on("beforeCreate", this.listener);
|
|
54
59
|
}
|
|
55
60
|
unbind() {
|
|
56
61
|
super.unbind();
|
|
57
62
|
this.off("beforeValidate", this.listener);
|
|
63
|
+
this.off("beforeBulkCreate", this.listener);
|
|
64
|
+
this.off("beforeCreate", this.listener);
|
|
58
65
|
}
|
|
59
66
|
};
|
|
60
67
|
__name(_NanoidField, "NanoidField");
|
|
@@ -11,7 +11,7 @@ export interface SetFieldOptions extends Omit<ArrayFieldOptions, 'type'> {
|
|
|
11
11
|
type: 'set';
|
|
12
12
|
}
|
|
13
13
|
export declare class SetField extends ArrayField {
|
|
14
|
-
beforeSave: (
|
|
14
|
+
beforeSave: (instances: any) => void;
|
|
15
15
|
bind(): void;
|
|
16
16
|
unbind(): void;
|
|
17
17
|
}
|
package/lib/fields/set-field.js
CHANGED
|
@@ -32,19 +32,24 @@ __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 = /* @__PURE__ */ __name((
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
35
|
+
beforeSave = /* @__PURE__ */ __name((instances) => {
|
|
36
|
+
instances = Array.isArray(instances) ? instances : [instances];
|
|
37
|
+
for (const instance of instances) {
|
|
38
|
+
const oldValue = instance.get(this.options.name);
|
|
39
|
+
if (oldValue) {
|
|
40
|
+
instance.set(this.options.name, [...new Set(oldValue)]);
|
|
41
|
+
}
|
|
39
42
|
}
|
|
40
43
|
}, "beforeSave");
|
|
41
44
|
bind() {
|
|
42
45
|
super.bind();
|
|
43
46
|
this.on("beforeSave", this.beforeSave);
|
|
47
|
+
this.on("beforeBulkCreate", this.beforeSave);
|
|
44
48
|
}
|
|
45
49
|
unbind() {
|
|
46
50
|
super.unbind();
|
|
47
51
|
this.off("beforeSave", this.beforeSave);
|
|
52
|
+
this.off("beforeBulkCreate", this.beforeSave);
|
|
48
53
|
}
|
|
49
54
|
};
|
|
50
55
|
__name(_SetField, "SetField");
|
|
@@ -10,8 +10,12 @@ import { DataTypes } from 'sequelize';
|
|
|
10
10
|
import { BaseColumnFieldOptions, Field } from './field';
|
|
11
11
|
export declare class StringField extends Field {
|
|
12
12
|
get dataType(): DataTypes.StringDataTypeConstructor | DataTypes.StringDataType;
|
|
13
|
+
additionalSequelizeOptions(): {
|
|
14
|
+
set(value: any): void;
|
|
15
|
+
};
|
|
13
16
|
}
|
|
14
17
|
export interface StringFieldOptions extends BaseColumnFieldOptions {
|
|
15
18
|
type: 'string';
|
|
16
19
|
length?: number;
|
|
20
|
+
trim?: boolean;
|
|
17
21
|
}
|
|
@@ -39,6 +39,24 @@ const _StringField = class _StringField extends import_field.Field {
|
|
|
39
39
|
}
|
|
40
40
|
return import_sequelize.DataTypes.STRING;
|
|
41
41
|
}
|
|
42
|
+
additionalSequelizeOptions() {
|
|
43
|
+
const { name, trim, unique } = this.options;
|
|
44
|
+
return {
|
|
45
|
+
set(value) {
|
|
46
|
+
if (unique && value === "") {
|
|
47
|
+
value = null;
|
|
48
|
+
}
|
|
49
|
+
if (value == null) {
|
|
50
|
+
this.setDataValue(name, null);
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
if (typeof value !== "string") {
|
|
54
|
+
value = value.toString();
|
|
55
|
+
}
|
|
56
|
+
this.setDataValue(name, trim ? value.trim() : value);
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
}
|
|
42
60
|
};
|
|
43
61
|
__name(_StringField, "StringField");
|
|
44
62
|
let StringField = _StringField;
|
|
@@ -11,8 +11,12 @@ import { BaseColumnFieldOptions, Field } from './field';
|
|
|
11
11
|
export declare class TextField extends Field {
|
|
12
12
|
get dataType(): DataTypes.TextDataTypeConstructor | DataTypes.TextDataType;
|
|
13
13
|
init(): void;
|
|
14
|
+
additionalSequelizeOptions(): {
|
|
15
|
+
set(value: any): void;
|
|
16
|
+
};
|
|
14
17
|
}
|
|
15
18
|
export interface TextFieldOptions extends BaseColumnFieldOptions {
|
|
16
19
|
type: 'text';
|
|
17
20
|
length?: 'tiny' | 'medium' | 'long';
|
|
21
|
+
trim?: boolean;
|
|
18
22
|
}
|
package/lib/fields/text-field.js
CHANGED
|
@@ -44,6 +44,24 @@ const _TextField = class _TextField extends import_field.Field {
|
|
|
44
44
|
this.options.defaultValue = null;
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
|
+
additionalSequelizeOptions() {
|
|
48
|
+
const { name, trim, unique } = this.options;
|
|
49
|
+
return {
|
|
50
|
+
set(value) {
|
|
51
|
+
if (unique && value === "") {
|
|
52
|
+
value = null;
|
|
53
|
+
}
|
|
54
|
+
if (value == null) {
|
|
55
|
+
this.setDataValue(name, null);
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
if (typeof value !== "string") {
|
|
59
|
+
value = value.toString();
|
|
60
|
+
}
|
|
61
|
+
this.setDataValue(name, trim ? value.trim() : value);
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
}
|
|
47
65
|
};
|
|
48
66
|
__name(_TextField, "TextField");
|
|
49
67
|
let TextField = _TextField;
|
package/lib/fields/uuid-field.js
CHANGED
|
@@ -39,20 +39,27 @@ const _UuidField = class _UuidField extends import_field.Field {
|
|
|
39
39
|
}
|
|
40
40
|
init() {
|
|
41
41
|
const { name, autoFill } = this.options;
|
|
42
|
-
this.listener = async (
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
instance.
|
|
42
|
+
this.listener = async (instances) => {
|
|
43
|
+
instances = Array.isArray(instances) ? instances : [instances];
|
|
44
|
+
for (const instance of instances) {
|
|
45
|
+
const value = instance.get(name);
|
|
46
|
+
if (!value && autoFill !== false) {
|
|
47
|
+
instance.set(name, (0, import_uuid.v4)());
|
|
48
|
+
}
|
|
46
49
|
}
|
|
47
50
|
};
|
|
48
51
|
}
|
|
49
52
|
bind() {
|
|
50
53
|
super.bind();
|
|
51
54
|
this.on("beforeValidate", this.listener);
|
|
55
|
+
this.on("beforeBulkCreate", this.listener);
|
|
56
|
+
this.on("beforeCreate", this.listener);
|
|
52
57
|
}
|
|
53
58
|
unbind() {
|
|
54
59
|
super.unbind();
|
|
55
60
|
this.off("beforeValidate", this.listener);
|
|
61
|
+
this.off("beforeBulkCreate", this.listener);
|
|
62
|
+
this.off("beforeCreate", this.listener);
|
|
56
63
|
}
|
|
57
64
|
};
|
|
58
65
|
__name(_UuidField, "UuidField");
|
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -94,6 +94,7 @@ __reExport(src_exports, require("./value-parsers"), module.exports);
|
|
|
94
94
|
__reExport(src_exports, require("./view-collection"), module.exports);
|
|
95
95
|
var import_field_type_map = __toESM(require("./view/field-type-map"));
|
|
96
96
|
__reExport(src_exports, require("./view/view-inference"), module.exports);
|
|
97
|
+
__reExport(src_exports, require("./update-guard"), module.exports);
|
|
97
98
|
// Annotate the CommonJS export names for ESM import in node:
|
|
98
99
|
0 && (module.exports = {
|
|
99
100
|
BaseError,
|
|
@@ -143,5 +144,6 @@ __reExport(src_exports, require("./view/view-inference"), module.exports);
|
|
|
143
144
|
...require("./update-associations"),
|
|
144
145
|
...require("./value-parsers"),
|
|
145
146
|
...require("./view-collection"),
|
|
146
|
-
...require("./view/view-inference")
|
|
147
|
+
...require("./view/view-inference"),
|
|
148
|
+
...require("./update-guard")
|
|
147
149
|
});
|
package/lib/interfaces/index.js
CHANGED
|
@@ -31,6 +31,7 @@ __reExport(interfaces_exports, require("./datetime-interface"), module.exports);
|
|
|
31
31
|
__reExport(interfaces_exports, require("./datetime-no-tz-interface"), module.exports);
|
|
32
32
|
__reExport(interfaces_exports, require("./boolean-interface"), module.exports);
|
|
33
33
|
__reExport(interfaces_exports, require("./date-interface"), module.exports);
|
|
34
|
+
__reExport(interfaces_exports, require("./time-interface"), module.exports);
|
|
34
35
|
// Annotate the CommonJS export names for ESM import in node:
|
|
35
36
|
0 && (module.exports = {
|
|
36
37
|
...require("./base-interface"),
|
|
@@ -40,5 +41,6 @@ __reExport(interfaces_exports, require("./date-interface"), module.exports);
|
|
|
40
41
|
...require("./datetime-interface"),
|
|
41
42
|
...require("./datetime-no-tz-interface"),
|
|
42
43
|
...require("./boolean-interface"),
|
|
43
|
-
...require("./date-interface")
|
|
44
|
+
...require("./date-interface"),
|
|
45
|
+
...require("./time-interface")
|
|
44
46
|
});
|
|
@@ -0,0 +1,13 @@
|
|
|
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
|
+
import { BaseInterface } from './base-interface';
|
|
10
|
+
export declare class InputInterface extends BaseInterface {
|
|
11
|
+
toValue(value: any): any;
|
|
12
|
+
validate(value: any): boolean;
|
|
13
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
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 __create = Object.create;
|
|
11
|
+
var __defProp = Object.defineProperty;
|
|
12
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
13
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
14
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
15
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
16
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
17
|
+
var __export = (target, all) => {
|
|
18
|
+
for (var name in all)
|
|
19
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
20
|
+
};
|
|
21
|
+
var __copyProps = (to, from, except, desc) => {
|
|
22
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
23
|
+
for (let key of __getOwnPropNames(from))
|
|
24
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
25
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
26
|
+
}
|
|
27
|
+
return to;
|
|
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
|
+
));
|
|
37
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
38
|
+
var input_interface_exports = {};
|
|
39
|
+
__export(input_interface_exports, {
|
|
40
|
+
InputInterface: () => InputInterface
|
|
41
|
+
});
|
|
42
|
+
module.exports = __toCommonJS(input_interface_exports);
|
|
43
|
+
var import_lodash = __toESM(require("lodash"));
|
|
44
|
+
var import_base_interface = require("./base-interface");
|
|
45
|
+
const _InputInterface = class _InputInterface extends import_base_interface.BaseInterface {
|
|
46
|
+
toValue(value) {
|
|
47
|
+
if (value === null || value === void 0 || typeof value === "string") {
|
|
48
|
+
return value;
|
|
49
|
+
}
|
|
50
|
+
if (this.validate(value)) {
|
|
51
|
+
return value.toString();
|
|
52
|
+
}
|
|
53
|
+
throw new Error("Invalid value, expected string");
|
|
54
|
+
}
|
|
55
|
+
validate(value) {
|
|
56
|
+
return import_lodash.default.isString(value) || import_lodash.default.isNumber(value);
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
__name(_InputInterface, "InputInterface");
|
|
60
|
+
let InputInterface = _InputInterface;
|
|
61
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
62
|
+
0 && (module.exports = {
|
|
63
|
+
InputInterface
|
|
64
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
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
|
+
import { BaseInterface } from './base-interface';
|
|
10
|
+
export declare class TimeInterface extends BaseInterface {
|
|
11
|
+
toValue(value: any, ctx?: any): any;
|
|
12
|
+
validate(value: any): boolean;
|
|
13
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
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 __create = Object.create;
|
|
11
|
+
var __defProp = Object.defineProperty;
|
|
12
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
13
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
14
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
15
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
16
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
17
|
+
var __export = (target, all) => {
|
|
18
|
+
for (var name in all)
|
|
19
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
20
|
+
};
|
|
21
|
+
var __copyProps = (to, from, except, desc) => {
|
|
22
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
23
|
+
for (let key of __getOwnPropNames(from))
|
|
24
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
25
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
26
|
+
}
|
|
27
|
+
return to;
|
|
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
|
+
));
|
|
37
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
38
|
+
var time_interface_exports = {};
|
|
39
|
+
__export(time_interface_exports, {
|
|
40
|
+
TimeInterface: () => TimeInterface
|
|
41
|
+
});
|
|
42
|
+
module.exports = __toCommonJS(time_interface_exports);
|
|
43
|
+
var import_dayjs = __toESM(require("dayjs"));
|
|
44
|
+
var import_utc = __toESM(require("dayjs/plugin/utc"));
|
|
45
|
+
var import_base_interface = require("./base-interface");
|
|
46
|
+
import_dayjs.default.extend(import_utc.default);
|
|
47
|
+
const _TimeInterface = class _TimeInterface extends import_base_interface.BaseInterface {
|
|
48
|
+
toValue(value, ctx) {
|
|
49
|
+
if (this.validate(value)) {
|
|
50
|
+
const result = import_dayjs.default.utc(value).format("HH:mm:ss");
|
|
51
|
+
return result;
|
|
52
|
+
}
|
|
53
|
+
return value;
|
|
54
|
+
}
|
|
55
|
+
validate(value) {
|
|
56
|
+
const result = (0, import_dayjs.default)(value).isValid();
|
|
57
|
+
return result;
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
__name(_TimeInterface, "TimeInterface");
|
|
61
|
+
let TimeInterface = _TimeInterface;
|
|
62
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
63
|
+
0 && (module.exports = {
|
|
64
|
+
TimeInterface
|
|
65
|
+
});
|
package/lib/interfaces/utils.js
CHANGED
|
@@ -39,6 +39,7 @@ var import_one_to_many_interface = require("./one-to-many-interface");
|
|
|
39
39
|
var import_integer_interface = require("./integer-interface");
|
|
40
40
|
var import_number_interface = require("./number-interface");
|
|
41
41
|
var import_json_interface = require("./json-interface");
|
|
42
|
+
var import_input_interface = require("./input-interface");
|
|
42
43
|
const interfaces = {
|
|
43
44
|
integer: import_integer_interface.IntegerInterface,
|
|
44
45
|
number: import_number_interface.NumberInterface,
|
|
@@ -62,7 +63,9 @@ const interfaces = {
|
|
|
62
63
|
obo: import_one_belongs_to_one_interface.OneBelongsToOneInterface,
|
|
63
64
|
o2m: import_one_to_many_interface.OneToManyInterface,
|
|
64
65
|
m2o: import_many_to_one_interface.ManyToOneInterface,
|
|
65
|
-
m2m: import_many_to_many_interface.ManyToManyInterface
|
|
66
|
+
m2m: import_many_to_many_interface.ManyToManyInterface,
|
|
67
|
+
time: import_index.TimeInterface,
|
|
68
|
+
input: import_input_interface.InputInterface
|
|
66
69
|
};
|
|
67
70
|
function registerInterfaces(db) {
|
|
68
71
|
for (const [interfaceName, type] of Object.entries(interfaces)) {
|
package/lib/options-parser.d.ts
CHANGED
|
@@ -27,7 +27,9 @@ export declare class OptionsParser {
|
|
|
27
27
|
isAssociation(key: string): boolean;
|
|
28
28
|
isAssociationPath(path: string): boolean;
|
|
29
29
|
filterByTkToWhereOption(): {};
|
|
30
|
-
toSequelizeParams(
|
|
30
|
+
toSequelizeParams(options?: {
|
|
31
|
+
parseSort?: boolean;
|
|
32
|
+
}): any;
|
|
31
33
|
/**
|
|
32
34
|
* parser sort options
|
|
33
35
|
* @param filterParams
|
package/lib/options-parser.js
CHANGED
|
@@ -111,7 +111,7 @@ const _OptionsParser = class _OptionsParser {
|
|
|
111
111
|
[filterTargetKey]: filterByTkOption
|
|
112
112
|
};
|
|
113
113
|
}
|
|
114
|
-
toSequelizeParams() {
|
|
114
|
+
toSequelizeParams(options = { parseSort: true }) {
|
|
115
115
|
var _a, _b;
|
|
116
116
|
const queryParams = this.filterParser.toSequelizeParams();
|
|
117
117
|
if ((_a = this.options) == null ? void 0 : _a.filterByTk) {
|
|
@@ -126,7 +126,8 @@ const _OptionsParser = class _OptionsParser {
|
|
|
126
126
|
}
|
|
127
127
|
queryParams.include.push(...import_lodash.default.castArray(this.options.include));
|
|
128
128
|
}
|
|
129
|
-
|
|
129
|
+
const fields = this.parseFields(queryParams);
|
|
130
|
+
return options.parseSort ? this.parseSort(fields) : fields;
|
|
130
131
|
}
|
|
131
132
|
/**
|
|
132
133
|
* parser sort options
|
|
@@ -129,6 +129,9 @@ const _MysqlQueryInterface = class _MysqlQueryInterface extends import_query_int
|
|
|
129
129
|
await this.db.sequelize.query(sql, { transaction });
|
|
130
130
|
}
|
|
131
131
|
}
|
|
132
|
+
generateJoinOnForJSONArray(left, right) {
|
|
133
|
+
return this.db.sequelize.literal(`JSON_CONTAINS(${right}, JSON_ARRAY(${left}))`);
|
|
134
|
+
}
|
|
132
135
|
};
|
|
133
136
|
__name(_MysqlQueryInterface, "MysqlQueryInterface");
|
|
134
137
|
let MysqlQueryInterface = _MysqlQueryInterface;
|
|
@@ -202,6 +202,9 @@ $BODY$
|
|
|
202
202
|
);
|
|
203
203
|
return res[0]["show_create_table"];
|
|
204
204
|
}
|
|
205
|
+
generateJoinOnForJSONArray(left, right) {
|
|
206
|
+
return this.db.sequelize.literal(`${left}=any(${right})`);
|
|
207
|
+
}
|
|
205
208
|
};
|
|
206
209
|
__name(_PostgresQueryInterface, "PostgresQueryInterface");
|
|
207
210
|
let PostgresQueryInterface = _PostgresQueryInterface;
|
|
@@ -57,6 +57,10 @@ const _QueryInterface = class _QueryInterface {
|
|
|
57
57
|
quoteIdentifier(identifier) {
|
|
58
58
|
return this.db.sequelize.getQueryInterface().queryGenerator.quoteIdentifier(identifier);
|
|
59
59
|
}
|
|
60
|
+
generateJoinOnForJSONArray(left, right) {
|
|
61
|
+
const dialect = this.db.sequelize.getDialect();
|
|
62
|
+
throw new Error(`Filtering by many to many (array) associations is not supported on ${dialect}`);
|
|
63
|
+
}
|
|
60
64
|
};
|
|
61
65
|
__name(_QueryInterface, "QueryInterface");
|
|
62
66
|
let QueryInterface = _QueryInterface;
|
|
@@ -136,6 +136,9 @@ const _SqliteQueryInterface = class _SqliteQueryInterface extends import_query_i
|
|
|
136
136
|
WHERE name = '${tableName}';`;
|
|
137
137
|
await this.db.sequelize.query(sql, { transaction });
|
|
138
138
|
}
|
|
139
|
+
generateJoinOnForJSONArray(left, right) {
|
|
140
|
+
return this.db.sequelize.literal(`${left} in (SELECT value from json_each(${right}))`);
|
|
141
|
+
}
|
|
139
142
|
};
|
|
140
143
|
__name(_SqliteQueryInterface, "SqliteQueryInterface");
|
|
141
144
|
let SqliteQueryInterface = _SqliteQueryInterface;
|
|
@@ -80,7 +80,13 @@ const _HasManyRepository = class _HasManyRepository extends import_multiple_rela
|
|
|
80
80
|
if (options && options["filter"]) {
|
|
81
81
|
const filterResult = this.parseFilter(options["filter"], options);
|
|
82
82
|
if (filterResult.include && filterResult.include.length > 0) {
|
|
83
|
-
return await this.destroyByFilter(
|
|
83
|
+
return await this.destroyByFilter(
|
|
84
|
+
{
|
|
85
|
+
filter: options["filter"],
|
|
86
|
+
filterByTk: options["filterByTk"]
|
|
87
|
+
},
|
|
88
|
+
transaction2
|
|
89
|
+
);
|
|
84
90
|
}
|
|
85
91
|
where.push(filterResult.where);
|
|
86
92
|
}
|
|
@@ -18,7 +18,10 @@ export declare abstract class MultipleRelationRepository extends RelationReposit
|
|
|
18
18
|
remove(options: TargetKey | TargetKey[] | AssociatedOptions): Promise<void>;
|
|
19
19
|
update(options?: UpdateOptions): Promise<any>;
|
|
20
20
|
destroy(options?: TargetKey | DestroyOptions): Promise<boolean>;
|
|
21
|
-
protected destroyByFilter(
|
|
21
|
+
protected destroyByFilter(options: {
|
|
22
|
+
filter?: Filter;
|
|
23
|
+
filterByTk?: TargetKey | TargetKey[];
|
|
24
|
+
}, transaction?: Transaction): Promise<boolean>;
|
|
22
25
|
protected filterHasInclude(filter: Filter, options?: any): boolean;
|
|
23
26
|
protected accessors(): MultiAssociationAccessors;
|
|
24
27
|
updateOrCreate(options: FirstOrCreateOptions): Promise<any>;
|
|
@@ -174,9 +174,9 @@ const _MultipleRelationRepository = class _MultipleRelationRepository extends im
|
|
|
174
174
|
async destroy(options) {
|
|
175
175
|
return false;
|
|
176
176
|
}
|
|
177
|
-
async destroyByFilter(
|
|
177
|
+
async destroyByFilter(options, transaction2) {
|
|
178
178
|
const instances = await this.find({
|
|
179
|
-
|
|
179
|
+
...options,
|
|
180
180
|
transaction: transaction2
|
|
181
181
|
});
|
|
182
182
|
return await this.destroy({
|
package/lib/repository.d.ts
CHANGED
|
@@ -20,6 +20,7 @@ import { HasManyRepository } from './relation-repository/hasmany-repository';
|
|
|
20
20
|
import { HasOneRepository } from './relation-repository/hasone-repository';
|
|
21
21
|
import { RelationRepository } from './relation-repository/relation-repository';
|
|
22
22
|
import { valuesToFilter } from './utils/filter-utils';
|
|
23
|
+
import { SmartCursorBuilder } from './cursor-builder';
|
|
23
24
|
interface CreateManyOptions extends BulkCreateOptions {
|
|
24
25
|
records: Values[];
|
|
25
26
|
}
|
|
@@ -145,6 +146,7 @@ export declare class Repository<TModelAttributes extends {} = any, TCreationAttr
|
|
|
145
146
|
database: Database;
|
|
146
147
|
collection: Collection;
|
|
147
148
|
model: ModelStatic<Model>;
|
|
149
|
+
cursorBuilder: SmartCursorBuilder;
|
|
148
150
|
constructor(collection: Collection);
|
|
149
151
|
static valuesToFilter: typeof valuesToFilter;
|
|
150
152
|
/**
|
|
@@ -157,6 +159,25 @@ export declare class Repository<TModelAttributes extends {} = any, TCreationAttr
|
|
|
157
159
|
chunk(options: FindOptions & {
|
|
158
160
|
chunkSize: number;
|
|
159
161
|
callback: (rows: Model[], options: FindOptions) => Promise<void>;
|
|
162
|
+
beforeFind?: (options: FindOptions) => Promise<void>;
|
|
163
|
+
afterFind?: (rows: Model[], options: FindOptions & {
|
|
164
|
+
offset: number;
|
|
165
|
+
}) => Promise<void>;
|
|
166
|
+
}): Promise<void>;
|
|
167
|
+
/**
|
|
168
|
+
* Cursor-based pagination query function.
|
|
169
|
+
* Ideal for large datasets (e.g., millions of rows)
|
|
170
|
+
* Note:
|
|
171
|
+
* 1. does not support jumping to arbitrary pages (e.g., "Page 5")
|
|
172
|
+
* 2. Requires a stable, indexed sort field (e.g. ID, createdAt)
|
|
173
|
+
* 3. If custom orderBy is used, it must match the cursor field(s) and direction, otherwise results may be incorrect or unstable.
|
|
174
|
+
* @param options
|
|
175
|
+
*/
|
|
176
|
+
chunkWithCursor(options: FindOptions & {
|
|
177
|
+
chunkSize: number;
|
|
178
|
+
callback: (rows: Model[], options: FindOptions) => Promise<void>;
|
|
179
|
+
beforeFind?: (options: FindOptions) => Promise<void>;
|
|
180
|
+
afterFind?: (rows: Model[], options: FindOptions) => Promise<void>;
|
|
160
181
|
}): Promise<void>;
|
|
161
182
|
/**
|
|
162
183
|
* find
|