@nocobase/database 1.4.0-alpha.0 → 1.4.0-alpha.10

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/README.md ADDED
@@ -0,0 +1,30 @@
1
+ # NocoBase
2
+
3
+ <video width="100%" controls>
4
+ <source src="https://static-docs.nocobase.com/NocoBase0510.mp4" type="video/mp4">
5
+ </video>
6
+
7
+
8
+ ## What is NocoBase
9
+
10
+ NocoBase is a scalability-first, open-source no-code development platform.
11
+ Instead of investing years of time and millions of dollars in research and development, deploy NocoBase in a few minutes and you'll have a private, controllable, and extremely scalable no-code development platform!
12
+
13
+ Homepage:
14
+ https://www.nocobase.com/
15
+
16
+ Online Demo:
17
+ https://demo.nocobase.com/new
18
+
19
+ Documents:
20
+ https://docs.nocobase.com/
21
+
22
+ Commericial license & plugins:
23
+ https://www.nocobase.com/en/commercial
24
+
25
+ License agreement:
26
+ https://www.nocobase.com/en/agreement
27
+
28
+
29
+ ## Contact Us:
30
+ hello@nocobase.com
@@ -95,6 +95,7 @@ export declare class Collection<TModelAttributes extends {} = any, TCreationAttr
95
95
  findField(callback: (field: Field) => boolean): any;
96
96
  hasField(name: string): boolean;
97
97
  getField<F extends Field>(name: string): F;
98
+ getFieldByField(field: string): Field;
98
99
  getFields(): any[];
99
100
  addField(name: string, options: FieldOptions): Field;
100
101
  checkFieldType(name: string, options: FieldOptions): void;
@@ -138,7 +139,7 @@ export declare class Collection<TModelAttributes extends {} = any, TCreationAttr
138
139
  quotedTableName(): any;
139
140
  collectionSchema(): string;
140
141
  isView(): boolean;
