@tachybase/database 0.23.8
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/.turbo/turbo-build.log +10 -0
- package/LICENSE +201 -0
- package/lib/collection-factory.d.ts +17 -0
- package/lib/collection-factory.js +52 -0
- package/lib/collection-group-manager.d.ts +26 -0
- package/lib/collection-group-manager.js +57 -0
- package/lib/collection-importer.d.ts +7 -0
- package/lib/collection-importer.js +74 -0
- package/lib/collection.d.ts +138 -0
- package/lib/collection.js +686 -0
- package/lib/database-utils/index.d.ts +9 -0
- package/lib/database-utils/index.js +71 -0
- package/lib/database-utils/traverseJSON.d.ts +10 -0
- package/lib/database-utils/traverseJSON.js +126 -0
- package/lib/database.d.ts +201 -0
- package/lib/database.js +765 -0
- package/lib/decorators/must-have-filter-decorator.d.ts +2 -0
- package/lib/decorators/must-have-filter-decorator.js +38 -0
- package/lib/decorators/target-collection-decorator.d.ts +2 -0
- package/lib/decorators/target-collection-decorator.js +47 -0
- package/lib/decorators/transaction-decorator.d.ts +1 -0
- package/lib/decorators/transaction-decorator.js +88 -0
- package/lib/eager-loading/eager-loading-tree.d.ts +31 -0
- package/lib/eager-loading/eager-loading-tree.js +439 -0
- package/lib/errors/identifier-error.d.ts +3 -0
- package/lib/errors/identifier-error.js +35 -0
- package/lib/errors/zero-column-table-error.d.ts +2 -0
- package/lib/errors/zero-column-table-error.js +31 -0
- package/lib/features/references-map.d.ts +18 -0
- package/lib/features/references-map.js +109 -0
- package/lib/features/referential-integrity-check.d.ts +8 -0
- package/lib/features/referential-integrity-check.js +83 -0
- package/lib/field-repository/array-field-repository.d.ts +28 -0
- package/lib/field-repository/array-field-repository.js +197 -0
- package/lib/fields/array-field.d.ts +11 -0
- package/lib/fields/array-field.js +57 -0
- package/lib/fields/belongs-to-field.d.ts +17 -0
- package/lib/fields/belongs-to-field.js +154 -0
- package/lib/fields/belongs-to-many-field.d.ts +20 -0
- package/lib/fields/belongs-to-many-field.js +187 -0
- package/lib/fields/boolean-field.d.ts +8 -0
- package/lib/fields/boolean-field.js +36 -0
- package/lib/fields/context-field.d.ts +14 -0
- package/lib/fields/context-field.js +70 -0
- package/lib/fields/date-field.d.ts +13 -0
- package/lib/fields/date-field.js +64 -0
- package/lib/fields/field.d.ts +43 -0
- package/lib/fields/field.js +156 -0
- package/lib/fields/has-inverse-field.d.ts +4 -0
- package/lib/fields/has-inverse-field.js +15 -0
- package/lib/fields/has-many-field.d.ts +68 -0
- package/lib/fields/has-many-field.js +156 -0
- package/lib/fields/has-one-field.d.ts +68 -0
- package/lib/fields/has-one-field.js +150 -0
- package/lib/fields/index.d.ts +46 -0
- package/lib/fields/index.js +65 -0
- package/lib/fields/json-field.d.ts +14 -0
- package/lib/fields/json-field.js +54 -0
- package/lib/fields/nanoid-field.d.ts +13 -0
- package/lib/fields/nanoid-field.js +58 -0
- package/lib/fields/number-field.d.ts +41 -0
- package/lib/fields/number-field.js +85 -0
- package/lib/fields/password-field.d.ts +21 -0
- package/lib/fields/password-field.js +95 -0
- package/lib/fields/radio-field.d.ts +16 -0
- package/lib/fields/radio-field.js +66 -0
- package/lib/fields/relation-field.d.ts +21 -0
- package/lib/fields/relation-field.js +79 -0
- package/lib/fields/set-field.d.ts +10 -0
- package/lib/fields/set-field.js +46 -0
- package/lib/fields/sort-field.d.ts +16 -0
- package/lib/fields/sort-field.js +187 -0
- package/lib/fields/string-field.d.ts +8 -0
- package/lib/fields/string-field.js +36 -0
- package/lib/fields/text-field.d.ts +8 -0
- package/lib/fields/text-field.js +36 -0
- package/lib/fields/time-field.d.ts +8 -0
- package/lib/fields/time-field.js +36 -0
- package/lib/fields/uid-field.d.ts +13 -0
- package/lib/fields/uid-field.js +63 -0
- package/lib/fields/uuid-field.d.ts +9 -0
- package/lib/fields/uuid-field.js +45 -0
- package/lib/fields/virtual-field.d.ts +8 -0
- package/lib/fields/virtual-field.js +36 -0
- package/lib/filter-match.d.ts +1 -0
- package/lib/filter-match.js +66 -0
- package/lib/filter-parser.d.ts +21 -0
- package/lib/filter-parser.js +230 -0
- package/lib/helpers.d.ts +3 -0
- package/lib/helpers.js +167 -0
- package/lib/index.d.ts +30 -0
- package/lib/index.js +114 -0
- package/lib/inherited-collection.d.ts +14 -0
- package/lib/inherited-collection.js +138 -0
- package/lib/inherited-map.d.ts +21 -0
- package/lib/inherited-map.js +113 -0
- package/lib/inherited-sync-runner.d.ts +4 -0
- package/lib/inherited-sync-runner.js +175 -0
- package/lib/listeners/adjacency-list.d.ts +2 -0
- package/lib/listeners/adjacency-list.js +42 -0
- package/lib/listeners/append-child-collection-name-after-repository-find.d.ts +6 -0
- package/lib/listeners/append-child-collection-name-after-repository-find.js +66 -0
- package/lib/listeners/index.d.ts +2 -0
- package/lib/listeners/index.js +33 -0
- package/lib/magic-attribute-model.d.ts +8 -0
- package/lib/magic-attribute-model.js +203 -0
- package/lib/migration.d.ts +35 -0
- package/lib/migration.js +103 -0
- package/lib/mock-database.d.ts +25 -0
- package/lib/mock-database.js +126 -0
- package/lib/model-hook.d.ts +12 -0
- package/lib/model-hook.js +92 -0
- package/lib/model.d.ts +23 -0
- package/lib/model.js +152 -0
- package/lib/operators/array.d.ts +2 -0
- package/lib/operators/array.js +158 -0
- package/lib/operators/association.d.ts +2 -0
- package/lib/operators/association.js +35 -0
- package/lib/operators/boolean.d.ts +2 -0
- package/lib/operators/boolean.js +38 -0
- package/lib/operators/child-collection.d.ts +2 -0
- package/lib/operators/child-collection.js +67 -0
- package/lib/operators/date.d.ts +2 -0
- package/lib/operators/date.js +140 -0
- package/lib/operators/empty.d.ts +5 -0
- package/lib/operators/empty.js +89 -0
- package/lib/operators/eq.d.ts +2 -0
- package/lib/operators/eq.js +35 -0
- package/lib/operators/index.d.ts +5 -0
- package/lib/operators/index.js +56 -0
- package/lib/operators/jsonb.d.ts +2 -0
- package/lib/operators/jsonb.js +50 -0
- package/lib/operators/ne.d.ts +2 -0
- package/lib/operators/ne.js +40 -0
- package/lib/operators/notIn.d.ts +2 -0
- package/lib/operators/notIn.js +33 -0
- package/lib/operators/string.d.ts +2 -0
- package/lib/operators/string.js +109 -0
- package/lib/operators/utils.d.ts +4 -0
- package/lib/operators/utils.js +40 -0
- package/lib/options-parser.d.ts +37 -0
- package/lib/options-parser.js +332 -0
- package/lib/playground.d.ts +1 -0
- package/lib/playground.js +43 -0
- package/lib/query-interface/mysql-query-interface.d.ts +35 -0
- package/lib/query-interface/mysql-query-interface.js +122 -0
- package/lib/query-interface/postgres-query-interface.d.ts +32 -0
- package/lib/query-interface/postgres-query-interface.js +189 -0
- package/lib/query-interface/query-interface-builder.d.ts +2 -0
- package/lib/query-interface/query-interface-builder.js +46 -0
- package/lib/query-interface/query-interface.d.ts +42 -0
- package/lib/query-interface/query-interface.js +46 -0
- package/lib/query-interface/sqlite-query-interface.d.ts +35 -0
- package/lib/query-interface/sqlite-query-interface.js +131 -0
- package/lib/relation-repository/belongs-to-many-repository.d.ts +21 -0
- package/lib/relation-repository/belongs-to-many-repository.js +280 -0
- package/lib/relation-repository/belongs-to-repository.d.ts +6 -0
- package/lib/relation-repository/belongs-to-repository.js +39 -0
- package/lib/relation-repository/hasmany-repository.d.ts +10 -0
- package/lib/relation-repository/hasmany-repository.js +182 -0
- package/lib/relation-repository/hasone-repository.d.ts +6 -0
- package/lib/relation-repository/hasone-repository.js +39 -0
- package/lib/relation-repository/multiple-relation-repository.d.ts +20 -0
- package/lib/relation-repository/multiple-relation-repository.js +229 -0
- package/lib/relation-repository/relation-repository.d.ts +29 -0
- package/lib/relation-repository/relation-repository.js +202 -0
- package/lib/relation-repository/single-relation-repository.d.ts +25 -0
- package/lib/relation-repository/single-relation-repository.js +162 -0
- package/lib/relation-repository/types.d.ts +7 -0
- package/lib/relation-repository/types.js +15 -0
- package/lib/repositories/tree-repository/adjacency-list-repository.d.ts +18 -0
- package/lib/repositories/tree-repository/adjacency-list-repository.js +183 -0
- package/lib/repositories/view-repository.d.ts +3 -0
- package/lib/repositories/view-repository.js +32 -0
- package/lib/repository.d.ts +206 -0
- package/lib/repository.js +597 -0
- package/lib/sql-collection/index.d.ts +2 -0
- package/lib/sql-collection/index.js +23 -0
- package/lib/sql-collection/query-generator.d.ts +10 -0
- package/lib/sql-collection/query-generator.js +70 -0
- package/lib/sql-collection/sql-collection.d.ts +7 -0
- package/lib/sql-collection/sql-collection.js +69 -0
- package/lib/sql-collection/sql-model.d.ts +16 -0
- package/lib/sql-collection/sql-model.js +168 -0
- package/lib/sql-parser/index.d.ts +10 -0
- package/lib/sql-parser/index.js +10699 -0
- package/lib/sql-parser/postgres.d.ts +10 -0
- package/lib/sql-parser/postgres.js +31506 -0
- package/lib/sql-parser/sql.pegjs +1297 -0
- package/lib/sync-runner.d.ts +30 -0
- package/lib/sync-runner.js +277 -0
- package/lib/types.d.ts +49 -0
- package/lib/types.js +15 -0
- package/lib/update-associations.d.ts +60 -0
- package/lib/update-associations.js +405 -0
- package/lib/update-guard.d.ts +28 -0
- package/lib/update-guard.js +202 -0
- package/lib/utils.d.ts +7 -0
- package/lib/utils.js +127 -0
- package/lib/value-parsers/array-value-parser.d.ts +8 -0
- package/lib/value-parsers/array-value-parser.js +58 -0
- package/lib/value-parsers/base-value-parser.d.ts +12 -0
- package/lib/value-parsers/base-value-parser.js +63 -0
- package/lib/value-parsers/boolean-value-parser.d.ts +4 -0
- package/lib/value-parsers/boolean-value-parser.js +52 -0
- package/lib/value-parsers/date-value-parser.d.ts +5 -0
- package/lib/value-parsers/date-value-parser.js +88 -0
- package/lib/value-parsers/index.d.ts +12 -0
- package/lib/value-parsers/index.js +78 -0
- package/lib/value-parsers/json-value-parser.d.ts +4 -0
- package/lib/value-parsers/json-value-parser.js +47 -0
- package/lib/value-parsers/number-value-parser.d.ts +4 -0
- package/lib/value-parsers/number-value-parser.js +58 -0
- package/lib/value-parsers/string-value-parser.d.ts +8 -0
- package/lib/value-parsers/string-value-parser.js +64 -0
- package/lib/value-parsers/to-many-value-parser.d.ts +13 -0
- package/lib/value-parsers/to-many-value-parser.js +108 -0
- package/lib/value-parsers/to-one-value-parser.d.ts +4 -0
- package/lib/value-parsers/to-one-value-parser.js +48 -0
- package/lib/view/field-type-map.d.ts +97 -0
- package/lib/view/field-type-map.js +90 -0
- package/lib/view/view-inference.d.ts +32 -0
- package/lib/view/view-inference.js +146 -0
- package/lib/view-collection.d.ts +6 -0
- package/lib/view-collection.js +45 -0
- package/package.json +38 -0
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __knownSymbol = (name, symbol) => (symbol = Symbol[name]) ? symbol : Symbol.for("Symbol." + name);
|
|
8
|
+
var __typeError = (msg) => {
|
|
9
|
+
throw TypeError(msg);
|
|
10
|
+
};
|
|
11
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
12
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
13
|
+
var __export = (target, all) => {
|
|
14
|
+
for (var name in all)
|
|
15
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
16
|
+
};
|
|
17
|
+
var __copyProps = (to, from, except, desc) => {
|
|
18
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
19
|
+
for (let key of __getOwnPropNames(from))
|
|
20
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
21
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
22
|
+
}
|
|
23
|
+
return to;
|
|
24
|
+
};
|
|
25
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
26
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
27
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
28
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
29
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
30
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
31
|
+
mod
|
|
32
|
+
));
|
|
33
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
34
|
+
var __decoratorStart = (base) => [, , , __create((base == null ? void 0 : base[__knownSymbol("metadata")]) ?? null)];
|
|
35
|
+
var __decoratorStrings = ["class", "method", "getter", "setter", "accessor", "field", "value", "get", "set"];
|
|
36
|
+
var __expectFn = (fn) => fn !== void 0 && typeof fn !== "function" ? __typeError("Function expected") : fn;
|
|
37
|
+
var __decoratorContext = (kind, name, done, metadata, fns) => ({ kind: __decoratorStrings[kind], name, metadata, addInitializer: (fn) => done._ ? __typeError("Already initialized") : fns.push(__expectFn(fn || null)) });
|
|
38
|
+
var __decoratorMetadata = (array, target) => __defNormalProp(target, __knownSymbol("metadata"), array[3]);
|
|
39
|
+
var __runInitializers = (array, flags, self, value) => {
|
|
40
|
+
for (var i = 0, fns = array[flags >> 1], n = fns && fns.length; i < n; i++) flags & 1 ? fns[i].call(self) : value = fns[i].call(self, value);
|
|
41
|
+
return value;
|
|
42
|
+
};
|
|
43
|
+
var __decorateElement = (array, flags, name, decorators, target, extra) => {
|
|
44
|
+
var fn, it, done, ctx, access, k = flags & 7, s = !!(flags & 8), p = !!(flags & 16);
|
|
45
|
+
var j = k > 3 ? array.length + 1 : k ? s ? 1 : 2 : 0, key = __decoratorStrings[k + 5];
|
|
46
|
+
var initializers = k > 3 && (array[j - 1] = []), extraInitializers = array[j] || (array[j] = []);
|
|
47
|
+
var desc = k && (!p && !s && (target = target.prototype), k < 5 && (k > 3 || !p) && __getOwnPropDesc(k < 4 ? target : { get [name]() {
|
|
48
|
+
return __privateGet(this, extra);
|
|
49
|
+
}, set [name](x) {
|
|
50
|
+
return __privateSet(this, extra, x);
|
|
51
|
+
} }, name));
|
|
52
|
+
k ? p && k < 4 && __name(extra, (k > 2 ? "set " : k > 1 ? "get " : "") + name) : __name(target, name);
|
|
53
|
+
for (var i = decorators.length - 1; i >= 0; i--) {
|
|
54
|
+
ctx = __decoratorContext(k, name, done = {}, array[3], extraInitializers);
|
|
55
|
+
if (k) {
|
|
56
|
+
ctx.static = s, ctx.private = p, access = ctx.access = { has: p ? (x) => __privateIn(target, x) : (x) => name in x };
|
|
57
|
+
if (k ^ 3) access.get = p ? (x) => (k ^ 1 ? __privateGet : __privateMethod)(x, target, k ^ 4 ? extra : desc.get) : (x) => x[name];
|
|
58
|
+
if (k > 2) access.set = p ? (x, y) => __privateSet(x, target, y, k ^ 4 ? extra : desc.set) : (x, y) => x[name] = y;
|
|
59
|
+
}
|
|
60
|
+
it = (0, decorators[i])(k ? k < 4 ? p ? extra : desc[key] : k > 4 ? void 0 : { get: desc.get, set: desc.set } : target, ctx), done._ = 1;
|
|
61
|
+
if (k ^ 4 || it === void 0) __expectFn(it) && (k > 4 ? initializers.unshift(it) : k ? p ? extra = it : desc[key] = it : target = it);
|
|
62
|
+
else if (typeof it !== "object" || it === null) __typeError("Object expected");
|
|
63
|
+
else __expectFn(fn = it.get) && (desc.get = fn), __expectFn(fn = it.set) && (desc.set = fn), __expectFn(fn = it.init) && initializers.unshift(fn);
|
|
64
|
+
}
|
|
65
|
+
return k || __decoratorMetadata(array, target), desc && __defProp(target, name, desc), p ? k ^ 4 ? extra : desc : target;
|
|
66
|
+
};
|
|
67
|
+
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
68
|
+
var __privateIn = (member, obj) => Object(obj) !== obj ? __typeError('Cannot use the "in" operator on this value') : member.has(obj);
|
|
69
|
+
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
70
|
+
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
71
|
+
var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
|
|
72
|
+
var multiple_relation_repository_exports = {};
|
|
73
|
+
__export(multiple_relation_repository_exports, {
|
|
74
|
+
MultipleRelationRepository: () => MultipleRelationRepository
|
|
75
|
+
});
|
|
76
|
+
module.exports = __toCommonJS(multiple_relation_repository_exports);
|
|
77
|
+
var import_lodash = __toESM(require("lodash"));
|
|
78
|
+
var import_sequelize = require("sequelize");
|
|
79
|
+
var import_target_collection_decorator = __toESM(require("../decorators/target-collection-decorator"));
|
|
80
|
+
var import_update_associations = require("../update-associations");
|
|
81
|
+
var import_update_guard = require("../update-guard");
|
|
82
|
+
var import_relation_repository = require("./relation-repository");
|
|
83
|
+
var _update_dec, _remove_dec, _a, _init;
|
|
84
|
+
const _MultipleRelationRepository = class _MultipleRelationRepository extends (_a = import_relation_repository.RelationRepository, _remove_dec = [(0, import_relation_repository.transaction)((args, transaction2) => {
|
|
85
|
+
return {
|
|
86
|
+
tk: args[0],
|
|
87
|
+
transaction: transaction2
|
|
88
|
+
};
|
|
89
|
+
})], _update_dec = [(0, import_relation_repository.transaction)(), import_target_collection_decorator.default], _a) {
|
|
90
|
+
constructor() {
|
|
91
|
+
super(...arguments);
|
|
92
|
+
__runInitializers(_init, 5, this);
|
|
93
|
+
}
|
|
94
|
+
extendFindOptions(findOptions) {
|
|
95
|
+
return findOptions;
|
|
96
|
+
}
|
|
97
|
+
async find(options) {
|
|
98
|
+
const targetRepository = this.targetCollection.repository;
|
|
99
|
+
const association = this.association;
|
|
100
|
+
const oneFromTargetOptions = {
|
|
101
|
+
as: "_pivot_",
|
|
102
|
+
foreignKey: association.otherKey,
|
|
103
|
+
sourceKey: association.targetKey,
|
|
104
|
+
realAs: association.through.model.name
|
|
105
|
+
};
|
|
106
|
+
const pivotAssoc = new import_sequelize.HasOne(association.target, association.through.model, oneFromTargetOptions);
|
|
107
|
+
const appendFilter = {
|
|
108
|
+
isPivotFilter: true,
|
|
109
|
+
association: pivotAssoc,
|
|
110
|
+
where: {
|
|
111
|
+
[association.foreignKey]: this.sourceKeyValue
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
return targetRepository.find({
|
|
115
|
+
include: [appendFilter],
|
|
116
|
+
...options
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
async findAndCount(options) {
|
|
120
|
+
const transaction2 = await this.getTransaction(options, false);
|
|
121
|
+
return [
|
|
122
|
+
await this.find({
|
|
123
|
+
...options,
|
|
124
|
+
transaction: transaction2
|
|
125
|
+
}),
|
|
126
|
+
await this.count({
|
|
127
|
+
...options,
|
|
128
|
+
transaction: transaction2
|
|
129
|
+
})
|
|
130
|
+
];
|
|
131
|
+
}
|
|
132
|
+
async count(options) {
|
|
133
|
+
const transaction2 = await this.getTransaction(options);
|
|
134
|
+
const sourceModel = await this.getSourceModel(transaction2);
|
|
135
|
+
if (!sourceModel) return 0;
|
|
136
|
+
const queryOptions = this.buildQueryOptions(options);
|
|
137
|
+
const count = await sourceModel[this.accessors().get]({
|
|
138
|
+
where: queryOptions.where,
|
|
139
|
+
include: queryOptions.include,
|
|
140
|
+
includeIgnoreAttributes: false,
|
|
141
|
+
attributes: [
|
|
142
|
+
[
|
|
143
|
+
import_sequelize.Sequelize.fn(
|
|
144
|
+
"COUNT",
|
|
145
|
+
import_sequelize.Sequelize.fn("DISTINCT", import_sequelize.Sequelize.col(`${this.targetModel.name}.${this.targetKey()}`))
|
|
146
|
+
),
|
|
147
|
+
"count"
|
|
148
|
+
]
|
|
149
|
+
],
|
|
150
|
+
raw: true,
|
|
151
|
+
plain: true,
|
|
152
|
+
transaction: transaction2
|
|
153
|
+
});
|
|
154
|
+
return parseInt(count.count);
|
|
155
|
+
}
|
|
156
|
+
async findOne(options) {
|
|
157
|
+
const transaction2 = await this.getTransaction(options, false);
|
|
158
|
+
const rows = await this.find({ ...options, limit: 1, transaction: transaction2 });
|
|
159
|
+
return rows.length == 1 ? rows[0] : null;
|
|
160
|
+
}
|
|
161
|
+
async remove(options) {
|
|
162
|
+
const transaction2 = await this.getTransaction(options);
|
|
163
|
+
const sourceModel = await this.getSourceModel(transaction2);
|
|
164
|
+
await sourceModel[this.accessors().removeMultiple](this.convertTks(options), {
|
|
165
|
+
transaction: transaction2
|
|
166
|
+
});
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
async update(options) {
|
|
170
|
+
const transaction2 = await this.getTransaction(options);
|
|
171
|
+
const guard = import_update_guard.UpdateGuard.fromOptions(this.targetModel, options);
|
|
172
|
+
const values = guard.sanitize(options.values);
|
|
173
|
+
const instances = await this.find({
|
|
174
|
+
...import_lodash.default.omit(options, ["values"]),
|
|
175
|
+
transaction: transaction2
|
|
176
|
+
});
|
|
177
|
+
for (const instance of instances) {
|
|
178
|
+
await (0, import_update_associations.updateModelByValues)(instance, values, {
|
|
179
|
+
...options,
|
|
180
|
+
sanitized: true,
|
|
181
|
+
sourceModel: await this.getSourceModel(transaction2),
|
|
182
|
+
transaction: transaction2
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
for (const instance of instances) {
|
|
186
|
+
if (options.hooks !== false) {
|
|
187
|
+
await this.db.emitAsync(`${this.targetCollection.name}.afterUpdateWithAssociations`, instance, {
|
|
188
|
+
...options,
|
|
189
|
+
transaction: transaction2
|
|
190
|
+
});
|
|
191
|
+
await this.db.emitAsync(`${this.targetCollection.name}.afterSaveWithAssociations`, instance, {
|
|
192
|
+
...options,
|
|
193
|
+
transaction: transaction2
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
return instances;
|
|
198
|
+
}
|
|
199
|
+
async destroy(options) {
|
|
200
|
+
return false;
|
|
201
|
+
}
|
|
202
|
+
async destroyByFilter(filter, transaction2) {
|
|
203
|
+
const instances = await this.find({
|
|
204
|
+
filter,
|
|
205
|
+
transaction: transaction2
|
|
206
|
+
});
|
|
207
|
+
return await this.destroy({
|
|
208
|
+
filterByTk: instances.map((instance) => instance.get(this.targetCollection.filterTargetKey)),
|
|
209
|
+
transaction: transaction2
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
filterHasInclude(filter, options) {
|
|
213
|
+
const filterResult = this.parseFilter(filter, options);
|
|
214
|
+
return filterResult.include && filterResult.include.length > 0;
|
|
215
|
+
}
|
|
216
|
+
accessors() {
|
|
217
|
+
return super.accessors();
|
|
218
|
+
}
|
|
219
|
+
};
|
|
220
|
+
_init = __decoratorStart(_a);
|
|
221
|
+
__decorateElement(_init, 1, "remove", _remove_dec, _MultipleRelationRepository);
|
|
222
|
+
__decorateElement(_init, 1, "update", _update_dec, _MultipleRelationRepository);
|
|
223
|
+
__decoratorMetadata(_init, _MultipleRelationRepository);
|
|
224
|
+
__name(_MultipleRelationRepository, "MultipleRelationRepository");
|
|
225
|
+
let MultipleRelationRepository = _MultipleRelationRepository;
|
|
226
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
227
|
+
0 && (module.exports = {
|
|
228
|
+
MultipleRelationRepository
|
|
229
|
+
});
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Association, ModelStatic, Transaction } from 'sequelize';
|
|
2
|
+
import { Collection } from '../collection';
|
|
3
|
+
import Database from '../database';
|
|
4
|
+
import { RelationField } from '../fields/relation-field';
|
|
5
|
+
import { Model } from '../model';
|
|
6
|
+
import { CreateOptions, Filter, FindOptions } from '../repository';
|
|
7
|
+
export declare const transaction: (transactionInjector?: any) => (originalMethod: any, context: ClassMethodDecoratorContext) => (...args: unknown[]) => Promise<any>;
|
|
8
|
+
export declare abstract class RelationRepository {
|
|
9
|
+
sourceCollection: Collection;
|
|
10
|
+
association: Association;
|
|
11
|
+
targetModel: ModelStatic<any>;
|
|
12
|
+
targetCollection: Collection;
|
|
13
|
+
associationName: string;
|
|
14
|
+
associationField: RelationField;
|
|
15
|
+
sourceKeyValue: string | number;
|
|
16
|
+
sourceInstance: Model;
|
|
17
|
+
db: Database;
|
|
18
|
+
constructor(sourceCollection: Collection, association: string, sourceKeyValue: string | number);
|
|
19
|
+
get collection(): Collection<any, any>;
|
|
20
|
+
convertTk(options: any): any;
|
|
21
|
+
convertTks(options: any): any[];
|
|
22
|
+
targetKey(): any;
|
|
23
|
+
protected accessors(): import("sequelize").SingleAssociationAccessors | import("sequelize").MultiAssociationAccessors;
|
|
24
|
+
create(options?: CreateOptions): Promise<any>;
|
|
25
|
+
getSourceModel(transaction?: Transaction): Promise<Model<any, any>>;
|
|
26
|
+
protected buildQueryOptions(options: FindOptions): any;
|
|
27
|
+
protected parseFilter(filter: Filter, options?: any): any;
|
|
28
|
+
protected getTransaction(options: any, autoGen?: boolean): Promise<Transaction | null>;
|
|
29
|
+
}
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __knownSymbol = (name, symbol) => (symbol = Symbol[name]) ? symbol : Symbol.for("Symbol." + name);
|
|
8
|
+
var __typeError = (msg) => {
|
|
9
|
+
throw TypeError(msg);
|
|
10
|
+
};
|
|
11
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
12
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
13
|
+
var __export = (target, all) => {
|
|
14
|
+
for (var name in all)
|
|
15
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
16
|
+
};
|
|
17
|
+
var __copyProps = (to, from, except, desc) => {
|
|
18
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
19
|
+
for (let key of __getOwnPropNames(from))
|
|
20
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
21
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
22
|
+
}
|
|
23
|
+
return to;
|
|
24
|
+
};
|
|
25
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
26
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
27
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
28
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
29
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
30
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
31
|
+
mod
|
|
32
|
+
));
|
|
33
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
34
|
+
var __decoratorStart = (base) => [, , , __create((base == null ? void 0 : base[__knownSymbol("metadata")]) ?? null)];
|
|
35
|
+
var __decoratorStrings = ["class", "method", "getter", "setter", "accessor", "field", "value", "get", "set"];
|
|
36
|
+
var __expectFn = (fn) => fn !== void 0 && typeof fn !== "function" ? __typeError("Function expected") : fn;
|
|
37
|
+
var __decoratorContext = (kind, name, done, metadata, fns) => ({ kind: __decoratorStrings[kind], name, metadata, addInitializer: (fn) => done._ ? __typeError("Already initialized") : fns.push(__expectFn(fn || null)) });
|
|
38
|
+
var __decoratorMetadata = (array, target) => __defNormalProp(target, __knownSymbol("metadata"), array[3]);
|
|
39
|
+
var __runInitializers = (array, flags, self, value) => {
|
|
40
|
+
for (var i = 0, fns = array[flags >> 1], n = fns && fns.length; i < n; i++) flags & 1 ? fns[i].call(self) : value = fns[i].call(self, value);
|
|
41
|
+
return value;
|
|
42
|
+
};
|
|
43
|
+
var __decorateElement = (array, flags, name, decorators, target, extra) => {
|
|
44
|
+
var fn, it, done, ctx, access, k = flags & 7, s = !!(flags & 8), p = !!(flags & 16);
|
|
45
|
+
var j = k > 3 ? array.length + 1 : k ? s ? 1 : 2 : 0, key = __decoratorStrings[k + 5];
|
|
46
|
+
var initializers = k > 3 && (array[j - 1] = []), extraInitializers = array[j] || (array[j] = []);
|
|
47
|
+
var desc = k && (!p && !s && (target = target.prototype), k < 5 && (k > 3 || !p) && __getOwnPropDesc(k < 4 ? target : { get [name]() {
|
|
48
|
+
return __privateGet(this, extra);
|
|
49
|
+
}, set [name](x) {
|
|
50
|
+
return __privateSet(this, extra, x);
|
|
51
|
+
} }, name));
|
|
52
|
+
k ? p && k < 4 && __name(extra, (k > 2 ? "set " : k > 1 ? "get " : "") + name) : __name(target, name);
|
|
53
|
+
for (var i = decorators.length - 1; i >= 0; i--) {
|
|
54
|
+
ctx = __decoratorContext(k, name, done = {}, array[3], extraInitializers);
|
|
55
|
+
if (k) {
|
|
56
|
+
ctx.static = s, ctx.private = p, access = ctx.access = { has: p ? (x) => __privateIn(target, x) : (x) => name in x };
|
|
57
|
+
if (k ^ 3) access.get = p ? (x) => (k ^ 1 ? __privateGet : __privateMethod)(x, target, k ^ 4 ? extra : desc.get) : (x) => x[name];
|
|
58
|
+
if (k > 2) access.set = p ? (x, y) => __privateSet(x, target, y, k ^ 4 ? extra : desc.set) : (x, y) => x[name] = y;
|
|
59
|
+
}
|
|
60
|
+
it = (0, decorators[i])(k ? k < 4 ? p ? extra : desc[key] : k > 4 ? void 0 : { get: desc.get, set: desc.set } : target, ctx), done._ = 1;
|
|
61
|
+
if (k ^ 4 || it === void 0) __expectFn(it) && (k > 4 ? initializers.unshift(it) : k ? p ? extra = it : desc[key] = it : target = it);
|
|
62
|
+
else if (typeof it !== "object" || it === null) __typeError("Object expected");
|
|
63
|
+
else __expectFn(fn = it.get) && (desc.get = fn), __expectFn(fn = it.set) && (desc.set = fn), __expectFn(fn = it.init) && initializers.unshift(fn);
|
|
64
|
+
}
|
|
65
|
+
return k || __decoratorMetadata(array, target), desc && __defProp(target, name, desc), p ? k ^ 4 ? extra : desc : target;
|
|
66
|
+
};
|
|
67
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
68
|
+
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
69
|
+
var __privateIn = (member, obj) => Object(obj) !== obj ? __typeError('Cannot use the "in" operator on this value') : member.has(obj);
|
|
70
|
+
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
71
|
+
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
72
|
+
var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
|
|
73
|
+
var relation_repository_exports = {};
|
|
74
|
+
__export(relation_repository_exports, {
|
|
75
|
+
RelationRepository: () => RelationRepository,
|
|
76
|
+
transaction: () => transaction
|
|
77
|
+
});
|
|
78
|
+
module.exports = __toCommonJS(relation_repository_exports);
|
|
79
|
+
var import_lodash = __toESM(require("lodash"));
|
|
80
|
+
var import_transaction_decorator = require("../decorators/transaction-decorator");
|
|
81
|
+
var import_filter_parser = __toESM(require("../filter-parser"));
|
|
82
|
+
var import_options_parser = require("../options-parser");
|
|
83
|
+
var import_update_associations = require("../update-associations");
|
|
84
|
+
var import_update_guard = require("../update-guard");
|
|
85
|
+
var _create_dec, _init;
|
|
86
|
+
const transaction = (0, import_transaction_decorator.transactionWrapperBuilder)(function() {
|
|
87
|
+
return this.sourceCollection.model.sequelize.transaction();
|
|
88
|
+
});
|
|
89
|
+
_create_dec = [transaction()];
|
|
90
|
+
const _RelationRepository = class _RelationRepository {
|
|
91
|
+
constructor(sourceCollection, association, sourceKeyValue) {
|
|
92
|
+
__runInitializers(_init, 5, this);
|
|
93
|
+
__publicField(this, "sourceCollection");
|
|
94
|
+
__publicField(this, "association");
|
|
95
|
+
__publicField(this, "targetModel");
|
|
96
|
+
__publicField(this, "targetCollection");
|
|
97
|
+
__publicField(this, "associationName");
|
|
98
|
+
__publicField(this, "associationField");
|
|
99
|
+
__publicField(this, "sourceKeyValue");
|
|
100
|
+
__publicField(this, "sourceInstance");
|
|
101
|
+
__publicField(this, "db");
|
|
102
|
+
this.db = sourceCollection.context.database;
|
|
103
|
+
this.sourceCollection = sourceCollection;
|
|
104
|
+
this.sourceKeyValue = sourceKeyValue;
|
|
105
|
+
this.associationName = association;
|
|
106
|
+
this.association = this.sourceCollection.model.associations[association];
|
|
107
|
+
this.associationField = this.sourceCollection.getField(association);
|
|
108
|
+
this.targetModel = this.association.target;
|
|
109
|
+
this.targetCollection = this.sourceCollection.context.database.modelCollection.get(this.targetModel);
|
|
110
|
+
}
|
|
111
|
+
get collection() {
|
|
112
|
+
return this.db.getCollection(this.targetModel.name);
|
|
113
|
+
}
|
|
114
|
+
convertTk(options) {
|
|
115
|
+
let tk = options;
|
|
116
|
+
if (typeof options === "object" && options["tk"]) {
|
|
117
|
+
tk = options["tk"];
|
|
118
|
+
}
|
|
119
|
+
return tk;
|
|
120
|
+
}
|
|
121
|
+
convertTks(options) {
|
|
122
|
+
let tk = this.convertTk(options);
|
|
123
|
+
if (typeof tk === "string") {
|
|
124
|
+
tk = tk.split(",");
|
|
125
|
+
}
|
|
126
|
+
return import_lodash.default.castArray(tk);
|
|
127
|
+
}
|
|
128
|
+
targetKey() {
|
|
129
|
+
return this.associationField.targetKey;
|
|
130
|
+
}
|
|
131
|
+
accessors() {
|
|
132
|
+
return this.association.accessors;
|
|
133
|
+
}
|
|
134
|
+
async create(options) {
|
|
135
|
+
if (Array.isArray(options.values)) {
|
|
136
|
+
return Promise.all(options.values.map((record) => this.create({ ...options, values: record })));
|
|
137
|
+
}
|
|
138
|
+
const createAccessor = this.accessors().create;
|
|
139
|
+
const guard = import_update_guard.UpdateGuard.fromOptions(this.targetModel, options);
|
|
140
|
+
const values = options.values;
|
|
141
|
+
const transaction2 = await this.getTransaction(options);
|
|
142
|
+
const sourceModel = await this.getSourceModel(transaction2);
|
|
143
|
+
const instance = await sourceModel[createAccessor](guard.sanitize(options.values), { ...options, transaction: transaction2 });
|
|
144
|
+
await (0, import_update_associations.updateAssociations)(instance, values, { ...options, transaction: transaction2 });
|
|
145
|
+
if (options.hooks !== false) {
|
|
146
|
+
await this.db.emitAsync(`${this.targetCollection.name}.afterCreateWithAssociations`, instance, {
|
|
147
|
+
...options,
|
|
148
|
+
transaction: transaction2
|
|
149
|
+
});
|
|
150
|
+
const eventName = `${this.targetCollection.name}.afterSaveWithAssociations`;
|
|
151
|
+
await this.db.emitAsync(eventName, instance, { ...options, transaction: transaction2 });
|
|
152
|
+
}
|
|
153
|
+
return instance;
|
|
154
|
+
}
|
|
155
|
+
async getSourceModel(transaction2) {
|
|
156
|
+
if (!this.sourceInstance) {
|
|
157
|
+
this.sourceInstance = await this.sourceCollection.model.findOne({
|
|
158
|
+
where: {
|
|
159
|
+
[this.associationField.sourceKey]: this.sourceKeyValue
|
|
160
|
+
},
|
|
161
|
+
transaction: transaction2
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
return this.sourceInstance;
|
|
165
|
+
}
|
|
166
|
+
buildQueryOptions(options) {
|
|
167
|
+
const parser = new import_options_parser.OptionsParser(options, {
|
|
168
|
+
collection: this.targetCollection,
|
|
169
|
+
targetKey: this.targetKey()
|
|
170
|
+
});
|
|
171
|
+
const params = parser.toSequelizeParams();
|
|
172
|
+
return { ...options, ...params };
|
|
173
|
+
}
|
|
174
|
+
parseFilter(filter, options) {
|
|
175
|
+
const parser = new import_filter_parser.default(filter, {
|
|
176
|
+
collection: this.targetCollection,
|
|
177
|
+
app: {
|
|
178
|
+
ctx: options == null ? void 0 : options.context
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
return parser.toSequelizeParams();
|
|
182
|
+
}
|
|
183
|
+
async getTransaction(options, autoGen = false) {
|
|
184
|
+
if (import_lodash.default.isPlainObject(options) && options.transaction) {
|
|
185
|
+
return options.transaction;
|
|
186
|
+
}
|
|
187
|
+
if (autoGen) {
|
|
188
|
+
return await this.sourceCollection.model.sequelize.transaction();
|
|
189
|
+
}
|
|
190
|
+
return null;
|
|
191
|
+
}
|
|
192
|
+
};
|
|
193
|
+
_init = __decoratorStart(null);
|
|
194
|
+
__decorateElement(_init, 1, "create", _create_dec, _RelationRepository);
|
|
195
|
+
__decoratorMetadata(_init, _RelationRepository);
|
|
196
|
+
__name(_RelationRepository, "RelationRepository");
|
|
197
|
+
let RelationRepository = _RelationRepository;
|
|
198
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
199
|
+
0 && (module.exports = {
|
|
200
|
+
RelationRepository,
|
|
201
|
+
transaction
|
|
202
|
+
});
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { SingleAssociationAccessors, Transactionable } from 'sequelize';
|
|
2
|
+
import { Model } from '../model';
|
|
3
|
+
import { Appends, Except, Fields, Filter, TargetKey, UpdateOptions } from '../repository';
|
|
4
|
+
import { RelationRepository } from './relation-repository';
|
|
5
|
+
export interface SingleRelationFindOption extends Transactionable {
|
|
6
|
+
fields?: Fields;
|
|
7
|
+
except?: Except;
|
|
8
|
+
appends?: Appends;
|
|
9
|
+
filter?: Filter;
|
|
10
|
+
targetCollection?: string;
|
|
11
|
+
}
|
|
12
|
+
interface SetOption extends Transactionable {
|
|
13
|
+
tk?: TargetKey;
|
|
14
|
+
}
|
|
15
|
+
export declare abstract class SingleRelationRepository extends RelationRepository {
|
|
16
|
+
abstract filterOptions(sourceModel: any): any;
|
|
17
|
+
remove(options?: Transactionable): Promise<void>;
|
|
18
|
+
set(options: TargetKey | SetOption): Promise<void>;
|
|
19
|
+
find(options?: SingleRelationFindOption): Promise<any>;
|
|
20
|
+
findOne(options?: SingleRelationFindOption): Promise<Model<any>>;
|
|
21
|
+
destroy(options?: Transactionable): Promise<boolean>;
|
|
22
|
+
update(options: UpdateOptions): Promise<any>;
|
|
23
|
+
accessors(): SingleAssociationAccessors;
|
|
24
|
+
}
|
|
25
|
+
export {};
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __knownSymbol = (name, symbol) => (symbol = Symbol[name]) ? symbol : Symbol.for("Symbol." + name);
|
|
8
|
+
var __typeError = (msg) => {
|
|
9
|
+
throw TypeError(msg);
|
|
10
|
+
};
|
|
11
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
12
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
13
|
+
var __export = (target, all) => {
|
|
14
|
+
for (var name in all)
|
|
15
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
16
|
+
};
|
|
17
|
+
var __copyProps = (to, from, except, desc) => {
|
|
18
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
19
|
+
for (let key of __getOwnPropNames(from))
|
|
20
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
21
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
22
|
+
}
|
|
23
|
+
return to;
|
|
24
|
+
};
|
|
25
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
26
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
27
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
28
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
29
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
30
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
31
|
+
mod
|
|
32
|
+
));
|
|
33
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
34
|
+
var __decoratorStart = (base) => [, , , __create((base == null ? void 0 : base[__knownSymbol("metadata")]) ?? null)];
|
|
35
|
+
var __decoratorStrings = ["class", "method", "getter", "setter", "accessor", "field", "value", "get", "set"];
|
|
36
|
+
var __expectFn = (fn) => fn !== void 0 && typeof fn !== "function" ? __typeError("Function expected") : fn;
|
|
37
|
+
var __decoratorContext = (kind, name, done, metadata, fns) => ({ kind: __decoratorStrings[kind], name, metadata, addInitializer: (fn) => done._ ? __typeError("Already initialized") : fns.push(__expectFn(fn || null)) });
|
|
38
|
+
var __decoratorMetadata = (array, target) => __defNormalProp(target, __knownSymbol("metadata"), array[3]);
|
|
39
|
+
var __runInitializers = (array, flags, self, value) => {
|
|
40
|
+
for (var i = 0, fns = array[flags >> 1], n = fns && fns.length; i < n; i++) flags & 1 ? fns[i].call(self) : value = fns[i].call(self, value);
|
|
41
|
+
return value;
|
|
42
|
+
};
|
|
43
|
+
var __decorateElement = (array, flags, name, decorators, target, extra) => {
|
|
44
|
+
var fn, it, done, ctx, access, k = flags & 7, s = !!(flags & 8), p = !!(flags & 16);
|
|
45
|
+
var j = k > 3 ? array.length + 1 : k ? s ? 1 : 2 : 0, key = __decoratorStrings[k + 5];
|
|
46
|
+
var initializers = k > 3 && (array[j - 1] = []), extraInitializers = array[j] || (array[j] = []);
|
|
47
|
+
var desc = k && (!p && !s && (target = target.prototype), k < 5 && (k > 3 || !p) && __getOwnPropDesc(k < 4 ? target : { get [name]() {
|
|
48
|
+
return __privateGet(this, extra);
|
|
49
|
+
}, set [name](x) {
|
|
50
|
+
return __privateSet(this, extra, x);
|
|
51
|
+
} }, name));
|
|
52
|
+
k ? p && k < 4 && __name(extra, (k > 2 ? "set " : k > 1 ? "get " : "") + name) : __name(target, name);
|
|
53
|
+
for (var i = decorators.length - 1; i >= 0; i--) {
|
|
54
|
+
ctx = __decoratorContext(k, name, done = {}, array[3], extraInitializers);
|
|
55
|
+
if (k) {
|
|
56
|
+
ctx.static = s, ctx.private = p, access = ctx.access = { has: p ? (x) => __privateIn(target, x) : (x) => name in x };
|
|
57
|
+
if (k ^ 3) access.get = p ? (x) => (k ^ 1 ? __privateGet : __privateMethod)(x, target, k ^ 4 ? extra : desc.get) : (x) => x[name];
|
|
58
|
+
if (k > 2) access.set = p ? (x, y) => __privateSet(x, target, y, k ^ 4 ? extra : desc.set) : (x, y) => x[name] = y;
|
|
59
|
+
}
|
|
60
|
+
it = (0, decorators[i])(k ? k < 4 ? p ? extra : desc[key] : k > 4 ? void 0 : { get: desc.get, set: desc.set } : target, ctx), done._ = 1;
|
|
61
|
+
if (k ^ 4 || it === void 0) __expectFn(it) && (k > 4 ? initializers.unshift(it) : k ? p ? extra = it : desc[key] = it : target = it);
|
|
62
|
+
else if (typeof it !== "object" || it === null) __typeError("Object expected");
|
|
63
|
+
else __expectFn(fn = it.get) && (desc.get = fn), __expectFn(fn = it.set) && (desc.set = fn), __expectFn(fn = it.init) && initializers.unshift(fn);
|
|
64
|
+
}
|
|
65
|
+
return k || __decoratorMetadata(array, target), desc && __defProp(target, name, desc), p ? k ^ 4 ? extra : desc : target;
|
|
66
|
+
};
|
|
67
|
+
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
68
|
+
var __privateIn = (member, obj) => Object(obj) !== obj ? __typeError('Cannot use the "in" operator on this value') : member.has(obj);
|
|
69
|
+
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
70
|
+
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
71
|
+
var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
|
|
72
|
+
var single_relation_repository_exports = {};
|
|
73
|
+
__export(single_relation_repository_exports, {
|
|
74
|
+
SingleRelationRepository: () => SingleRelationRepository
|
|
75
|
+
});
|
|
76
|
+
module.exports = __toCommonJS(single_relation_repository_exports);
|
|
77
|
+
var import_lodash = __toESM(require("lodash"));
|
|
78
|
+
var import_target_collection_decorator = __toESM(require("../decorators/target-collection-decorator"));
|
|
79
|
+
var import_update_associations = require("../update-associations");
|
|
80
|
+
var import_relation_repository = require("./relation-repository");
|
|
81
|
+
var _update_dec, _destroy_dec, _set_dec, _remove_dec, _a, _init;
|
|
82
|
+
const _SingleRelationRepository = class _SingleRelationRepository extends (_a = import_relation_repository.RelationRepository, _remove_dec = [(0, import_relation_repository.transaction)()], _set_dec = [(0, import_relation_repository.transaction)((args, transaction2) => {
|
|
83
|
+
return {
|
|
84
|
+
tk: args[0],
|
|
85
|
+
transaction: transaction2
|
|
86
|
+
};
|
|
87
|
+
})], _destroy_dec = [(0, import_relation_repository.transaction)()], _update_dec = [(0, import_relation_repository.transaction)(), import_target_collection_decorator.default], _a) {
|
|
88
|
+
constructor() {
|
|
89
|
+
super(...arguments);
|
|
90
|
+
__runInitializers(_init, 5, this);
|
|
91
|
+
}
|
|
92
|
+
async remove(options) {
|
|
93
|
+
const transaction2 = await this.getTransaction(options);
|
|
94
|
+
const sourceModel = await this.getSourceModel(transaction2);
|
|
95
|
+
return await sourceModel[this.accessors().set](null, {
|
|
96
|
+
transaction: transaction2
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
async set(options) {
|
|
100
|
+
const transaction2 = await this.getTransaction(options);
|
|
101
|
+
const sourceModel = await this.getSourceModel(transaction2);
|
|
102
|
+
return await sourceModel[this.accessors().set](this.convertTk(options), {
|
|
103
|
+
transaction: transaction2
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
async find(options) {
|
|
107
|
+
const targetRepository = this.targetCollection.repository;
|
|
108
|
+
const sourceModel = await this.getSourceModel(await this.getTransaction(options));
|
|
109
|
+
if (!sourceModel) return null;
|
|
110
|
+
const addFilter = await this.filterOptions(sourceModel);
|
|
111
|
+
const findOptions = {
|
|
112
|
+
...options,
|
|
113
|
+
filter: {
|
|
114
|
+
$and: [(options == null ? void 0 : options.filter) || {}, addFilter]
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
return await targetRepository.findOne(findOptions);
|
|
118
|
+
}
|
|
119
|
+
async findOne(options) {
|
|
120
|
+
return this.find({ ...options, filterByTk: null });
|
|
121
|
+
}
|
|
122
|
+
async destroy(options) {
|
|
123
|
+
const transaction2 = await this.getTransaction(options);
|
|
124
|
+
const target = await this.find({
|
|
125
|
+
transaction: transaction2
|
|
126
|
+
});
|
|
127
|
+
await target.destroy({
|
|
128
|
+
transaction: transaction2
|
|
129
|
+
});
|
|
130
|
+
return true;
|
|
131
|
+
}
|
|
132
|
+
async update(options) {
|
|
133
|
+
const transaction2 = await this.getTransaction(options);
|
|
134
|
+
const target = await this.find({
|
|
135
|
+
transaction: transaction2,
|
|
136
|
+
targetCollection: options.targetCollection
|
|
137
|
+
});
|
|
138
|
+
if (!target) {
|
|
139
|
+
throw new Error("The record does not exist");
|
|
140
|
+
}
|
|
141
|
+
await (0, import_update_associations.updateModelByValues)(target, options == null ? void 0 : options.values, {
|
|
142
|
+
...import_lodash.default.omit(options, "values"),
|
|
143
|
+
transaction: transaction2
|
|
144
|
+
});
|
|
145
|
+
return target;
|
|
146
|
+
}
|
|
147
|
+
accessors() {
|
|
148
|
+
return super.accessors();
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
_init = __decoratorStart(_a);
|
|
152
|
+
__decorateElement(_init, 1, "remove", _remove_dec, _SingleRelationRepository);
|
|
153
|
+
__decorateElement(_init, 1, "set", _set_dec, _SingleRelationRepository);
|
|
154
|
+
__decorateElement(_init, 1, "destroy", _destroy_dec, _SingleRelationRepository);
|
|
155
|
+
__decorateElement(_init, 1, "update", _update_dec, _SingleRelationRepository);
|
|
156
|
+
__decoratorMetadata(_init, _SingleRelationRepository);
|
|
157
|
+
__name(_SingleRelationRepository, "SingleRelationRepository");
|
|
158
|
+
let SingleRelationRepository = _SingleRelationRepository;
|
|
159
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
160
|
+
0 && (module.exports = {
|
|
161
|
+
SingleRelationRepository
|
|
162
|
+
});
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Transactionable } from 'sequelize';
|
|
2
|
+
import { TargetKey, Values } from '../repository';
|
|
3
|
+
export type PrimaryKeyWithThroughValues = [TargetKey, Values];
|
|
4
|
+
export interface AssociatedOptions extends Transactionable {
|
|
5
|
+
tk?: TargetKey | TargetKey[] | PrimaryKeyWithThroughValues | PrimaryKeyWithThroughValues[];
|
|
6
|
+
}
|
|
7
|
+
export type setAssociationOptions = TargetKey | TargetKey[] | PrimaryKeyWithThroughValues | PrimaryKeyWithThroughValues[] | AssociatedOptions;
|