@abedmurrar/objection 4.0.0-beta.0 → 4.0.0-beta.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (163) hide show
  1. package/README.md +1 -1
  2. package/lib/initialize.js +4 -5
  3. package/lib/model/AjvValidator.js +24 -21
  4. package/lib/model/Model.js +116 -114
  5. package/lib/model/ModifierNotFoundError.js +4 -4
  6. package/lib/model/NotFoundError.js +4 -4
  7. package/lib/model/RelationDoesNotExistError.js +4 -4
  8. package/lib/model/ValidationError.js +8 -8
  9. package/lib/model/Validator.js +7 -6
  10. package/lib/model/getModel.js +4 -4
  11. package/lib/model/graph/ModelGraph.js +9 -7
  12. package/lib/model/graph/ModelGraphBuilder.js +24 -24
  13. package/lib/model/graph/ModelGraphEdge.js +4 -4
  14. package/lib/model/graph/ModelGraphNode.js +17 -11
  15. package/lib/model/inheritModel.js +3 -4
  16. package/lib/model/modelBindKnex.js +12 -13
  17. package/lib/model/modelClone.js +15 -16
  18. package/lib/model/modelColPropMap.js +7 -8
  19. package/lib/model/modelConcurrency.js +6 -7
  20. package/lib/model/modelId.js +4 -5
  21. package/lib/model/modelJsonAttributes.js +10 -11
  22. package/lib/model/modelParseRelations.js +5 -6
  23. package/lib/model/modelQueryProps.js +12 -13
  24. package/lib/model/modelSet.js +17 -18
  25. package/lib/model/modelTableMetadata.js +9 -10
  26. package/lib/model/modelToJson.js +13 -14
  27. package/lib/model/modelUtils.js +7 -7
  28. package/lib/model/modelValidate.js +5 -6
  29. package/lib/model/modelValues.js +10 -10
  30. package/lib/model/modelVisitor.js +3 -4
  31. package/lib/objection.js +4 -26
  32. package/lib/queryBuilder/FunctionBuilder.js +35 -31
  33. package/lib/queryBuilder/InternalOptions.js +4 -4
  34. package/lib/queryBuilder/JoinBuilder.js +46 -45
  35. package/lib/queryBuilder/QueryBuilder.js +161 -135
  36. package/lib/queryBuilder/QueryBuilderBase.js +203 -203
  37. package/lib/queryBuilder/QueryBuilderContext.js +6 -6
  38. package/lib/queryBuilder/QueryBuilderContextBase.js +12 -8
  39. package/lib/queryBuilder/QueryBuilderOperationSupport.js +30 -25
  40. package/lib/queryBuilder/QueryBuilderUserContext.js +4 -4
  41. package/lib/queryBuilder/RawBuilder.js +15 -13
  42. package/lib/queryBuilder/ReferenceBuilder.js +25 -23
  43. package/lib/queryBuilder/RelationExpression.js +29 -20
  44. package/lib/queryBuilder/StaticHookArguments.js +11 -11
  45. package/lib/queryBuilder/ValueBuilder.js +20 -19
  46. package/lib/queryBuilder/expressions.js +8 -18
  47. package/lib/queryBuilder/functions/mysql.js +18 -42
  48. package/lib/queryBuilder/graph/GraphAction.js +7 -7
  49. package/lib/queryBuilder/graph/GraphData.js +4 -4
  50. package/lib/queryBuilder/graph/GraphFetcher.js +18 -17
  51. package/lib/queryBuilder/graph/GraphNodeDbExistence.js +45 -12
  52. package/lib/queryBuilder/graph/GraphOperation.js +4 -4
  53. package/lib/queryBuilder/graph/GraphOptions.js +5 -5
  54. package/lib/queryBuilder/graph/GraphUpsert.js +36 -36
  55. package/lib/queryBuilder/graph/delete/GraphDelete.js +8 -8
  56. package/lib/queryBuilder/graph/delete/GraphDeleteAction.js +46 -11
  57. package/lib/queryBuilder/graph/insert/GraphInsert.js +12 -12
  58. package/lib/queryBuilder/graph/insert/GraphInsertAction.js +59 -21
  59. package/lib/queryBuilder/graph/insert/JoinRowGraphInsertAction.js +49 -11
  60. package/lib/queryBuilder/graph/patch/GraphPatch.js +8 -8
  61. package/lib/queryBuilder/graph/patch/GraphPatchAction.js +52 -19
  62. package/lib/queryBuilder/graph/recursiveUpsert/GraphRecursiveUpsert.js +8 -8
  63. package/lib/queryBuilder/graph/recursiveUpsert/GraphRecursiveUpsertAction.js +54 -18
  64. package/lib/queryBuilder/join/JoinResultColumn.js +6 -4
  65. package/lib/queryBuilder/join/JoinResultParser.js +10 -8
  66. package/lib/queryBuilder/join/RelationJoiner.js +40 -35
  67. package/lib/queryBuilder/join/TableNode.js +7 -5
  68. package/lib/queryBuilder/join/TableTree.js +13 -9
  69. package/lib/queryBuilder/join/utils.js +8 -8
  70. package/lib/queryBuilder/operations/DelegateOperation.js +6 -6
  71. package/lib/queryBuilder/operations/DeleteOperation.js +11 -11
  72. package/lib/queryBuilder/operations/FindByIdOperation.js +8 -8
  73. package/lib/queryBuilder/operations/FindByIdsOperation.js +6 -6
  74. package/lib/queryBuilder/operations/FindOperation.js +23 -23
  75. package/lib/queryBuilder/operations/FirstOperation.js +6 -6
  76. package/lib/queryBuilder/operations/FromOperation.js +13 -13
  77. package/lib/queryBuilder/operations/InsertAndFetchOperation.js +12 -12
  78. package/lib/queryBuilder/operations/InsertGraphAndFetchOperation.js +10 -10
  79. package/lib/queryBuilder/operations/InsertGraphOperation.js +11 -11
  80. package/lib/queryBuilder/operations/InsertOperation.js +23 -22
  81. package/lib/queryBuilder/operations/InstanceDeleteOperation.js +12 -12
  82. package/lib/queryBuilder/operations/InstanceFindOperation.js +10 -10
  83. package/lib/queryBuilder/operations/InstanceInsertOperation.js +6 -6
  84. package/lib/queryBuilder/operations/InstanceUpdateOperation.js +14 -14
  85. package/lib/queryBuilder/operations/JoinRelatedOperation.js +13 -13
  86. package/lib/queryBuilder/operations/KnexOperation.js +6 -6
  87. package/lib/queryBuilder/operations/MergeOperation.js +11 -11
  88. package/lib/queryBuilder/operations/ObjectionToKnexConvertingOperation.js +26 -22
  89. package/lib/queryBuilder/operations/OnBuildKnexOperation.js +6 -6
  90. package/lib/queryBuilder/operations/OnBuildOperation.js +6 -6
  91. package/lib/queryBuilder/operations/OnErrorOperation.js +6 -6
  92. package/lib/queryBuilder/operations/QueryBuilderOperation.js +6 -4
  93. package/lib/queryBuilder/operations/RangeOperation.js +7 -6
  94. package/lib/queryBuilder/operations/RelateOperation.js +6 -6
  95. package/lib/queryBuilder/operations/ReturningOperation.js +8 -8
  96. package/lib/queryBuilder/operations/RunAfterOperation.js +6 -6
  97. package/lib/queryBuilder/operations/RunBeforeOperation.js +6 -6
  98. package/lib/queryBuilder/operations/UnrelateOperation.js +6 -6
  99. package/lib/queryBuilder/operations/UpdateAndFetchOperation.js +12 -12
  100. package/lib/queryBuilder/operations/UpdateOperation.js +24 -24
  101. package/lib/queryBuilder/operations/UpsertGraphAndFetchOperation.js +10 -10
  102. package/lib/queryBuilder/operations/UpsertGraphOperation.js +10 -10
  103. package/lib/queryBuilder/operations/WhereCompositeOperation.js +8 -8
  104. package/lib/queryBuilder/operations/WhereInOperation.js +11 -9
  105. package/lib/queryBuilder/operations/eager/EagerOperation.js +11 -9
  106. package/lib/queryBuilder/operations/eager/JoinEagerOperation.js +10 -12
  107. package/lib/queryBuilder/operations/eager/NaiveEagerOperation.js +6 -6
  108. package/lib/queryBuilder/operations/eager/WhereInEagerOperation.js +64 -28
  109. package/lib/queryBuilder/operations/jsonApi/WhereJsonHasOperation.js +45 -12
  110. package/lib/queryBuilder/operations/jsonApi/WhereJsonNotObjectOperation.js +45 -12
  111. package/lib/queryBuilder/operations/jsonApi/WhereJsonOperation.js +45 -12
  112. package/lib/queryBuilder/operations/jsonApi/WhereJsonOverlapsOperation.js +46 -13
  113. package/lib/queryBuilder/operations/jsonApi/mysqlJsonApi.js +22 -27
  114. package/lib/queryBuilder/operations/jsonApi/postgresJsonApi.js +51 -17
  115. package/lib/queryBuilder/operations/select/SelectOperation.js +12 -12
  116. package/lib/queryBuilder/operations/select/Selection.js +23 -19
  117. package/lib/queryBuilder/operations/types.js +8 -0
  118. package/lib/queryBuilder/operations/whereInComposite/WhereInCompositeMsSqlOperation.js +13 -12
  119. package/lib/queryBuilder/operations/whereInComposite/WhereInCompositeOperation.js +11 -11
  120. package/lib/queryBuilder/operations/whereInComposite/WhereInCompositeSqliteOperation.js +10 -10
  121. package/lib/queryBuilder/transformations/CompositeQueryTransformation.js +6 -6
  122. package/lib/queryBuilder/transformations/QueryTransformation.js +4 -4
  123. package/lib/queryBuilder/transformations/WrapMysqlModifySubqueryTransformation.js +11 -8
  124. package/lib/queryBuilder/transformations/index.js +8 -8
  125. package/lib/queryBuilder/whereScopes.js +15 -21
  126. package/lib/relations/Relation.js +31 -29
  127. package/lib/relations/RelationDeleteOperation.js +8 -8
  128. package/lib/relations/RelationFindOperation.js +8 -6
  129. package/lib/relations/RelationInsertOperation.js +6 -6
  130. package/lib/relations/RelationOwner.js +16 -13
  131. package/lib/relations/RelationProperty.js +18 -15
  132. package/lib/relations/RelationUpdateOperation.js +8 -8
  133. package/lib/relations/belongsToOne/BelongsToOneDeleteOperation.js +6 -6
  134. package/lib/relations/belongsToOne/BelongsToOneInsertOperation.js +8 -8
  135. package/lib/relations/belongsToOne/BelongsToOneRelateOperation.js +8 -8
  136. package/lib/relations/belongsToOne/BelongsToOneRelation.js +14 -14
  137. package/lib/relations/belongsToOne/BelongsToOneUnrelateOperation.js +6 -6
  138. package/lib/relations/hasMany/HasManyInsertOperation.js +6 -6
  139. package/lib/relations/hasMany/HasManyRelateOperation.js +11 -11
  140. package/lib/relations/hasMany/HasManyRelation.js +12 -12
  141. package/lib/relations/hasMany/HasManyUnrelateOperation.js +9 -9
  142. package/lib/relations/hasOne/HasOneRelation.js +6 -6
  143. package/lib/relations/hasOneThrough/HasOneThroughRelation.js +6 -6
  144. package/lib/relations/manyToMany/ManyToManyModifyMixin.js +9 -8
  145. package/lib/relations/manyToMany/ManyToManyRelation.js +52 -49
  146. package/lib/relations/manyToMany/ManyToManySqliteModifyMixin.js +6 -6
  147. package/lib/relations/manyToMany/delete/ManyToManyDeleteOperation.js +7 -7
  148. package/lib/relations/manyToMany/delete/ManyToManyDeleteOperationBase.js +6 -6
  149. package/lib/relations/manyToMany/delete/ManyToManyDeleteSqliteOperation.js +7 -7
  150. package/lib/relations/manyToMany/find/ManyToManyFindOperation.js +8 -8
  151. package/lib/relations/manyToMany/insert/ManyToManyInsertOperation.js +8 -8
  152. package/lib/relations/manyToMany/relate/ManyToManyRelateOperation.js +11 -10
  153. package/lib/relations/manyToMany/unrelate/ManyToManyUnrelateOperation.js +7 -7
  154. package/lib/relations/manyToMany/unrelate/ManyToManyUnrelateOperationBase.js +8 -8
  155. package/lib/relations/manyToMany/unrelate/ManyToManyUnrelateSqliteOperation.js +7 -7
  156. package/lib/relations/manyToMany/update/ManyToManyUpdateOperation.js +7 -7
  157. package/lib/relations/manyToMany/update/ManyToManyUpdateOperationBase.js +8 -8
  158. package/lib/relations/manyToMany/update/ManyToManyUpdateSqliteOperation.js +7 -7
  159. package/lib/transaction.js +44 -12
  160. package/lib/utils/objectUtils.js +6 -1
  161. package/lib/utils/parseFieldExpression.js +4 -35
  162. package/lib/utils/promiseUtils/index.js +19 -9
  163. package/package.json +1 -1
