@nocobase/database 2.1.0-alpha.4 → 2.1.0-alpha.40
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/LICENSE +201 -661
- package/README.md +79 -10
- package/lib/database.d.ts +1 -0
- package/lib/database.js +3 -0
- package/lib/eager-loading/eager-loading-tree.js +14 -4
- package/lib/errors/association-not-found-error.d.ts +11 -0
- package/lib/errors/association-not-found-error.js +44 -0
- package/lib/fields/relation-field.js +1 -1
- package/lib/index.d.ts +3 -0
- package/lib/index.js +6 -0
- package/lib/interfaces/date-interface.d.ts +9 -0
- package/lib/interfaces/date-interface.js +27 -0
- package/lib/interfaces/datetime-interface.d.ts +3 -1
- package/lib/interfaces/datetime-interface.js +84 -9
- package/lib/interfaces/datetime-no-tz-interface.d.ts +9 -0
- package/lib/interfaces/datetime-no-tz-interface.js +16 -2
- package/lib/interfaces/time-interface.js +16 -0
- package/lib/interfaces/to-one-interface.js +1 -1
- package/lib/operators/date.js +12 -4
- package/lib/options-parser.d.ts +1 -0
- package/lib/options-parser.js +20 -4
- package/lib/query/builder.d.ts +17 -0
- package/lib/query/builder.js +268 -0
- package/lib/query/formatter.d.ts +29 -0
- package/lib/query/formatter.js +100 -0
- package/lib/query/formatters/mysql.d.ts +14 -0
- package/lib/query/formatters/mysql.js +70 -0
- package/lib/query/formatters/oracle.d.ts +14 -0
- package/lib/query/formatters/oracle.js +64 -0
- package/lib/query/formatters/postgres.d.ts +15 -0
- package/lib/query/formatters/postgres.js +70 -0
- package/lib/query/formatters/sqlite.d.ts +14 -0
- package/lib/query/formatters/sqlite.js +63 -0
- package/lib/query/having.d.ts +22 -0
- package/lib/query/having.js +112 -0
- package/lib/query/types.d.ts +40 -0
- package/lib/query/types.js +24 -0
- package/lib/repository.d.ts +4 -0
- package/lib/repository.js +23 -3
- package/lib/utils/field-validation.js +38 -7
- package/lib/view/field-type-map.d.ts +4 -4
- package/lib/view/field-type-map.js +4 -4
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -1,17 +1,24 @@
|
|
|
1
1
|
# NocoBase
|
|
2
2
|
|
|
3
3
|
<video width="100%" controls>
|
|
4
|
-
|
|
4
|
+
<source src="https://github.com/user-attachments/assets/4d11a87b-00e2-48f3-9bf7-389d21072d13" type="video/mp4">
|
|
5
5
|
</video>
|
|
6
6
|
|
|
7
|
+
<p align="center">
|
|
8
|
+
<a href="https://trendshift.io/repositories/4112" target="_blank"><img src="https://trendshift.io/api/badge/repositories/4112" alt="nocobase%2Fnocobase | Trendshift" style="width: 250px; height: 55px;" width="250" height="55"/></a>
|
|
9
|
+
<a href="https://www.producthunt.com/posts/nocobase?embed=true&utm_source=badge-top-post-topic-badge&utm_medium=badge&utm_souce=badge-nocobase" target="_blank"><img src="https://api.producthunt.com/widgets/embed-image/v1/top-post-topic-badge.svg?post_id=456520&theme=light&period=weekly&topic_id=267" alt="NocoBase - Scalability-first, open-source no-code platform | Product Hunt" style="width: 250px; height: 54px;" width="250" height="54" /></a>
|
|
10
|
+
</p>
|
|
7
11
|
|
|
8
12
|
## What is NocoBase
|
|
9
13
|
|
|
10
|
-
NocoBase is
|
|
11
|
-
|
|
14
|
+
NocoBase is the most extensible AI-powered no-code platform.
|
|
15
|
+
Total control. Infinite extensibility. AI collaboration.
|
|
16
|
+
Enable your team to adapt quickly and cut costs dramatically.
|
|
17
|
+
No years of development. No millions wasted.
|
|
18
|
+
Deploy NocoBase in minutes — and take control of everything.
|
|
12
19
|
|
|
13
20
|
Homepage:
|
|
14
|
-
https://www.nocobase.com/
|
|
21
|
+
https://www.nocobase.com/
|
|
15
22
|
|
|
16
23
|
Online Demo:
|
|
17
24
|
https://demo.nocobase.com/new
|
|
@@ -19,12 +26,74 @@ https://demo.nocobase.com/new
|
|
|
19
26
|
Documents:
|
|
20
27
|
https://docs.nocobase.com/
|
|
21
28
|
|
|
22
|
-
|
|
23
|
-
https://
|
|
29
|
+
Forum:
|
|
30
|
+
https://forum.nocobase.com/
|
|
24
31
|
|
|
25
|
-
|
|
26
|
-
https://www.nocobase.com/en/
|
|
32
|
+
Use Cases:
|
|
33
|
+
https://www.nocobase.com/en/blog/tags/customer-stories
|
|
27
34
|
|
|
35
|
+
## Release Notes
|
|
28
36
|
|
|
29
|
-
|
|
30
|
-
|
|
37
|
+
Our [blog](https://www.nocobase.com/en/blog/timeline) is regularly updated with release notes and provides a weekly summary.
|
|
38
|
+
|
|
39
|
+
## Distinctive features
|
|
40
|
+
|
|
41
|
+
### 1. Data model-driven, not form/table–driven
|
|
42
|
+
|
|
43
|
+
Instead of being constrained by forms or tables, NocoBase adopts a data model–driven approach, separating data structure from user interface to unlock unlimited possibilities.
|
|
44
|
+
|
|
45
|
+
- UI and data structure are fully decoupled
|
|
46
|
+
- Multiple blocks and actions can be created for the same table or record in any quantity or form
|
|
47
|
+
- Supports the main database, external databases, and third-party APIs as data sources
|
|
48
|
+
|
|
49
|
+

|
|
50
|
+
|
|
51
|
+
### 2. AI employees, integrated into your business systems
|
|
52
|
+
Unlike standalone AI demos, NocoBase allows you to embed AI capabilities seamlessly into your interfaces, workflows, and data context, making AI truly useful in real business scenarios.
|
|
53
|
+
|
|
54
|
+
- Define AI employees for roles such as translator, analyst, researcher, or assistant
|
|
55
|
+
- Seamless AI–human collaboration in interfaces and workflows
|
|
56
|
+
- Ensure AI usage is secure, transparent, and customizable for your business needs
|
|
57
|
+
|
|
58
|
+

|
|
59
|
+
|
|
60
|
+
### 3. What you see is what you get, incredibly easy to use
|
|
61
|
+
|
|
62
|
+
While enabling the development of complex business systems, NocoBase keeps the experience simple and intuitive.
|
|
63
|
+
|
|
64
|
+
- One-click switch between usage mode and configuration mode
|
|
65
|
+
- Pages serve as a canvas to arrange blocks and actions, similar to Notion
|
|
66
|
+
- Configuration mode is designed for ordinary users, not just programmers
|
|
67
|
+
|
|
68
|
+

|
|
69
|
+
|
|
70
|
+
### 4. Everything is a plugin, designed for extension
|
|
71
|
+
Adding more no-code features will never cover every business case. NocoBase is built for extension through its plugin-based microkernel architecture.
|
|
72
|
+
|
|
73
|
+
- All functionalities are plugins, similar to WordPress
|
|
74
|
+
- Plugins are ready to use upon installation
|
|
75
|
+
- Pages, blocks, actions, APIs, and data sources can all be extended through custom plugins
|
|
76
|
+
|
|
77
|
+

|
|
78
|
+
|
|
79
|
+
## Installation
|
|
80
|
+
|
|
81
|
+
NocoBase supports three installation methods:
|
|
82
|
+
|
|
83
|
+
- <a target="_blank" href="https://docs.nocobase.com/welcome/getting-started/installation/docker-compose">Installing With Docker (👍Recommended)</a>
|
|
84
|
+
|
|
85
|
+
Suitable for no-code scenarios, no code to write. When upgrading, just download the latest image and reboot.
|
|
86
|
+
|
|
87
|
+
- <a target="_blank" href="https://docs.nocobase.com/welcome/getting-started/installation/create-nocobase-app">Installing from create-nocobase-app CLI</a>
|
|
88
|
+
|
|
89
|
+
The business code of the project is completely independent and supports low-code development.
|
|
90
|
+
|
|
91
|
+
- <a target="_blank" href="https://docs.nocobase.com/welcome/getting-started/installation/git-clone">Installing from Git source code</a>
|
|
92
|
+
|
|
93
|
+
If you want to experience the latest unreleased version, or want to participate in the contribution, you need to make changes and debug on the source code, it is recommended to choose this installation method, which requires a high level of development skills, and if the code has been updated, you can git pull the latest code.
|
|
94
|
+
|
|
95
|
+
## How NocoBase works
|
|
96
|
+
|
|
97
|
+
<video width="100%" controls>
|
|
98
|
+
<source src="https://github.com/user-attachments/assets/8d183b44-9bb5-4792-b08f-bc08fe8dfaaf" type="video/mp4">
|
|
99
|
+
</video>
|
package/lib/database.d.ts
CHANGED
package/lib/database.js
CHANGED
|
@@ -213,6 +213,9 @@ const _Database = class _Database extends import_events.EventEmitter {
|
|
|
213
213
|
this.migrations = new import_migration.Migrations(context);
|
|
214
214
|
this.sequelize.beforeDefine((model, opts2) => {
|
|
215
215
|
if (this.options.tablePrefix) {
|
|
216
|
+
if (opts2.tableName && opts2["from"] === "dbsync") {
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
216
219
|
if (opts2.tableName && opts2.tableName.startsWith(this.options.tablePrefix)) {
|
|
217
220
|
return;
|
|
218
221
|
}
|
|
@@ -75,16 +75,20 @@ const queryParentSQL = /* @__PURE__ */ __name((options) => {
|
|
|
75
75
|
const targetKeyField = collection.model.rawAttributes[targetKey].field;
|
|
76
76
|
const queryInterface = db.sequelize.getQueryInterface();
|
|
77
77
|
const q = queryInterface.quoteIdentifier.bind(queryInterface);
|
|
78
|
-
|
|
78
|
+
const placeholders = nodeIds.map((_, index) => `$${index + 1}`).join(", ");
|
|
79
|
+
return {
|
|
80
|
+
sql: `WITH RECURSIVE cte AS (
|
|
79
81
|
SELECT ${q(targetKeyField)}, ${q(foreignKeyField)}
|
|
80
82
|
FROM ${tableName}
|
|
81
|
-
WHERE ${q(targetKeyField)} IN (
|
|
83
|
+
WHERE ${q(targetKeyField)} IN (${placeholders})
|
|
82
84
|
UNION ALL
|
|
83
85
|
SELECT t.${q(targetKeyField)}, t.${q(foreignKeyField)}
|
|
84
86
|
FROM ${tableName} AS t
|
|
85
87
|
INNER JOIN cte ON t.${q(targetKeyField)} = cte.${q(foreignKeyField)}
|
|
86
88
|
)
|
|
87
|
-
SELECT ${q(targetKeyField)} AS ${q(targetKey)}, ${q(foreignKeyField)} AS ${q(foreignKey)} FROM cte
|
|
89
|
+
SELECT ${q(targetKeyField)} AS ${q(targetKey)}, ${q(foreignKeyField)} AS ${q(foreignKey)} FROM cte`,
|
|
90
|
+
bind: nodeIds
|
|
91
|
+
};
|
|
88
92
|
}, "queryParentSQL");
|
|
89
93
|
const _EagerLoadingTree = class _EagerLoadingTree {
|
|
90
94
|
root;
|
|
@@ -149,6 +153,11 @@ const _EagerLoadingTree = class _EagerLoadingTree {
|
|
|
149
153
|
const { sourceKey } = association;
|
|
150
154
|
pushAttribute(eagerLoadingTreeParent, sourceKey);
|
|
151
155
|
}
|
|
156
|
+
if (associationType == "BelongsToArray") {
|
|
157
|
+
const { foreignKey, targetKey } = association;
|
|
158
|
+
pushAttribute(eagerLoadingTreeParent, foreignKey);
|
|
159
|
+
pushAttribute(child, targetKey);
|
|
160
|
+
}
|
|
152
161
|
eagerLoadingTreeParent.children.push(child);
|
|
153
162
|
if (include.include) {
|
|
154
163
|
traverseIncludeOption(include.include, child);
|
|
@@ -300,7 +309,7 @@ const _EagerLoadingTree = class _EagerLoadingTree {
|
|
|
300
309
|
});
|
|
301
310
|
if (node.includeOption.recursively && instances.length > 0) {
|
|
302
311
|
const targetKey = association.targetKey;
|
|
303
|
-
const sql = queryParentSQL({
|
|
312
|
+
const { sql, bind } = queryParentSQL({
|
|
304
313
|
db: this.db,
|
|
305
314
|
collection: collection2,
|
|
306
315
|
foreignKey,
|
|
@@ -308,6 +317,7 @@ const _EagerLoadingTree = class _EagerLoadingTree {
|
|
|
308
317
|
nodeIds: instances.map((instance) => instance.get(targetKey))
|
|
309
318
|
});
|
|
310
319
|
const results = await this.db.sequelize.query(sql, {
|
|
320
|
+
bind,
|
|
311
321
|
type: "SELECT",
|
|
312
322
|
transaction
|
|
313
323
|
});
|
|
@@ -0,0 +1,11 @@
|
|
|
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
|
+
export declare class AssociationNotFoundError extends Error {
|
|
10
|
+
constructor(message: string);
|
|
11
|
+
}
|
|
@@ -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 association_not_found_error_exports = {};
|
|
29
|
+
__export(association_not_found_error_exports, {
|
|
30
|
+
AssociationNotFoundError: () => AssociationNotFoundError
|
|
31
|
+
});
|
|
32
|
+
module.exports = __toCommonJS(association_not_found_error_exports);
|
|
33
|
+
const _AssociationNotFoundError = class _AssociationNotFoundError extends Error {
|
|
34
|
+
constructor(message) {
|
|
35
|
+
super(message);
|
|
36
|
+
this.name = "AssociationNotFoundError";
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
__name(_AssociationNotFoundError, "AssociationNotFoundError");
|
|
40
|
+
let AssociationNotFoundError = _AssociationNotFoundError;
|
|
41
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
42
|
+
0 && (module.exports = {
|
|
43
|
+
AssociationNotFoundError
|
|
44
|
+
});
|
|
@@ -43,7 +43,7 @@ const _RelationField = class _RelationField extends import_field.Field {
|
|
|
43
43
|
return this.options.foreignKey;
|
|
44
44
|
}
|
|
45
45
|
get sourceKey() {
|
|
46
|
-
return this.options.sourceKey || this.collection.
|
|
46
|
+
return this.options.sourceKey || this.collection.filterTargetKey;
|
|
47
47
|
}
|
|
48
48
|
get targetKey() {
|
|
49
49
|
return this.options.targetKey || this.TargetModel.primaryKeyAttribute;
|
package/lib/index.d.ts
CHANGED
|
@@ -32,6 +32,9 @@ export * from './relation-repository/hasmany-repository';
|
|
|
32
32
|
export * from './relation-repository/hasone-repository';
|
|
33
33
|
export * from './relation-repository/multiple-relation-repository';
|
|
34
34
|
export * from './relation-repository/single-relation-repository';
|
|
35
|
+
export * from './query/builder';
|
|
36
|
+
export * from './query/formatter';
|
|
37
|
+
export * from './query/types';
|
|
35
38
|
export * from './repository';
|
|
36
39
|
export * from './relation-repository/relation-repository';
|
|
37
40
|
export { default as sqlParser, SQLParserTypes } from './sql-parser';
|
package/lib/index.js
CHANGED
|
@@ -93,6 +93,9 @@ __reExport(src_exports, require("./relation-repository/hasmany-repository"), mod
|
|
|
93
93
|
__reExport(src_exports, require("./relation-repository/hasone-repository"), module.exports);
|
|
94
94
|
__reExport(src_exports, require("./relation-repository/multiple-relation-repository"), module.exports);
|
|
95
95
|
__reExport(src_exports, require("./relation-repository/single-relation-repository"), module.exports);
|
|
96
|
+
__reExport(src_exports, require("./query/builder"), module.exports);
|
|
97
|
+
__reExport(src_exports, require("./query/formatter"), module.exports);
|
|
98
|
+
__reExport(src_exports, require("./query/types"), module.exports);
|
|
96
99
|
__reExport(src_exports, require("./repository"), module.exports);
|
|
97
100
|
__reExport(src_exports, require("./relation-repository/relation-repository"), module.exports);
|
|
98
101
|
var import_sql_parser = __toESM(require("./sql-parser"));
|
|
@@ -157,6 +160,9 @@ var import_filter_include = require("./utils/filter-include");
|
|
|
157
160
|
...require("./relation-repository/hasone-repository"),
|
|
158
161
|
...require("./relation-repository/multiple-relation-repository"),
|
|
159
162
|
...require("./relation-repository/single-relation-repository"),
|
|
163
|
+
...require("./query/builder"),
|
|
164
|
+
...require("./query/formatter"),
|
|
165
|
+
...require("./query/types"),
|
|
160
166
|
...require("./repository"),
|
|
161
167
|
...require("./relation-repository/relation-repository"),
|
|
162
168
|
...require("./update-associations"),
|
|
@@ -1,4 +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
|
+
*/
|
|
1
9
|
import { DatetimeInterface } from './datetime-interface';
|
|
2
10
|
export declare class DateInterface extends DatetimeInterface {
|
|
11
|
+
toValue(value: any, ctx?: any): Promise<any>;
|
|
3
12
|
toString(value: any, ctx?: any): any;
|
|
4
13
|
}
|
|
@@ -31,7 +31,34 @@ __export(date_interface_exports, {
|
|
|
31
31
|
});
|
|
32
32
|
module.exports = __toCommonJS(date_interface_exports);
|
|
33
33
|
var import_datetime_interface = require("./datetime-interface");
|
|
34
|
+
function pad2(value) {
|
|
35
|
+
return String(value).padStart(2, "0");
|
|
36
|
+
}
|
|
37
|
+
__name(pad2, "pad2");
|
|
38
|
+
function formatDateOnlyFromDate(date, timezone) {
|
|
39
|
+
const offsetMinutes = (0, import_datetime_interface.getTimeZoneOffsetMinutes)(timezone);
|
|
40
|
+
if (offsetMinutes == null) {
|
|
41
|
+
return `${date.getFullYear()}-${pad2(date.getMonth() + 1)}-${pad2(date.getDate())}`;
|
|
42
|
+
}
|
|
43
|
+
const shifted = new Date(date.getTime() + offsetMinutes * 60 * 1e3);
|
|
44
|
+
return `${shifted.getUTCFullYear()}-${pad2(shifted.getUTCMonth() + 1)}-${pad2(shifted.getUTCDate())}`;
|
|
45
|
+
}
|
|
46
|
+
__name(formatDateOnlyFromDate, "formatDateOnlyFromDate");
|
|
34
47
|
const _DateInterface = class _DateInterface extends import_datetime_interface.DatetimeInterface {
|
|
48
|
+
async toValue(value, ctx) {
|
|
49
|
+
const normalized = await super.toValue(value, ctx);
|
|
50
|
+
if (!normalized) {
|
|
51
|
+
return normalized;
|
|
52
|
+
}
|
|
53
|
+
if (typeof normalized === "string" && /^\d{4}-\d{2}-\d{2}$/.test(normalized)) {
|
|
54
|
+
return normalized;
|
|
55
|
+
}
|
|
56
|
+
const date = normalized instanceof Date ? normalized : new Date(normalized);
|
|
57
|
+
if (Number.isNaN(date.getTime())) {
|
|
58
|
+
return normalized;
|
|
59
|
+
}
|
|
60
|
+
return formatDateOnlyFromDate(date, (0, import_datetime_interface.resolveTimeZoneFromCtx)(ctx));
|
|
61
|
+
}
|
|
35
62
|
toString(value, ctx) {
|
|
36
63
|
return value;
|
|
37
64
|
}
|
|
@@ -7,6 +7,8 @@
|
|
|
7
7
|
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
8
|
*/
|
|
9
9
|
import { BaseInterface } from './base-interface';
|
|
10
|
+
export declare function getTimeZoneOffsetMinutes(timezone: string | number | null | undefined): number;
|
|
11
|
+
export declare function resolveTimeZoneFromCtx(ctx: any): any;
|
|
10
12
|
export declare class DatetimeInterface extends BaseInterface {
|
|
11
13
|
protected parseDateString(value: string): {
|
|
12
14
|
year: string;
|
|
@@ -30,7 +32,7 @@ export declare class DatetimeInterface extends BaseInterface {
|
|
|
30
32
|
hour?: string;
|
|
31
33
|
minute?: string;
|
|
32
34
|
second?: string;
|
|
33
|
-
}): string;
|
|
35
|
+
}, ctx?: any): string;
|
|
34
36
|
toValue(value: any, ctx?: any): Promise<any>;
|
|
35
37
|
toString(value: any, ctx?: any): any;
|
|
36
38
|
}
|
|
@@ -37,7 +37,9 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
37
37
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
38
38
|
var datetime_interface_exports = {};
|
|
39
39
|
__export(datetime_interface_exports, {
|
|
40
|
-
DatetimeInterface: () => DatetimeInterface
|
|
40
|
+
DatetimeInterface: () => DatetimeInterface,
|
|
41
|
+
getTimeZoneOffsetMinutes: () => getTimeZoneOffsetMinutes,
|
|
42
|
+
resolveTimeZoneFromCtx: () => resolveTimeZoneFromCtx
|
|
41
43
|
});
|
|
42
44
|
module.exports = __toCommonJS(datetime_interface_exports);
|
|
43
45
|
var import_base_interface = require("./base-interface");
|
|
@@ -54,13 +56,79 @@ function isNumeric(str) {
|
|
|
54
56
|
return !isNaN(str) && !isNaN(parseFloat(str));
|
|
55
57
|
}
|
|
56
58
|
__name(isNumeric, "isNumeric");
|
|
59
|
+
function getTimeZoneOffsetMinutes(timezone) {
|
|
60
|
+
if (typeof timezone === "number" && Number.isFinite(timezone)) {
|
|
61
|
+
return timezone;
|
|
62
|
+
}
|
|
63
|
+
if (typeof timezone !== "string") {
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
const normalized = timezone.trim().toUpperCase();
|
|
67
|
+
if (!normalized) {
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
70
|
+
if (normalized === "Z" || normalized === "UTC") {
|
|
71
|
+
return 0;
|
|
72
|
+
}
|
|
73
|
+
const match = normalized.match(/^([+-])(\d{2})(?::?(\d{2}))?$/);
|
|
74
|
+
if (!match) {
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
const [, sign, hours, minutes = "00"] = match;
|
|
78
|
+
const totalMinutes = Number(hours) * 60 + Number(minutes);
|
|
79
|
+
return sign === "+" ? totalMinutes : -totalMinutes;
|
|
80
|
+
}
|
|
81
|
+
__name(getTimeZoneOffsetMinutes, "getTimeZoneOffsetMinutes");
|
|
57
82
|
function resolveTimeZoneFromCtx(ctx) {
|
|
58
|
-
|
|
59
|
-
|
|
83
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
|
|
84
|
+
let timezone;
|
|
85
|
+
if (typeof (ctx == null ? void 0 : ctx.get) === "function") {
|
|
86
|
+
timezone = ctx.get("X-Timezone") || ctx.get("x-timezone");
|
|
87
|
+
} else if (typeof ((_a = ctx == null ? void 0 : ctx.request) == null ? void 0 : _a.get) === "function") {
|
|
88
|
+
timezone = ctx.request.get("X-Timezone") || ctx.request.get("x-timezone");
|
|
89
|
+
}
|
|
90
|
+
timezone = timezone || ((_c = (_b = ctx == null ? void 0 : ctx.request) == null ? void 0 : _b.headers) == null ? void 0 : _c["x-timezone"]) || ((_e = (_d = ctx == null ? void 0 : ctx.request) == null ? void 0 : _d.headers) == null ? void 0 : _e["X-Timezone"]) || ((_g = (_f = ctx == null ? void 0 : ctx.request) == null ? void 0 : _f.header) == null ? void 0 : _g["x-timezone"]) || ((_i = (_h = ctx == null ? void 0 : ctx.request) == null ? void 0 : _h.header) == null ? void 0 : _i["X-Timezone"]) || ((_k = (_j = ctx == null ? void 0 : ctx.req) == null ? void 0 : _j.headers) == null ? void 0 : _k["x-timezone"]) || ((_m = (_l = ctx == null ? void 0 : ctx.req) == null ? void 0 : _l.headers) == null ? void 0 : _m["X-Timezone"]);
|
|
91
|
+
if (timezone !== void 0 && timezone !== null && timezone !== "") {
|
|
92
|
+
return timezone;
|
|
60
93
|
}
|
|
61
|
-
return
|
|
94
|
+
return null;
|
|
62
95
|
}
|
|
63
96
|
__name(resolveTimeZoneFromCtx, "resolveTimeZoneFromCtx");
|
|
97
|
+
function toISOWithTimezone(dateInfo, timezone) {
|
|
98
|
+
const offsetMinutes = getTimeZoneOffsetMinutes(timezone);
|
|
99
|
+
if (offsetMinutes == null) {
|
|
100
|
+
return null;
|
|
101
|
+
}
|
|
102
|
+
const utcMillis = Date.UTC(
|
|
103
|
+
Number(dateInfo.year),
|
|
104
|
+
Number(dateInfo.month) - 1,
|
|
105
|
+
Number(dateInfo.day),
|
|
106
|
+
Number(dateInfo.hour || "00"),
|
|
107
|
+
Number(dateInfo.minute || "00"),
|
|
108
|
+
Number(dateInfo.second || "00"),
|
|
109
|
+
0
|
|
110
|
+
) - offsetMinutes * 60 * 1e3;
|
|
111
|
+
return new Date(utcMillis).toISOString();
|
|
112
|
+
}
|
|
113
|
+
__name(toISOWithTimezone, "toISOWithTimezone");
|
|
114
|
+
function excelSerialToISO(value, timezone) {
|
|
115
|
+
const wallClockUtcDate = (0, import_excel_date_to_js.getJsDateFromExcel)(value);
|
|
116
|
+
const offsetMinutes = getTimeZoneOffsetMinutes(timezone);
|
|
117
|
+
if (offsetMinutes == null) {
|
|
118
|
+
return wallClockUtcDate.toISOString();
|
|
119
|
+
}
|
|
120
|
+
const utcMillis = Date.UTC(
|
|
121
|
+
wallClockUtcDate.getUTCFullYear(),
|
|
122
|
+
wallClockUtcDate.getUTCMonth(),
|
|
123
|
+
wallClockUtcDate.getUTCDate(),
|
|
124
|
+
wallClockUtcDate.getUTCHours(),
|
|
125
|
+
wallClockUtcDate.getUTCMinutes(),
|
|
126
|
+
wallClockUtcDate.getUTCSeconds(),
|
|
127
|
+
wallClockUtcDate.getUTCMilliseconds()
|
|
128
|
+
) - offsetMinutes * 60 * 1e3;
|
|
129
|
+
return new Date(utcMillis).toISOString();
|
|
130
|
+
}
|
|
131
|
+
__name(excelSerialToISO, "excelSerialToISO");
|
|
64
132
|
const _DatetimeInterface = class _DatetimeInterface extends import_base_interface.BaseInterface {
|
|
65
133
|
parseDateString(value) {
|
|
66
134
|
const dateOnlyMatch = /^(\d{4})[-/]?(\d{2})[-/]?(\d{2})$/.exec(value);
|
|
@@ -75,7 +143,12 @@ const _DatetimeInterface = class _DatetimeInterface extends import_base_interfac
|
|
|
75
143
|
}
|
|
76
144
|
return null;
|
|
77
145
|
}
|
|
78
|
-
formatDateTimeToISO(dateInfo) {
|
|
146
|
+
formatDateTimeToISO(dateInfo, ctx) {
|
|
147
|
+
const timezone = resolveTimeZoneFromCtx(ctx);
|
|
148
|
+
const timezoneAwareISO = toISOWithTimezone(dateInfo, timezone);
|
|
149
|
+
if (timezoneAwareISO) {
|
|
150
|
+
return timezoneAwareISO;
|
|
151
|
+
}
|
|
79
152
|
const { year, month, day, hour = "00", minute = "00", second = "00" } = dateInfo;
|
|
80
153
|
const m = (0, import_dayjs.default)(`${year}-${month}-${day} ${hour}:${minute}:${second}.000`);
|
|
81
154
|
return m.toISOString();
|
|
@@ -94,7 +167,7 @@ const _DatetimeInterface = class _DatetimeInterface extends import_base_interfac
|
|
|
94
167
|
if (typeof value === "string") {
|
|
95
168
|
const dateInfo = this.parseDateString(value);
|
|
96
169
|
if (dateInfo) {
|
|
97
|
-
return this.formatDateTimeToISO(dateInfo);
|
|
170
|
+
return this.formatDateTimeToISO(dateInfo, ctx);
|
|
98
171
|
}
|
|
99
172
|
}
|
|
100
173
|
if (import_dayjs.default.isDayjs(value)) {
|
|
@@ -102,7 +175,7 @@ const _DatetimeInterface = class _DatetimeInterface extends import_base_interfac
|
|
|
102
175
|
} else if (isDate(value)) {
|
|
103
176
|
return value;
|
|
104
177
|
} else if (isNumeric(value)) {
|
|
105
|
-
return (
|
|
178
|
+
return excelSerialToISO(value, resolveTimeZoneFromCtx(ctx));
|
|
106
179
|
} else if (typeof value === "string") {
|
|
107
180
|
return value;
|
|
108
181
|
}
|
|
@@ -110,7 +183,7 @@ const _DatetimeInterface = class _DatetimeInterface extends import_base_interfac
|
|
|
110
183
|
}
|
|
111
184
|
toString(value, ctx) {
|
|
112
185
|
var _a, _b;
|
|
113
|
-
const utcOffset = resolveTimeZoneFromCtx(ctx);
|
|
186
|
+
const utcOffset = resolveTimeZoneFromCtx(ctx) ?? 0;
|
|
114
187
|
const props = ((_b = (_a = this.options) == null ? void 0 : _a.uiSchema) == null ? void 0 : _b["x-component-props"]) ?? {};
|
|
115
188
|
const format = (0, import_utils.getDefaultFormat)(props);
|
|
116
189
|
const m = (0, import_utils.str2moment)(value, { ...props, utcOffset });
|
|
@@ -121,5 +194,7 @@ __name(_DatetimeInterface, "DatetimeInterface");
|
|
|
121
194
|
let DatetimeInterface = _DatetimeInterface;
|
|
122
195
|
// Annotate the CommonJS export names for ESM import in node:
|
|
123
196
|
0 && (module.exports = {
|
|
124
|
-
DatetimeInterface
|
|
197
|
+
DatetimeInterface,
|
|
198
|
+
getTimeZoneOffsetMinutes,
|
|
199
|
+
resolveTimeZoneFromCtx
|
|
125
200
|
});
|
|
@@ -1,3 +1,11 @@
|
|
|
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
|
+
*/
|
|
1
9
|
import { DatetimeInterface } from './datetime-interface';
|
|
2
10
|
export declare class DatetimeNoTzInterface extends DatetimeInterface {
|
|
3
11
|
protected formatDateTimeToString(dateInfo: {
|
|
@@ -8,6 +16,7 @@ export declare class DatetimeNoTzInterface extends DatetimeInterface {
|
|
|
8
16
|
minute?: string;
|
|
9
17
|
second?: string;
|
|
10
18
|
}): string;
|
|
19
|
+
protected formatExcelSerialToString(value: number | string): string;
|
|
11
20
|
toValue(value: any, ctx?: any): Promise<any>;
|
|
12
21
|
toString(value: any, ctx?: any): any;
|
|
13
22
|
}
|
|
@@ -54,6 +54,10 @@ function isNumeric(str) {
|
|
|
54
54
|
return !isNaN(str) && !isNaN(parseFloat(str));
|
|
55
55
|
}
|
|
56
56
|
__name(isNumeric, "isNumeric");
|
|
57
|
+
function pad2(value) {
|
|
58
|
+
return String(value).padStart(2, "0");
|
|
59
|
+
}
|
|
60
|
+
__name(pad2, "pad2");
|
|
57
61
|
const _DatetimeNoTzInterface = class _DatetimeNoTzInterface extends import_datetime_interface.DatetimeInterface {
|
|
58
62
|
formatDateTimeToString(dateInfo) {
|
|
59
63
|
const { year, month, day, hour, minute, second } = dateInfo;
|
|
@@ -62,6 +66,17 @@ const _DatetimeNoTzInterface = class _DatetimeNoTzInterface extends import_datet
|
|
|
62
66
|
}
|
|
63
67
|
return `${year}-${month}-${day}`;
|
|
64
68
|
}
|
|
69
|
+
formatExcelSerialToString(value) {
|
|
70
|
+
const date = (0, import_excel_date_to_js.getJsDateFromExcel)(value);
|
|
71
|
+
return this.formatDateTimeToString({
|
|
72
|
+
year: String(date.getUTCFullYear()),
|
|
73
|
+
month: pad2(date.getUTCMonth() + 1),
|
|
74
|
+
day: pad2(date.getUTCDate()),
|
|
75
|
+
hour: pad2(date.getUTCHours()),
|
|
76
|
+
minute: pad2(date.getUTCMinutes()),
|
|
77
|
+
second: pad2(date.getUTCSeconds())
|
|
78
|
+
});
|
|
79
|
+
}
|
|
65
80
|
async toValue(value, ctx = {}) {
|
|
66
81
|
if (!value) {
|
|
67
82
|
return null;
|
|
@@ -77,8 +92,7 @@ const _DatetimeNoTzInterface = class _DatetimeNoTzInterface extends import_datet
|
|
|
77
92
|
} else if (isDate(value)) {
|
|
78
93
|
return value;
|
|
79
94
|
} else if (isNumeric(value)) {
|
|
80
|
-
|
|
81
|
-
return date.toISOString();
|
|
95
|
+
return this.formatExcelSerialToString(value);
|
|
82
96
|
} else if (typeof value === "string") {
|
|
83
97
|
return value;
|
|
84
98
|
}
|
|
@@ -44,8 +44,24 @@ var import_dayjs = __toESM(require("dayjs"));
|
|
|
44
44
|
var import_utc = __toESM(require("dayjs/plugin/utc"));
|
|
45
45
|
var import_base_interface = require("./base-interface");
|
|
46
46
|
import_dayjs.default.extend(import_utc.default);
|
|
47
|
+
function isNumeric(value) {
|
|
48
|
+
return typeof value === "number" && Number.isFinite(value);
|
|
49
|
+
}
|
|
50
|
+
__name(isNumeric, "isNumeric");
|
|
51
|
+
function formatExcelTimeSerial(value) {
|
|
52
|
+
const normalized = (value % 1 + 1) % 1;
|
|
53
|
+
const totalSeconds = Math.round(normalized * 24 * 60 * 60) % (24 * 60 * 60);
|
|
54
|
+
const hours = Math.floor(totalSeconds / 3600).toString().padStart(2, "0");
|
|
55
|
+
const minutes = Math.floor(totalSeconds % 3600 / 60).toString().padStart(2, "0");
|
|
56
|
+
const seconds = (totalSeconds % 60).toString().padStart(2, "0");
|
|
57
|
+
return `${hours}:${minutes}:${seconds}`;
|
|
58
|
+
}
|
|
59
|
+
__name(formatExcelTimeSerial, "formatExcelTimeSerial");
|
|
47
60
|
const _TimeInterface = class _TimeInterface extends import_base_interface.BaseInterface {
|
|
48
61
|
toValue(value, ctx) {
|
|
62
|
+
if (isNumeric(value)) {
|
|
63
|
+
return formatExcelTimeSerial(value);
|
|
64
|
+
}
|
|
49
65
|
if (this.validate(value)) {
|
|
50
66
|
const result = (0, import_dayjs.default)(value).format("HH:mm:ss");
|
|
51
67
|
return result;
|
|
@@ -42,7 +42,7 @@ const _ToOneInterface = class _ToOneInterface extends import_base_interface.Base
|
|
|
42
42
|
const { filterKey, associationField, targetCollection, transaction } = ctx;
|
|
43
43
|
const targetInstance = await targetCollection.repository.findOne({
|
|
44
44
|
filter: {
|
|
45
|
-
[filterKey]: str
|
|
45
|
+
[filterKey]: str.toString()
|
|
46
46
|
},
|
|
47
47
|
transaction
|
|
48
48
|
});
|
package/lib/operators/date.js
CHANGED
|
@@ -47,6 +47,14 @@ function isDate(input) {
|
|
|
47
47
|
return input instanceof Date || Object.prototype.toString.call(input) === "[object Date]";
|
|
48
48
|
}
|
|
49
49
|
__name(isDate, "isDate");
|
|
50
|
+
function isDatetimeNoTzField(field) {
|
|
51
|
+
return (field == null ? void 0 : field.type) === "datetimeNoTz" || (field == null ? void 0 : field.constructor.name) === "DatetimeNoTzField";
|
|
52
|
+
}
|
|
53
|
+
__name(isDatetimeNoTzField, "isDatetimeNoTzField");
|
|
54
|
+
function isDateOnlyField(field) {
|
|
55
|
+
return (field == null ? void 0 : field.type) === "dateOnly" || (field == null ? void 0 : field.constructor.name) === "DateOnlyField";
|
|
56
|
+
}
|
|
57
|
+
__name(isDateOnlyField, "isDateOnlyField");
|
|
50
58
|
const toDate = /* @__PURE__ */ __name((date, options = {}) => {
|
|
51
59
|
const { ctx } = options;
|
|
52
60
|
let val = isDate(date) ? date : new Date(date);
|
|
@@ -57,10 +65,10 @@ const toDate = /* @__PURE__ */ __name((date, options = {}) => {
|
|
|
57
65
|
if (field.constructor.name === "UnixTimestampField") {
|
|
58
66
|
val = field.dateToValue(val);
|
|
59
67
|
}
|
|
60
|
-
if (field
|
|
68
|
+
if (isDatetimeNoTzField(field)) {
|
|
61
69
|
val = (0, import_moment.default)(val).utcOffset("+00:00").format("YYYY-MM-DD HH:mm:ss");
|
|
62
70
|
}
|
|
63
|
-
if (field
|
|
71
|
+
if (isDateOnlyField(field)) {
|
|
64
72
|
val = import_moment.default.utc(val).format("YYYY-MM-DD HH:mm:ss");
|
|
65
73
|
}
|
|
66
74
|
const eventObj = {
|
|
@@ -75,10 +83,10 @@ function parseDateTimezone(ctx) {
|
|
|
75
83
|
if (!field) {
|
|
76
84
|
return ctx.db.options.timezone;
|
|
77
85
|
}
|
|
78
|
-
if (field
|
|
86
|
+
if (isDatetimeNoTzField(field)) {
|
|
79
87
|
return "+00:00";
|
|
80
88
|
}
|
|
81
|
-
if (field
|
|
89
|
+
if (isDateOnlyField(field)) {
|
|
82
90
|
return "+00:00";
|
|
83
91
|
}
|
|
84
92
|
return ctx.db.options.timezone;
|
package/lib/options-parser.d.ts
CHANGED
|
@@ -22,6 +22,7 @@ export declare class OptionsParser {
|
|
|
22
22
|
model: ModelStatic<any>;
|
|
23
23
|
filterParser: FilterParser;
|
|
24
24
|
context: OptionsParserContext;
|
|
25
|
+
associationNotFoundWarnings: string[];
|
|
25
26
|
constructor(options: FindOptions, context: OptionsParserContext);
|
|
26
27
|
static appendInheritInspectAttribute(include: any, collection: any): any;
|
|
27
28
|
isAssociation(key: string): boolean;
|