@nocobase/database 1.2.13-alpha → 1.3.0-alpha.20240710084543
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/package.json +4 -4
- package/lib/collection-factory.d.ts +0 -25
- package/lib/collection-factory.js +0 -61
- package/lib/collection-group-manager.d.ts +0 -34
- package/lib/collection-group-manager.js +0 -66
- package/lib/collection-importer.d.ts +0 -15
- package/lib/collection-importer.js +0 -83
- package/lib/collection.d.ts +0 -145
- package/lib/collection.js +0 -663
- package/lib/database-utils/index.d.ts +0 -16
- package/lib/database-utils/index.js +0 -75
- package/lib/database.d.ts +0 -228
- package/lib/database.js +0 -795
- package/lib/decorators/must-have-filter-decorator.d.ts +0 -10
- package/lib/decorators/must-have-filter-decorator.js +0 -48
- package/lib/decorators/target-collection-decorator.d.ts +0 -10
- package/lib/decorators/target-collection-decorator.js +0 -56
- package/lib/decorators/transaction-decorator.d.ts +0 -9
- package/lib/decorators/transaction-decorator.js +0 -95
- package/lib/eager-loading/eager-loading-tree.d.ts +0 -39
- package/lib/eager-loading/eager-loading-tree.js +0 -448
- package/lib/errors/identifier-error.d.ts +0 -11
- package/lib/errors/identifier-error.js +0 -44
- package/lib/errors/zero-column-table-error.d.ts +0 -10
- package/lib/errors/zero-column-table-error.js +0 -40
- package/lib/features/references-map.d.ts +0 -29
- package/lib/features/references-map.js +0 -120
- package/lib/features/referential-integrity-check.d.ts +0 -16
- package/lib/features/referential-integrity-check.js +0 -86
- package/lib/field-repository/array-field-repository.d.ts +0 -36
- package/lib/field-repository/array-field-repository.js +0 -179
- package/lib/fields/array-field.d.ts +0 -19
- package/lib/fields/array-field.js +0 -66
- package/lib/fields/belongs-to-field.d.ts +0 -25
- package/lib/fields/belongs-to-field.js +0 -166
- package/lib/fields/belongs-to-many-field.d.ts +0 -28
- package/lib/fields/belongs-to-many-field.js +0 -196
- package/lib/fields/boolean-field.d.ts +0 -16
- package/lib/fields/boolean-field.js +0 -45
- package/lib/fields/context-field.d.ts +0 -22
- package/lib/fields/context-field.js +0 -79
- package/lib/fields/date-field.d.ts +0 -21
- package/lib/fields/date-field.js +0 -73
- package/lib/fields/field.d.ts +0 -52
- package/lib/fields/field.js +0 -168
- package/lib/fields/has-inverse-field.d.ts +0 -12
- package/lib/fields/has-inverse-field.js +0 -24
- package/lib/fields/has-many-field.d.ts +0 -76
- package/lib/fields/has-many-field.js +0 -165
- package/lib/fields/has-one-field.d.ts +0 -76
- package/lib/fields/has-one-field.js +0 -159
- package/lib/fields/index.d.ts +0 -54
- package/lib/fields/index.js +0 -74
- package/lib/fields/json-field.d.ts +0 -22
- package/lib/fields/json-field.js +0 -63
- package/lib/fields/nanoid-field.d.ts +0 -22
- package/lib/fields/nanoid-field.js +0 -65
- package/lib/fields/number-field.d.ts +0 -49
- package/lib/fields/number-field.js +0 -94
- package/lib/fields/password-field.d.ts +0 -29
- package/lib/fields/password-field.js +0 -106
- package/lib/fields/radio-field.d.ts +0 -24
- package/lib/fields/radio-field.js +0 -75
- package/lib/fields/relation-field.d.ts +0 -31
- package/lib/fields/relation-field.js +0 -94
- package/lib/fields/set-field.d.ts +0 -18
- package/lib/fields/set-field.js +0 -55
- package/lib/fields/sort-field.d.ts +0 -22
- package/lib/fields/sort-field.js +0 -197
- package/lib/fields/string-field.d.ts +0 -16
- package/lib/fields/string-field.js +0 -45
- package/lib/fields/text-field.d.ts +0 -18
- package/lib/fields/text-field.js +0 -53
- package/lib/fields/time-field.d.ts +0 -16
- package/lib/fields/time-field.js +0 -45
- package/lib/fields/uid-field.d.ts +0 -21
- package/lib/fields/uid-field.js +0 -72
- package/lib/fields/uuid-field.d.ts +0 -20
- package/lib/fields/uuid-field.js +0 -63
- package/lib/fields/virtual-field.d.ts +0 -16
- package/lib/fields/virtual-field.js +0 -45
- package/lib/filter-match.d.ts +0 -9
- package/lib/filter-match.js +0 -75
- package/lib/filter-parser.d.ts +0 -29
- package/lib/filter-parser.js +0 -238
- package/lib/helpers.d.ts +0 -11
- package/lib/helpers.js +0 -182
- package/lib/index.d.ts +0 -37
- package/lib/index.js +0 -138
- package/lib/inherited-collection.d.ts +0 -22
- package/lib/inherited-collection.js +0 -147
- package/lib/inherited-map.d.ts +0 -29
- package/lib/inherited-map.js +0 -125
- package/lib/inherited-sync-runner.d.ts +0 -12
- package/lib/inherited-sync-runner.js +0 -184
- package/lib/interface-manager.d.ts +0 -17
- package/lib/interface-manager.js +0 -50
- package/lib/interfaces/base-interface.d.ts +0 -33
- package/lib/interfaces/base-interface.js +0 -80
- package/lib/interfaces/boolean-interface.d.ts +0 -13
- package/lib/interfaces/boolean-interface.js +0 -70
- package/lib/interfaces/checkboxes-interface.d.ts +0 -11
- package/lib/interfaces/checkboxes-interface.js +0 -41
- package/lib/interfaces/datetime-interface.d.ts +0 -13
- package/lib/interfaces/datetime-interface.js +0 -108
- package/lib/interfaces/index.d.ts +0 -14
- package/lib/interfaces/index.js +0 -40
- package/lib/interfaces/integer-interface.d.ts +0 -12
- package/lib/interfaces/integer-interface.js +0 -44
- package/lib/interfaces/json-interface.d.ts +0 -13
- package/lib/interfaces/json-interface.js +0 -47
- package/lib/interfaces/many-to-many-interface.d.ts +0 -11
- package/lib/interfaces/many-to-many-interface.js +0 -41
- package/lib/interfaces/many-to-one-interface.d.ts +0 -11
- package/lib/interfaces/many-to-one-interface.js +0 -41
- package/lib/interfaces/multiple-select-interface.d.ts +0 -13
- package/lib/interfaces/multiple-select-interface.js +0 -76
- package/lib/interfaces/number-interface.d.ts +0 -15
- package/lib/interfaces/number-interface.js +0 -72
- package/lib/interfaces/one-belongs-to-one-interface.d.ts +0 -11
- package/lib/interfaces/one-belongs-to-one-interface.js +0 -41
- package/lib/interfaces/one-has-one-interface.d.ts +0 -11
- package/lib/interfaces/one-has-one-interface.js +0 -41
- package/lib/interfaces/one-to-many-interface.d.ts +0 -11
- package/lib/interfaces/one-to-many-interface.js +0 -41
- package/lib/interfaces/percent-interface.d.ts +0 -13
- package/lib/interfaces/percent-interface.js +0 -55
- package/lib/interfaces/select-interface.d.ts +0 -13
- package/lib/interfaces/select-interface.js +0 -63
- package/lib/interfaces/to-many-interface.d.ts +0 -12
- package/lib/interfaces/to-many-interface.js +0 -61
- package/lib/interfaces/to-one-interface.d.ts +0 -13
- package/lib/interfaces/to-one-interface.js +0 -61
- package/lib/interfaces/utils.d.ts +0 -10
- package/lib/interfaces/utils.js +0 -72
- package/lib/listeners/adjacency-list.d.ts +0 -10
- package/lib/listeners/adjacency-list.js +0 -51
- package/lib/listeners/append-child-collection-name-after-repository-find.d.ts +0 -14
- package/lib/listeners/append-child-collection-name-after-repository-find.js +0 -75
- package/lib/listeners/index.d.ts +0 -10
- package/lib/listeners/index.js +0 -42
- package/lib/magic-attribute-model.d.ts +0 -16
- package/lib/magic-attribute-model.js +0 -213
- package/lib/migration.d.ts +0 -43
- package/lib/migration.js +0 -112
- package/lib/mock-database.d.ts +0 -33
- package/lib/mock-database.js +0 -136
- package/lib/model-hook.d.ts +0 -20
- package/lib/model-hook.js +0 -96
- package/lib/model.d.ts +0 -32
- package/lib/model.js +0 -179
- package/lib/operators/array.d.ts +0 -10
- package/lib/operators/array.js +0 -196
- package/lib/operators/association.d.ts +0 -10
- package/lib/operators/association.js +0 -44
- package/lib/operators/boolean.d.ts +0 -10
- package/lib/operators/boolean.js +0 -47
- package/lib/operators/child-collection.d.ts +0 -10
- package/lib/operators/child-collection.js +0 -77
- package/lib/operators/date.d.ts +0 -10
- package/lib/operators/date.js +0 -149
- package/lib/operators/empty.d.ts +0 -13
- package/lib/operators/empty.js +0 -102
- package/lib/operators/eq.d.ts +0 -10
- package/lib/operators/eq.js +0 -44
- package/lib/operators/index.d.ts +0 -13
- package/lib/operators/index.js +0 -63
- package/lib/operators/ne.d.ts +0 -10
- package/lib/operators/ne.js +0 -49
- package/lib/operators/notIn.d.ts +0 -10
- package/lib/operators/notIn.js +0 -42
- package/lib/operators/string.d.ts +0 -10
- package/lib/operators/string.js +0 -118
- package/lib/operators/utils.d.ts +0 -12
- package/lib/operators/utils.js +0 -53
- package/lib/options-parser.d.ts +0 -45
- package/lib/options-parser.js +0 -350
- package/lib/query-interface/mysql-query-interface.d.ts +0 -44
- package/lib/query-interface/mysql-query-interface.js +0 -134
- package/lib/query-interface/postgres-query-interface.d.ts +0 -41
- package/lib/query-interface/postgres-query-interface.js +0 -207
- package/lib/query-interface/query-interface-builder.d.ts +0 -10
- package/lib/query-interface/query-interface-builder.js +0 -55
- package/lib/query-interface/query-interface.d.ts +0 -52
- package/lib/query-interface/query-interface.js +0 -59
- package/lib/query-interface/sqlite-query-interface.d.ts +0 -44
- package/lib/query-interface/sqlite-query-interface.js +0 -141
- package/lib/relation-repository/belongs-to-many-repository.d.ts +0 -28
- package/lib/relation-repository/belongs-to-many-repository.js +0 -248
- package/lib/relation-repository/belongs-to-repository.d.ts +0 -17
- package/lib/relation-repository/belongs-to-repository.js +0 -51
- package/lib/relation-repository/hasmany-repository.d.ts +0 -21
- package/lib/relation-repository/hasmany-repository.js +0 -158
- package/lib/relation-repository/hasone-repository.d.ts +0 -17
- package/lib/relation-repository/hasone-repository.js +0 -51
- package/lib/relation-repository/multiple-relation-repository.d.ts +0 -27
- package/lib/relation-repository/multiple-relation-repository.js +0 -200
- package/lib/relation-repository/relation-repository.d.ts +0 -38
- package/lib/relation-repository/relation-repository.js +0 -175
- package/lib/relation-repository/single-relation-repository.d.ts +0 -36
- package/lib/relation-repository/single-relation-repository.js +0 -151
- package/lib/relation-repository/types.d.ts +0 -15
- package/lib/relation-repository/types.js +0 -24
- package/lib/repositories/tree-repository/adjacency-list-repository.d.ts +0 -26
- package/lib/repositories/tree-repository/adjacency-list-repository.js +0 -192
- package/lib/repositories/view-repository.d.ts +0 -11
- package/lib/repositories/view-repository.js +0 -41
- package/lib/repository.d.ts +0 -214
- package/lib/repository.js +0 -609
- package/lib/sql-parser/index.d.ts +0 -13
- package/lib/sql-parser/index.js +0 -33
- package/lib/sync-runner.d.ts +0 -41
- package/lib/sync-runner.js +0 -335
- package/lib/types.d.ts +0 -57
- package/lib/types.js +0 -24
- package/lib/update-associations.d.ts +0 -68
- package/lib/update-associations.js +0 -429
- package/lib/update-guard.d.ts +0 -36
- package/lib/update-guard.js +0 -212
- package/lib/utils.d.ts +0 -15
- package/lib/utils.js +0 -136
- package/lib/value-parsers/array-value-parser.d.ts +0 -16
- package/lib/value-parsers/array-value-parser.js +0 -67
- package/lib/value-parsers/base-value-parser.d.ts +0 -20
- package/lib/value-parsers/base-value-parser.js +0 -72
- package/lib/value-parsers/boolean-value-parser.d.ts +0 -12
- package/lib/value-parsers/boolean-value-parser.js +0 -61
- package/lib/value-parsers/date-value-parser.d.ts +0 -13
- package/lib/value-parsers/date-value-parser.js +0 -99
- package/lib/value-parsers/index.d.ts +0 -20
- package/lib/value-parsers/index.js +0 -87
- package/lib/value-parsers/json-value-parser.d.ts +0 -12
- package/lib/value-parsers/json-value-parser.js +0 -56
- package/lib/value-parsers/number-value-parser.d.ts +0 -12
- package/lib/value-parsers/number-value-parser.js +0 -67
- package/lib/value-parsers/string-value-parser.d.ts +0 -16
- package/lib/value-parsers/string-value-parser.js +0 -73
- package/lib/value-parsers/to-many-value-parser.d.ts +0 -21
- package/lib/value-parsers/to-many-value-parser.js +0 -117
- package/lib/value-parsers/to-one-value-parser.d.ts +0 -12
- package/lib/value-parsers/to-one-value-parser.js +0 -57
- package/lib/view/field-type-map.d.ts +0 -109
- package/lib/view/field-type-map.js +0 -101
- package/lib/view/view-inference.d.ts +0 -40
- package/lib/view/view-inference.js +0 -157
- package/lib/view-collection.d.ts +0 -14
- package/lib/view-collection.js +0 -54
|
@@ -1,120 +0,0 @@
|
|
|
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 references_map_exports = {};
|
|
29
|
-
__export(references_map_exports, {
|
|
30
|
-
buildReference: () => buildReference,
|
|
31
|
-
default: () => references_map_default
|
|
32
|
-
});
|
|
33
|
-
module.exports = __toCommonJS(references_map_exports);
|
|
34
|
-
const DEFAULT_ON_DELETE = "NO ACTION";
|
|
35
|
-
function buildReference(options) {
|
|
36
|
-
const { sourceCollectionName, sourceField, targetField, targetCollectionName, onDelete, priority } = options;
|
|
37
|
-
return {
|
|
38
|
-
sourceCollectionName,
|
|
39
|
-
sourceField,
|
|
40
|
-
targetField,
|
|
41
|
-
targetCollectionName,
|
|
42
|
-
onDelete: (onDelete || DEFAULT_ON_DELETE).toUpperCase(),
|
|
43
|
-
priority: assignPriority(priority, onDelete)
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
__name(buildReference, "buildReference");
|
|
47
|
-
function assignPriority(priority, onDelete) {
|
|
48
|
-
if (priority) {
|
|
49
|
-
return priority;
|
|
50
|
-
}
|
|
51
|
-
return onDelete ? "user" : "default";
|
|
52
|
-
}
|
|
53
|
-
__name(assignPriority, "assignPriority");
|
|
54
|
-
const PRIORITY_MAP = {
|
|
55
|
-
default: 1,
|
|
56
|
-
user: 2
|
|
57
|
-
};
|
|
58
|
-
const _ReferencesMap = class _ReferencesMap {
|
|
59
|
-
constructor(db) {
|
|
60
|
-
this.db = db;
|
|
61
|
-
}
|
|
62
|
-
map = /* @__PURE__ */ new Map();
|
|
63
|
-
addReference(reference) {
|
|
64
|
-
const existReference = this.existReference(reference);
|
|
65
|
-
if (existReference && existReference.onDelete !== reference.onDelete) {
|
|
66
|
-
const existPriority = PRIORITY_MAP[existReference.priority];
|
|
67
|
-
const newPriority = PRIORITY_MAP[reference.priority];
|
|
68
|
-
if (newPriority > existPriority) {
|
|
69
|
-
existReference.onDelete = reference.onDelete;
|
|
70
|
-
existReference.priority = reference.priority;
|
|
71
|
-
} else if (newPriority === existPriority && newPriority === PRIORITY_MAP["user"]) {
|
|
72
|
-
if (existReference.onDelete === "SET NULL" && reference.onDelete === "CASCADE") {
|
|
73
|
-
existReference.onDelete = reference.onDelete;
|
|
74
|
-
} else {
|
|
75
|
-
this.db.logger.warn(
|
|
76
|
-
`On Delete Conflict, exist reference ${JSON.stringify(existReference)}, new reference ${JSON.stringify(
|
|
77
|
-
reference
|
|
78
|
-
)}`
|
|
79
|
-
);
|
|
80
|
-
return;
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
if (!existReference) {
|
|
85
|
-
this.map.set(reference.targetCollectionName, [
|
|
86
|
-
...this.map.get(reference.targetCollectionName) || [],
|
|
87
|
-
reference
|
|
88
|
-
]);
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
getReferences(collectionName) {
|
|
92
|
-
return this.map.get(collectionName);
|
|
93
|
-
}
|
|
94
|
-
existReference(reference) {
|
|
95
|
-
const references = this.map.get(reference.targetCollectionName);
|
|
96
|
-
if (!references) {
|
|
97
|
-
return null;
|
|
98
|
-
}
|
|
99
|
-
const keys = Object.keys(reference).filter((k) => k !== "onDelete" && k !== "priority");
|
|
100
|
-
return references.find((ref) => keys.every((key) => ref[key] === reference[key]));
|
|
101
|
-
}
|
|
102
|
-
removeReference(reference) {
|
|
103
|
-
const references = this.map.get(reference.targetCollectionName);
|
|
104
|
-
if (!references) {
|
|
105
|
-
return;
|
|
106
|
-
}
|
|
107
|
-
const keys = ["sourceCollectionName", "sourceField", "targetField", "targetCollectionName"];
|
|
108
|
-
this.map.set(
|
|
109
|
-
reference.targetCollectionName,
|
|
110
|
-
references.filter((ref) => !keys.every((key) => ref[key] === reference[key]))
|
|
111
|
-
);
|
|
112
|
-
}
|
|
113
|
-
};
|
|
114
|
-
__name(_ReferencesMap, "ReferencesMap");
|
|
115
|
-
let ReferencesMap = _ReferencesMap;
|
|
116
|
-
var references_map_default = ReferencesMap;
|
|
117
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
118
|
-
0 && (module.exports = {
|
|
119
|
-
buildReference
|
|
120
|
-
});
|
|
@@ -1,16 +0,0 @@
|
|
|
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 { Model, Transactionable } from 'sequelize';
|
|
10
|
-
import Database from '../database';
|
|
11
|
-
interface ReferentialIntegrityCheckOptions extends Transactionable {
|
|
12
|
-
db: Database;
|
|
13
|
-
referencedInstance: Model;
|
|
14
|
-
}
|
|
15
|
-
export declare function referentialIntegrityCheck(options: ReferentialIntegrityCheckOptions): Promise<void>;
|
|
16
|
-
export {};
|
|
@@ -1,86 +0,0 @@
|
|
|
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 referential_integrity_check_exports = {};
|
|
29
|
-
__export(referential_integrity_check_exports, {
|
|
30
|
-
referentialIntegrityCheck: () => referentialIntegrityCheck
|
|
31
|
-
});
|
|
32
|
-
module.exports = __toCommonJS(referential_integrity_check_exports);
|
|
33
|
-
async function referentialIntegrityCheck(options) {
|
|
34
|
-
const { referencedInstance, db, transaction } = options;
|
|
35
|
-
const collection = db.modelCollection.get(referencedInstance.constructor);
|
|
36
|
-
const collectionName = collection.name;
|
|
37
|
-
const references = db.referenceMap.getReferences(collectionName);
|
|
38
|
-
if (!references) {
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
for (const reference of references) {
|
|
42
|
-
const { sourceCollectionName, sourceField, targetField, onDelete } = reference;
|
|
43
|
-
if (onDelete === "NO ACTION") {
|
|
44
|
-
continue;
|
|
45
|
-
}
|
|
46
|
-
const sourceCollection = db.collections.get(sourceCollectionName);
|
|
47
|
-
const sourceRepository = sourceCollection.repository;
|
|
48
|
-
if (sourceCollection.isView()) {
|
|
49
|
-
continue;
|
|
50
|
-
}
|
|
51
|
-
const filter = {
|
|
52
|
-
[sourceField]: referencedInstance[targetField]
|
|
53
|
-
};
|
|
54
|
-
const referencingExists = await sourceRepository.count({
|
|
55
|
-
filter,
|
|
56
|
-
transaction
|
|
57
|
-
});
|
|
58
|
-
if (!referencingExists) {
|
|
59
|
-
continue;
|
|
60
|
-
}
|
|
61
|
-
if (onDelete === "RESTRICT") {
|
|
62
|
-
throw new Error("RESTRICT");
|
|
63
|
-
}
|
|
64
|
-
if (onDelete === "CASCADE") {
|
|
65
|
-
await sourceRepository.destroy({
|
|
66
|
-
filter,
|
|
67
|
-
transaction
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
if (onDelete === "SET NULL") {
|
|
71
|
-
await sourceRepository.update({
|
|
72
|
-
filter,
|
|
73
|
-
values: {
|
|
74
|
-
[sourceField]: null
|
|
75
|
-
},
|
|
76
|
-
hooks: false,
|
|
77
|
-
transaction
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
__name(referentialIntegrityCheck, "referentialIntegrityCheck");
|
|
83
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
84
|
-
0 && (module.exports = {
|
|
85
|
-
referentialIntegrityCheck
|
|
86
|
-
});
|
|
@@ -1,36 +0,0 @@
|
|
|
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 { Transactionable } from 'sequelize/types';
|
|
10
|
-
import { Collection } from '../collection';
|
|
11
|
-
export declare class ArrayFieldRepository {
|
|
12
|
-
protected collection: Collection;
|
|
13
|
-
protected fieldName: string;
|
|
14
|
-
protected targetValue: string | number;
|
|
15
|
-
constructor(collection: Collection, fieldName: string, targetValue: string | number);
|
|
16
|
-
get(options?: Transactionable): Promise<any>;
|
|
17
|
-
find(options?: Transactionable): Promise<any>;
|
|
18
|
-
set(options: Transactionable & {
|
|
19
|
-
values: Array<string | number> | string | number;
|
|
20
|
-
hooks?: boolean;
|
|
21
|
-
}): Promise<void>;
|
|
22
|
-
protected emitAfterSave(instance: any, options: any): Promise<void>;
|
|
23
|
-
toggle(options: Transactionable & {
|
|
24
|
-
value: string | number;
|
|
25
|
-
hooks?: boolean;
|
|
26
|
-
}): Promise<void>;
|
|
27
|
-
add(options: Transactionable & {
|
|
28
|
-
values: Array<string | number> | string | number;
|
|
29
|
-
hooks?: boolean;
|
|
30
|
-
}): Promise<void>;
|
|
31
|
-
remove(options: Transactionable & {
|
|
32
|
-
values: Array<string | number> | string | number;
|
|
33
|
-
hooks?: boolean;
|
|
34
|
-
}): Promise<void>;
|
|
35
|
-
protected getInstance(options: Transactionable): Promise<any>;
|
|
36
|
-
}
|
|
@@ -1,179 +0,0 @@
|
|
|
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 __decorateClass = (decorators, target, key, kind) => {
|
|
39
|
-
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
40
|
-
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
41
|
-
if (decorator = decorators[i])
|
|
42
|
-
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
43
|
-
if (kind && result)
|
|
44
|
-
__defProp(target, key, result);
|
|
45
|
-
return result;
|
|
46
|
-
};
|
|
47
|
-
var array_field_repository_exports = {};
|
|
48
|
-
__export(array_field_repository_exports, {
|
|
49
|
-
ArrayFieldRepository: () => ArrayFieldRepository
|
|
50
|
-
});
|
|
51
|
-
module.exports = __toCommonJS(array_field_repository_exports);
|
|
52
|
-
var import_lodash = __toESM(require("lodash"));
|
|
53
|
-
var import_transaction_decorator = require("../decorators/transaction-decorator");
|
|
54
|
-
var import_fields = require("../fields");
|
|
55
|
-
const transaction = (0, import_transaction_decorator.transactionWrapperBuilder)(function() {
|
|
56
|
-
return this.collection.model.sequelize.transaction();
|
|
57
|
-
});
|
|
58
|
-
const _ArrayFieldRepository = class _ArrayFieldRepository {
|
|
59
|
-
constructor(collection, fieldName, targetValue) {
|
|
60
|
-
this.collection = collection;
|
|
61
|
-
this.fieldName = fieldName;
|
|
62
|
-
this.targetValue = targetValue;
|
|
63
|
-
const field = collection.getField(fieldName);
|
|
64
|
-
if (!(field instanceof import_fields.ArrayField)) {
|
|
65
|
-
throw new Error("Field must be of type Array");
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
async get(options) {
|
|
69
|
-
const instance = await this.getInstance(options);
|
|
70
|
-
return instance.get(this.fieldName);
|
|
71
|
-
}
|
|
72
|
-
async find(options) {
|
|
73
|
-
return await this.get(options);
|
|
74
|
-
}
|
|
75
|
-
async set(options) {
|
|
76
|
-
const { transaction: transaction2 } = options;
|
|
77
|
-
const instance = await this.getInstance({
|
|
78
|
-
transaction: transaction2
|
|
79
|
-
});
|
|
80
|
-
instance.set(this.fieldName, import_lodash.default.castArray(options.values));
|
|
81
|
-
await instance.save({ transaction: transaction2 });
|
|
82
|
-
if (options.hooks !== false) {
|
|
83
|
-
await this.emitAfterSave(instance, options);
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
async emitAfterSave(instance, options) {
|
|
87
|
-
await this.collection.db.emitAsync(`${this.collection.name}.afterSaveWithAssociations`, instance, {
|
|
88
|
-
...options
|
|
89
|
-
});
|
|
90
|
-
instance.clearChangedWithAssociations();
|
|
91
|
-
}
|
|
92
|
-
async toggle(options) {
|
|
93
|
-
const { transaction: transaction2 } = options;
|
|
94
|
-
const instance = await this.getInstance({
|
|
95
|
-
transaction: transaction2
|
|
96
|
-
});
|
|
97
|
-
const oldValue = instance.get(this.fieldName) || [];
|
|
98
|
-
const newValue = oldValue.includes(options.value) ? import_lodash.default.without(oldValue, options.value) : [...oldValue, options.value];
|
|
99
|
-
instance.set(this.fieldName, newValue);
|
|
100
|
-
await instance.save({ transaction: transaction2 });
|
|
101
|
-
if (options.hooks !== false) {
|
|
102
|
-
await this.emitAfterSave(instance, options);
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
async add(options) {
|
|
106
|
-
const { transaction: transaction2 } = options;
|
|
107
|
-
const instance = await this.getInstance({
|
|
108
|
-
transaction: transaction2
|
|
109
|
-
});
|
|
110
|
-
const oldValue = instance.get(this.fieldName) || [];
|
|
111
|
-
const newValue = [...oldValue, ...import_lodash.default.castArray(options.values)];
|
|
112
|
-
instance.set(this.fieldName, newValue);
|
|
113
|
-
await instance.save({ transaction: transaction2 });
|
|
114
|
-
if (options.hooks !== false) {
|
|
115
|
-
await this.emitAfterSave(instance, options);
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
async remove(options) {
|
|
119
|
-
const { transaction: transaction2 } = options;
|
|
120
|
-
const instance = await this.getInstance({
|
|
121
|
-
transaction: transaction2
|
|
122
|
-
});
|
|
123
|
-
const oldValue = instance.get(this.fieldName) || [];
|
|
124
|
-
instance.set(this.fieldName, import_lodash.default.without(oldValue, ...import_lodash.default.castArray(options.values)));
|
|
125
|
-
await instance.save({ transaction: transaction2 });
|
|
126
|
-
if (options.hooks !== false) {
|
|
127
|
-
await this.emitAfterSave(instance, options);
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
getInstance(options) {
|
|
131
|
-
return this.collection.repository.findOne({
|
|
132
|
-
filterByTk: this.targetValue
|
|
133
|
-
});
|
|
134
|
-
}
|
|
135
|
-
};
|
|
136
|
-
__name(_ArrayFieldRepository, "ArrayFieldRepository");
|
|
137
|
-
__decorateClass([
|
|
138
|
-
transaction()
|
|
139
|
-
], _ArrayFieldRepository.prototype, "get", 1);
|
|
140
|
-
__decorateClass([
|
|
141
|
-
transaction()
|
|
142
|
-
], _ArrayFieldRepository.prototype, "find", 1);
|
|
143
|
-
__decorateClass([
|
|
144
|
-
transaction((args, transaction2) => {
|
|
145
|
-
return {
|
|
146
|
-
values: args[0],
|
|
147
|
-
transaction: transaction2
|
|
148
|
-
};
|
|
149
|
-
})
|
|
150
|
-
], _ArrayFieldRepository.prototype, "set", 1);
|
|
151
|
-
__decorateClass([
|
|
152
|
-
transaction((args, transaction2) => {
|
|
153
|
-
return {
|
|
154
|
-
value: args[0],
|
|
155
|
-
transaction: transaction2
|
|
156
|
-
};
|
|
157
|
-
})
|
|
158
|
-
], _ArrayFieldRepository.prototype, "toggle", 1);
|
|
159
|
-
__decorateClass([
|
|
160
|
-
transaction((args, transaction2) => {
|
|
161
|
-
return {
|
|
162
|
-
values: args[0],
|
|
163
|
-
transaction: transaction2
|
|
164
|
-
};
|
|
165
|
-
})
|
|
166
|
-
], _ArrayFieldRepository.prototype, "add", 1);
|
|
167
|
-
__decorateClass([
|
|
168
|
-
transaction((args, transaction2) => {
|
|
169
|
-
return {
|
|
170
|
-
values: args[0],
|
|
171
|
-
transaction: transaction2
|
|
172
|
-
};
|
|
173
|
-
})
|
|
174
|
-
], _ArrayFieldRepository.prototype, "remove", 1);
|
|
175
|
-
let ArrayFieldRepository = _ArrayFieldRepository;
|
|
176
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
177
|
-
0 && (module.exports = {
|
|
178
|
-
ArrayFieldRepository
|
|
179
|
-
});
|
|
@@ -1,19 +0,0 @@
|
|
|
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 ArrayField extends Field {
|
|
12
|
-
get dataType(): DataTypes.AbstractDataTypeConstructor;
|
|
13
|
-
sortValue: (model: any) => void;
|
|
14
|
-
bind(): void;
|
|
15
|
-
unbind(): void;
|
|
16
|
-
}
|
|
17
|
-
export interface ArrayFieldOptions extends BaseColumnFieldOptions {
|
|
18
|
-
type: 'array';
|
|
19
|
-
}
|
|
@@ -1,66 +0,0 @@
|
|
|
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 array_field_exports = {};
|
|
29
|
-
__export(array_field_exports, {
|
|
30
|
-
ArrayField: () => ArrayField
|
|
31
|
-
});
|
|
32
|
-
module.exports = __toCommonJS(array_field_exports);
|
|
33
|
-
var import_sequelize = require("sequelize");
|
|
34
|
-
var import_field = require("./field");
|
|
35
|
-
const _ArrayField = class _ArrayField extends import_field.Field {
|
|
36
|
-
get dataType() {
|
|
37
|
-
if (this.database.sequelize.getDialect() === "postgres") {
|
|
38
|
-
return import_sequelize.DataTypes.JSONB;
|
|
39
|
-
}
|
|
40
|
-
return import_sequelize.DataTypes.JSON;
|
|
41
|
-
}
|
|
42
|
-
sortValue = (model) => {
|
|
43
|
-
let oldValue = model.get(this.options.name);
|
|
44
|
-
if (oldValue) {
|
|
45
|
-
if (typeof oldValue === "string") {
|
|
46
|
-
oldValue = JSON.parse(oldValue);
|
|
47
|
-
}
|
|
48
|
-
const newValue = oldValue.sort();
|
|
49
|
-
model.set(this.options.name, newValue);
|
|
50
|
-
}
|
|
51
|
-
};
|
|
52
|
-
bind() {
|
|
53
|
-
super.bind();
|
|
54
|
-
this.on("beforeSave", this.sortValue);
|
|
55
|
-
}
|
|
56
|
-
unbind() {
|
|
57
|
-
super.unbind();
|
|
58
|
-
this.off("beforeSave", this.sortValue);
|
|
59
|
-
}
|
|
60
|
-
};
|
|
61
|
-
__name(_ArrayField, "ArrayField");
|
|
62
|
-
let ArrayField = _ArrayField;
|
|
63
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
64
|
-
0 && (module.exports = {
|
|
65
|
-
ArrayField
|
|
66
|
-
});
|
|
@@ -1,25 +0,0 @@
|
|
|
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 { BelongsToOptions as SequelizeBelongsToOptions } from 'sequelize';
|
|
10
|
-
import { Reference, ReferencePriority } from '../features/references-map';
|
|
11
|
-
import { BaseRelationFieldOptions, RelationField } from './relation-field';
|
|
12
|
-
export declare class BelongsToField extends RelationField {
|
|
13
|
-
static type: string;
|
|
14
|
-
get dataType(): string;
|
|
15
|
-
get target(): any;
|
|
16
|
-
static toReference(db: any, association: any, onDelete: any, priority?: ReferencePriority): Reference;
|
|
17
|
-
reference(association: any): Reference;
|
|
18
|
-
checkAssociationKeys(): void;
|
|
19
|
-
bind(): boolean;
|
|
20
|
-
unbind(): void;
|
|
21
|
-
}
|
|
22
|
-
export interface BelongsToFieldOptions extends BaseRelationFieldOptions, SequelizeBelongsToOptions {
|
|
23
|
-
type: 'belongsTo';
|
|
24
|
-
target?: string;
|
|
25
|
-
}
|