@nocobase/database 1.4.0-alpha.20240906133133 → 1.4.0-alpha.20240911231734
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 +3 -2
- package/lib/collection.js +6 -0
- package/lib/database.d.ts +3 -3
- package/lib/database.js +2 -2
- package/lib/fields/date-field.d.ts +7 -2
- package/lib/fields/date-field.js +89 -0
- package/lib/fields/date-only-field.d.ts +15 -0
- package/lib/fields/date-only-field.js +45 -0
- package/lib/fields/datetime-field.d.ts +15 -0
- package/lib/fields/datetime-field.js +41 -0
- package/lib/fields/datetime-no-tz-field.d.ts +24 -0
- package/lib/fields/datetime-no-tz-field.js +128 -0
- package/lib/fields/datetime-tz-field.d.ts +15 -0
- package/lib/fields/datetime-tz-field.js +41 -0
- package/lib/fields/field.d.ts +1 -1
- package/lib/fields/field.js +3 -2
- package/lib/fields/index.d.ts +10 -1
- package/lib/fields/index.js +11 -1
- package/lib/fields/unix-timestamp-field.d.ts +22 -0
- package/lib/fields/unix-timestamp-field.js +94 -0
- package/lib/model.d.ts +1 -0
- package/lib/model.js +12 -0
- package/lib/operators/date.js +65 -24
- package/lib/options-parser.d.ts +1 -0
- package/lib/options-parser.js +24 -7
- package/lib/relation-repository/hasmany-repository.js +8 -11
- package/lib/relation-repository/multiple-relation-repository.d.ts +1 -0
- package/lib/relation-repository/multiple-relation-repository.js +11 -3
- package/lib/relation-repository/relation-repository.d.ts +6 -3
- package/lib/relation-repository/relation-repository.js +22 -2
- package/lib/repository.d.ts +5 -2
- package/lib/repository.js +27 -16
- package/lib/update-associations.d.ts +2 -1
- package/lib/view/field-type-map.d.ts +2 -2
- package/lib/view/field-type-map.js +17 -17
- package/package.json +4 -4
package/lib/collection.d.ts
CHANGED
|
@@ -38,7 +38,7 @@ export interface CollectionOptions extends Omit<ModelOptions, 'name' | 'hooks'>
|
|
|
38
38
|
inherits?: string[] | string;
|
|
39
39
|
viewName?: string;
|
|
40
40
|
writableView?: boolean;
|
|
41
|
-
filterTargetKey?: string;
|
|
41
|
+
filterTargetKey?: string | string[];
|
|
42
42
|
fields?: FieldOptions[];
|
|
43
43
|
model?: string | ModelStatic<Model>;
|
|
44
44
|
repository?: string | RepositoryType;
|
|
@@ -77,7 +77,8 @@ export declare class Collection<TModelAttributes extends {} = any, TCreationAttr
|
|
|
77
77
|
model: ModelStatic<Model>;
|
|
78
78
|
repository: Repository<TModelAttributes, TCreationAttributes>;
|
|
79
79
|
constructor(options: CollectionOptions, context: CollectionContext);
|
|
80
|
-
get filterTargetKey(): string;
|
|
80
|
+
get filterTargetKey(): string | string[];
|
|
81
|
+
isMultiFilterTargetKey(): boolean;
|
|
81
82
|
get name(): string;
|
|
82
83
|
get origin(): string;
|
|
83
84
|
get titleField(): string;
|
package/lib/collection.js
CHANGED
|
@@ -111,6 +111,9 @@ const _Collection = class _Collection extends import_events.EventEmitter {
|
|
|
111
111
|
get filterTargetKey() {
|
|
112
112
|
var _a;
|
|
113
113
|
const targetKey = (_a = this.options) == null ? void 0 : _a.filterTargetKey;
|
|
114
|
+
if (Array.isArray(targetKey)) {
|
|
115
|
+
return targetKey;
|
|
116
|
+
}
|
|
114
117
|
if (targetKey && this.model.getAttributes()[targetKey]) {
|
|
115
118
|
return targetKey;
|
|
116
119
|
}
|
|
@@ -119,6 +122,9 @@ const _Collection = class _Collection extends import_events.EventEmitter {
|
|
|
119
122
|
}
|
|
120
123
|
return this.model.primaryKeyAttribute;
|
|
121
124
|
}
|
|
125
|
+
isMultiFilterTargetKey() {
|
|
126
|
+
return Array.isArray(this.filterTargetKey) && this.filterTargetKey.length > 1;
|
|
127
|
+
}
|
|
122
128
|
get name() {
|
|
123
129
|
return this.options.name;
|
|
124
130
|
}
|
package/lib/database.d.ts
CHANGED
|
@@ -28,7 +28,7 @@ import { Model } from './model';
|
|
|
28
28
|
import { ModelHook } from './model-hook';
|
|
29
29
|
import QueryInterface from './query-interface/query-interface';
|
|
30
30
|
import { RelationRepository } from './relation-repository/relation-repository';
|
|
31
|
-
import { Repository } from './repository';
|
|
31
|
+
import { Repository, TargetKey } from './repository';
|
|
32
32
|
import { AfterDefineCollectionListener, BeforeDefineCollectionListener, CreateListener, CreateWithAssociationsListener, DatabaseAfterDefineCollectionEventType, DatabaseAfterRemoveCollectionEventType, DatabaseBeforeDefineCollectionEventType, DatabaseBeforeRemoveCollectionEventType, DestroyListener, EventType, ModelCreateEventTypes, ModelCreateWithAssociationsEventTypes, ModelDestroyEventTypes, ModelSaveEventTypes, ModelSaveWithAssociationsEventTypes, ModelUpdateEventTypes, ModelUpdateWithAssociationsEventTypes, ModelValidateEventTypes, RemoveCollectionListener, SaveListener, SaveWithAssociationsListener, SyncListener, UpdateListener, UpdateWithAssociationsListener, ValidateListener } from './types';
|
|
33
33
|
import { BaseValueParser } from './value-parsers';
|
|
34
34
|
export type MergeOptions = merge.Options;
|
|
@@ -153,8 +153,8 @@ export declare class Database extends EventEmitter implements AsyncEmitter {
|
|
|
153
153
|
removeCollection(name: string): Collection<any, any>;
|
|
154
154
|
getModel<M extends Model>(name: string): ModelStatic<M>;
|
|
155
155
|
getRepository<R extends Repository>(name: string): R;
|
|
156
|
-
getRepository<R extends RelationRepository>(name: string, relationId:
|
|
157
|
-
getRepository<R extends ArrayFieldRepository>(name: string, relationId:
|
|
156
|
+
getRepository<R extends RelationRepository>(name: string, relationId: TargetKey): R;
|
|
157
|
+
getRepository<R extends ArrayFieldRepository>(name: string, relationId: TargetKey): R;
|
|
158
158
|
/**
|
|
159
159
|
* @internal
|
|
160
160
|
*/
|
package/lib/database.js
CHANGED
|
@@ -64,7 +64,6 @@ var import_database_utils = __toESM(require("./database-utils"));
|
|
|
64
64
|
var import_references_map = __toESM(require("./features/references-map"));
|
|
65
65
|
var import_referential_integrity_check = require("./features/referential-integrity-check");
|
|
66
66
|
var FieldTypes = __toESM(require("./fields"));
|
|
67
|
-
var import_helpers = require("./helpers");
|
|
68
67
|
var import_inherited_collection = require("./inherited-collection");
|
|
69
68
|
var import_inherited_map = __toESM(require("./inherited-map"));
|
|
70
69
|
var import_interface_manager = require("./interface-manager");
|
|
@@ -159,6 +158,7 @@ const _Database = class _Database extends import_events.EventEmitter {
|
|
|
159
158
|
opts.storage = (0, import_path.resolve)(process.cwd(), options.storage);
|
|
160
159
|
}
|
|
161
160
|
}
|
|
161
|
+
opts.rawTimezone = opts.timezone;
|
|
162
162
|
if (options.dialect === "sqlite") {
|
|
163
163
|
delete opts.timezone;
|
|
164
164
|
} else if (!opts.timezone) {
|
|
@@ -661,7 +661,7 @@ const _Database = class _Database extends import_events.EventEmitter {
|
|
|
661
661
|
* @internal
|
|
662
662
|
*/
|
|
663
663
|
async checkVersion() {
|
|
664
|
-
return
|
|
664
|
+
return true;
|
|
665
665
|
}
|
|
666
666
|
/**
|
|
667
667
|
* @internal
|
|
@@ -6,15 +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 { DataTypes } from 'sequelize';
|
|
10
9
|
import { BaseColumnFieldOptions, Field } from './field';
|
|
11
10
|
export declare class DateField extends Field {
|
|
12
|
-
get dataType():
|
|
11
|
+
get dataType(): any;
|
|
13
12
|
get timezone(): string;
|
|
14
13
|
getProps(): any;
|
|
15
14
|
isDateOnly(): boolean;
|
|
16
15
|
isGMT(): any;
|
|
16
|
+
init(): void;
|
|
17
|
+
setter(value: any, options: any): any;
|
|
18
|
+
additionalSequelizeOptions(): {
|
|
19
|
+
get(): any;
|
|
20
|
+
};
|
|
17
21
|
bind(): void;
|
|
22
|
+
unbind(): void;
|
|
18
23
|
}
|
|
19
24
|
export interface DateFieldOptions extends BaseColumnFieldOptions {
|
|
20
25
|
type: 'date';
|
package/lib/fields/date-field.js
CHANGED
|
@@ -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 date_field_exports = {};
|
|
29
39
|
__export(date_field_exports, {
|
|
@@ -32,6 +42,12 @@ __export(date_field_exports, {
|
|
|
32
42
|
module.exports = __toCommonJS(date_field_exports);
|
|
33
43
|
var import_sequelize = require("sequelize");
|
|
34
44
|
var import_field = require("./field");
|
|
45
|
+
var import_moment = __toESM(require("moment"));
|
|
46
|
+
const datetimeRegex = /^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/;
|
|
47
|
+
function isValidDatetime(str) {
|
|
48
|
+
return datetimeRegex.test(str);
|
|
49
|
+
}
|
|
50
|
+
__name(isValidDatetime, "isValidDatetime");
|
|
35
51
|
const _DateField = class _DateField extends import_field.Field {
|
|
36
52
|
get dataType() {
|
|
37
53
|
return import_sequelize.DataTypes.DATE(3);
|
|
@@ -51,6 +67,69 @@ const _DateField = class _DateField extends import_field.Field {
|
|
|
51
67
|
const props = this.getProps();
|
|
52
68
|
return props.gmt;
|
|
53
69
|
}
|
|
70
|
+
init() {
|
|
71
|
+
const { name, defaultToCurrentTime, onUpdateToCurrentTime, timezone } = this.options;
|
|
72
|
+
this.resolveTimeZone = (context) => {
|
|
73
|
+
const serverTimeZone = this.database.options.rawTimezone;
|
|
74
|
+
if (timezone === "server") {
|
|
75
|
+
return serverTimeZone;
|
|
76
|
+
}
|
|
77
|
+
if (timezone === "client") {
|
|
78
|
+
return (context == null ? void 0 : context.timezone) || serverTimeZone;
|
|
79
|
+
}
|
|
80
|
+
if (timezone) {
|
|
81
|
+
return timezone;
|
|
82
|
+
}
|
|
83
|
+
return serverTimeZone;
|
|
84
|
+
};
|
|
85
|
+
this.beforeSave = async (instance, options) => {
|
|
86
|
+
const value = instance.get(name);
|
|
87
|
+
if (!value && instance.isNewRecord && defaultToCurrentTime) {
|
|
88
|
+
instance.set(name, /* @__PURE__ */ new Date());
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
if (onUpdateToCurrentTime) {
|
|
92
|
+
instance.set(name, /* @__PURE__ */ new Date());
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
if (this.options.defaultValue && this.database.isMySQLCompatibleDialect()) {
|
|
97
|
+
if (typeof this.options.defaultValue === "string" && isIso8601(this.options.defaultValue)) {
|
|
98
|
+
this.options.defaultValue = (0, import_moment.default)(this.options.defaultValue).utcOffset(this.resolveTimeZone()).format("YYYY-MM-DD HH:mm:ss");
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
setter(value, options) {
|
|
103
|
+
if (value === null) {
|
|
104
|
+
return value;
|
|
105
|
+
}
|
|
106
|
+
if (value instanceof Date) {
|
|
107
|
+
return value;
|
|
108
|
+
}
|
|
109
|
+
if (typeof value === "string" && isValidDatetime(value)) {
|
|
110
|
+
const dateTimezone = this.resolveTimeZone(options == null ? void 0 : options.context);
|
|
111
|
+
const dateString = `${value} ${dateTimezone}`;
|
|
112
|
+
return new Date(dateString);
|
|
113
|
+
}
|
|
114
|
+
return value;
|
|
115
|
+
}
|
|
116
|
+
additionalSequelizeOptions() {
|
|
117
|
+
const { name } = this.options;
|
|
118
|
+
const serverTimeZone = this.database.options.rawTimezone;
|
|
119
|
+
return {
|
|
120
|
+
get() {
|
|
121
|
+
const value = this.getDataValue(name);
|
|
122
|
+
if (value === null || value === void 0) {
|
|
123
|
+
return value;
|
|
124
|
+
}
|
|
125
|
+
if (typeof value === "string" && isValidDatetime(value)) {
|
|
126
|
+
const dateString = `${value} ${serverTimeZone}`;
|
|
127
|
+
return new Date(dateString);
|
|
128
|
+
}
|
|
129
|
+
return new Date(value);
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
}
|
|
54
133
|
bind() {
|
|
55
134
|
super.bind();
|
|
56
135
|
if (this.options.interface === "createdAt") {
|
|
@@ -63,10 +142,20 @@ const _DateField = class _DateField extends import_field.Field {
|
|
|
63
142
|
model._timestampAttributes.updatedAt = this.name;
|
|
64
143
|
model.refreshAttributes();
|
|
65
144
|
}
|
|
145
|
+
this.on("beforeSave", this.beforeSave);
|
|
146
|
+
}
|
|
147
|
+
unbind() {
|
|
148
|
+
super.unbind();
|
|
149
|
+
this.off("beforeSave", this.beforeSave);
|
|
66
150
|
}
|
|
67
151
|
};
|
|
68
152
|
__name(_DateField, "DateField");
|
|
69
153
|
let DateField = _DateField;
|
|
154
|
+
function isIso8601(str) {
|
|
155
|
+
const iso8601StrictRegex = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/;
|
|
156
|
+
return iso8601StrictRegex.test(str);
|
|
157
|
+
}
|
|
158
|
+
__name(isIso8601, "isIso8601");
|
|
70
159
|
// Annotate the CommonJS export names for ESM import in node:
|
|
71
160
|
0 && (module.exports = {
|
|
72
161
|
DateField
|
|
@@ -0,0 +1,15 @@
|
|
|
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 { BaseColumnFieldOptions, Field } from './field';
|
|
10
|
+
export declare class DateOnlyField extends Field {
|
|
11
|
+
get dataType(): any;
|
|
12
|
+
}
|
|
13
|
+
export interface DateOnlyFieldOptions extends BaseColumnFieldOptions {
|
|
14
|
+
type: 'dateOnly';
|
|
15
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
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_only_field_exports = {};
|
|
29
|
+
__export(date_only_field_exports, {
|
|
30
|
+
DateOnlyField: () => DateOnlyField
|
|
31
|
+
});
|
|
32
|
+
module.exports = __toCommonJS(date_only_field_exports);
|
|
33
|
+
var import_field = require("./field");
|
|
34
|
+
var import_sequelize = require("sequelize");
|
|
35
|
+
const _DateOnlyField = class _DateOnlyField extends import_field.Field {
|
|
36
|
+
get dataType() {
|
|
37
|
+
return import_sequelize.DataTypes.DATEONLY;
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
__name(_DateOnlyField, "DateOnlyField");
|
|
41
|
+
let DateOnlyField = _DateOnlyField;
|
|
42
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
43
|
+
0 && (module.exports = {
|
|
44
|
+
DateOnlyField
|
|
45
|
+
});
|
|
@@ -0,0 +1,15 @@
|
|
|
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 { DateField } from './date-field';
|
|
10
|
+
import { BaseColumnFieldOptions } from './field';
|
|
11
|
+
export declare class DatetimeField extends DateField {
|
|
12
|
+
}
|
|
13
|
+
export interface DatetimeFieldOptions extends BaseColumnFieldOptions {
|
|
14
|
+
type: 'datetime';
|
|
15
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
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 datetime_field_exports = {};
|
|
29
|
+
__export(datetime_field_exports, {
|
|
30
|
+
DatetimeField: () => DatetimeField
|
|
31
|
+
});
|
|
32
|
+
module.exports = __toCommonJS(datetime_field_exports);
|
|
33
|
+
var import_date_field = require("./date-field");
|
|
34
|
+
const _DatetimeField = class _DatetimeField extends import_date_field.DateField {
|
|
35
|
+
};
|
|
36
|
+
__name(_DatetimeField, "DatetimeField");
|
|
37
|
+
let DatetimeField = _DatetimeField;
|
|
38
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
39
|
+
0 && (module.exports = {
|
|
40
|
+
DatetimeField
|
|
41
|
+
});
|
|
@@ -0,0 +1,24 @@
|
|
|
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 { BaseColumnFieldOptions, Field } from './field';
|
|
10
|
+
import { DataTypes } from 'sequelize';
|
|
11
|
+
declare class DatetimeNoTzTypeMySQL extends DataTypes.ABSTRACT {
|
|
12
|
+
key: string;
|
|
13
|
+
}
|
|
14
|
+
export declare class DatetimeNoTzField extends Field {
|
|
15
|
+
get dataType(): typeof DatetimeNoTzTypeMySQL;
|
|
16
|
+
init(): void;
|
|
17
|
+
additionalSequelizeOptions(): {};
|
|
18
|
+
bind(): void;
|
|
19
|
+
unbind(): void;
|
|
20
|
+
}
|
|
21
|
+
export interface DatetimeNoTzFieldOptions extends BaseColumnFieldOptions {
|
|
22
|
+
type: 'datetimeNoTz';
|
|
23
|
+
}
|
|
24
|
+
export {};
|
|
@@ -0,0 +1,128 @@
|
|
|
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_field_exports = {};
|
|
39
|
+
__export(datetime_no_tz_field_exports, {
|
|
40
|
+
DatetimeNoTzField: () => DatetimeNoTzField
|
|
41
|
+
});
|
|
42
|
+
module.exports = __toCommonJS(datetime_no_tz_field_exports);
|
|
43
|
+
var import_field = require("./field");
|
|
44
|
+
var import_sequelize = require("sequelize");
|
|
45
|
+
var import_moment = __toESM(require("moment"));
|
|
46
|
+
const _DatetimeNoTzTypeMySQL = class _DatetimeNoTzTypeMySQL extends import_sequelize.DataTypes.ABSTRACT {
|
|
47
|
+
key = "DATETIME";
|
|
48
|
+
};
|
|
49
|
+
__name(_DatetimeNoTzTypeMySQL, "DatetimeNoTzTypeMySQL");
|
|
50
|
+
let DatetimeNoTzTypeMySQL = _DatetimeNoTzTypeMySQL;
|
|
51
|
+
const _DatetimeNoTzTypePostgres = class _DatetimeNoTzTypePostgres extends import_sequelize.DataTypes.ABSTRACT {
|
|
52
|
+
key = "TIMESTAMP";
|
|
53
|
+
};
|
|
54
|
+
__name(_DatetimeNoTzTypePostgres, "DatetimeNoTzTypePostgres");
|
|
55
|
+
let DatetimeNoTzTypePostgres = _DatetimeNoTzTypePostgres;
|
|
56
|
+
const _DatetimeNoTzField = class _DatetimeNoTzField extends import_field.Field {
|
|
57
|
+
get dataType() {
|
|
58
|
+
if (this.database.inDialect("postgres")) {
|
|
59
|
+
return DatetimeNoTzTypePostgres;
|
|
60
|
+
}
|
|
61
|
+
if (this.database.isMySQLCompatibleDialect()) {
|
|
62
|
+
return DatetimeNoTzTypeMySQL;
|
|
63
|
+
}
|
|
64
|
+
return import_sequelize.DataTypes.STRING;
|
|
65
|
+
}
|
|
66
|
+
init() {
|
|
67
|
+
const { name, defaultToCurrentTime, onUpdateToCurrentTime } = this.options;
|
|
68
|
+
this.beforeSave = async (instance, options) => {
|
|
69
|
+
const value = instance.get(name);
|
|
70
|
+
if (!value && instance.isNewRecord && defaultToCurrentTime) {
|
|
71
|
+
instance.set(name, /* @__PURE__ */ new Date());
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
if (onUpdateToCurrentTime) {
|
|
75
|
+
instance.set(name, /* @__PURE__ */ new Date());
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
additionalSequelizeOptions() {
|
|
81
|
+
const { name } = this.options;
|
|
82
|
+
const timezone = this.database.options.rawTimezone || "+00:00";
|
|
83
|
+
const isPg = this.database.inDialect("postgres");
|
|
84
|
+
return {
|
|
85
|
+
get() {
|
|
86
|
+
const val = this.getDataValue(name);
|
|
87
|
+
if (val instanceof Date) {
|
|
88
|
+
if (isPg) {
|
|
89
|
+
return (0, import_moment.default)(val).format("YYYY-MM-DD HH:mm:ss");
|
|
90
|
+
}
|
|
91
|
+
const momentVal = (0, import_moment.default)(val).utcOffset(timezone);
|
|
92
|
+
return momentVal.format("YYYY-MM-DD HH:mm:ss");
|
|
93
|
+
}
|
|
94
|
+
return val;
|
|
95
|
+
},
|
|
96
|
+
set(val) {
|
|
97
|
+
if (typeof val === "string" && isIso8601(val)) {
|
|
98
|
+
const momentVal = (0, import_moment.default)(val).utcOffset(timezone);
|
|
99
|
+
val = momentVal.format("YYYY-MM-DD HH:mm:ss");
|
|
100
|
+
}
|
|
101
|
+
if (val && val instanceof Date) {
|
|
102
|
+
const momentVal = (0, import_moment.default)(val).utcOffset(timezone);
|
|
103
|
+
val = momentVal.format("YYYY-MM-DD HH:mm:ss");
|
|
104
|
+
}
|
|
105
|
+
return this.setDataValue(name, val);
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
bind() {
|
|
110
|
+
super.bind();
|
|
111
|
+
this.on("beforeSave", this.beforeSave);
|
|
112
|
+
}
|
|
113
|
+
unbind() {
|
|
114
|
+
super.unbind();
|
|
115
|
+
this.off("beforeSave", this.beforeSave);
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
__name(_DatetimeNoTzField, "DatetimeNoTzField");
|
|
119
|
+
let DatetimeNoTzField = _DatetimeNoTzField;
|
|
120
|
+
function isIso8601(str) {
|
|
121
|
+
const iso8601StrictRegex = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/;
|
|
122
|
+
return iso8601StrictRegex.test(str);
|
|
123
|
+
}
|
|
124
|
+
__name(isIso8601, "isIso8601");
|
|
125
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
126
|
+
0 && (module.exports = {
|
|
127
|
+
DatetimeNoTzField
|
|
128
|
+
});
|
|
@@ -0,0 +1,15 @@
|
|
|
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 { DateField } from './date-field';
|
|
10
|
+
import { BaseColumnFieldOptions } from './field';
|
|
11
|
+
export declare class DatetimeTzField extends DateField {
|
|
12
|
+
}
|
|
13
|
+
export interface DatetimeTzFieldOptions extends BaseColumnFieldOptions {
|
|
14
|
+
type: 'datetimeTz';
|
|
15
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
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 datetime_tz_field_exports = {};
|
|
29
|
+
__export(datetime_tz_field_exports, {
|
|
30
|
+
DatetimeTzField: () => DatetimeTzField
|
|
31
|
+
});
|
|
32
|
+
module.exports = __toCommonJS(datetime_tz_field_exports);
|
|
33
|
+
var import_date_field = require("./date-field");
|
|
34
|
+
const _DatetimeTzField = class _DatetimeTzField extends import_date_field.DateField {
|
|
35
|
+
};
|
|
36
|
+
__name(_DatetimeTzField, "DatetimeTzField");
|
|
37
|
+
let DatetimeTzField = _DatetimeTzField;
|
|
38
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
39
|
+
0 && (module.exports = {
|
|
40
|
+
DatetimeTzField
|
|
41
|
+
});
|
package/lib/fields/field.d.ts
CHANGED
package/lib/fields/field.js
CHANGED
|
@@ -151,10 +151,11 @@ const _Field = class _Field {
|
|
|
151
151
|
if (this.dataType) {
|
|
152
152
|
Object.assign(opts, { type: this.database.sequelize.normalizeDataType(this.dataType) });
|
|
153
153
|
}
|
|
154
|
+
Object.assign(opts, this.additionalSequelizeOptions());
|
|
154
155
|
return opts;
|
|
155
156
|
}
|
|
156
|
-
|
|
157
|
-
return
|
|
157
|
+
additionalSequelizeOptions() {
|
|
158
|
+
return {};
|
|
158
159
|
}
|
|
159
160
|
typeToString() {
|
|
160
161
|
return this.dataType.toString();
|
package/lib/fields/index.d.ts
CHANGED
|
@@ -29,12 +29,20 @@ import { UUIDFieldOptions } from './uuid-field';
|
|
|
29
29
|
import { VirtualFieldOptions } from './virtual-field';
|
|
30
30
|
import { NanoidFieldOptions } from './nanoid-field';
|
|
31
31
|
import { EncryptionField } from './encryption-field';
|
|
32
|
+
import { UnixTimestampFieldOptions } from './unix-timestamp-field';
|
|
33
|
+
import { DateOnlyFieldOptions } from './date-only-field';
|
|
34
|
+
import { DatetimeNoTzFieldOptions } from './datetime-no-tz-field';
|
|
35
|
+
import { DatetimeTzFieldOptions } from './datetime-tz-field';
|
|
32
36
|
export * from './array-field';
|
|
33
37
|
export * from './belongs-to-field';
|
|
34
38
|
export * from './belongs-to-many-field';
|
|
35
39
|
export * from './boolean-field';
|
|
36
40
|
export * from './context-field';
|
|
37
41
|
export * from './date-field';
|
|
42
|
+
export * from './datetime-field';
|
|
43
|
+
export * from './datetime-tz-field';
|
|
44
|
+
export * from './datetime-no-tz-field';
|
|
45
|
+
export * from './date-only-field';
|
|
38
46
|
export * from './field';
|
|
39
47
|
export * from './has-many-field';
|
|
40
48
|
export * from './has-one-field';
|
|
@@ -53,4 +61,5 @@ export * from './uuid-field';
|
|
|
53
61
|
export * from './virtual-field';
|
|
54
62
|
export * from './nanoid-field';
|
|
55
63
|
export * from './encryption-field';
|
|
56
|
-
export
|
|
64
|
+
export * from './unix-timestamp-field';
|
|
65
|
+
export type FieldOptions = BaseFieldOptions | StringFieldOptions | IntegerFieldOptions | FloatFieldOptions | DecimalFieldOptions | DoubleFieldOptions | RealFieldOptions | JsonFieldOptions | JsonbFieldOptions | BooleanFieldOptions | RadioFieldOptions | SortFieldOptions | TextFieldOptions | VirtualFieldOptions | ArrayFieldOptions | SetFieldOptions | TimeFieldOptions | DateFieldOptions | DatetimeTzFieldOptions | DatetimeNoTzFieldOptions | DateOnlyFieldOptions | UnixTimestampFieldOptions | UidFieldOptions | UUIDFieldOptions | NanoidFieldOptions | PasswordFieldOptions | ContextFieldOptions | BelongsToFieldOptions | HasOneFieldOptions | HasManyFieldOptions | BelongsToManyFieldOptions | EncryptionField;
|
package/lib/fields/index.js
CHANGED
|
@@ -29,6 +29,10 @@ __reExport(fields_exports, require("./belongs-to-many-field"), module.exports);
|
|
|
29
29
|
__reExport(fields_exports, require("./boolean-field"), module.exports);
|
|
30
30
|
__reExport(fields_exports, require("./context-field"), module.exports);
|
|
31
31
|
__reExport(fields_exports, require("./date-field"), module.exports);
|
|
32
|
+
__reExport(fields_exports, require("./datetime-field"), module.exports);
|
|
33
|
+
__reExport(fields_exports, require("./datetime-tz-field"), module.exports);
|
|
34
|
+
__reExport(fields_exports, require("./datetime-no-tz-field"), module.exports);
|
|
35
|
+
__reExport(fields_exports, require("./date-only-field"), module.exports);
|
|
32
36
|
__reExport(fields_exports, require("./field"), module.exports);
|
|
33
37
|
__reExport(fields_exports, require("./has-many-field"), module.exports);
|
|
34
38
|
__reExport(fields_exports, require("./has-one-field"), module.exports);
|
|
@@ -47,6 +51,7 @@ __reExport(fields_exports, require("./uuid-field"), module.exports);
|
|
|
47
51
|
__reExport(fields_exports, require("./virtual-field"), module.exports);
|
|
48
52
|
__reExport(fields_exports, require("./nanoid-field"), module.exports);
|
|
49
53
|
__reExport(fields_exports, require("./encryption-field"), module.exports);
|
|
54
|
+
__reExport(fields_exports, require("./unix-timestamp-field"), module.exports);
|
|
50
55
|
// Annotate the CommonJS export names for ESM import in node:
|
|
51
56
|
0 && (module.exports = {
|
|
52
57
|
...require("./array-field"),
|
|
@@ -55,6 +60,10 @@ __reExport(fields_exports, require("./encryption-field"), module.exports);
|
|
|
55
60
|
...require("./boolean-field"),
|
|
56
61
|
...require("./context-field"),
|
|
57
62
|
...require("./date-field"),
|
|
63
|
+
...require("./datetime-field"),
|
|
64
|
+
...require("./datetime-tz-field"),
|
|
65
|
+
...require("./datetime-no-tz-field"),
|
|
66
|
+
...require("./date-only-field"),
|
|
58
67
|
...require("./field"),
|
|
59
68
|
...require("./has-many-field"),
|
|
60
69
|
...require("./has-one-field"),
|
|
@@ -72,5 +81,6 @@ __reExport(fields_exports, require("./encryption-field"), module.exports);
|
|
|
72
81
|
...require("./uuid-field"),
|
|
73
82
|
...require("./virtual-field"),
|
|
74
83
|
...require("./nanoid-field"),
|
|
75
|
-
...require("./encryption-field")
|
|
84
|
+
...require("./encryption-field"),
|
|
85
|
+
...require("./unix-timestamp-field")
|
|
76
86
|
});
|