@@ -1,6 +1,8 @@
1
- 'use strict';
2
- const { QueryTransformation } = require('./QueryTransformation');
3
- const { isMySql } = require('../../utils/knexUtils');
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.WrapMysqlModifySubqueryTransformation = void 0;
4
+ const QueryTransformation_1 = require("./QueryTransformation");
5
+ const knexUtils_1 = require("../../utils/knexUtils");
4
6
  /**
5
7
  * Mysql doesn't allow queries like this:
6
8
  *
@@ -13,7 +15,8 @@ const { isMySql } = require('../../utils/knexUtils');
13
15
  *
14
16
  * update foo set bar = 1 where id in (select * from (select id from foo))
15
17
  */
16
- class WrapMysqlModifySubqueryTransformation extends QueryTransformation {
18
+ class WrapMysqlModifySubqueryTransformation extends QueryTransformation_1.QueryTransformation {
19
+ // In a join callback `parentQuery` is a `JoinBuilder`, which the loop below walks past.
17
20
  onConvertQueryBuilderBase(query, parentQuery) {
18
21
  const knex = parentQuery.unsafeKnex();
19
22
  // Cannot detect anything if, for whatever reason, a knex instance
@@ -22,11 +25,12 @@ class WrapMysqlModifySubqueryTransformation extends QueryTransformation {
22
25
  return query;
23
26
  }
24
27
  // This transformation only applies to MySQL.
25
- if (!isMySql(knex)) {
28
+ if (!(0, knexUtils_1.isMySql)(knex)) {
26
29
  return query;
27
30
  }
28
31
  // A subquery in a join callback belongs to the query of the join.
29
32
  while (parentQuery && typeof parentQuery.isUpdate !== 'function') {
33
+ // The loop stops at the first parent query that is a `QueryBuilder`.
30
34
  parentQuery = parentQuery.parentQuery();
31
35
  }
32
36
  // This transformation only applies to update and delete queries.
@@ -42,9 +46,11 @@ class WrapMysqlModifySubqueryTransformation extends QueryTransformation {
42
46
  return query.modelClass().query().from(query.as('mysql_subquery_fix'));
43
47
  }
44
48
  }
49
+ exports.WrapMysqlModifySubqueryTransformation = WrapMysqlModifySubqueryTransformation;
45
50
  function hasJoinsToTable(query, tableName) {
46
51
  let found = false;
47
52
  query.forEachOperation(query.constructor.JoinSelector, (op) => {
53
+ // The join operations are `KnexOperation`s, which have `args`.
48
54
  if (op.args[0] === tableName) {
49
55
  found = true;
50
56
  return false;
@@ -52,6 +58,3 @@ function hasJoinsToTable(query, tableName) {
52
58
  });
53
59
  return found;
54
60
  }
55
- module.exports = {
56
- WrapMysqlModifySubqueryTransformation,
57
- };
@@ -1,9 +1,9 @@
1
- 'use strict';
2
- const { CompositeQueryTransformation } = require('./CompositeQueryTransformation');
3
- const { WrapMysqlModifySubqueryTransformation, } = require('./WrapMysqlModifySubqueryTransformation');
4
- const transformation = new CompositeQueryTransformation([
5
- new WrapMysqlModifySubqueryTransformation(),
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.transformation = void 0;
4
+ const CompositeQueryTransformation_1 = require("./CompositeQueryTransformation");
5
+ const WrapMysqlModifySubqueryTransformation_1 = require("./WrapMysqlModifySubqueryTransformation");
6
+ const transformation = new CompositeQueryTransformation_1.CompositeQueryTransformation([
7
+ new WrapMysqlModifySubqueryTransformation_1.WrapMysqlModifySubqueryTransformation(),
6
8
  ]);
7
- module.exports = {
8
- transformation,
9
- };
9
+ exports.transformation = transformation;
@@ -1,15 +1,10 @@
1
- 'use strict';
2
- const { isObject, isFunction } = require('../utils/objectUtils');
3
- const { isKnexRaw } = require('../utils/knexUtils');
4
- // Where clauses objection adds on its own, like the owner condition of a relation
5
- // query or the id condition of `$query()`, are tagged with a "where scope". When
6
- // a query has where clauses from more than one scope, the clauses of each scope
7
- // are wrapped in parentheses so that an `orWhere` in one scope can't escape the
8
- // conditions of the others. Without this, `$relatedQuery('pets').where(a).orWhere(b)`
9
- // would produce `owner and a or b` and match other owners' pets.
10
- //
11
- // The scopes are only used when the knex query is built. The operation tree is
12
- // never modified.
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.withWhereScope = withWhereScope;
4
+ exports.effectiveWhereScope = effectiveWhereScope;
5
+ exports.createWhereGrouping = createWhereGrouping;
6
+ const objectUtils_1 = require("../utils/objectUtils");
7
+ const knexUtils_1 = require("../utils/knexUtils");
13
8
  const WhereSelector = /^(where|orWhere|andWhere|find\w+)/;
14
9
  // Where operations that only ever produce a single predicate or predicates
15
10
  // joined with `and`. A scope that only contains these (and no raw arguments)
@@ -63,6 +58,7 @@ function withWhereScope(builder, callback) {
63
58
  builder._whereScope = previous;
64
59
  }
65
60
  }
61
+ // Returns the where scope token, or null.
66
62
  function effectiveWhereScope(op) {
67
63
  while (op) {
68
64
  if (op.whereScope !== null) {
@@ -139,6 +135,7 @@ function buildOperationTree(builder, op, knexBuilder) {
139
135
  }
140
136
  function hasWhereAncestor(op) {
141
137
  for (let parent = op.parentOperation; parent; parent = parent.parentOperation) {
138
+ // A null name is tested as 'null', as `test()` converts it to a string.
142
139
  if (WhereSelector.test(parent.name)) {
143
140
  return true;
144
141
  }
@@ -159,13 +156,15 @@ function isAndOnlyTree(op) {
159
156
  return andOnly;
160
157
  }
161
158
  function isAndOnly(op) {
162
- return AND_ONLY_OPERATIONS.has(op.name) && !containsRaw(op.args);
159
+ // The operations that convert their arguments for knex have `args`.
160
+ return (AND_ONLY_OPERATIONS.has(op.name) && !containsRaw(op.args));
163
161
  }
162
+ // `value` is a user value of any shape: operation arguments.
164
163
  function containsRaw(value) {
165
164
  if (Array.isArray(value)) {
166
165
  return value.some(containsRaw);
167
166
  }
168
- else if (!isObject(value)) {
167
+ else if (!(0, objectUtils_1.isObject)(value)) {
169
168
  return false;
170
169
  }
171
170
  else if (value.isObjectionReferenceBuilder) {
@@ -177,11 +176,11 @@ function containsRaw(value) {
177
176
  // so only their arguments can contain anything.
178
177
  return containsRaw(value._args);
179
178
  }
180
- else if (isKnexRaw(value) || isFunction(value.toKnexRaw)) {
179
+ else if ((0, knexUtils_1.isKnexRaw)(value) || (0, objectUtils_1.isFunction)(value.toKnexRaw)) {
181
180
  // Raw sql (and anything that is converted into it) can contain anything.
182
181
  return true;
183
182
  }
184
- else if (value.isObjectionQueryBuilderBase || isFunction(value.toSQL)) {
183
+ else if (value.isObjectionQueryBuilderBase || (0, objectUtils_1.isFunction)(value.toSQL)) {
185
184
  // Subqueries are always wrapped in parentheses.
186
185
  return false;
187
186
  }
@@ -192,8 +191,3 @@ function containsRaw(value) {
192
191
  return false;
193
192
  }
194
193
  }
195
- module.exports = {
196
- withWhereScope,
197
- effectiveWhereScope,
198
- createWhereGrouping,
199
- };
@@ -1,13 +1,15 @@
1
- 'use strict';
2
- const { withWhereScope } = require('../queryBuilder/whereScopes');
3
- const { RelationProperty } = require('./RelationProperty');
4
- const { RelationFindOperation } = require('./RelationFindOperation');
5
- const { RelationUpdateOperation } = require('./RelationUpdateOperation');
6
- const { RelationDeleteOperation } = require('./RelationDeleteOperation');
7
- const { resolveModel } = require('../utils/resolveModel');
8
- const { get, isFunction } = require('../utils/objectUtils');
9
- const { mapAfterAllReturn } = require('../utils/promiseUtils');
10
- const { createModifier } = require('../utils/createModifier');
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
- relatedModelClass = resolveModel(ctx.mapping.modelClass, ctx.ownerModelClass.modelPaths, 'modelClass');
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,7 +1,9 @@
1
- 'use strict';
2
- const { DeleteOperation } = require('../queryBuilder/operations/DeleteOperation');
3
- const { RelationFindOperation } = require('./RelationFindOperation');
4
- class RelationDeleteOperation extends DeleteOperation {
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) {
6
8
  super(name, opt);
7
9
  this.relation = opt.relation;
@@ -12,12 +14,10 @@ class RelationDeleteOperation extends DeleteOperation {
12
14
  this.relation.findQuery(builder, this.owner);
13
15
  }
14
16
  toFindOperation() {
15
- return new RelationFindOperation('find', {
17
+ return new RelationFindOperation_1.RelationFindOperation('find', {
16
18
  relation: this.relation,
17
19
  owner: this.owner,
18
20
  });
19
21
  }
20
22
  }
21
- module.exports = {
22
- RelationDeleteOperation,
23
- };
23
+ exports.RelationDeleteOperation = RelationDeleteOperation;
@@ -1,6 +1,8 @@
1
- 'use strict';
2
- const { FindOperation } = require('../queryBuilder/operations/FindOperation');
3
- class RelationFindOperation extends FindOperation {
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) {
5
7
  super(name, opt);
6
8
  this.relation = opt.relation;
@@ -47,6 +49,8 @@ class RelationFindOperation extends FindOperation {
47
49
  }
48
50
  return related;
49
51
  }
52
+ // `related` is the array of the found models. It becomes a single model
53
+ // (or undefined) for one-to-one relations.
50
54
  onAfter3(builder, related) {
51
55
  const isOneToOne = this.relation.isOneToOne();
52
56
  const intOpt = builder.internalOptions();
@@ -111,6 +115,4 @@ class RelationFindOperation extends FindOperation {
111
115
  return clone;
112
116
  }
113
117
  }
114
- module.exports = {
115
- RelationFindOperation,
116
- };
118
+ exports.RelationFindOperation = RelationFindOperation;
@@ -1,6 +1,8 @@
1
- 'use strict';
2
- const { InsertOperation } = require('../queryBuilder/operations/InsertOperation');
3
- class RelationInsertOperation extends InsertOperation {
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
- module.exports = {
24
- RelationInsertOperation,
25
- };
25
+ exports.RelationInsertOperation = RelationInsertOperation;
@@ -1,6 +1,8 @@
1
- 'use strict';
2
- const { isObject, asArray, asSingle, uniqBy } = require('../utils/objectUtils');
3
- const { normalizeIds } = require('../utils/normalizeIds');
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) && !!item.isObjectionReferenceBuilder;
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
- 'use strict';
2
- const { asArray, isObject, uniqBy, get, set } = require('../utils/objectUtils');
3
- const { ref: createRef } = require('../queryBuilder/ReferenceBuilder');
4
- const { propToStr, PROP_KEY_PREFIX } = require('../model/modelValues');
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) || !it.isObjectionReferenceBuilder) {
142
- return createRef(it);
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
- 'use strict';
2
- const { UpdateOperation } = require('../queryBuilder/operations/UpdateOperation');
3
- const { RelationFindOperation } = require('./RelationFindOperation');
4
- class RelationUpdateOperation extends UpdateOperation {
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;
@@ -12,12 +14,10 @@ class RelationUpdateOperation extends UpdateOperation {
12
14
  this.relation.findQuery(builder, this.owner);
13
15
  }
14
16
  toFindOperation() {
15
- return new RelationFindOperation('find', {
17
+ return new RelationFindOperation_1.RelationFindOperation('find', {
16
18
  relation: this.relation,
17
19
  owner: this.owner,
18
20
  });
19
21
  }
20
22
  }
21
- module.exports = {
22
- RelationUpdateOperation,
23
- };
23
+ exports.RelationUpdateOperation = RelationUpdateOperation;
@@ -1,6 +1,8 @@
1
- 'use strict';
2
- const { RelationDeleteOperation } = require('../RelationDeleteOperation');
3
- class BelongsToOneDeleteOperation extends RelationDeleteOperation {
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
- module.exports = {
17
- BelongsToOneDeleteOperation,
18
- };
18
+ exports.BelongsToOneDeleteOperation = BelongsToOneDeleteOperation;