141
- unavailableActions(): string[];
142
+ unavailableActions(): any[];
142
143
  protected sequelizeModelOptions(): {
143
144
  modelName: string;
144
145
  sequelize: import("sequelize").Sequelize;
package/lib/collection.js CHANGED
@@ -113,6 +113,9 @@ const _Collection = class _Collection extends import_events.EventEmitter {
113
113
  var _a;
114
114
  const targetKey = (_a = this.options) == null ? void 0 : _a.filterTargetKey;
115
115
  if (Array.isArray(targetKey)) {
116
+ if (targetKey.length === 1) {
117
+ return targetKey[0];
118
+ }
116
119
  return targetKey;
117
120
  }
118
121
  if (targetKey && this.model.getAttributes()[targetKey]) {
@@ -258,6 +261,9 @@ const _Collection = class _Collection extends import_events.EventEmitter {
258
261
  getField(name) {
259
262
  return this.fields.get(name);
260
263
  }
264
+ getFieldByField(field) {
265
+ return this.findField((f) => f.options.field === field);
266
+ }
261
267
  getFields() {
262
268
  return [...this.fields.values()];
263
269
  }
@@ -684,9 +690,6 @@ const _Collection = class _Collection extends import_events.EventEmitter {
684
690
  return false;
685
691
  }
686
692
  unavailableActions() {
687
- if (this.options.template === "file") {
688
- return ["create", "update", "destroy"];
689
- }
690
693
  return [];
691
694
  }
692
695
  sequelizeModelOptions() {
package/lib/database.d.ts CHANGED
@@ -78,6 +78,7 @@ export declare class Database extends EventEmitter implements AsyncEmitter {
78
78
  repositories: Map<string, typeof Repository>;
79
79
  operators: Map<any, any>;
80
80
  collections: Map<string, Collection<any, any>>;
81
+ collectionsSort: Map<string, number>;
81
82
  pendingFields: Map<string, FieldTypes.RelationField[]>;
82
83
  modelCollection: Map<ModelStatic<any>, Collection<any, any>>;
83
84
  modelNameCollectionMap: Map<string, Collection<any, any>>;
package/lib/database.js CHANGED
@@ -88,6 +88,7 @@ const _Database = class _Database extends import_events.EventEmitter {
88
88
  repositories = /* @__PURE__ */ new Map();
89
89
  operators = /* @__PURE__ */ new Map();
90
90
  collections = /* @__PURE__ */ new Map();
91
+ collectionsSort = /* @__PURE__ */ new Map();
91
92
  pendingFields = /* @__PURE__ */ new Map();
92
93
  modelCollection = /* @__PURE__ */ new Map();
93
94
  modelNameCollectionMap = /* @__PURE__ */ new Map();
@@ -0,0 +1,4 @@
1
+ import { DatetimeInterface } from './datetime-interface';
2
+ export declare class DateInterface extends DatetimeInterface {
3
+ toString(value: any, ctx?: any): any;
4
+ }
@@ -0,0 +1,44 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+
10
+ var __defProp = Object.defineProperty;
11
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
12
+ var __getOwnPropNames = Object.getOwnPropertyNames;
13
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
14
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
15
+ var __export = (target, all) => {
16
+ for (var name in all)
17
+ __defProp(target, name, { get: all[name], enumerable: true });
18
+ };
19
+ var __copyProps = (to, from, except, desc) => {
20
+ if (from && typeof from === "object" || typeof from === "function") {
21
+ for (let key of __getOwnPropNames(from))
22
+ if (!__hasOwnProp.call(to, key) && key !== except)
23
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
24
+ }
25
+ return to;
26
+ };
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+ var date_interface_exports = {};
29
+ __export(date_interface_exports, {
30
+ DateInterface: () => DateInterface
31
+ });
32
+ module.exports = __toCommonJS(date_interface_exports);
33
+ var import_datetime_interface = require("./datetime-interface");
34
+ const _DateInterface = class _DateInterface extends import_datetime_interface.DatetimeInterface {
35
+ toString(value, ctx) {
36
+ return value;
37
+ }
38
+ };
39
+ __name(_DateInterface, "DateInterface");
40
+ let DateInterface = _DateInterface;
41
+ // Annotate the CommonJS export names for ESM import in node:
42
+ 0 && (module.exports = {
43
+ DateInterface
44
+ });
@@ -63,7 +63,6 @@ function resolveTimeZoneFromCtx(ctx) {
63
63
  __name(resolveTimeZoneFromCtx, "resolveTimeZoneFromCtx");
64
64
  const _DatetimeInterface = class _DatetimeInterface extends import_base_interface.BaseInterface {
65
65
  async toValue(value, ctx = {}) {
66
- var _a, _b, _c;
67
66
  if (!value) {
68
67
  return null;
69
68
  }
@@ -81,11 +80,7 @@ const _DatetimeInterface = class _DatetimeInterface extends import_base_interfac
81
80
  } else if (isNumeric(value)) {
82
81
  return (0, import_excel_date_to_js.getJsDateFromExcel)(value).toISOString();
83
82
  } else if (typeof value === "string") {
84
- const props = ((_c = (_b = (_a = ctx.field) == null ? void 0 : _a.options) == null ? void 0 : _b.uiSchema) == null ? void 0 : _c["x-component-props"]) || {};
85
- const m = (0, import_dayjs.default)(value);
86
- if (m.isValid()) {
87
- return (0, import_utils.moment2str)(m, props);
88
- }
83
+ return value;
89
84
  }
90
85
  throw new Error(`Invalid date - ${value}`);
91
86
  }
@@ -0,0 +1,5 @@
1
+ import { DatetimeInterface } from './datetime-interface';
2
+ export declare class DatetimeNoTzInterface extends DatetimeInterface {
3
+ toValue(value: any, ctx?: any): Promise<any>;
4
+ toString(value: any, ctx?: any): any;
5
+ }
@@ -0,0 +1,93 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+
10
+ var __create = Object.create;
11
+ var __defProp = Object.defineProperty;
12
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
13
+ var __getOwnPropNames = Object.getOwnPropertyNames;
14
+ var __getProtoOf = Object.getPrototypeOf;
15
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
16
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
17
+ var __export = (target, all) => {
18
+ for (var name in all)
19
+ __defProp(target, name, { get: all[name], enumerable: true });
20
+ };
21
+ var __copyProps = (to, from, except, desc) => {
22
+ if (from && typeof from === "object" || typeof from === "function") {
23
+ for (let key of __getOwnPropNames(from))
24
+ if (!__hasOwnProp.call(to, key) && key !== except)
25
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
26
+ }
27
+ return to;
28
+ };
29
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
30
+ // If the importer is in node compatibility mode or this is not an ESM
31
+ // file that has been converted to a CommonJS file using a Babel-
32
+ // compatible transform (i.e. "__esModule" has not been set), then set
33
+ // "default" to the CommonJS "module.exports" for node compatibility.
34
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
35
+ mod
36
+ ));
37
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
38
+ var datetime_no_tz_interface_exports = {};
39
+ __export(datetime_no_tz_interface_exports, {
40
+ DatetimeNoTzInterface: () => DatetimeNoTzInterface
41
+ });
42
+ module.exports = __toCommonJS(datetime_no_tz_interface_exports);
43
+ var import_datetime_interface = require("./datetime-interface");
44
+ var import_dayjs = __toESM(require("dayjs"));
45
+ var import_excel_date_to_js = require("excel-date-to-js");
46
+ var import_utils = require("@nocobase/utils");
47
+ function isDate(v) {
48
+ return v instanceof Date;
49
+ }
50
+ __name(isDate, "isDate");
51
+ function isNumeric(str) {
52
+ if (typeof str === "number") return true;
53
+ if (typeof str != "string") return false;
54
+ return !isNaN(str) && !isNaN(parseFloat(str));
55
+ }
56
+ __name(isNumeric, "isNumeric");
57
+ const _DatetimeNoTzInterface = class _DatetimeNoTzInterface extends import_datetime_interface.DatetimeInterface {
58
+ async toValue(value, ctx = {}) {
59
+ if (!value) {
60
+ return null;
61
+ }
62
+ if (typeof value === "string") {
63
+ const match = /^(\d{4})[-/]?(\d{2})[-/]?(\d{2})$/.exec(value);
64
+ if (match) {
65
+ return `${match[1]}-${match[2]}-${match[3]}`;
66
+ }
67
+ }
68
+ if (import_dayjs.default.isDayjs(value)) {
69
+ return value;
70
+ } else if (isDate(value)) {
71
+ return value;
72
+ } else if (isNumeric(value)) {
73
+ const date = (0, import_excel_date_to_js.getJsDateFromExcel)(value);
74
+ return date.toISOString();
75
+ } else if (typeof value === "string") {
76
+ return value;
77
+ }
78
+ throw new Error(`Invalid date - ${value}`);
79
+ }
80
+ toString(value, ctx) {
81
+ var _a, _b;
82
+ const props = ((_b = (_a = this.options) == null ? void 0 : _a.uiSchema) == null ? void 0 : _b["x-component-props"]) ?? {};
83
+ const format = (0, import_utils.getDefaultFormat)(props);
84
+ const m = (0, import_utils.str2moment)(value, { ...props });
85
+ return m ? m.format(format) : "";
86
+ }
87
+ };
88
+ __name(_DatetimeNoTzInterface, "DatetimeNoTzInterface");
89
+ let DatetimeNoTzInterface = _DatetimeNoTzInterface;
90
+ // Annotate the CommonJS export names for ESM import in node:
91
+ 0 && (module.exports = {
92
+ DatetimeNoTzInterface
93
+ });
@@ -11,4 +11,6 @@ export * from './percent-interface';
11
11
  export * from './multiple-select-interface';
12
12
  export * from './select-interface';
13
13
  export * from './datetime-interface';
14
+ export * from './datetime-no-tz-interface';
14
15
  export * from './boolean-interface';
16
+ export * from './date-interface';
@@ -28,7 +28,9 @@ __reExport(interfaces_exports, require("./percent-interface"), module.exports);
28
28
  __reExport(interfaces_exports, require("./multiple-select-interface"), module.exports);
29
29
  __reExport(interfaces_exports, require("./select-interface"), module.exports);
30
30
  __reExport(interfaces_exports, require("./datetime-interface"), module.exports);
31
+ __reExport(interfaces_exports, require("./datetime-no-tz-interface"), module.exports);
31
32
  __reExport(interfaces_exports, require("./boolean-interface"), module.exports);
33
+ __reExport(interfaces_exports, require("./date-interface"), module.exports);
32
34
  // Annotate the CommonJS export names for ESM import in node:
33
35
  0 && (module.exports = {
34
36
  ...require("./base-interface"),
@@ -36,5 +38,7 @@ __reExport(interfaces_exports, require("./boolean-interface"), module.exports);
36
38
  ...require("./multiple-select-interface"),
37
39
  ...require("./select-interface"),
38
40
  ...require("./datetime-interface"),
39
- ...require("./boolean-interface")
41
+ ...require("./datetime-no-tz-interface"),
42
+ ...require("./boolean-interface"),
43
+ ...require("./date-interface")
40
44
  });
@@ -36,6 +36,7 @@ const _ToManyInterface = class _ToManyInterface extends import_base_interface.Ba
36
36
  if (!str) {
37
37
  return null;
38
38
  }
39
+ str = `${str}`.trim();
39
40
  const items = str.split(",");
40
41
  const { filterKey, targetCollection, transaction } = ctx;
41
42
  const targetInstances = await targetCollection.repository.find({
@@ -45,7 +46,7 @@ const _ToManyInterface = class _ToManyInterface extends import_base_interface.Ba
45
46
  transaction
46
47
  });
47
48
  items.forEach((item) => {
48
- if (!targetInstances.find((targetInstance) => targetInstance[filterKey] === item)) {
49
+ if (!targetInstances.find((targetInstance) => targetInstance[filterKey] == item)) {
49
50
  throw new Error(`"${item}" not found in ${targetCollection.model.name} ${filterKey}`);
50
51
  }
51
52
  });
@@ -51,6 +51,9 @@ const interfaces = {
51
51
  radioGroup: import_index.SelectInterface,
52
52
  percent: import_index.PercentInterface,
53
53
  datetime: import_index.DatetimeInterface,
54
+ datetimeNoTz: import_index.DatetimeNoTzInterface,
55
+ unixTimestamp: import_index.DatetimeInterface,
56
+ date: import_index.DateInterface,
54
57
  createdAt: import_index.DatetimeInterface,
55
58
  updatedAt: import_index.DatetimeInterface,
56
59
  boolean: import_index.BooleanInterface,
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@nocobase/database",
3
- "version": "1.4.0-alpha.0",
3
+ "version": "1.4.0-alpha.10",
4
4
  "description": "",
5
5
  "main": "./lib/index.js",
6
6
  "types": "./lib/index.d.ts",
7
7
  "license": "AGPL-3.0",
8
8
  "dependencies": {
9
- "@nocobase/logger": "1.4.0-alpha.0",
10
- "@nocobase/utils": "1.4.0-alpha.0",
9
+ "@nocobase/logger": "1.4.0-alpha.10",
10
+ "@nocobase/utils": "1.4.0-alpha.10",
11
11
  "async-mutex": "^0.3.2",
12
12
  "chalk": "^4.1.1",
13
13
  "cron-parser": "4.4.0",
@@ -38,5 +38,5 @@
38
38
  "url": "git+https://github.com/nocobase/nocobase.git",
39
39
  "directory": "packages/database"
40
40
  },
41
- "gitHead": "8ffa7b54bbaf720c0c9857da4b19a99110dffc4b"
41
+ "gitHead": "74c99c0f2d84690d7e3db62c7a913e6aca97c762"
42
42
  }