@nocobase/database 2.1.0-alpha.1 → 2.1.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/LICENSE +201 -661
- package/README.md +79 -10
- package/lib/eager-loading/eager-loading-tree.js +5 -0
- package/lib/fields/blob-field.d.ts +17 -0
- package/lib/fields/blob-field.js +48 -0
- package/lib/fields/context-field.d.ts +6 -0
- package/lib/fields/context-field.js +4 -1
- package/lib/fields/index.d.ts +3 -1
- package/lib/fields/index.js +2 -0
- package/lib/fields/text-field.js +1 -1
- package/lib/interfaces/to-one-interface.js +1 -1
- package/lib/operators/empty.js +1 -1
- package/lib/options-parser.d.ts +1 -0
- package/lib/options-parser.js +35 -11
- package/lib/relation-repository/belongs-to-many-repository.js +1 -0
- package/lib/update-associations.js +38 -11
- package/lib/update-guard.js +1 -1
- package/lib/utils/field-validation.js +11 -7
- package/lib/view/view-inference.js +1 -2
- package/package.json +5 -6
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>
|
|
@@ -149,6 +149,11 @@ const _EagerLoadingTree = class _EagerLoadingTree {
|
|
|
149
149
|
const { sourceKey } = association;
|
|
150
150
|
pushAttribute(eagerLoadingTreeParent, sourceKey);
|
|
151
151
|
}
|
|
152
|
+
if (associationType == "BelongsToArray") {
|
|
153
|
+
const { foreignKey, targetKey } = association;
|
|
154
|
+
pushAttribute(eagerLoadingTreeParent, foreignKey);
|
|
155
|
+
pushAttribute(child, targetKey);
|
|
156
|
+
}
|
|
152
157
|
eagerLoadingTreeParent.children.push(child);
|
|
153
158
|
if (include.include) {
|
|
154
159
|
traverseIncludeOption(include.include, child);
|
|
@@ -0,0 +1,17 @@
|
|
|
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 { BaseColumnFieldOptions, Field } from './field';
|
|
11
|
+
export declare class BlobField extends Field {
|
|
12
|
+
get dataType(): DataTypes.BlobDataTypeConstructor | DataTypes.BlobDataType;
|
|
13
|
+
}
|
|
14
|
+
export interface BlobFieldOptions extends BaseColumnFieldOptions {
|
|
15
|
+
type: 'blob';
|
|
16
|
+
length?: 'tiny' | 'medium' | 'long';
|
|
17
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
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 blob_field_exports = {};
|
|
29
|
+
__export(blob_field_exports, {
|
|
30
|
+
BlobField: () => BlobField
|
|
31
|
+
});
|
|
32
|
+
module.exports = __toCommonJS(blob_field_exports);
|
|
33
|
+
var import_sequelize = require("sequelize");
|
|
34
|
+
var import_field = require("./field");
|
|
35
|
+
const _BlobField = class _BlobField extends import_field.Field {
|
|
36
|
+
get dataType() {
|
|
37
|
+
if (this.options.length) {
|
|
38
|
+
return import_sequelize.DataTypes.BLOB(this.options.length);
|
|
39
|
+
}
|
|
40
|
+
return import_sequelize.DataTypes.BLOB;
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
__name(_BlobField, "BlobField");
|
|
44
|
+
let BlobField = _BlobField;
|
|
45
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
46
|
+
0 && (module.exports = {
|
|
47
|
+
BlobField
|
|
48
|
+
});
|
|
@@ -19,4 +19,10 @@ export interface ContextFieldOptions extends BaseColumnFieldOptions {
|
|
|
19
19
|
dataIndex: string;
|
|
20
20
|
dataType?: string;
|
|
21
21
|
createOnly?: boolean;
|
|
22
|
+
/**
|
|
23
|
+
* applyIfUndefined:
|
|
24
|
+
* When true, the context value will be applied
|
|
25
|
+
* only if the field value is `undefined`.
|
|
26
|
+
*/
|
|
27
|
+
applyIfUndefined?: boolean;
|
|
22
28
|
}
|
|
@@ -50,9 +50,12 @@ const _ContextField = class _ContextField extends import_field.Field {
|
|
|
50
50
|
}
|
|
51
51
|
listener = /* @__PURE__ */ __name(async (instances, options) => {
|
|
52
52
|
instances = Array.isArray(instances) ? instances : [instances];
|
|
53
|
-
const { name, dataIndex } = this.options;
|
|
53
|
+
const { name, dataIndex, applyIfUndefined } = this.options;
|
|
54
54
|
const { context } = options;
|
|
55
55
|
for (const instance of instances) {
|
|
56
|
+
if (applyIfUndefined && instance.get(name) !== void 0) {
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
56
59
|
instance.set(name, import_lodash.default.get(context, dataIndex));
|
|
57
60
|
instance.changed(name, true);
|
|
58
61
|
}
|
package/lib/fields/index.d.ts
CHANGED
|
@@ -32,9 +32,11 @@ import { DateOnlyFieldOptions } from './date-only-field';
|
|
|
32
32
|
import { DatetimeNoTzFieldOptions } from './datetime-no-tz-field';
|
|
33
33
|
import { DatetimeTzFieldOptions } from './datetime-tz-field';
|
|
34
34
|
import { SnowflakeIdFieldOptions } from './snowflake-id-field';
|
|
35
|
+
import { BlobFieldOptions } from './blob-field';
|
|
35
36
|
export * from './array-field';
|
|
36
37
|
export * from './belongs-to-field';
|
|
37
38
|
export * from './belongs-to-many-field';
|
|
39
|
+
export * from './blob-field';
|
|
38
40
|
export * from './boolean-field';
|
|
39
41
|
export * from './context-field';
|
|
40
42
|
export * from './date-field';
|
|
@@ -60,4 +62,4 @@ export * from './virtual-field';
|
|
|
60
62
|
export * from './nanoid-field';
|
|
61
63
|
export * from './unix-timestamp-field';
|
|
62
64
|
export * from './snowflake-id-field';
|
|
63
|
-
export type FieldOptions = BaseFieldOptions | StringFieldOptions | IntegerFieldOptions | FloatFieldOptions | DecimalFieldOptions | DoubleFieldOptions | RealFieldOptions | JsonFieldOptions | JsonbFieldOptions | BooleanFieldOptions | RadioFieldOptions | TextFieldOptions | VirtualFieldOptions | ArrayFieldOptions | SetFieldOptions | TimeFieldOptions | DateFieldOptions | DatetimeTzFieldOptions | DatetimeNoTzFieldOptions | DateOnlyFieldOptions | UnixTimestampFieldOptions | UidFieldOptions | UUIDFieldOptions | NanoidFieldOptions | PasswordFieldOptions | ContextFieldOptions | BelongsToFieldOptions | HasOneFieldOptions | HasManyFieldOptions | BelongsToManyFieldOptions | SnowflakeIdFieldOptions;
|
|
65
|
+
export type FieldOptions = BaseFieldOptions | StringFieldOptions | IntegerFieldOptions | FloatFieldOptions | DecimalFieldOptions | DoubleFieldOptions | RealFieldOptions | JsonFieldOptions | JsonbFieldOptions | BlobFieldOptions | BooleanFieldOptions | RadioFieldOptions | TextFieldOptions | VirtualFieldOptions | ArrayFieldOptions | SetFieldOptions | TimeFieldOptions | DateFieldOptions | DatetimeTzFieldOptions | DatetimeNoTzFieldOptions | DateOnlyFieldOptions | UnixTimestampFieldOptions | UidFieldOptions | UUIDFieldOptions | NanoidFieldOptions | PasswordFieldOptions | ContextFieldOptions | BelongsToFieldOptions | HasOneFieldOptions | HasManyFieldOptions | BelongsToManyFieldOptions | SnowflakeIdFieldOptions;
|
package/lib/fields/index.js
CHANGED
|
@@ -26,6 +26,7 @@ module.exports = __toCommonJS(fields_exports);
|
|
|
26
26
|
__reExport(fields_exports, require("./array-field"), module.exports);
|
|
27
27
|
__reExport(fields_exports, require("./belongs-to-field"), module.exports);
|
|
28
28
|
__reExport(fields_exports, require("./belongs-to-many-field"), module.exports);
|
|
29
|
+
__reExport(fields_exports, require("./blob-field"), module.exports);
|
|
29
30
|
__reExport(fields_exports, require("./boolean-field"), module.exports);
|
|
30
31
|
__reExport(fields_exports, require("./context-field"), module.exports);
|
|
31
32
|
__reExport(fields_exports, require("./date-field"), module.exports);
|
|
@@ -56,6 +57,7 @@ __reExport(fields_exports, require("./snowflake-id-field"), module.exports);
|
|
|
56
57
|
...require("./array-field"),
|
|
57
58
|
...require("./belongs-to-field"),
|
|
58
59
|
...require("./belongs-to-many-field"),
|
|
60
|
+
...require("./blob-field"),
|
|
59
61
|
...require("./boolean-field"),
|
|
60
62
|
...require("./context-field"),
|
|
61
63
|
...require("./date-field"),
|
package/lib/fields/text-field.js
CHANGED
|
@@ -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/empty.js
CHANGED
|
@@ -61,7 +61,7 @@ const findFilterFieldType = /* @__PURE__ */ __name((ctx) => {
|
|
|
61
61
|
}
|
|
62
62
|
model = modelAssociation.target;
|
|
63
63
|
}
|
|
64
|
-
const collection = db.
|
|
64
|
+
const collection = db.getCollection(model.name);
|
|
65
65
|
return collection.getField(fieldName);
|
|
66
66
|
}, "findFilterFieldType");
|
|
67
67
|
var empty_default = {
|
package/lib/options-parser.d.ts
CHANGED
package/lib/options-parser.js
CHANGED
|
@@ -41,9 +41,9 @@ __export(options_parser_exports, {
|
|
|
41
41
|
});
|
|
42
42
|
module.exports = __toCommonJS(options_parser_exports);
|
|
43
43
|
var import_lodash = __toESM(require("lodash"));
|
|
44
|
-
var import_qs = __toESM(require("qs"));
|
|
45
44
|
var import_sequelize = require("sequelize");
|
|
46
45
|
var import_filter_parser = __toESM(require("./filter-parser"));
|
|
46
|
+
var import_qs = __toESM(require("qs"));
|
|
47
47
|
const debug = require("debug")("noco-database");
|
|
48
48
|
const _OptionsParser = class _OptionsParser {
|
|
49
49
|
options;
|
|
@@ -281,10 +281,26 @@ const _OptionsParser = class _OptionsParser {
|
|
|
281
281
|
}
|
|
282
282
|
return obj;
|
|
283
283
|
}
|
|
284
|
+
normalizeAppends(appends) {
|
|
285
|
+
if (Array.isArray(appends)) {
|
|
286
|
+
return appends.filter((item) => typeof item === "string" && item.length > 0);
|
|
287
|
+
}
|
|
288
|
+
if (import_lodash.default.isPlainObject(appends)) {
|
|
289
|
+
return Object.values(appends).filter((item) => typeof item === "string" && item.length > 0);
|
|
290
|
+
}
|
|
291
|
+
if (typeof appends === "string" && appends.length > 0) {
|
|
292
|
+
return [appends];
|
|
293
|
+
}
|
|
294
|
+
return [];
|
|
295
|
+
}
|
|
284
296
|
parseAppends(appends, filterParams) {
|
|
285
297
|
if (!appends) return filterParams;
|
|
286
|
-
|
|
287
|
-
|
|
298
|
+
const appendList = this.normalizeAppends(appends);
|
|
299
|
+
if (!appendList.length) {
|
|
300
|
+
return filterParams;
|
|
301
|
+
}
|
|
302
|
+
const sortedAppends = import_lodash.default.sortBy(appendList, (append) => append.split(".").length);
|
|
303
|
+
const setInclude = /* @__PURE__ */ __name((model, queryParams, append, parentAs) => {
|
|
288
304
|
var _a;
|
|
289
305
|
const appendWithOptions = this.parseAppendWithOptions(append);
|
|
290
306
|
append = appendWithOptions.name;
|
|
@@ -323,10 +339,21 @@ const _OptionsParser = class _OptionsParser {
|
|
|
323
339
|
return;
|
|
324
340
|
}
|
|
325
341
|
if (existIncludeIndex == -1) {
|
|
326
|
-
|
|
342
|
+
const association = associations[appendAssociation];
|
|
343
|
+
if (!association) {
|
|
344
|
+
throw new Error(`association ${appendAssociation} in ${model.name} not found`);
|
|
345
|
+
}
|
|
346
|
+
let includeOptions = {
|
|
327
347
|
association: appendAssociation,
|
|
328
348
|
options: appendWithOptions.options || {}
|
|
329
|
-
}
|
|
349
|
+
};
|
|
350
|
+
if (association.associationType === "BelongsToArray") {
|
|
351
|
+
includeOptions = {
|
|
352
|
+
...includeOptions,
|
|
353
|
+
...association.generateInclude(parentAs)
|
|
354
|
+
};
|
|
355
|
+
}
|
|
356
|
+
queryParams["include"].push(includeOptions);
|
|
330
357
|
existIncludeIndex = queryParams["include"].length - 1;
|
|
331
358
|
}
|
|
332
359
|
if (lastLevel) {
|
|
@@ -362,14 +389,11 @@ const _OptionsParser = class _OptionsParser {
|
|
|
362
389
|
if (appendWithOptions.raw) {
|
|
363
390
|
nextAppend += appendWithOptions.raw;
|
|
364
391
|
}
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
queryParams["include"][existIncludeIndex],
|
|
368
|
-
nextAppend
|
|
369
|
-
);
|
|
392
|
+
const association = model.associations[queryParams["include"][existIncludeIndex].association];
|
|
393
|
+
setInclude(association.target, queryParams["include"][existIncludeIndex], nextAppend, association.as);
|
|
370
394
|
}
|
|
371
395
|
}, "setInclude");
|
|
372
|
-
for (const append of
|
|
396
|
+
for (const append of sortedAppends) {
|
|
373
397
|
setInclude(this.model, filterParams, append);
|
|
374
398
|
}
|
|
375
399
|
debug("filter params: %o", filterParams);
|
|
@@ -219,16 +219,6 @@ async function updateSingleAssociation(model, key, value, options = {}) {
|
|
|
219
219
|
);
|
|
220
220
|
}
|
|
221
221
|
}, "checkBelongsToForeignKeyValue");
|
|
222
|
-
if ((0, import_utils.isStringOrNumber)(value)) {
|
|
223
|
-
await model[setAccessor](value, { context, transaction });
|
|
224
|
-
return true;
|
|
225
|
-
}
|
|
226
|
-
if (value instanceof import_model.Model) {
|
|
227
|
-
await model[setAccessor](value, { context, transaction });
|
|
228
|
-
model.setDataValue(key, value);
|
|
229
|
-
return true;
|
|
230
|
-
}
|
|
231
|
-
const createAccessor = association.accessors.create;
|
|
232
222
|
let dataKey;
|
|
233
223
|
let M;
|
|
234
224
|
if (association.associationType === "BelongsTo") {
|
|
@@ -238,6 +228,24 @@ async function updateSingleAssociation(model, key, value, options = {}) {
|
|
|
238
228
|
M = association.target;
|
|
239
229
|
dataKey = M.primaryKeyAttribute;
|
|
240
230
|
}
|
|
231
|
+
if ((0, import_utils.isStringOrNumber)(value)) {
|
|
232
|
+
const instance2 = await M.findOne({
|
|
233
|
+
where: {
|
|
234
|
+
[dataKey]: value
|
|
235
|
+
},
|
|
236
|
+
transaction
|
|
237
|
+
});
|
|
238
|
+
if (instance2) {
|
|
239
|
+
await model[setAccessor](value, { context, transaction });
|
|
240
|
+
}
|
|
241
|
+
return true;
|
|
242
|
+
}
|
|
243
|
+
if (value instanceof import_model.Model) {
|
|
244
|
+
await model[setAccessor](value, { context, transaction });
|
|
245
|
+
model.setDataValue(key, value);
|
|
246
|
+
return true;
|
|
247
|
+
}
|
|
248
|
+
const createAccessor = association.accessors.create;
|
|
241
249
|
if ((0, import_utils.isStringOrNumber)(value[dataKey])) {
|
|
242
250
|
const instance2 = await M.findOne({
|
|
243
251
|
where: {
|
|
@@ -311,7 +319,7 @@ async function updateMultipleAssociation(model, key, value, options = {}) {
|
|
|
311
319
|
return;
|
|
312
320
|
}
|
|
313
321
|
value = import_lodash.default.castArray(value);
|
|
314
|
-
|
|
322
|
+
let setItems = [];
|
|
315
323
|
const objectItems = [];
|
|
316
324
|
for (const item of value) {
|
|
317
325
|
if ((0, import_utils.isUndefinedOrNull)(item)) {
|
|
@@ -335,6 +343,25 @@ async function updateMultipleAssociation(model, key, value, options = {}) {
|
|
|
335
343
|
objectItems.push(item);
|
|
336
344
|
}
|
|
337
345
|
}
|
|
346
|
+
if (setItems.length > 0) {
|
|
347
|
+
const TargetModel = association.target;
|
|
348
|
+
const pk2 = TargetModel.primaryKeyAttribute;
|
|
349
|
+
const targetKey2 = association.targetKey || association.options.targetKey || pk2;
|
|
350
|
+
const rawKeys = [];
|
|
351
|
+
const instanceItems = [];
|
|
352
|
+
for (const item of setItems) {
|
|
353
|
+
if (item instanceof import_model.Model) {
|
|
354
|
+
instanceItems.push(item);
|
|
355
|
+
} else if ((0, import_utils.isStringOrNumber)(item)) {
|
|
356
|
+
rawKeys.push(item);
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
const validInstances = rawKeys.length ? await TargetModel.findAll({
|
|
360
|
+
where: { [targetKey2]: rawKeys },
|
|
361
|
+
transaction
|
|
362
|
+
}) : [];
|
|
363
|
+
setItems = [...instanceItems, ...validInstances];
|
|
364
|
+
}
|
|
338
365
|
await model[setAccessor](setItems, { transaction, context, individualHooks: true, validate: false });
|
|
339
366
|
const newItems = [];
|
|
340
367
|
const pk = association.target.primaryKeyAttribute;
|
package/lib/update-guard.js
CHANGED
|
@@ -69,7 +69,7 @@ const _UpdateGuard = class _UpdateGuard {
|
|
|
69
69
|
}
|
|
70
70
|
setAssociationKeysToBeUpdate(associationKeysToBeUpdate) {
|
|
71
71
|
if (this.action == "create") {
|
|
72
|
-
this.associationKeysToBeUpdate = Object.keys(this.model.associations);
|
|
72
|
+
this.associationKeysToBeUpdate = (associationKeysToBeUpdate == null ? void 0 : associationKeysToBeUpdate.length) ? associationKeysToBeUpdate : Object.keys(this.model.associations);
|
|
73
73
|
} else {
|
|
74
74
|
this.associationKeysToBeUpdate = associationKeysToBeUpdate;
|
|
75
75
|
}
|
|
@@ -58,16 +58,20 @@ function buildJoiSchema(validation, options) {
|
|
|
58
58
|
}
|
|
59
59
|
if (rules) {
|
|
60
60
|
rules.forEach((rule) => {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
61
|
+
const args = import_lodash.default.cloneDeep(rule.args);
|
|
62
|
+
if (rule.name === "precision") {
|
|
63
|
+
schema = schema.strict();
|
|
64
|
+
}
|
|
65
|
+
if (!import_lodash.default.isEmpty(args)) {
|
|
66
|
+
if (rule.name === "pattern" && !import_lodash.default.isRegExp(args.regex)) {
|
|
67
|
+
const lastSlash = args.regex.lastIndexOf("/");
|
|
68
|
+
const isRegExpStr = args.regex.startsWith("/") && lastSlash > 0;
|
|
65
69
|
if (isRegExpStr) {
|
|
66
|
-
|
|
70
|
+
args.regex = args.regex.slice(1, lastSlash);
|
|
67
71
|
}
|
|
68
|
-
|
|
72
|
+
args.regex = new RegExp(args.regex);
|
|
69
73
|
}
|
|
70
|
-
schema = rule.paramsType === "object" ? schema[rule.name](
|
|
74
|
+
schema = rule.paramsType === "object" ? schema[rule.name](args) : schema[rule.name](...Object.values(args));
|
|
71
75
|
} else {
|
|
72
76
|
schema = schema[rule.name]();
|
|
73
77
|
}
|
|
@@ -40,7 +40,6 @@ __export(view_inference_exports, {
|
|
|
40
40
|
ViewFieldInference: () => ViewFieldInference
|
|
41
41
|
});
|
|
42
42
|
module.exports = __toCommonJS(view_inference_exports);
|
|
43
|
-
var import_mathjs = require("mathjs");
|
|
44
43
|
var import_field_type_map = __toESM(require("./field-type-map"));
|
|
45
44
|
const _ViewFieldInference = class _ViewFieldInference {
|
|
46
45
|
static extractTypeFromDefinition(typeDefinition) {
|
|
@@ -137,7 +136,7 @@ const _ViewFieldInference = class _ViewFieldInference {
|
|
|
137
136
|
}
|
|
138
137
|
const queryType = this.extractTypeFromDefinition(options.type);
|
|
139
138
|
const mappedType = fieldTypeMap[queryType];
|
|
140
|
-
if (
|
|
139
|
+
if (Array.isArray(mappedType)) {
|
|
141
140
|
return {
|
|
142
141
|
type: mappedType[0],
|
|
143
142
|
possibleTypes: mappedType
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nocobase/database",
|
|
3
|
-
"version": "2.1.0-alpha.
|
|
3
|
+
"version": "2.1.0-alpha.10",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"types": "./lib/index.d.ts",
|
|
7
|
-
"license": "
|
|
7
|
+
"license": "Apache-2.0",
|
|
8
8
|
"dependencies": {
|
|
9
|
-
"@nocobase/logger": "2.1.0-alpha.
|
|
10
|
-
"@nocobase/utils": "2.1.0-alpha.
|
|
9
|
+
"@nocobase/logger": "2.1.0-alpha.10",
|
|
10
|
+
"@nocobase/utils": "2.1.0-alpha.10",
|
|
11
11
|
"async-mutex": "^0.3.2",
|
|
12
12
|
"chalk": "^4.1.1",
|
|
13
13
|
"cron-parser": "4.4.0",
|
|
@@ -20,7 +20,6 @@
|
|
|
20
20
|
"graphlib": "^2.1.8",
|
|
21
21
|
"joi": "^17.13.3",
|
|
22
22
|
"lodash": "^4.17.21",
|
|
23
|
-
"mathjs": "^10.6.1",
|
|
24
23
|
"nanoid": "^3.3.11",
|
|
25
24
|
"node-fetch": "^2.6.7",
|
|
26
25
|
"node-sql-parser": "^4.18.0",
|
|
@@ -39,5 +38,5 @@
|
|
|
39
38
|
"url": "git+https://github.com/nocobase/nocobase.git",
|
|
40
39
|
"directory": "packages/database"
|
|
41
40
|
},
|
|
42
|
-
"gitHead": "
|
|
41
|
+
"gitHead": "ce790d46c0a5768ca9618c7d0d77ab8300de75c8"
|
|
43
42
|
}
|