@nocobase/database 1.2.12-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,51 +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 hasone_repository_exports = {};
|
|
29
|
-
__export(hasone_repository_exports, {
|
|
30
|
-
HasOneRepository: () => HasOneRepository
|
|
31
|
-
});
|
|
32
|
-
module.exports = __toCommonJS(hasone_repository_exports);
|
|
33
|
-
var import_single_relation_repository = require("./single-relation-repository");
|
|
34
|
-
const _HasOneRepository = class _HasOneRepository extends import_single_relation_repository.SingleRelationRepository {
|
|
35
|
-
/**
|
|
36
|
-
* @internal
|
|
37
|
-
*/
|
|
38
|
-
filterOptions(sourceModel) {
|
|
39
|
-
const association = this.association;
|
|
40
|
-
return {
|
|
41
|
-
// @ts-ignore
|
|
42
|
-
[association.foreignKey]: sourceModel.get(association.sourceKey)
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
};
|
|
46
|
-
__name(_HasOneRepository, "HasOneRepository");
|
|
47
|
-
let HasOneRepository = _HasOneRepository;
|
|
48
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
49
|
-
0 && (module.exports = {
|
|
50
|
-
HasOneRepository
|
|
51
|
-
});
|
|
@@ -1,27 +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 { MultiAssociationAccessors, Transaction, Transactionable } from 'sequelize';
|
|
10
|
-
import { CommonFindOptions, CountOptions, DestroyOptions, Filter, FindOneOptions, FindOptions, TargetKey, TK, UpdateOptions } from '../repository';
|
|
11
|
-
import { RelationRepository } from './relation-repository';
|
|
12
|
-
export type FindAndCountOptions = CommonFindOptions;
|
|
13
|
-
export interface AssociatedOptions extends Transactionable {
|
|
14
|
-
tk?: TK;
|
|
15
|
-
}
|
|
16
|
-
export declare abstract class MultipleRelationRepository extends RelationRepository {
|
|
17
|
-
find(options?: FindOptions): Promise<any>;
|
|
18
|
-
findAndCount(options?: FindAndCountOptions): Promise<[any[], number]>;
|
|
19
|
-
count(options?: CountOptions): Promise<number>;
|
|
20
|
-
findOne(options?: FindOneOptions): Promise<any>;
|
|
21
|
-
remove(options: TargetKey | TargetKey[] | AssociatedOptions): Promise<void>;
|
|
22
|
-
update(options?: UpdateOptions): Promise<any>;
|
|
23
|
-
destroy(options?: TK | DestroyOptions): Promise<boolean>;
|
|
24
|
-
protected destroyByFilter(filter: Filter, transaction?: Transaction): Promise<boolean>;
|
|
25
|
-
protected filterHasInclude(filter: Filter, options?: any): boolean;
|
|
26
|
-
protected accessors(): MultiAssociationAccessors;
|
|
27
|
-
}
|
|
@@ -1,200 +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 multiple_relation_repository_exports = {};
|
|
48
|
-
__export(multiple_relation_repository_exports, {
|
|
49
|
-
MultipleRelationRepository: () => MultipleRelationRepository
|
|
50
|
-
});
|
|
51
|
-
module.exports = __toCommonJS(multiple_relation_repository_exports);
|
|
52
|
-
var import_lodash = __toESM(require("lodash"));
|
|
53
|
-
var import_sequelize = require("sequelize");
|
|
54
|
-
var import_target_collection_decorator = __toESM(require("../decorators/target-collection-decorator"));
|
|
55
|
-
var import_update_associations = require("../update-associations");
|
|
56
|
-
var import_update_guard = require("../update-guard");
|
|
57
|
-
var import_relation_repository = require("./relation-repository");
|
|
58
|
-
const _MultipleRelationRepository = class _MultipleRelationRepository extends import_relation_repository.RelationRepository {
|
|
59
|
-
async find(options) {
|
|
60
|
-
const targetRepository = this.targetCollection.repository;
|
|
61
|
-
const association = this.association;
|
|
62
|
-
const oneFromTargetOptions = {
|
|
63
|
-
as: "_pivot_",
|
|
64
|
-
foreignKey: association.otherKey,
|
|
65
|
-
sourceKey: association.targetKey,
|
|
66
|
-
realAs: association.through.model.name
|
|
67
|
-
};
|
|
68
|
-
const pivotAssoc = new import_sequelize.HasOne(association.target, association.through.model, oneFromTargetOptions);
|
|
69
|
-
const appendFilter = {
|
|
70
|
-
isPivotFilter: true,
|
|
71
|
-
association: pivotAssoc,
|
|
72
|
-
where: {
|
|
73
|
-
[association.foreignKey]: this.sourceKeyValue
|
|
74
|
-
}
|
|
75
|
-
};
|
|
76
|
-
return targetRepository.find({
|
|
77
|
-
include: [appendFilter],
|
|
78
|
-
...options
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
async findAndCount(options) {
|
|
82
|
-
const transaction2 = await this.getTransaction(options, false);
|
|
83
|
-
return [
|
|
84
|
-
await this.find({
|
|
85
|
-
...options,
|
|
86
|
-
transaction: transaction2
|
|
87
|
-
}),
|
|
88
|
-
await this.count({
|
|
89
|
-
...options,
|
|
90
|
-
transaction: transaction2
|
|
91
|
-
})
|
|
92
|
-
];
|
|
93
|
-
}
|
|
94
|
-
async count(options) {
|
|
95
|
-
const transaction2 = await this.getTransaction(options);
|
|
96
|
-
const sourceModel = await this.getSourceModel(transaction2);
|
|
97
|
-
if (!sourceModel)
|
|
98
|
-
return 0;
|
|
99
|
-
const queryOptions = this.buildQueryOptions(options);
|
|
100
|
-
const count = await sourceModel[this.accessors().get]({
|
|
101
|
-
where: queryOptions.where,
|
|
102
|
-
include: queryOptions.include,
|
|
103
|
-
includeIgnoreAttributes: false,
|
|
104
|
-
attributes: [
|
|
105
|
-
[
|
|
106
|
-
import_sequelize.Sequelize.fn(
|
|
107
|
-
"COUNT",
|
|
108
|
-
import_sequelize.Sequelize.fn("DISTINCT", import_sequelize.Sequelize.col(`${this.targetModel.name}.${this.targetKey()}`))
|
|
109
|
-
),
|
|
110
|
-
"count"
|
|
111
|
-
]
|
|
112
|
-
],
|
|
113
|
-
raw: true,
|
|
114
|
-
plain: true,
|
|
115
|
-
transaction: transaction2
|
|
116
|
-
});
|
|
117
|
-
return parseInt(count.count);
|
|
118
|
-
}
|
|
119
|
-
async findOne(options) {
|
|
120
|
-
const transaction2 = await this.getTransaction(options, false);
|
|
121
|
-
const rows = await this.find({ ...options, limit: 1, transaction: transaction2 });
|
|
122
|
-
return rows.length == 1 ? rows[0] : null;
|
|
123
|
-
}
|
|
124
|
-
async remove(options) {
|
|
125
|
-
const transaction2 = await this.getTransaction(options);
|
|
126
|
-
const sourceModel = await this.getSourceModel(transaction2);
|
|
127
|
-
await sourceModel[this.accessors().removeMultiple](this.convertTks(options), {
|
|
128
|
-
transaction: transaction2
|
|
129
|
-
});
|
|
130
|
-
return;
|
|
131
|
-
}
|
|
132
|
-
async update(options) {
|
|
133
|
-
const transaction2 = await this.getTransaction(options);
|
|
134
|
-
const guard = import_update_guard.UpdateGuard.fromOptions(this.targetModel, options);
|
|
135
|
-
const values = guard.sanitize(options.values);
|
|
136
|
-
const instances = await this.find({
|
|
137
|
-
...import_lodash.default.omit(options, ["values"]),
|
|
138
|
-
transaction: transaction2
|
|
139
|
-
});
|
|
140
|
-
for (const instance of instances) {
|
|
141
|
-
await (0, import_update_associations.updateModelByValues)(instance, values, {
|
|
142
|
-
...options,
|
|
143
|
-
sanitized: true,
|
|
144
|
-
sourceModel: await this.getSourceModel(transaction2),
|
|
145
|
-
transaction: transaction2
|
|
146
|
-
});
|
|
147
|
-
}
|
|
148
|
-
for (const instance of instances) {
|
|
149
|
-
if (options.hooks !== false) {
|
|
150
|
-
await this.db.emitAsync(`${this.targetCollection.name}.afterUpdateWithAssociations`, instance, {
|
|
151
|
-
...options,
|
|
152
|
-
transaction: transaction2
|
|
153
|
-
});
|
|
154
|
-
await this.db.emitAsync(`${this.targetCollection.name}.afterSaveWithAssociations`, instance, {
|
|
155
|
-
...options,
|
|
156
|
-
transaction: transaction2
|
|
157
|
-
});
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
return instances;
|
|
161
|
-
}
|
|
162
|
-
async destroy(options) {
|
|
163
|
-
return false;
|
|
164
|
-
}
|
|
165
|
-
async destroyByFilter(filter, transaction2) {
|
|
166
|
-
const instances = await this.find({
|
|
167
|
-
filter,
|
|
168
|
-
transaction: transaction2
|
|
169
|
-
});
|
|
170
|
-
return await this.destroy({
|
|
171
|
-
filterByTk: instances.map((instance) => instance.get(this.targetCollection.filterTargetKey)),
|
|
172
|
-
transaction: transaction2
|
|
173
|
-
});
|
|
174
|
-
}
|
|
175
|
-
filterHasInclude(filter, options) {
|
|
176
|
-
const filterResult = this.parseFilter(filter, options);
|
|
177
|
-
return filterResult.include && filterResult.include.length > 0;
|
|
178
|
-
}
|
|
179
|
-
accessors() {
|
|
180
|
-
return super.accessors();
|
|
181
|
-
}
|
|
182
|
-
};
|
|
183
|
-
__name(_MultipleRelationRepository, "MultipleRelationRepository");
|
|
184
|
-
__decorateClass([
|
|
185
|
-
(0, import_relation_repository.transaction)((args, transaction2) => {
|
|
186
|
-
return {
|
|
187
|
-
tk: args[0],
|
|
188
|
-
transaction: transaction2
|
|
189
|
-
};
|
|
190
|
-
})
|
|
191
|
-
], _MultipleRelationRepository.prototype, "remove", 1);
|
|
192
|
-
__decorateClass([
|
|
193
|
-
(0, import_relation_repository.transaction)(),
|
|
194
|
-
import_target_collection_decorator.default
|
|
195
|
-
], _MultipleRelationRepository.prototype, "update", 1);
|
|
196
|
-
let MultipleRelationRepository = _MultipleRelationRepository;
|
|
197
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
198
|
-
0 && (module.exports = {
|
|
199
|
-
MultipleRelationRepository
|
|
200
|
-
});
|
|
@@ -1,38 +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 { Association, ModelStatic, Transaction } from 'sequelize';
|
|
10
|
-
import { Collection } from '../collection';
|
|
11
|
-
import Database from '../database';
|
|
12
|
-
import { RelationField } from '../fields/relation-field';
|
|
13
|
-
import { Model } from '../model';
|
|
14
|
-
import { CreateOptions, Filter, FindOptions } from '../repository';
|
|
15
|
-
export declare const transaction: (transactionInjector?: any) => (target: any, name: any, descriptor: any) => any;
|
|
16
|
-
export declare abstract class RelationRepository {
|
|
17
|
-
sourceCollection: Collection;
|
|
18
|
-
association: Association;
|
|
19
|
-
targetModel: ModelStatic<any>;
|
|
20
|
-
targetCollection: Collection;
|
|
21
|
-
associationName: string;
|
|
22
|
-
associationField: RelationField;
|
|
23
|
-
sourceKeyValue: string | number;
|
|
24
|
-
sourceInstance: Model;
|
|
25
|
-
db: Database;
|
|
26
|
-
database: Database;
|
|
27
|
-
constructor(sourceCollection: Collection, association: string, sourceKeyValue: string | number);
|
|
28
|
-
get collection(): Collection<any, any>;
|
|
29
|
-
convertTk(options: any): any;
|
|
30
|
-
convertTks(options: any): any[];
|
|
31
|
-
targetKey(): any;
|
|
32
|
-
create(options?: CreateOptions): Promise<any>;
|
|
33
|
-
getSourceModel(transaction?: Transaction): Promise<Model<any, any>>;
|
|
34
|
-
protected accessors(): import("sequelize").SingleAssociationAccessors | import("sequelize").MultiAssociationAccessors;
|
|
35
|
-
protected buildQueryOptions(options: FindOptions): any;
|
|
36
|
-
protected parseFilter(filter: Filter, options?: any): any;
|
|
37
|
-
protected getTransaction(options: any, autoGen?: boolean): Promise<Transaction | null>;
|
|
38
|
-
}
|
|
@@ -1,175 +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 relation_repository_exports = {};
|
|
48
|
-
__export(relation_repository_exports, {
|
|
49
|
-
RelationRepository: () => RelationRepository,
|
|
50
|
-
transaction: () => transaction
|
|
51
|
-
});
|
|
52
|
-
module.exports = __toCommonJS(relation_repository_exports);
|
|
53
|
-
var import_lodash = __toESM(require("lodash"));
|
|
54
|
-
var import_transaction_decorator = require("../decorators/transaction-decorator");
|
|
55
|
-
var import_filter_parser = __toESM(require("../filter-parser"));
|
|
56
|
-
var import_options_parser = require("../options-parser");
|
|
57
|
-
var import_update_associations = require("../update-associations");
|
|
58
|
-
var import_update_guard = require("../update-guard");
|
|
59
|
-
const transaction = (0, import_transaction_decorator.transactionWrapperBuilder)(function() {
|
|
60
|
-
return this.sourceCollection.model.sequelize.transaction();
|
|
61
|
-
});
|
|
62
|
-
const _RelationRepository = class _RelationRepository {
|
|
63
|
-
sourceCollection;
|
|
64
|
-
association;
|
|
65
|
-
targetModel;
|
|
66
|
-
targetCollection;
|
|
67
|
-
associationName;
|
|
68
|
-
associationField;
|
|
69
|
-
sourceKeyValue;
|
|
70
|
-
sourceInstance;
|
|
71
|
-
db;
|
|
72
|
-
database;
|
|
73
|
-
constructor(sourceCollection, association, sourceKeyValue) {
|
|
74
|
-
this.db = sourceCollection.context.database;
|
|
75
|
-
this.database = this.db;
|
|
76
|
-
this.sourceCollection = sourceCollection;
|
|
77
|
-
this.sourceKeyValue = sourceKeyValue;
|
|
78
|
-
this.associationName = association;
|
|
79
|
-
this.association = this.sourceCollection.model.associations[association];
|
|
80
|
-
this.associationField = this.sourceCollection.getField(association);
|
|
81
|
-
this.targetModel = this.association.target;
|
|
82
|
-
this.targetCollection = this.sourceCollection.context.database.modelCollection.get(this.targetModel);
|
|
83
|
-
}
|
|
84
|
-
get collection() {
|
|
85
|
-
return this.db.getCollection(this.targetModel.name);
|
|
86
|
-
}
|
|
87
|
-
convertTk(options) {
|
|
88
|
-
let tk = options;
|
|
89
|
-
if (typeof options === "object" && options["tk"]) {
|
|
90
|
-
tk = options["tk"];
|
|
91
|
-
}
|
|
92
|
-
return tk;
|
|
93
|
-
}
|
|
94
|
-
convertTks(options) {
|
|
95
|
-
let tk = this.convertTk(options);
|
|
96
|
-
if (typeof tk === "string") {
|
|
97
|
-
tk = tk.split(",");
|
|
98
|
-
}
|
|
99
|
-
return import_lodash.default.castArray(tk);
|
|
100
|
-
}
|
|
101
|
-
targetKey() {
|
|
102
|
-
return this.associationField.targetKey;
|
|
103
|
-
}
|
|
104
|
-
async create(options) {
|
|
105
|
-
if (Array.isArray(options.values)) {
|
|
106
|
-
return Promise.all(options.values.map((record) => this.create({ ...options, values: record })));
|
|
107
|
-
}
|
|
108
|
-
const createAccessor = this.accessors().create;
|
|
109
|
-
const guard = import_update_guard.UpdateGuard.fromOptions(this.targetModel, options);
|
|
110
|
-
const values = options.values;
|
|
111
|
-
const transaction2 = await this.getTransaction(options);
|
|
112
|
-
const sourceModel = await this.getSourceModel(transaction2);
|
|
113
|
-
const instance = await sourceModel[createAccessor](guard.sanitize(options.values), { ...options, transaction: transaction2 });
|
|
114
|
-
await (0, import_update_associations.updateAssociations)(instance, values, { ...options, transaction: transaction2 });
|
|
115
|
-
if (options.hooks !== false) {
|
|
116
|
-
await this.db.emitAsync(`${this.targetCollection.name}.afterCreateWithAssociations`, instance, {
|
|
117
|
-
...options,
|
|
118
|
-
transaction: transaction2
|
|
119
|
-
});
|
|
120
|
-
const eventName = `${this.targetCollection.name}.afterSaveWithAssociations`;
|
|
121
|
-
await this.db.emitAsync(eventName, instance, { ...options, transaction: transaction2 });
|
|
122
|
-
}
|
|
123
|
-
return instance;
|
|
124
|
-
}
|
|
125
|
-
async getSourceModel(transaction2) {
|
|
126
|
-
if (!this.sourceInstance) {
|
|
127
|
-
this.sourceInstance = await this.sourceCollection.model.findOne({
|
|
128
|
-
where: {
|
|
129
|
-
[this.associationField.sourceKey]: this.sourceKeyValue
|
|
130
|
-
},
|
|
131
|
-
transaction: transaction2
|
|
132
|
-
});
|
|
133
|
-
}
|
|
134
|
-
return this.sourceInstance;
|
|
135
|
-
}
|
|
136
|
-
accessors() {
|
|
137
|
-
return this.association.accessors;
|
|
138
|
-
}
|
|
139
|
-
buildQueryOptions(options) {
|
|
140
|
-
const parser = new import_options_parser.OptionsParser(options, {
|
|
141
|
-
collection: this.targetCollection,
|
|
142
|
-
targetKey: this.targetKey()
|
|
143
|
-
});
|
|
144
|
-
const params = parser.toSequelizeParams();
|
|
145
|
-
return { ...options, ...params };
|
|
146
|
-
}
|
|
147
|
-
parseFilter(filter, options) {
|
|
148
|
-
const parser = new import_filter_parser.default(filter, {
|
|
149
|
-
collection: this.targetCollection,
|
|
150
|
-
app: {
|
|
151
|
-
ctx: options == null ? void 0 : options.context
|
|
152
|
-
}
|
|
153
|
-
});
|
|
154
|
-
return parser.toSequelizeParams();
|
|
155
|
-
}
|
|
156
|
-
async getTransaction(options, autoGen = false) {
|
|
157
|
-
if (import_lodash.default.isPlainObject(options) && options.transaction) {
|
|
158
|
-
return options.transaction;
|
|
159
|
-
}
|
|
160
|
-
if (autoGen) {
|
|
161
|
-
return await this.sourceCollection.model.sequelize.transaction();
|
|
162
|
-
}
|
|
163
|
-
return null;
|
|
164
|
-
}
|
|
165
|
-
};
|
|
166
|
-
__name(_RelationRepository, "RelationRepository");
|
|
167
|
-
__decorateClass([
|
|
168
|
-
transaction()
|
|
169
|
-
], _RelationRepository.prototype, "create", 1);
|
|
170
|
-
let RelationRepository = _RelationRepository;
|
|
171
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
172
|
-
0 && (module.exports = {
|
|
173
|
-
RelationRepository,
|
|
174
|
-
transaction
|
|
175
|
-
});
|
|
@@ -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 { SingleAssociationAccessors, Transactionable } from 'sequelize';
|
|
10
|
-
import { Model } from '../model';
|
|
11
|
-
import { Appends, Except, Fields, Filter, TargetKey, UpdateOptions } from '../repository';
|
|
12
|
-
import { RelationRepository } from './relation-repository';
|
|
13
|
-
export interface SingleRelationFindOption extends Transactionable {
|
|
14
|
-
fields?: Fields;
|
|
15
|
-
except?: Except;
|
|
16
|
-
appends?: Appends;
|
|
17
|
-
filter?: Filter;
|
|
18
|
-
targetCollection?: string;
|
|
19
|
-
}
|
|
20
|
-
interface SetOption extends Transactionable {
|
|
21
|
-
tk?: TargetKey;
|
|
22
|
-
}
|
|
23
|
-
export declare abstract class SingleRelationRepository extends RelationRepository {
|
|
24
|
-
abstract filterOptions(sourceModel: any): any;
|
|
25
|
-
remove(options?: Transactionable): Promise<void>;
|
|
26
|
-
set(options: TargetKey | SetOption): Promise<void>;
|
|
27
|
-
find(options?: SingleRelationFindOption): Promise<any>;
|
|
28
|
-
findOne(options?: SingleRelationFindOption): Promise<Model<any>>;
|
|
29
|
-
destroy(options?: Transactionable): Promise<boolean>;
|
|
30
|
-
update(options: UpdateOptions): Promise<any>;
|
|
31
|
-
/**
|
|
32
|
-
* @internal
|
|
33
|
-
*/
|
|
34
|
-
accessors(): SingleAssociationAccessors;
|
|
35
|
-
}
|
|
36
|
-
export {};
|
|
@@ -1,151 +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 single_relation_repository_exports = {};
|
|
48
|
-
__export(single_relation_repository_exports, {
|
|
49
|
-
SingleRelationRepository: () => SingleRelationRepository
|
|
50
|
-
});
|
|
51
|
-
module.exports = __toCommonJS(single_relation_repository_exports);
|
|
52
|
-
var import_lodash = __toESM(require("lodash"));
|
|
53
|
-
var import_target_collection_decorator = __toESM(require("../decorators/target-collection-decorator"));
|
|
54
|
-
var import_update_associations = require("../update-associations");
|
|
55
|
-
var import_relation_repository = require("./relation-repository");
|
|
56
|
-
const _SingleRelationRepository = class _SingleRelationRepository extends import_relation_repository.RelationRepository {
|
|
57
|
-
async remove(options) {
|
|
58
|
-
const transaction2 = await this.getTransaction(options);
|
|
59
|
-
const sourceModel = await this.getSourceModel(transaction2);
|
|
60
|
-
return await sourceModel[this.accessors().set](null, {
|
|
61
|
-
transaction: transaction2
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
async set(options) {
|
|
65
|
-
const transaction2 = await this.getTransaction(options);
|
|
66
|
-
const sourceModel = await this.getSourceModel(transaction2);
|
|
67
|
-
return await sourceModel[this.accessors().set](this.convertTk(options), {
|
|
68
|
-
transaction: transaction2
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
async find(options) {
|
|
72
|
-
const targetRepository = this.targetCollection.repository;
|
|
73
|
-
const sourceModel = await this.getSourceModel(await this.getTransaction(options));
|
|
74
|
-
if (!sourceModel)
|
|
75
|
-
return null;
|
|
76
|
-
const addFilter = await this.filterOptions(sourceModel);
|
|
77
|
-
const findOptions = {
|
|
78
|
-
...options,
|
|
79
|
-
filter: {
|
|
80
|
-
$and: [(options == null ? void 0 : options.filter) || {}, addFilter]
|
|
81
|
-
}
|
|
82
|
-
};
|
|
83
|
-
return await targetRepository.findOne(findOptions);
|
|
84
|
-
}
|
|
85
|
-
async findOne(options) {
|
|
86
|
-
return this.find({ ...options, filterByTk: null });
|
|
87
|
-
}
|
|
88
|
-
async destroy(options) {
|
|
89
|
-
const transaction2 = await this.getTransaction(options);
|
|
90
|
-
const target = await this.find({
|
|
91
|
-
transaction: transaction2
|
|
92
|
-
});
|
|
93
|
-
await target.destroy({
|
|
94
|
-
transaction: transaction2
|
|
95
|
-
});
|
|
96
|
-
return true;
|
|
97
|
-
}
|
|
98
|
-
async update(options) {
|
|
99
|
-
const transaction2 = await this.getTransaction(options);
|
|
100
|
-
const target = await this.find({
|
|
101
|
-
transaction: transaction2,
|
|
102
|
-
targetCollection: options.targetCollection
|
|
103
|
-
});
|
|
104
|
-
if (!target) {
|
|
105
|
-
throw new Error("The record does not exist");
|
|
106
|
-
}
|
|
107
|
-
await (0, import_update_associations.updateModelByValues)(target, options == null ? void 0 : options.values, {
|
|
108
|
-
...import_lodash.default.omit(options, "values"),
|
|
109
|
-
transaction: transaction2
|
|
110
|
-
});
|
|
111
|
-
if (options.hooks !== false) {
|
|
112
|
-
await this.db.emitAsync(`${this.targetCollection.name}.afterUpdateWithAssociations`, target, {
|
|
113
|
-
...options,
|
|
114
|
-
transaction: transaction2
|
|
115
|
-
});
|
|
116
|
-
const eventName = `${this.targetCollection.name}.afterSaveWithAssociations`;
|
|
117
|
-
await this.db.emitAsync(eventName, target, { ...options, transaction: transaction2 });
|
|
118
|
-
}
|
|
119
|
-
return target;
|
|
120
|
-
}
|
|
121
|
-
/**
|
|
122
|
-
* @internal
|
|
123
|
-
*/
|
|
124
|
-
accessors() {
|
|
125
|
-
return super.accessors();
|
|
126
|
-
}
|
|
127
|
-
};
|
|
128
|
-
__name(_SingleRelationRepository, "SingleRelationRepository");
|
|
129
|
-
__decorateClass([
|
|
130
|
-
(0, import_relation_repository.transaction)()
|
|
131
|
-
], _SingleRelationRepository.prototype, "remove", 1);
|
|
132
|
-
__decorateClass([
|
|
133
|
-
(0, import_relation_repository.transaction)((args, transaction2) => {
|
|
134
|
-
return {
|
|
135
|
-
tk: args[0],
|
|
136
|
-
transaction: transaction2
|
|
137
|
-
};
|
|
138
|
-
})
|
|
139
|
-
], _SingleRelationRepository.prototype, "set", 1);
|
|
140
|
-
__decorateClass([
|
|
141
|
-
(0, import_relation_repository.transaction)()
|
|
142
|
-
], _SingleRelationRepository.prototype, "destroy", 1);
|
|
143
|
-
__decorateClass([
|
|
144
|
-
(0, import_relation_repository.transaction)(),
|
|
145
|
-
import_target_collection_decorator.default
|
|
146
|
-
], _SingleRelationRepository.prototype, "update", 1);
|
|
147
|
-
let SingleRelationRepository = _SingleRelationRepository;
|
|
148
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
149
|
-
0 && (module.exports = {
|
|
150
|
-
SingleRelationRepository
|
|
151
|
-
});
|