@nocobase/database 1.3.39-beta → 1.4.0-alpha

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.
Files changed (53) hide show
  1. package/lib/collection.d.ts +3 -2
  2. package/lib/collection.js +6 -0
  3. package/lib/database.d.ts +11 -23
  4. package/lib/database.js +21 -42
  5. package/lib/dialects/base-dialect.d.ts +20 -0
  6. package/lib/dialects/base-dialect.js +75 -0
  7. package/lib/dialects/index.d.ts +9 -0
  8. package/lib/dialects/index.js +30 -0
  9. package/lib/dialects/mariadb-dialect.d.ts +17 -0
  10. package/lib/dialects/mariadb-dialect.js +54 -0
  11. package/lib/dialects/mysql-dialect.d.ts +17 -0
  12. package/lib/dialects/mysql-dialect.js +54 -0
  13. package/lib/dialects/postgres-dialect.d.ts +18 -0
  14. package/lib/dialects/postgres-dialect.js +77 -0
  15. package/lib/dialects/sqlite-dialect.d.ts +17 -0
  16. package/lib/dialects/sqlite-dialect.js +51 -0
  17. package/lib/fields/date-field.d.ts +7 -2
  18. package/lib/fields/date-field.js +89 -0
  19. package/lib/fields/date-only-field.d.ts +15 -0
  20. package/lib/fields/date-only-field.js +45 -0
  21. package/lib/fields/datetime-field.d.ts +15 -0
  22. package/lib/fields/datetime-field.js +41 -0
  23. package/lib/fields/datetime-no-tz-field.d.ts +24 -0
  24. package/lib/fields/datetime-no-tz-field.js +128 -0
  25. package/lib/fields/datetime-tz-field.d.ts +15 -0
  26. package/lib/fields/datetime-tz-field.js +41 -0
  27. package/lib/fields/field.d.ts +1 -1
  28. package/lib/fields/field.js +3 -2
  29. package/lib/fields/index.d.ts +10 -1
  30. package/lib/fields/index.js +11 -1
  31. package/lib/fields/unix-timestamp-field.d.ts +22 -0
  32. package/lib/fields/unix-timestamp-field.js +94 -0
  33. package/lib/helpers.d.ts +2 -1
  34. package/lib/helpers.js +16 -49
  35. package/lib/index.d.ts +1 -0
  36. package/lib/index.js +3 -1
  37. package/lib/model.d.ts +1 -0
  38. package/lib/model.js +12 -0
  39. package/lib/operators/date.js +66 -24
  40. package/lib/options-parser.d.ts +1 -0
  41. package/lib/options-parser.js +32 -9
  42. package/lib/query-interface/query-interface-builder.js +3 -0
  43. package/lib/relation-repository/hasmany-repository.js +8 -11
  44. package/lib/relation-repository/multiple-relation-repository.d.ts +1 -0
  45. package/lib/relation-repository/multiple-relation-repository.js +11 -3
  46. package/lib/relation-repository/relation-repository.d.ts +6 -3
  47. package/lib/relation-repository/relation-repository.js +27 -4
  48. package/lib/repository.d.ts +5 -2
  49. package/lib/repository.js +27 -16
  50. package/lib/update-associations.d.ts +2 -1
  51. package/lib/view/field-type-map.d.ts +2 -2
  52. package/lib/view/field-type-map.js +17 -17
  53. package/package.json +4 -4
@@ -0,0 +1,51 @@
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 __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
15
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
16
+ var __export = (target, all) => {
17
+ for (var name in all)
18
+ __defProp(target, name, { get: all[name], enumerable: true });
19
+ };
20
+ var __copyProps = (to, from, except, desc) => {
21
+ if (from && typeof from === "object" || typeof from === "function") {
22
+ for (let key of __getOwnPropNames(from))
23
+ if (!__hasOwnProp.call(to, key) && key !== except)
24
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
25
+ }
26
+ return to;
27
+ };
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
30
+ var sqlite_dialect_exports = {};
31
+ __export(sqlite_dialect_exports, {
32
+ SqliteDialect: () => SqliteDialect
33
+ });
34
+ module.exports = __toCommonJS(sqlite_dialect_exports);
35
+ var import_base_dialect = require("./base-dialect");
36
+ const _SqliteDialect = class _SqliteDialect extends import_base_dialect.BaseDialect {
37
+ getVersionGuard() {
38
+ return {
39
+ sql: "select sqlite_version() as version",
40
+ get: /* @__PURE__ */ __name((v) => v, "get"),
41
+ version: "3.x"
42
+ };
43
+ }
44
+ };
45
+ __name(_SqliteDialect, "SqliteDialect");
46
+ __publicField(_SqliteDialect, "dialectName", "sqlite");
47
+ let SqliteDialect = _SqliteDialect;
48
+ // Annotate the CommonJS export names for ESM import in node:
49
+ 0 && (module.exports = {
50
+ SqliteDialect
51
+ });
@@ -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(): DataTypes.DateDataType;
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';
@@ -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
+ });
@@ -47,6 +47,6 @@ export declare abstract class Field {
47
47
  bind(): void;
48
48
  unbind(): void;
49
49
  toSequelize(): any;
50
- isSqlite(): boolean;
50
+ additionalSequelizeOptions(): {};
51
51
  typeToString(): any;
52
52
  }
@@ -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
- isSqlite() {
157
- return this.database.sequelize.getDialect() === "sqlite";
157
+ additionalSequelizeOptions() {
158
+ return {};
158
159
  }
159
160
  typeToString() {
160
161
  return this.dataType.toString();
@@ -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 type FieldOptions = BaseFieldOptions | StringFieldOptions | IntegerFieldOptions | FloatFieldOptions | DecimalFieldOptions | DoubleFieldOptions | RealFieldOptions | JsonFieldOptions | JsonbFieldOptions | BooleanFieldOptions | RadioFieldOptions | SortFieldOptions | TextFieldOptions | VirtualFieldOptions | ArrayFieldOptions | SetFieldOptions | TimeFieldOptions | DateFieldOptions | UidFieldOptions | UUIDFieldOptions | NanoidFieldOptions | PasswordFieldOptions | ContextFieldOptions | BelongsToFieldOptions | HasOneFieldOptions | HasManyFieldOptions | BelongsToManyFieldOptions | EncryptionField;
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;
@@ -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
  });
@@ -0,0 +1,22 @@
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 { DataTypes } from 'sequelize';
10
+ import { DateField } from './date-field';
11
+ import { BaseColumnFieldOptions } from './field';
12
+ export declare class UnixTimestampField extends DateField {
13
+ get dataType(): DataTypes.BigIntDataTypeConstructor;
14
+ dateToValue(val: any): any;
15
+ additionalSequelizeOptions(): {
16
+ get(): any;
17
+ set(value: any): void;
18
+ };
19
+ }
20
+ export interface UnixTimestampFieldOptions extends BaseColumnFieldOptions {
21
+ type: 'unixTimestamp';
22
+ }