@nocobase/database 1.4.0-alpha.20241105230315 → 1.4.0-alpha.3
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 +1 -1
- package/lib/collection.js +0 -3
- package/lib/interfaces/boolean-interface.js +5 -1
- package/lib/interfaces/date-interface.d.ts +4 -0
- package/lib/interfaces/date-interface.js +44 -0
- package/lib/interfaces/datetime-interface.js +1 -6
- package/lib/interfaces/datetime-no-tz-interface.d.ts +5 -0
- package/lib/interfaces/datetime-no-tz-interface.js +93 -0
- package/lib/interfaces/index.d.ts +2 -0
- package/lib/interfaces/index.js +5 -1
- package/lib/interfaces/multiple-select-interface.js +7 -1
- package/lib/interfaces/select-interface.js +7 -1
- package/lib/interfaces/to-one-interface.js +3 -3
- package/lib/interfaces/utils.js +3 -0
- package/lib/options-parser.js +4 -1
- package/package.json +4 -4
package/lib/collection.d.ts
CHANGED
|
@@ -138,7 +138,7 @@ export declare class Collection<TModelAttributes extends {} = any, TCreationAttr
|
|
|
138
138
|
quotedTableName(): any;
|
|
139
139
|
collectionSchema(): string;
|
|
140
140
|
isView(): boolean;
|
|
141
|
-
unavailableActions():
|
|
141
|
+
unavailableActions(): any[];
|
|
142
142
|
protected sequelizeModelOptions(): {
|
|
143
143
|
modelName: string;
|
|
144
144
|
sequelize: import("sequelize").Sequelize;
|
package/lib/collection.js
CHANGED
|
@@ -684,9 +684,6 @@ const _Collection = class _Collection extends import_events.EventEmitter {
|
|
|
684
684
|
return false;
|
|
685
685
|
}
|
|
686
686
|
unavailableActions() {
|
|
687
|
-
if (this.options.template === "file") {
|
|
688
|
-
return ["create", "update", "destroy"];
|
|
689
|
-
}
|
|
690
687
|
return [];
|
|
691
688
|
}
|
|
692
689
|
sequelizeModelOptions() {
|
|
@@ -58,7 +58,11 @@ const _BooleanInterface = class _BooleanInterface extends import_base_interface.
|
|
|
58
58
|
const option = enumConfig.find((item) => item.value === value);
|
|
59
59
|
return option == null ? void 0 : option.label;
|
|
60
60
|
} else {
|
|
61
|
-
|
|
61
|
+
const label = value ? "True" : value === null || value === void 0 ? "" : "False";
|
|
62
|
+
if (ctx == null ? void 0 : ctx.t) {
|
|
63
|
+
return ctx.t(label, { ns: "action-export" });
|
|
64
|
+
}
|
|
65
|
+
return label;
|
|
62
66
|
}
|
|
63
67
|
}
|
|
64
68
|
};
|
|
@@ -0,0 +1,44 @@
|
|
|
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 __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
15
|
+
var __export = (target, all) => {
|
|
16
|
+
for (var name in all)
|
|
17
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
18
|
+
};
|
|
19
|
+
var __copyProps = (to, from, except, desc) => {
|
|
20
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
21
|
+
for (let key of __getOwnPropNames(from))
|
|
22
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
23
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
24
|
+
}
|
|
25
|
+
return to;
|
|
26
|
+
};
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
var date_interface_exports = {};
|
|
29
|
+
__export(date_interface_exports, {
|
|
30
|
+
DateInterface: () => DateInterface
|
|
31
|
+
});
|
|
32
|
+
module.exports = __toCommonJS(date_interface_exports);
|
|
33
|
+
var import_datetime_interface = require("./datetime-interface");
|
|
34
|
+
const _DateInterface = class _DateInterface extends import_datetime_interface.DatetimeInterface {
|
|
35
|
+
toString(value, ctx) {
|
|
36
|
+
return value;
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
__name(_DateInterface, "DateInterface");
|
|
40
|
+
let DateInterface = _DateInterface;
|
|
41
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
42
|
+
0 && (module.exports = {
|
|
43
|
+
DateInterface
|
|
44
|
+
});
|
|
@@ -63,7 +63,6 @@ function resolveTimeZoneFromCtx(ctx) {
|
|
|
63
63
|
__name(resolveTimeZoneFromCtx, "resolveTimeZoneFromCtx");
|
|
64
64
|
const _DatetimeInterface = class _DatetimeInterface extends import_base_interface.BaseInterface {
|
|
65
65
|
async toValue(value, ctx = {}) {
|
|
66
|
-
var _a, _b, _c;
|
|
67
66
|
if (!value) {
|
|
68
67
|
return null;
|
|
69
68
|
}
|
|
@@ -81,11 +80,7 @@ const _DatetimeInterface = class _DatetimeInterface extends import_base_interfac
|
|
|
81
80
|
} else if (isNumeric(value)) {
|
|
82
81
|
return (0, import_excel_date_to_js.getJsDateFromExcel)(value).toISOString();
|
|
83
82
|
} else if (typeof value === "string") {
|
|
84
|
-
|
|
85
|
-
const m = (0, import_dayjs.default)(value);
|
|
86
|
-
if (m.isValid()) {
|
|
87
|
-
return (0, import_utils.moment2str)(m, props);
|
|
88
|
-
}
|
|
83
|
+
return value;
|
|
89
84
|
}
|
|
90
85
|
throw new Error(`Invalid date - ${value}`);
|
|
91
86
|
}
|
|
@@ -0,0 +1,93 @@
|
|
|
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 datetime_no_tz_interface_exports = {};
|
|
39
|
+
__export(datetime_no_tz_interface_exports, {
|
|
40
|
+
DatetimeNoTzInterface: () => DatetimeNoTzInterface
|
|
41
|
+
});
|
|
42
|
+
module.exports = __toCommonJS(datetime_no_tz_interface_exports);
|
|
43
|
+
var import_datetime_interface = require("./datetime-interface");
|
|
44
|
+
var import_dayjs = __toESM(require("dayjs"));
|
|
45
|
+
var import_excel_date_to_js = require("excel-date-to-js");
|
|
46
|
+
var import_utils = require("@nocobase/utils");
|
|
47
|
+
function isDate(v) {
|
|
48
|
+
return v instanceof Date;
|
|
49
|
+
}
|
|
50
|
+
__name(isDate, "isDate");
|
|
51
|
+
function isNumeric(str) {
|
|
52
|
+
if (typeof str === "number") return true;
|
|
53
|
+
if (typeof str != "string") return false;
|
|
54
|
+
return !isNaN(str) && !isNaN(parseFloat(str));
|
|
55
|
+
}
|
|
56
|
+
__name(isNumeric, "isNumeric");
|
|
57
|
+
const _DatetimeNoTzInterface = class _DatetimeNoTzInterface extends import_datetime_interface.DatetimeInterface {
|
|
58
|
+
async toValue(value, ctx = {}) {
|
|
59
|
+
if (!value) {
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
if (typeof value === "string") {
|
|
63
|
+
const match = /^(\d{4})[-/]?(\d{2})[-/]?(\d{2})$/.exec(value);
|
|
64
|
+
if (match) {
|
|
65
|
+
return `${match[1]}-${match[2]}-${match[3]}`;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
if (import_dayjs.default.isDayjs(value)) {
|
|
69
|
+
return value;
|
|
70
|
+
} else if (isDate(value)) {
|
|
71
|
+
return value;
|
|
72
|
+
} else if (isNumeric(value)) {
|
|
73
|
+
const date = (0, import_excel_date_to_js.getJsDateFromExcel)(value);
|
|
74
|
+
return `${date.getFullYear()}-${date.getMonth() + 1}-${date.getDate()}`;
|
|
75
|
+
} else if (typeof value === "string") {
|
|
76
|
+
return value;
|
|
77
|
+
}
|
|
78
|
+
throw new Error(`Invalid date - ${value}`);
|
|
79
|
+
}
|
|
80
|
+
toString(value, ctx) {
|
|
81
|
+
var _a, _b;
|
|
82
|
+
const props = ((_b = (_a = this.options) == null ? void 0 : _a.uiSchema) == null ? void 0 : _b["x-component-props"]) ?? {};
|
|
83
|
+
const format = (0, import_utils.getDefaultFormat)(props);
|
|
84
|
+
const m = (0, import_utils.str2moment)(value, { ...props });
|
|
85
|
+
return m ? m.format(format) : "";
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
__name(_DatetimeNoTzInterface, "DatetimeNoTzInterface");
|
|
89
|
+
let DatetimeNoTzInterface = _DatetimeNoTzInterface;
|
|
90
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
91
|
+
0 && (module.exports = {
|
|
92
|
+
DatetimeNoTzInterface
|
|
93
|
+
});
|
|
@@ -11,4 +11,6 @@ export * from './percent-interface';
|
|
|
11
11
|
export * from './multiple-select-interface';
|
|
12
12
|
export * from './select-interface';
|
|
13
13
|
export * from './datetime-interface';
|
|
14
|
+
export * from './datetime-no-tz-interface';
|
|
14
15
|
export * from './boolean-interface';
|
|
16
|
+
export * from './date-interface';
|
package/lib/interfaces/index.js
CHANGED
|
@@ -28,7 +28,9 @@ __reExport(interfaces_exports, require("./percent-interface"), module.exports);
|
|
|
28
28
|
__reExport(interfaces_exports, require("./multiple-select-interface"), module.exports);
|
|
29
29
|
__reExport(interfaces_exports, require("./select-interface"), module.exports);
|
|
30
30
|
__reExport(interfaces_exports, require("./datetime-interface"), module.exports);
|
|
31
|
+
__reExport(interfaces_exports, require("./datetime-no-tz-interface"), module.exports);
|
|
31
32
|
__reExport(interfaces_exports, require("./boolean-interface"), module.exports);
|
|
33
|
+
__reExport(interfaces_exports, require("./date-interface"), module.exports);
|
|
32
34
|
// Annotate the CommonJS export names for ESM import in node:
|
|
33
35
|
0 && (module.exports = {
|
|
34
36
|
...require("./base-interface"),
|
|
@@ -36,5 +38,7 @@ __reExport(interfaces_exports, require("./boolean-interface"), module.exports);
|
|
|
36
38
|
...require("./multiple-select-interface"),
|
|
37
39
|
...require("./select-interface"),
|
|
38
40
|
...require("./datetime-interface"),
|
|
39
|
-
...require("./
|
|
41
|
+
...require("./datetime-no-tz-interface"),
|
|
42
|
+
...require("./boolean-interface"),
|
|
43
|
+
...require("./date-interface")
|
|
40
44
|
});
|
|
@@ -64,7 +64,13 @@ const _MultipleSelectInterface = class _MultipleSelectInterface extends import_b
|
|
|
64
64
|
const enumConfig = ((_a = this.options.uiSchema) == null ? void 0 : _a.enum) || [];
|
|
65
65
|
return import_lodash.default.castArray(value).map((value2) => {
|
|
66
66
|
const option = enumConfig.find((item) => item.value === value2);
|
|
67
|
-
|
|
67
|
+
if (option) {
|
|
68
|
+
if (ctx == null ? void 0 : ctx.t) {
|
|
69
|
+
return ctx.t(option.label, { ns: "lm-collections" });
|
|
70
|
+
}
|
|
71
|
+
return option.label;
|
|
72
|
+
}
|
|
73
|
+
return value2;
|
|
68
74
|
}).join(",");
|
|
69
75
|
}
|
|
70
76
|
};
|
|
@@ -52,7 +52,13 @@ const _SelectInterface = class _SelectInterface extends import_base_interface.Ba
|
|
|
52
52
|
var _a;
|
|
53
53
|
const enumConfig = ((_a = this.options.uiSchema) == null ? void 0 : _a.enum) || [];
|
|
54
54
|
const option = enumConfig.find((item) => item.value === value);
|
|
55
|
-
|
|
55
|
+
if (option) {
|
|
56
|
+
if (ctx == null ? void 0 : ctx.t) {
|
|
57
|
+
return ctx.t(option.label, { ns: "lm-collections" });
|
|
58
|
+
}
|
|
59
|
+
return option.label;
|
|
60
|
+
}
|
|
61
|
+
return value;
|
|
56
62
|
}
|
|
57
63
|
};
|
|
58
64
|
__name(_SelectInterface, "SelectInterface");
|
|
@@ -39,7 +39,7 @@ const _ToOneInterface = class _ToOneInterface extends import_base_interface.Base
|
|
|
39
39
|
if (!str) {
|
|
40
40
|
return null;
|
|
41
41
|
}
|
|
42
|
-
const { filterKey, targetCollection, transaction } = ctx;
|
|
42
|
+
const { filterKey, associationField, targetCollection, transaction } = ctx;
|
|
43
43
|
const targetInstance = await targetCollection.repository.findOne({
|
|
44
44
|
filter: {
|
|
45
45
|
[filterKey]: str
|
|
@@ -49,8 +49,8 @@ const _ToOneInterface = class _ToOneInterface extends import_base_interface.Base
|
|
|
49
49
|
if (!targetInstance) {
|
|
50
50
|
throw new Error(`"${str}" not found in ${targetCollection.model.name} ${filterKey}`);
|
|
51
51
|
}
|
|
52
|
-
const
|
|
53
|
-
return targetInstance[
|
|
52
|
+
const targetKey = associationField.targetKey || targetCollection.model.primaryKeyAttribute;
|
|
53
|
+
return targetInstance[targetKey];
|
|
54
54
|
}
|
|
55
55
|
};
|
|
56
56
|
__name(_ToOneInterface, "ToOneInterface");
|
package/lib/interfaces/utils.js
CHANGED
|
@@ -51,6 +51,9 @@ const interfaces = {
|
|
|
51
51
|
radioGroup: import_index.SelectInterface,
|
|
52
52
|
percent: import_index.PercentInterface,
|
|
53
53
|
datetime: import_index.DatetimeInterface,
|
|
54
|
+
datetimeNoTz: import_index.DatetimeNoTzInterface,
|
|
55
|
+
unixTimestamp: import_index.DatetimeInterface,
|
|
56
|
+
date: import_index.DateInterface,
|
|
54
57
|
createdAt: import_index.DatetimeInterface,
|
|
55
58
|
updatedAt: import_index.DatetimeInterface,
|
|
56
59
|
boolean: import_index.BooleanInterface,
|
package/lib/options-parser.js
CHANGED
|
@@ -174,7 +174,10 @@ const _OptionsParser = class _OptionsParser {
|
|
|
174
174
|
}
|
|
175
175
|
sortField.push(direction);
|
|
176
176
|
if (this.database.isMySQLCompatibleDialect()) {
|
|
177
|
-
|
|
177
|
+
const fieldName = sortField[0];
|
|
178
|
+
if (this.model.fieldRawAttributesMap[fieldName]) {
|
|
179
|
+
orderParams.push([import_sequelize.Sequelize.fn("ISNULL", import_sequelize.Sequelize.col(`${this.model.name}.${sortField[0]}`))]);
|
|
180
|
+
}
|
|
178
181
|
}
|
|
179
182
|
orderParams.push(sortField);
|
|
180
183
|
}
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nocobase/database",
|
|
3
|
-
"version": "1.4.0-alpha.
|
|
3
|
+
"version": "1.4.0-alpha.3",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"types": "./lib/index.d.ts",
|
|
7
7
|
"license": "AGPL-3.0",
|
|
8
8
|
"dependencies": {
|
|
9
|
-
"@nocobase/logger": "1.4.0-alpha.
|
|
10
|
-
"@nocobase/utils": "1.4.0-alpha.
|
|
9
|
+
"@nocobase/logger": "1.4.0-alpha.3",
|
|
10
|
+
"@nocobase/utils": "1.4.0-alpha.3",
|
|
11
11
|
"async-mutex": "^0.3.2",
|
|
12
12
|
"chalk": "^4.1.1",
|
|
13
13
|
"cron-parser": "4.4.0",
|
|
@@ -38,5 +38,5 @@
|
|
|
38
38
|
"url": "git+https://github.com/nocobase/nocobase.git",
|
|
39
39
|
"directory": "packages/database"
|
|
40
40
|
},
|
|
41
|
-
"gitHead": "
|
|
41
|
+
"gitHead": "9268a5b29cbbe9f83255e5cd66fa82f012aab46a"
|
|
42
42
|
}
|