@abedmurrar/objection 4.0.0-beta.0 → 4.0.0-beta.1
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/lib/relations/Relation.js +31 -29
- package/lib/relations/RelationDeleteOperation.js +10 -8
- package/lib/relations/RelationFindOperation.js +9 -6
- package/lib/relations/RelationInsertOperation.js +6 -6
- package/lib/relations/RelationOwner.js +16 -13
- package/lib/relations/RelationProperty.js +18 -15
- package/lib/relations/RelationUpdateOperation.js +9 -8
- package/lib/relations/belongsToOne/BelongsToOneDeleteOperation.js +6 -6
- package/lib/relations/belongsToOne/BelongsToOneInsertOperation.js +8 -8
- package/lib/relations/belongsToOne/BelongsToOneRelateOperation.js +8 -8
- package/lib/relations/belongsToOne/BelongsToOneRelation.js +14 -14
- package/lib/relations/belongsToOne/BelongsToOneUnrelateOperation.js +6 -6
- package/lib/relations/hasMany/HasManyInsertOperation.js +6 -6
- package/lib/relations/hasMany/HasManyRelateOperation.js +11 -11
- package/lib/relations/hasMany/HasManyRelation.js +12 -12
- package/lib/relations/hasMany/HasManyUnrelateOperation.js +9 -9
- package/lib/relations/hasOne/HasOneRelation.js +6 -6
- package/lib/relations/hasOneThrough/HasOneThroughRelation.js +6 -6
- package/lib/relations/manyToMany/ManyToManyModifyMixin.js +9 -8
- package/lib/relations/manyToMany/ManyToManyRelation.js +52 -49
- package/lib/relations/manyToMany/ManyToManySqliteModifyMixin.js +6 -6
- package/lib/relations/manyToMany/delete/ManyToManyDeleteOperation.js +7 -7
- package/lib/relations/manyToMany/delete/ManyToManyDeleteOperationBase.js +7 -6
- package/lib/relations/manyToMany/delete/ManyToManyDeleteSqliteOperation.js +7 -7
- package/lib/relations/manyToMany/find/ManyToManyFindOperation.js +8 -8
- package/lib/relations/manyToMany/insert/ManyToManyInsertOperation.js +8 -8
- package/lib/relations/manyToMany/relate/ManyToManyRelateOperation.js +11 -10
- package/lib/relations/manyToMany/unrelate/ManyToManyUnrelateOperation.js +7 -7
- package/lib/relations/manyToMany/unrelate/ManyToManyUnrelateOperationBase.js +8 -8
- package/lib/relations/manyToMany/unrelate/ManyToManyUnrelateSqliteOperation.js +7 -7
- package/lib/relations/manyToMany/update/ManyToManyUpdateOperation.js +7 -7
- package/lib/relations/manyToMany/update/ManyToManyUpdateOperationBase.js +8 -8
- package/lib/relations/manyToMany/update/ManyToManyUpdateSqliteOperation.js +7 -7
- package/package.json +1 -1
|
@@ -1,13 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
const
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Relation = void 0;
|
|
4
|
+
const whereScopes_1 = require("../queryBuilder/whereScopes");
|
|
5
|
+
const RelationProperty_1 = require("./RelationProperty");
|
|
6
|
+
const RelationFindOperation_1 = require("./RelationFindOperation");
|
|
7
|
+
const RelationUpdateOperation_1 = require("./RelationUpdateOperation");
|
|
8
|
+
const RelationDeleteOperation_1 = require("./RelationDeleteOperation");
|
|
9
|
+
const resolveModel_1 = require("../utils/resolveModel");
|
|
10
|
+
const objectUtils_1 = require("../utils/objectUtils");
|
|
11
|
+
const promiseUtils_1 = require("../utils/promiseUtils");
|
|
12
|
+
const createModifier_1 = require("../utils/createModifier");
|
|
11
13
|
class Relation {
|
|
12
14
|
constructor(relationName, OwnerClass) {
|
|
13
15
|
this.name = relationName;
|
|
@@ -92,7 +94,7 @@ class Relation {
|
|
|
92
94
|
}
|
|
93
95
|
findQuery(builder, owner) {
|
|
94
96
|
const relatedRefs = this.relatedProp.refs(builder);
|
|
95
|
-
withWhereScope(builder, () => {
|
|
97
|
+
(0, whereScopes_1.withWhereScope)(builder, () => {
|
|
96
98
|
owner.buildFindQuery(builder, this, relatedRefs);
|
|
97
99
|
});
|
|
98
100
|
return this.applyModify(builder);
|
|
@@ -101,7 +103,7 @@ class Relation {
|
|
|
101
103
|
try {
|
|
102
104
|
// The relation's `modify` gets its own scope so that an `orWhere`
|
|
103
105
|
// in it can't escape the owner condition.
|
|
104
|
-
return withWhereScope(builder, () => builder.modify(this.modify));
|
|
106
|
+
return (0, whereScopes_1.withWhereScope)(builder, () => builder.modify(this.modify));
|
|
105
107
|
}
|
|
106
108
|
catch (err) {
|
|
107
109
|
if (err instanceof this.relatedModelClass.ModifierNotFoundError) {
|
|
@@ -129,7 +131,7 @@ class Relation {
|
|
|
129
131
|
});
|
|
130
132
|
}
|
|
131
133
|
find(_, owner) {
|
|
132
|
-
return new RelationFindOperation('find', {
|
|
134
|
+
return new RelationFindOperation_1.RelationFindOperation('find', {
|
|
133
135
|
relation: this,
|
|
134
136
|
owner,
|
|
135
137
|
});
|
|
@@ -139,20 +141,20 @@ class Relation {
|
|
|
139
141
|
throw this.createError('not implemented');
|
|
140
142
|
}
|
|
141
143
|
update(_, owner) {
|
|
142
|
-
return new RelationUpdateOperation('update', {
|
|
144
|
+
return new RelationUpdateOperation_1.RelationUpdateOperation('update', {
|
|
143
145
|
relation: this,
|
|
144
146
|
owner,
|
|
145
147
|
});
|
|
146
148
|
}
|
|
147
149
|
patch(_, owner) {
|
|
148
|
-
return new RelationUpdateOperation('patch', {
|
|
150
|
+
return new RelationUpdateOperation_1.RelationUpdateOperation('patch', {
|
|
149
151
|
relation: this,
|
|
150
152
|
owner,
|
|
151
153
|
modelOptions: { patch: true },
|
|
152
154
|
});
|
|
153
155
|
}
|
|
154
156
|
delete(_, owner) {
|
|
155
|
-
return new RelationDeleteOperation('delete', {
|
|
157
|
+
return new RelationDeleteOperation_1.RelationDeleteOperation('delete', {
|
|
156
158
|
relation: this,
|
|
157
159
|
owner,
|
|
158
160
|
});
|
|
@@ -174,7 +176,7 @@ class Relation {
|
|
|
174
176
|
});
|
|
175
177
|
}
|
|
176
178
|
executeBeforeInsert(models, queryContext, result) {
|
|
177
|
-
return mapAfterAllReturn(models, (model) => this.beforeInsert(model, queryContext), result);
|
|
179
|
+
return (0, promiseUtils_1.mapAfterAllReturn)(models, (model) => this.beforeInsert(model, queryContext), result);
|
|
178
180
|
}
|
|
179
181
|
createError(message) {
|
|
180
182
|
if (this.ownerModelClass && this.ownerModelClass.name && this.name) {
|
|
@@ -185,6 +187,7 @@ class Relation {
|
|
|
185
187
|
}
|
|
186
188
|
}
|
|
187
189
|
}
|
|
190
|
+
exports.Relation = Relation;
|
|
188
191
|
Object.defineProperties(Relation, {
|
|
189
192
|
isObjectionRelationClass: {
|
|
190
193
|
enumerable: false,
|
|
@@ -201,14 +204,14 @@ Object.defineProperties(Relation.prototype, {
|
|
|
201
204
|
});
|
|
202
205
|
function checkForbiddenProperties(ctx) {
|
|
203
206
|
ctx.forbiddenMappingProperties.forEach((prop) => {
|
|
204
|
-
if (get(ctx.mapping, prop.split('.')) !== undefined) {
|
|
207
|
+
if ((0, objectUtils_1.get)(ctx.mapping, prop.split('.')) !== undefined) {
|
|
205
208
|
throw ctx.createError(`Property ${prop} is not supported for this relation type.`);
|
|
206
209
|
}
|
|
207
210
|
});
|
|
208
211
|
return ctx;
|
|
209
212
|
}
|
|
210
213
|
function checkOwnerModelClass(ctx) {
|
|
211
|
-
if (!isFunction(ctx.ownerModelClass) || !ctx.ownerModelClass.isObjectionModelClass) {
|
|
214
|
+
if (!(0, objectUtils_1.isFunction)(ctx.ownerModelClass) || !ctx.ownerModelClass.isObjectionModelClass) {
|
|
212
215
|
throw ctx.createError(`Relation's owner is not a subclass of Model`);
|
|
213
216
|
}
|
|
214
217
|
return ctx;
|
|
@@ -222,7 +225,9 @@ function checkRelatedModelClass(ctx) {
|
|
|
222
225
|
function resolveRelatedModelClass(ctx) {
|
|
223
226
|
let relatedModelClass;
|
|
224
227
|
try {
|
|
225
|
-
|
|
228
|
+
// undefined only for a relative path without `modelPaths`, which then
|
|
229
|
+
// fails further on, as it did in the JavaScript code.
|
|
230
|
+
relatedModelClass = (0, resolveModel_1.resolveModel)(ctx.mapping.modelClass, ctx.ownerModelClass.modelPaths, 'modelClass');
|
|
226
231
|
}
|
|
227
232
|
catch (err) {
|
|
228
233
|
throw ctx.createError(err.message);
|
|
@@ -233,7 +238,7 @@ function checkRelation(ctx) {
|
|
|
233
238
|
if (!ctx.mapping.relation) {
|
|
234
239
|
throw ctx.createError('relation is not defined');
|
|
235
240
|
}
|
|
236
|
-
if (!isFunction(ctx.mapping.relation) || !ctx.mapping.relation.isObjectionRelationClass) {
|
|
241
|
+
if (!(0, objectUtils_1.isFunction)(ctx.mapping.relation) || !ctx.mapping.relation.isObjectionRelationClass) {
|
|
237
242
|
throw ctx.createError('relation is not a subclass of Relation');
|
|
238
243
|
}
|
|
239
244
|
return ctx;
|
|
@@ -268,15 +273,15 @@ function createJoinProperties(ctx) {
|
|
|
268
273
|
}
|
|
269
274
|
function createRelationProperty(ctx, refString, propName) {
|
|
270
275
|
try {
|
|
271
|
-
return new RelationProperty(refString, (table) => {
|
|
276
|
+
return new RelationProperty_1.RelationProperty(refString, (table) => {
|
|
272
277
|
return [ctx.ownerModelClass, ctx.relatedModelClass].find((it) => it.getTableName() === table);
|
|
273
278
|
});
|
|
274
279
|
}
|
|
275
280
|
catch (err) {
|
|
276
|
-
if (err instanceof RelationProperty.ModelNotFoundError) {
|
|
281
|
+
if (err instanceof RelationProperty_1.RelationProperty.ModelNotFoundError) {
|
|
277
282
|
throw ctx.createError(`join: either \`from\` or \`to\` must point to the owner model table and the other one to the related table. It might be that specified table '${err.tableName}' is not correct`);
|
|
278
283
|
}
|
|
279
|
-
else if (err instanceof RelationProperty.InvalidReferenceError) {
|
|
284
|
+
else if (err instanceof RelationProperty_1.RelationProperty.InvalidReferenceError) {
|
|
280
285
|
throw ctx.createError(`${propName} must have format TableName.columnName. For example "SomeTable.id" or in case of composite key ["SomeTable.a", "SomeTable.b"].`);
|
|
281
286
|
}
|
|
282
287
|
else {
|
|
@@ -288,7 +293,7 @@ function parseModify(ctx) {
|
|
|
288
293
|
const mapping = ctx.mapping;
|
|
289
294
|
const modifier = mapping.modify || mapping.filter;
|
|
290
295
|
const modify = modifier &&
|
|
291
|
-
createModifier({
|
|
296
|
+
(0, createModifier_1.createModifier)({
|
|
292
297
|
modifier,
|
|
293
298
|
modelClass: ctx.relatedModelClass,
|
|
294
299
|
});
|
|
@@ -296,7 +301,7 @@ function parseModify(ctx) {
|
|
|
296
301
|
}
|
|
297
302
|
function parseBeforeInsert(ctx) {
|
|
298
303
|
let beforeInsert;
|
|
299
|
-
if (isFunction(ctx.mapping.beforeInsert)) {
|
|
304
|
+
if ((0, objectUtils_1.isFunction)(ctx.mapping.beforeInsert)) {
|
|
300
305
|
beforeInsert = ctx.mapping.beforeInsert;
|
|
301
306
|
}
|
|
302
307
|
else {
|
|
@@ -312,6 +317,3 @@ function aliasedTableName(tableName, alias) {
|
|
|
312
317
|
return `${tableName} as ${alias}`;
|
|
313
318
|
}
|
|
314
319
|
}
|
|
315
|
-
module.exports = {
|
|
316
|
-
Relation,
|
|
317
|
-
};
|
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RelationDeleteOperation = void 0;
|
|
4
|
+
const DeleteOperation_1 = require("../queryBuilder/operations/DeleteOperation");
|
|
5
|
+
const RelationFindOperation_1 = require("./RelationFindOperation");
|
|
6
|
+
class RelationDeleteOperation extends DeleteOperation_1.DeleteOperation {
|
|
5
7
|
constructor(name, opt) {
|
|
8
|
+
// @ts-expect-error The JavaScript QueryBuilderOperation's `name` is inferred as null.
|
|
6
9
|
super(name, opt);
|
|
7
10
|
this.relation = opt.relation;
|
|
8
11
|
this.owner = opt.owner;
|
|
@@ -11,13 +14,12 @@ class RelationDeleteOperation extends DeleteOperation {
|
|
|
11
14
|
super.onBuild(builder);
|
|
12
15
|
this.relation.findQuery(builder, this.owner);
|
|
13
16
|
}
|
|
17
|
+
// @ts-expect-error The JavaScript base class's toFindOperation() is inferred to return null.
|
|
14
18
|
toFindOperation() {
|
|
15
|
-
return new RelationFindOperation('find', {
|
|
19
|
+
return new RelationFindOperation_1.RelationFindOperation('find', {
|
|
16
20
|
relation: this.relation,
|
|
17
21
|
owner: this.owner,
|
|
18
22
|
});
|
|
19
23
|
}
|
|
20
24
|
}
|
|
21
|
-
|
|
22
|
-
RelationDeleteOperation,
|
|
23
|
-
};
|
|
25
|
+
exports.RelationDeleteOperation = RelationDeleteOperation;
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RelationFindOperation = void 0;
|
|
4
|
+
const FindOperation_1 = require("../queryBuilder/operations/FindOperation");
|
|
5
|
+
class RelationFindOperation extends FindOperation_1.FindOperation {
|
|
4
6
|
constructor(name, opt) {
|
|
7
|
+
// @ts-expect-error The JavaScript QueryBuilderOperation's `name` is inferred as null.
|
|
5
8
|
super(name, opt);
|
|
6
9
|
this.relation = opt.relation;
|
|
7
10
|
this.owner = opt.owner;
|
|
@@ -47,6 +50,8 @@ class RelationFindOperation extends FindOperation {
|
|
|
47
50
|
}
|
|
48
51
|
return related;
|
|
49
52
|
}
|
|
53
|
+
// `related` is the array of the found models. It becomes a single model
|
|
54
|
+
// (or undefined) for one-to-one relations.
|
|
50
55
|
onAfter3(builder, related) {
|
|
51
56
|
const isOneToOne = this.relation.isOneToOne();
|
|
52
57
|
const intOpt = builder.internalOptions();
|
|
@@ -111,6 +116,4 @@ class RelationFindOperation extends FindOperation {
|
|
|
111
116
|
return clone;
|
|
112
117
|
}
|
|
113
118
|
}
|
|
114
|
-
|
|
115
|
-
RelationFindOperation,
|
|
116
|
-
};
|
|
119
|
+
exports.RelationFindOperation = RelationFindOperation;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RelationInsertOperation = void 0;
|
|
4
|
+
const InsertOperation_1 = require("../queryBuilder/operations/InsertOperation");
|
|
5
|
+
class RelationInsertOperation extends InsertOperation_1.InsertOperation {
|
|
4
6
|
constructor(name, opt) {
|
|
5
7
|
super(name, opt);
|
|
6
8
|
this.relation = opt.relation;
|
|
@@ -20,6 +22,4 @@ class RelationInsertOperation extends InsertOperation {
|
|
|
20
22
|
return clone;
|
|
21
23
|
}
|
|
22
24
|
}
|
|
23
|
-
|
|
24
|
-
RelationInsertOperation,
|
|
25
|
-
};
|
|
25
|
+
exports.RelationInsertOperation = RelationInsertOperation;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RelationOwner = void 0;
|
|
4
|
+
const objectUtils_1 = require("../utils/objectUtils");
|
|
5
|
+
const normalizeIds_1 = require("../utils/normalizeIds");
|
|
4
6
|
const Type = {
|
|
5
7
|
Models: 'Models',
|
|
6
8
|
Reference: 'Reference',
|
|
@@ -31,10 +33,10 @@ class RelationOwner {
|
|
|
31
33
|
return this.type === Type.Identifiers;
|
|
32
34
|
}
|
|
33
35
|
get modelArray() {
|
|
34
|
-
return asArray(this.owner);
|
|
36
|
+
return (0, objectUtils_1.asArray)(this.owner);
|
|
35
37
|
}
|
|
36
38
|
get model() {
|
|
37
|
-
return asSingle(this.owner);
|
|
39
|
+
return (0, objectUtils_1.asSingle)(this.owner);
|
|
38
40
|
}
|
|
39
41
|
get reference() {
|
|
40
42
|
return this.owner;
|
|
@@ -65,6 +67,8 @@ class RelationOwner {
|
|
|
65
67
|
}
|
|
66
68
|
return builder;
|
|
67
69
|
}
|
|
70
|
+
// Returns an array of value arrays (one per owner), or a query builder
|
|
71
|
+
// that selects them.
|
|
68
72
|
getProps(relation, ownerProp = relation.ownerProp) {
|
|
69
73
|
if (this.isModels) {
|
|
70
74
|
return this._getPropsFromModels(ownerProp);
|
|
@@ -97,7 +101,7 @@ class RelationOwner {
|
|
|
97
101
|
}
|
|
98
102
|
}
|
|
99
103
|
getNormalizedIdentifiers(ownerProp) {
|
|
100
|
-
return normalizeIds(this.identifiers, ownerProp, {
|
|
104
|
+
return (0, normalizeIds_1.normalizeIds)(this.identifiers, ownerProp, {
|
|
101
105
|
arrayOutput: true,
|
|
102
106
|
});
|
|
103
107
|
}
|
|
@@ -106,7 +110,7 @@ class RelationOwner {
|
|
|
106
110
|
if (!containsNonNull(props)) {
|
|
107
111
|
return null;
|
|
108
112
|
}
|
|
109
|
-
return uniqBy(props, join);
|
|
113
|
+
return (0, objectUtils_1.uniqBy)(props, join);
|
|
110
114
|
}
|
|
111
115
|
_getPropsFromIdentifiers(relation, ownerProp) {
|
|
112
116
|
const ids = this.getNormalizedIdentifiers(ownerProp);
|
|
@@ -129,6 +133,7 @@ class RelationOwner {
|
|
|
129
133
|
return query;
|
|
130
134
|
}
|
|
131
135
|
}
|
|
136
|
+
exports.RelationOwner = RelationOwner;
|
|
132
137
|
function detectType(owner) {
|
|
133
138
|
if (isModel(owner) || isModelArray(owner)) {
|
|
134
139
|
return Type.Models;
|
|
@@ -144,19 +149,20 @@ function detectType(owner) {
|
|
|
144
149
|
}
|
|
145
150
|
}
|
|
146
151
|
function isModel(item) {
|
|
147
|
-
return isObject(item) && !!item.$isObjectionModel;
|
|
152
|
+
return (0, objectUtils_1.isObject)(item) && !!item.$isObjectionModel;
|
|
148
153
|
}
|
|
149
154
|
function isModelArray(item) {
|
|
150
155
|
return Array.isArray(item) && isModel(item[0]);
|
|
151
156
|
}
|
|
152
157
|
function isReference(item) {
|
|
153
|
-
return isObject(item) &&
|
|
158
|
+
return ((0, objectUtils_1.isObject)(item) &&
|
|
159
|
+
!!item.isObjectionReferenceBuilder);
|
|
154
160
|
}
|
|
155
161
|
function isReferenceArray(item) {
|
|
156
162
|
return Array.isArray(item) && isReference(item[0]);
|
|
157
163
|
}
|
|
158
164
|
function isQueryBuilder(item) {
|
|
159
|
-
return isObject(item) && !!item.isObjectionQueryBuilder;
|
|
165
|
+
return ((0, objectUtils_1.isObject)(item) && !!item.isObjectionQueryBuilder);
|
|
160
166
|
}
|
|
161
167
|
function findFirstNonPartialAncestorQuery(builder) {
|
|
162
168
|
builder = builder.parentQuery();
|
|
@@ -194,6 +200,3 @@ function isIdProp(relationProp) {
|
|
|
194
200
|
function isOwnerModelClassQuery(query, relation) {
|
|
195
201
|
return query.modelClass().getTableName() === relation.ownerModelClass.getTableName();
|
|
196
202
|
}
|
|
197
|
-
module.exports = {
|
|
198
|
-
RelationOwner,
|
|
199
|
-
};
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RelationProperty = void 0;
|
|
4
|
+
const objectUtils_1 = require("../utils/objectUtils");
|
|
5
|
+
const ReferenceBuilder_1 = require("../queryBuilder/ReferenceBuilder");
|
|
6
|
+
const modelValues_1 = require("../model/modelValues");
|
|
5
7
|
class ModelNotFoundError extends Error {
|
|
6
8
|
constructor(tableName) {
|
|
7
9
|
super();
|
|
@@ -28,7 +30,7 @@ class RelationProperty {
|
|
|
28
30
|
// modelClassResolver must be a function that takes a table name
|
|
29
31
|
// and returns a model class.
|
|
30
32
|
constructor(references, modelClassResolver) {
|
|
31
|
-
const refs = createRefs(asArray(references));
|
|
33
|
+
const refs = createRefs((0, objectUtils_1.asArray)(references));
|
|
32
34
|
const paths = createPaths(refs, modelClassResolver);
|
|
33
35
|
const modelClass = resolveModelClass(paths);
|
|
34
36
|
this._refs = refs.map((ref) => ref.model(modelClass));
|
|
@@ -75,9 +77,9 @@ class RelationProperty {
|
|
|
75
77
|
// Creates a concatenated string from the property values of the given object.
|
|
76
78
|
propKey(obj) {
|
|
77
79
|
const size = this.size;
|
|
78
|
-
let key = PROP_KEY_PREFIX;
|
|
80
|
+
let key = modelValues_1.PROP_KEY_PREFIX;
|
|
79
81
|
for (let i = 0; i < size; ++i) {
|
|
80
|
-
key += propToStr(this.getProp(obj, i));
|
|
82
|
+
key += (0, modelValues_1.propToStr)(this.getProp(obj, i));
|
|
81
83
|
if (i !== size - 1) {
|
|
82
84
|
key += ',';
|
|
83
85
|
}
|
|
@@ -135,11 +137,13 @@ class RelationProperty {
|
|
|
135
137
|
return this._refs[index].expression;
|
|
136
138
|
}
|
|
137
139
|
}
|
|
140
|
+
exports.RelationProperty = RelationProperty;
|
|
138
141
|
function createRefs(refs) {
|
|
139
142
|
try {
|
|
140
143
|
return refs.map((it) => {
|
|
141
|
-
if (!isObject(it) ||
|
|
142
|
-
|
|
144
|
+
if (!(0, objectUtils_1.isObject)(it) ||
|
|
145
|
+
!it.isObjectionReferenceBuilder) {
|
|
146
|
+
return (0, ReferenceBuilder_1.ref)(it);
|
|
143
147
|
}
|
|
144
148
|
else {
|
|
145
149
|
return it;
|
|
@@ -160,6 +164,8 @@ function createPaths(refs, modelClassResolver) {
|
|
|
160
164
|
throw new ModelNotFoundError(ref.tableName);
|
|
161
165
|
}
|
|
162
166
|
const prop = modelClass.columnNameToPropertyName(ref.column);
|
|
167
|
+
// A ReferenceBuilder is only unparsed inside clone(), which copies the
|
|
168
|
+
// parsed expression right after.
|
|
163
169
|
const jsonPath = ref.parsedExpr.access.map((it) => it.ref);
|
|
164
170
|
return {
|
|
165
171
|
path: [prop].concat(jsonPath),
|
|
@@ -169,7 +175,7 @@ function createPaths(refs, modelClassResolver) {
|
|
|
169
175
|
}
|
|
170
176
|
function resolveModelClass(paths) {
|
|
171
177
|
const modelClasses = paths.map((it) => it.modelClass);
|
|
172
|
-
const uniqueModelClasses = uniqBy(modelClasses);
|
|
178
|
+
const uniqueModelClasses = (0, objectUtils_1.uniqBy)(modelClasses);
|
|
173
179
|
if (uniqueModelClasses.length !== 1) {
|
|
174
180
|
throw new InvalidReferenceError();
|
|
175
181
|
}
|
|
@@ -181,7 +187,7 @@ function createGetter(path) {
|
|
|
181
187
|
return (obj) => obj[prop];
|
|
182
188
|
}
|
|
183
189
|
else {
|
|
184
|
-
return (obj) => get(obj, path);
|
|
190
|
+
return (obj) => (0, objectUtils_1.get)(obj, path);
|
|
185
191
|
}
|
|
186
192
|
}
|
|
187
193
|
function createSetter(path) {
|
|
@@ -190,7 +196,7 @@ function createSetter(path) {
|
|
|
190
196
|
return (obj, value) => (obj[prop] = value);
|
|
191
197
|
}
|
|
192
198
|
else {
|
|
193
|
-
return (obj, value) => set(obj, path, value);
|
|
199
|
+
return (obj, value) => (0, objectUtils_1.set)(obj, path, value);
|
|
194
200
|
}
|
|
195
201
|
}
|
|
196
202
|
function createPatcher(ref, path) {
|
|
@@ -202,6 +208,3 @@ function createPatcher(ref, path) {
|
|
|
202
208
|
return (patch, value) => (patch[ref.expression] = value);
|
|
203
209
|
}
|
|
204
210
|
}
|
|
205
|
-
module.exports = {
|
|
206
|
-
RelationProperty,
|
|
207
|
-
};
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RelationUpdateOperation = void 0;
|
|
4
|
+
const UpdateOperation_1 = require("../queryBuilder/operations/UpdateOperation");
|
|
5
|
+
const RelationFindOperation_1 = require("./RelationFindOperation");
|
|
6
|
+
class RelationUpdateOperation extends UpdateOperation_1.UpdateOperation {
|
|
5
7
|
constructor(name, opt) {
|
|
6
8
|
super(name, opt);
|
|
7
9
|
this.relation = opt.relation;
|
|
@@ -11,13 +13,12 @@ class RelationUpdateOperation extends UpdateOperation {
|
|
|
11
13
|
super.onBuild(builder);
|
|
12
14
|
this.relation.findQuery(builder, this.owner);
|
|
13
15
|
}
|
|
16
|
+
// @ts-expect-error The JavaScript base class's toFindOperation() is inferred to return null.
|
|
14
17
|
toFindOperation() {
|
|
15
|
-
return new RelationFindOperation('find', {
|
|
18
|
+
return new RelationFindOperation_1.RelationFindOperation('find', {
|
|
16
19
|
relation: this.relation,
|
|
17
20
|
owner: this.owner,
|
|
18
21
|
});
|
|
19
22
|
}
|
|
20
23
|
}
|
|
21
|
-
|
|
22
|
-
RelationUpdateOperation,
|
|
23
|
-
};
|
|
24
|
+
exports.RelationUpdateOperation = RelationUpdateOperation;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BelongsToOneDeleteOperation = void 0;
|
|
4
|
+
const RelationDeleteOperation_1 = require("../RelationDeleteOperation");
|
|
5
|
+
class BelongsToOneDeleteOperation extends RelationDeleteOperation_1.RelationDeleteOperation {
|
|
4
6
|
onAfter1(_, result) {
|
|
5
7
|
if (this.owner.isModels) {
|
|
6
8
|
const ownerProp = this.relation.ownerProp;
|
|
@@ -13,6 +15,4 @@ class BelongsToOneDeleteOperation extends RelationDeleteOperation {
|
|
|
13
15
|
return result;
|
|
14
16
|
}
|
|
15
17
|
}
|
|
16
|
-
|
|
17
|
-
BelongsToOneDeleteOperation,
|
|
18
|
-
};
|
|
18
|
+
exports.BelongsToOneDeleteOperation = BelongsToOneDeleteOperation;
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BelongsToOneInsertOperation = void 0;
|
|
4
|
+
const RelationInsertOperation_1 = require("../RelationInsertOperation");
|
|
5
|
+
const BelongsToOneRelateOperation_1 = require("./BelongsToOneRelateOperation");
|
|
6
|
+
class BelongsToOneInsertOperation extends RelationInsertOperation_1.RelationInsertOperation {
|
|
5
7
|
onAdd(builder, args) {
|
|
6
8
|
const retVal = super.onAdd(builder, args);
|
|
7
9
|
if (this.models.length > 1) {
|
|
@@ -14,7 +16,7 @@ class BelongsToOneInsertOperation extends RelationInsertOperation {
|
|
|
14
16
|
if (!builder.isExecutable()) {
|
|
15
17
|
return inserted;
|
|
16
18
|
}
|
|
17
|
-
const relateOp = new BelongsToOneRelateOperation('relate', {
|
|
19
|
+
const relateOp = new BelongsToOneRelateOperation_1.BelongsToOneRelateOperation('relate', {
|
|
18
20
|
relation: this.relation,
|
|
19
21
|
owner: this.owner,
|
|
20
22
|
});
|
|
@@ -28,6 +30,4 @@ class BelongsToOneInsertOperation extends RelationInsertOperation {
|
|
|
28
30
|
return inserted;
|
|
29
31
|
}
|
|
30
32
|
}
|
|
31
|
-
|
|
32
|
-
BelongsToOneInsertOperation,
|
|
33
|
-
};
|
|
33
|
+
exports.BelongsToOneInsertOperation = BelongsToOneInsertOperation;
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BelongsToOneRelateOperation = void 0;
|
|
4
|
+
const normalizeIds_1 = require("../../utils/normalizeIds");
|
|
5
|
+
const RelateOperation_1 = require("../../queryBuilder/operations/RelateOperation");
|
|
6
|
+
class BelongsToOneRelateOperation extends RelateOperation_1.RelateOperation {
|
|
5
7
|
onAdd(_, args) {
|
|
6
8
|
this.input = args[0];
|
|
7
|
-
this.ids = normalizeIds(args[0], this.relation.relatedProp, { arrayOutput: true });
|
|
9
|
+
this.ids = (0, normalizeIds_1.normalizeIds)(args[0], this.relation.relatedProp, { arrayOutput: true });
|
|
8
10
|
assertOneId(this.ids);
|
|
9
11
|
return true;
|
|
10
12
|
}
|
|
@@ -29,11 +31,9 @@ class BelongsToOneRelateOperation extends RelateOperation {
|
|
|
29
31
|
.whereInComposite(ownerIdProp.refs(builder), ownerIds);
|
|
30
32
|
}
|
|
31
33
|
}
|
|
34
|
+
exports.BelongsToOneRelateOperation = BelongsToOneRelateOperation;
|
|
32
35
|
function assertOneId(ids) {
|
|
33
36
|
if (ids.length > 1) {
|
|
34
37
|
throw new Error('can only relate one model to a BelongsToOneRelation');
|
|
35
38
|
}
|
|
36
39
|
}
|
|
37
|
-
module.exports = {
|
|
38
|
-
BelongsToOneRelateOperation,
|
|
39
|
-
};
|
|
@@ -1,38 +1,41 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BelongsToOneRelation = void 0;
|
|
4
|
+
const Relation_1 = require("../Relation");
|
|
5
|
+
const BelongsToOneInsertOperation_1 = require("./BelongsToOneInsertOperation");
|
|
6
|
+
const BelongsToOneDeleteOperation_1 = require("./BelongsToOneDeleteOperation");
|
|
7
|
+
const BelongsToOneRelateOperation_1 = require("./BelongsToOneRelateOperation");
|
|
8
|
+
const BelongsToOneUnrelateOperation_1 = require("./BelongsToOneUnrelateOperation");
|
|
9
|
+
class BelongsToOneRelation extends Relation_1.Relation {
|
|
8
10
|
isOneToOne() {
|
|
9
11
|
return true;
|
|
10
12
|
}
|
|
11
13
|
insert(_, owner) {
|
|
12
|
-
return new BelongsToOneInsertOperation('insert', {
|
|
14
|
+
return new BelongsToOneInsertOperation_1.BelongsToOneInsertOperation('insert', {
|
|
13
15
|
relation: this,
|
|
14
16
|
owner,
|
|
15
17
|
});
|
|
16
18
|
}
|
|
17
19
|
delete(_, owner) {
|
|
18
|
-
return new BelongsToOneDeleteOperation('delete', {
|
|
20
|
+
return new BelongsToOneDeleteOperation_1.BelongsToOneDeleteOperation('delete', {
|
|
19
21
|
relation: this,
|
|
20
22
|
owner,
|
|
21
23
|
});
|
|
22
24
|
}
|
|
23
25
|
relate(_, owner) {
|
|
24
|
-
return new BelongsToOneRelateOperation('relate', {
|
|
26
|
+
return new BelongsToOneRelateOperation_1.BelongsToOneRelateOperation('relate', {
|
|
25
27
|
relation: this,
|
|
26
28
|
owner,
|
|
27
29
|
});
|
|
28
30
|
}
|
|
29
31
|
unrelate(_, owner) {
|
|
30
|
-
return new BelongsToOneUnrelateOperation('unrelate', {
|
|
32
|
+
return new BelongsToOneUnrelateOperation_1.BelongsToOneUnrelateOperation('unrelate', {
|
|
31
33
|
relation: this,
|
|
32
34
|
owner,
|
|
33
35
|
});
|
|
34
36
|
}
|
|
35
37
|
}
|
|
38
|
+
exports.BelongsToOneRelation = BelongsToOneRelation;
|
|
36
39
|
Object.defineProperties(BelongsToOneRelation.prototype, {
|
|
37
40
|
isObjectionBelongsToOneRelation: {
|
|
38
41
|
enumerable: false,
|
|
@@ -40,6 +43,3 @@ Object.defineProperties(BelongsToOneRelation.prototype, {
|
|
|
40
43
|
value: true,
|
|
41
44
|
},
|
|
42
45
|
});
|
|
43
|
-
module.exports = {
|
|
44
|
-
BelongsToOneRelation,
|
|
45
|
-
};
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BelongsToOneUnrelateOperation = void 0;
|
|
4
|
+
const UnrelateOperation_1 = require("../../queryBuilder/operations/UnrelateOperation");
|
|
5
|
+
class BelongsToOneUnrelateOperation extends UnrelateOperation_1.UnrelateOperation {
|
|
4
6
|
onAdd() {
|
|
5
7
|
const ids = new Array(this.relation.ownerProp.size);
|
|
6
8
|
this.relation.ownerProp.forEach((i) => {
|
|
@@ -41,6 +43,4 @@ class BelongsToOneUnrelateOperation extends UnrelateOperation {
|
|
|
41
43
|
return query;
|
|
42
44
|
}
|
|
43
45
|
}
|
|
44
|
-
|
|
45
|
-
BelongsToOneUnrelateOperation,
|
|
46
|
-
};
|
|
46
|
+
exports.BelongsToOneUnrelateOperation = BelongsToOneUnrelateOperation;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HasManyInsertOperation = void 0;
|
|
4
|
+
const RelationInsertOperation_1 = require("../RelationInsertOperation");
|
|
5
|
+
class HasManyInsertOperation extends RelationInsertOperation_1.RelationInsertOperation {
|
|
4
6
|
onAdd(builder, args) {
|
|
5
7
|
const retVal = super.onAdd(builder, args);
|
|
6
8
|
assertOwnerIsSingleItem(this.owner, this.relation);
|
|
@@ -26,6 +28,7 @@ class HasManyInsertOperation extends RelationInsertOperation {
|
|
|
26
28
|
return inserted;
|
|
27
29
|
}
|
|
28
30
|
}
|
|
31
|
+
exports.HasManyInsertOperation = HasManyInsertOperation;
|
|
29
32
|
function assertOwnerIsSingleItem(owner, relation) {
|
|
30
33
|
const { isModels, isIdentifiers, isQueryBuilder } = owner;
|
|
31
34
|
const { ownerProp } = relation;
|
|
@@ -40,6 +43,3 @@ function assertOwnerIsSingleItem(owner, relation) {
|
|
|
40
43
|
].join(' '));
|
|
41
44
|
}
|
|
42
45
|
}
|
|
43
|
-
module.exports = {
|
|
44
|
-
HasManyInsertOperation,
|
|
45
|
-
};
|