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

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 (85) hide show
  1. package/lib/queryBuilder/operations/DelegateOperation.js +6 -6
  2. package/lib/queryBuilder/operations/DeleteOperation.js +11 -11
  3. package/lib/queryBuilder/operations/FindByIdOperation.js +8 -8
  4. package/lib/queryBuilder/operations/FindByIdsOperation.js +6 -6
  5. package/lib/queryBuilder/operations/FindOperation.js +23 -23
  6. package/lib/queryBuilder/operations/FirstOperation.js +6 -6
  7. package/lib/queryBuilder/operations/FromOperation.js +13 -13
  8. package/lib/queryBuilder/operations/InsertAndFetchOperation.js +12 -12
  9. package/lib/queryBuilder/operations/InsertGraphAndFetchOperation.js +10 -10
  10. package/lib/queryBuilder/operations/InsertGraphOperation.js +11 -11
  11. package/lib/queryBuilder/operations/InsertOperation.js +23 -22
  12. package/lib/queryBuilder/operations/InstanceDeleteOperation.js +12 -12
  13. package/lib/queryBuilder/operations/InstanceFindOperation.js +10 -10
  14. package/lib/queryBuilder/operations/InstanceInsertOperation.js +6 -6
  15. package/lib/queryBuilder/operations/InstanceUpdateOperation.js +14 -14
  16. package/lib/queryBuilder/operations/JoinRelatedOperation.js +13 -13
  17. package/lib/queryBuilder/operations/KnexOperation.js +6 -6
  18. package/lib/queryBuilder/operations/MergeOperation.js +11 -11
  19. package/lib/queryBuilder/operations/ObjectionToKnexConvertingOperation.js +26 -22
  20. package/lib/queryBuilder/operations/OnBuildKnexOperation.js +6 -6
  21. package/lib/queryBuilder/operations/OnBuildOperation.js +6 -6
  22. package/lib/queryBuilder/operations/OnErrorOperation.js +6 -6
  23. package/lib/queryBuilder/operations/QueryBuilderOperation.js +6 -4
  24. package/lib/queryBuilder/operations/RangeOperation.js +7 -6
  25. package/lib/queryBuilder/operations/RelateOperation.js +6 -6
  26. package/lib/queryBuilder/operations/ReturningOperation.js +8 -8
  27. package/lib/queryBuilder/operations/RunAfterOperation.js +6 -6
  28. package/lib/queryBuilder/operations/RunBeforeOperation.js +6 -6
  29. package/lib/queryBuilder/operations/UnrelateOperation.js +6 -6
  30. package/lib/queryBuilder/operations/UpdateAndFetchOperation.js +12 -12
  31. package/lib/queryBuilder/operations/UpdateOperation.js +24 -24
  32. package/lib/queryBuilder/operations/UpsertGraphAndFetchOperation.js +10 -10
  33. package/lib/queryBuilder/operations/UpsertGraphOperation.js +10 -10
  34. package/lib/queryBuilder/operations/WhereCompositeOperation.js +8 -8
  35. package/lib/queryBuilder/operations/WhereInOperation.js +11 -9
  36. package/lib/queryBuilder/operations/eager/EagerOperation.js +11 -9
  37. package/lib/queryBuilder/operations/eager/JoinEagerOperation.js +10 -12
  38. package/lib/queryBuilder/operations/eager/NaiveEagerOperation.js +6 -6
  39. package/lib/queryBuilder/operations/eager/WhereInEagerOperation.js +64 -28
  40. package/lib/queryBuilder/operations/jsonApi/WhereJsonHasOperation.js +45 -12
  41. package/lib/queryBuilder/operations/jsonApi/WhereJsonNotObjectOperation.js +45 -12
  42. package/lib/queryBuilder/operations/jsonApi/WhereJsonOperation.js +45 -12
  43. package/lib/queryBuilder/operations/jsonApi/WhereJsonOverlapsOperation.js +46 -13
  44. package/lib/queryBuilder/operations/jsonApi/mysqlJsonApi.js +22 -27
  45. package/lib/queryBuilder/operations/jsonApi/postgresJsonApi.js +51 -17
  46. package/lib/queryBuilder/operations/select/SelectOperation.js +12 -12
  47. package/lib/queryBuilder/operations/select/Selection.js +23 -19
  48. package/lib/queryBuilder/operations/types.js +8 -0
  49. package/lib/queryBuilder/operations/whereInComposite/WhereInCompositeMsSqlOperation.js +13 -12
  50. package/lib/queryBuilder/operations/whereInComposite/WhereInCompositeOperation.js +11 -11
  51. package/lib/queryBuilder/operations/whereInComposite/WhereInCompositeSqliteOperation.js +10 -10
  52. package/lib/relations/Relation.js +31 -29
  53. package/lib/relations/RelationDeleteOperation.js +8 -8
  54. package/lib/relations/RelationFindOperation.js +8 -6
  55. package/lib/relations/RelationInsertOperation.js +6 -6
  56. package/lib/relations/RelationOwner.js +16 -13
  57. package/lib/relations/RelationProperty.js +18 -15
  58. package/lib/relations/RelationUpdateOperation.js +8 -8
  59. package/lib/relations/belongsToOne/BelongsToOneDeleteOperation.js +6 -6
  60. package/lib/relations/belongsToOne/BelongsToOneInsertOperation.js +8 -8
  61. package/lib/relations/belongsToOne/BelongsToOneRelateOperation.js +8 -8
  62. package/lib/relations/belongsToOne/BelongsToOneRelation.js +14 -14
  63. package/lib/relations/belongsToOne/BelongsToOneUnrelateOperation.js +6 -6
  64. package/lib/relations/hasMany/HasManyInsertOperation.js +6 -6
  65. package/lib/relations/hasMany/HasManyRelateOperation.js +11 -11
  66. package/lib/relations/hasMany/HasManyRelation.js +12 -12
  67. package/lib/relations/hasMany/HasManyUnrelateOperation.js +9 -9
  68. package/lib/relations/hasOne/HasOneRelation.js +6 -6
  69. package/lib/relations/hasOneThrough/HasOneThroughRelation.js +6 -6
  70. package/lib/relations/manyToMany/ManyToManyModifyMixin.js +9 -8
  71. package/lib/relations/manyToMany/ManyToManyRelation.js +52 -49
  72. package/lib/relations/manyToMany/ManyToManySqliteModifyMixin.js +6 -6
  73. package/lib/relations/manyToMany/delete/ManyToManyDeleteOperation.js +7 -7
  74. package/lib/relations/manyToMany/delete/ManyToManyDeleteOperationBase.js +6 -6
  75. package/lib/relations/manyToMany/delete/ManyToManyDeleteSqliteOperation.js +7 -7
  76. package/lib/relations/manyToMany/find/ManyToManyFindOperation.js +8 -8
  77. package/lib/relations/manyToMany/insert/ManyToManyInsertOperation.js +8 -8
  78. package/lib/relations/manyToMany/relate/ManyToManyRelateOperation.js +11 -10
  79. package/lib/relations/manyToMany/unrelate/ManyToManyUnrelateOperation.js +7 -7
  80. package/lib/relations/manyToMany/unrelate/ManyToManyUnrelateOperationBase.js +8 -8
  81. package/lib/relations/manyToMany/unrelate/ManyToManyUnrelateSqliteOperation.js +7 -7
  82. package/lib/relations/manyToMany/update/ManyToManyUpdateOperation.js +7 -7
  83. package/lib/relations/manyToMany/update/ManyToManyUpdateOperationBase.js +8 -8
  84. package/lib/relations/manyToMany/update/ManyToManyUpdateSqliteOperation.js +7 -7
  85. package/package.json +1 -1
@@ -1,12 +1,15 @@
1
- 'use strict';
2
- const { ref } = require('../../queryBuilder/ReferenceBuilder');
3
- const { isEmpty } = require('../../utils/objectUtils');
4
- const { isKnexRaw, isKnexQueryBuilder } = require('../../utils/knexUtils');
5
- const { toPgJsonPathLiteral, getJsonDialect } = require('../../utils/postgresJsonPath');
6
- const { toMySqlJsonPath, toJsonSql } = require('../../utils/mysqlJsonPath');
7
- const { QueryBuilderOperation } = require('./QueryBuilderOperation');
8
- const { StaticHookArguments, hasStaticHook } = require('../StaticHookArguments');
9
- class UpdateOperation extends QueryBuilderOperation {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.UpdateOperation = void 0;
4
+ exports.convertFieldExpressionsToRaw = convertFieldExpressionsToRaw;
5
+ const ReferenceBuilder_1 = require("../../queryBuilder/ReferenceBuilder");
6
+ const objectUtils_1 = require("../../utils/objectUtils");
7
+ const knexUtils_1 = require("../../utils/knexUtils");
8
+ const postgresJsonPath_1 = require("../../utils/postgresJsonPath");
9
+ const mysqlJsonPath_1 = require("../../utils/mysqlJsonPath");
10
+ const QueryBuilderOperation_1 = require("./QueryBuilderOperation");
11
+ const StaticHookArguments_1 = require("../StaticHookArguments");
12
+ class UpdateOperation extends QueryBuilderOperation_1.QueryBuilderOperation {
10
13
  constructor(name, opt) {
11
14
  super(name, opt);
12
15
  this.model = null;
@@ -24,7 +27,7 @@ class UpdateOperation extends QueryBuilderOperation {
24
27
  }
25
28
  onBefore3(builder) {
26
29
  const row = this.model.$toDatabaseJson(builder);
27
- if (isEmpty(row)) {
30
+ if ((0, objectUtils_1.isEmpty)(row)) {
28
31
  // Resolve the query if there is nothing to update.
29
32
  builder.resolve(0);
30
33
  }
@@ -46,6 +49,7 @@ class UpdateOperation extends QueryBuilderOperation {
46
49
  return clone;
47
50
  }
48
51
  }
52
+ exports.UpdateOperation = UpdateOperation;
49
53
  async function callBeforeUpdate(builder, model, modelOptions) {
50
54
  await callInstanceBeforeUpdate(builder, model, modelOptions);
51
55
  return callStaticBeforeUpdate(builder);
@@ -54,10 +58,10 @@ function callInstanceBeforeUpdate(builder, model, modelOptions) {
54
58
  return model.$beforeUpdate(modelOptions, builder.context());
55
59
  }
56
60
  function callStaticBeforeUpdate(builder) {
57
- if (!hasStaticHook(builder.modelClass(), 'beforeUpdate')) {
61
+ if (!(0, StaticHookArguments_1.hasStaticHook)(builder.modelClass(), 'beforeUpdate')) {
58
62
  return undefined;
59
63
  }
60
- const args = StaticHookArguments.create({ builder });
64
+ const args = StaticHookArguments_1.StaticHookArguments.create({ builder });
61
65
  return builder.modelClass().beforeUpdate(args);
62
66
  }
63
67
  async function callAfterUpdate(builder, model, modelOptions, result) {
@@ -68,10 +72,10 @@ function callInstanceAfterUpdate(builder, model, modelOptions) {
68
72
  return model.$afterUpdate(modelOptions, builder.context());
69
73
  }
70
74
  async function callStaticAfterUpdate(builder, result) {
71
- if (!hasStaticHook(builder.modelClass(), 'afterUpdate')) {
75
+ if (!(0, StaticHookArguments_1.hasStaticHook)(builder.modelClass(), 'afterUpdate')) {
72
76
  return result;
73
77
  }
74
- const args = StaticHookArguments.create({ builder, result });
78
+ const args = StaticHookArguments_1.StaticHookArguments.create({ builder, result });
75
79
  const maybeResult = await builder.modelClass().afterUpdate(args);
76
80
  if (maybeResult === undefined) {
77
81
  return result;
@@ -91,22 +95,22 @@ function convertFieldExpressionsToRaw(builder, model, json) {
91
95
  // on postgres and to
92
96
  // `col` : raw("JSON_SET(COALESCE(`col`, JSON_OBJECT()), '$.\"attr\"', JSON_EXTRACT(`other`, '$.\"lol\"'))")
93
97
  // on mysql. A NULL column is treated as an empty object (or array).
94
- const parsed = ref(key);
98
+ const parsed = (0, ReferenceBuilder_1.ref)(key);
95
99
  const access = parsed.parsedExpr.access;
96
- const isSqlValue = isKnexQueryBuilder(val) || isKnexRaw(val);
100
+ const isSqlValue = (0, knexUtils_1.isKnexQueryBuilder)(val) || (0, knexUtils_1.isKnexRaw)(val);
97
101
  // When the column is set by an earlier key, that expression is used instead.
98
102
  const target = convertedJson[parsed.column] || parsed.column;
99
103
  const isFirstSet = !convertedJson[parsed.column];
100
104
  if (!isSqlValue) {
101
105
  val = JSON.stringify(val);
102
106
  }
103
- if (getJsonDialect(knex, key) === 'mysql') {
107
+ if ((0, postgresJsonPath_1.getJsonDialect)(knex, key) === 'mysql') {
104
108
  const empty = access[0].type === 'array' ? 'JSON_ARRAY()' : 'JSON_OBJECT()';
105
109
  const column = isFirstSet ? `COALESCE(??, ${empty})` : '??';
106
- const value = isSqlValue ? '?' : toJsonSql('?', knex);
110
+ const value = isSqlValue ? '?' : (0, mysqlJsonPath_1.toJsonSql)('?', knex);
107
111
  convertedJson[parsed.column] = knex.raw(`JSON_SET(${column}, ?, ${value})`, [
108
112
  target,
109
- toMySqlJsonPath(access),
113
+ (0, mysqlJsonPath_1.toMySqlJsonPath)(access),
110
114
  val,
111
115
  ]);
112
116
  }
@@ -114,7 +118,7 @@ function convertFieldExpressionsToRaw(builder, model, json) {
114
118
  const empty = access[0].type === 'array' ? `'[]'::jsonb` : `'{}'::jsonb`;
115
119
  const column = isFirstSet ? `COALESCE(??, ${empty})` : '??';
116
120
  const value = isSqlValue ? 'to_jsonb(?)' : '?';
117
- convertedJson[parsed.column] = knex.raw(`jsonb_set(${column}, ${toPgJsonPathLiteral(access)}, ${value}, true)`, [target, val]);
121
+ convertedJson[parsed.column] = knex.raw(`jsonb_set(${column}, ${(0, postgresJsonPath_1.toPgJsonPathLiteral)(access)}, ${value}, true)`, [target, val]);
118
122
  }
119
123
  delete model[key];
120
124
  }
@@ -124,7 +128,3 @@ function convertFieldExpressionsToRaw(builder, model, json) {
124
128
  }
125
129
  return convertedJson;
126
130
  }
127
- module.exports = {
128
- UpdateOperation,
129
- convertFieldExpressionsToRaw,
130
- };
@@ -1,11 +1,13 @@
1
- 'use strict';
2
- const { DelegateOperation } = require('./DelegateOperation');
3
- const { UpsertGraphOperation } = require('./UpsertGraphOperation');
4
- const { RelationExpression } = require('../RelationExpression');
5
- class UpsertGraphAndFetchOperation extends DelegateOperation {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.UpsertGraphAndFetchOperation = void 0;
4
+ const DelegateOperation_1 = require("./DelegateOperation");
5
+ const UpsertGraphOperation_1 = require("./UpsertGraphOperation");
6
+ const RelationExpression_1 = require("../RelationExpression");
7
+ class UpsertGraphAndFetchOperation extends DelegateOperation_1.DelegateOperation {
6
8
  constructor(name, opt) {
7
9
  super(name, opt);
8
- if (!this.delegate.is(UpsertGraphOperation)) {
10
+ if (!this.delegate.is(UpsertGraphOperation_1.UpsertGraphOperation)) {
9
11
  throw new Error('Invalid delegate');
10
12
  }
11
13
  }
@@ -19,7 +21,7 @@ class UpsertGraphAndFetchOperation extends DelegateOperation {
19
21
  if (this.models.length === 0) {
20
22
  return this.isArray ? [] : null;
21
23
  }
22
- const eager = RelationExpression.fromModelGraph(this.models);
24
+ const eager = RelationExpression_1.RelationExpression.fromModelGraph(this.models);
23
25
  const modelClass = this.models[0].constructor;
24
26
  const ids = this.models.map((model) => model.$id());
25
27
  const models = await modelClass
@@ -30,6 +32,4 @@ class UpsertGraphAndFetchOperation extends DelegateOperation {
30
32
  return this.isArray ? models : models[0] || null;
31
33
  }
32
34
  }
33
- module.exports = {
34
- UpsertGraphAndFetchOperation,
35
- };
35
+ exports.UpsertGraphAndFetchOperation = UpsertGraphAndFetchOperation;
@@ -1,8 +1,10 @@
1
- 'use strict';
2
- const { QueryBuilderOperation } = require('./QueryBuilderOperation');
3
- const { GraphUpsert } = require('../graph/GraphUpsert');
4
- const { RelationFindOperation } = require('../../relations/RelationFindOperation');
5
- class UpsertGraphOperation extends QueryBuilderOperation {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.UpsertGraphOperation = void 0;
4
+ const QueryBuilderOperation_1 = require("./QueryBuilderOperation");
5
+ const GraphUpsert_1 = require("../graph/GraphUpsert");
6
+ const RelationFindOperation_1 = require("../../relations/RelationFindOperation");
7
+ class UpsertGraphOperation extends QueryBuilderOperation_1.QueryBuilderOperation {
6
8
  constructor(name, opt) {
7
9
  super(name, Object.assign({}, opt, {
8
10
  upsertOptions: {},
@@ -18,7 +20,7 @@ class UpsertGraphOperation extends QueryBuilderOperation {
18
20
  }
19
21
  onAdd(builder, args) {
20
22
  const [objects] = args;
21
- this.upsert = new GraphUpsert({
23
+ this.upsert = new GraphUpsert_1.GraphUpsert({
22
24
  objects,
23
25
  rootModelClass: builder.modelClass(),
24
26
  upsertOptions: this.upsertOptions,
@@ -39,9 +41,7 @@ class UpsertGraphOperation extends QueryBuilderOperation {
39
41
  return clone;
40
42
  }
41
43
  }
44
+ exports.UpsertGraphOperation = UpsertGraphOperation;
42
45
  function hasOtherSqlModifyingQueryBuilderCalls(builder) {
43
- return builder.has(/where/) || builder.has(RelationFindOperation);
46
+ return builder.has(/where/) || builder.has(RelationFindOperation_1.RelationFindOperation);
44
47
  }
45
- module.exports = {
46
- UpsertGraphOperation,
47
- };
@@ -1,7 +1,9 @@
1
- 'use strict';
2
- const { ObjectionToKnexConvertingOperation } = require('./ObjectionToKnexConvertingOperation');
3
- const { asSingle } = require('../../utils/objectUtils');
4
- class WhereCompositeOperation extends ObjectionToKnexConvertingOperation {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.WhereCompositeOperation = void 0;
4
+ const ObjectionToKnexConvertingOperation_1 = require("./ObjectionToKnexConvertingOperation");
5
+ const objectUtils_1 = require("../../utils/objectUtils");
6
+ class WhereCompositeOperation extends ObjectionToKnexConvertingOperation_1.ObjectionToKnexConvertingOperation {
5
7
  onBuildKnex(knexBuilder, builder) {
6
8
  const args = this.getKnexArgs(builder);
7
9
  if (args.length === 2) {
@@ -14,6 +16,7 @@ class WhereCompositeOperation extends ObjectionToKnexConvertingOperation {
14
16
  return knexBuilder.where(...buildWhereArgs(...args));
15
17
  }
16
18
  }
19
+ exports.WhereCompositeOperation = WhereCompositeOperation;
17
20
  function buildWhereArgs(cols, op, values) {
18
21
  if (isNormalWhere(cols, values)) {
19
22
  return buildNormalWhereArgs(cols, op, values);
@@ -29,7 +32,7 @@ function isNormalWhere(cols, values) {
29
32
  return ((!Array.isArray(cols) || cols.length === 1) && (!Array.isArray(values) || values.length === 1));
30
33
  }
31
34
  function buildNormalWhereArgs(cols, op, values) {
32
- return [asSingle(cols), op, asSingle(values)];
35
+ return [(0, objectUtils_1.asSingle)(cols), op, (0, objectUtils_1.asSingle)(values)];
33
36
  }
34
37
  function isCompositeWhere(cols, values) {
35
38
  return Array.isArray(cols) && Array.isArray(values) && cols.length === values.length;
@@ -43,6 +46,3 @@ function buildCompositeWhereArgs(cols, op, values) {
43
46
  },
44
47
  ];
45
48
  }
46
- module.exports = {
47
- WhereCompositeOperation,
48
- };
@@ -1,13 +1,15 @@
1
- 'use strict';
2
- const { ObjectionToKnexConvertingOperation } = require('./ObjectionToKnexConvertingOperation');
3
- const { isKnexRaw } = require('../../utils/knexUtils');
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.WhereInOperation = void 0;
4
+ const ObjectionToKnexConvertingOperation_1 = require("./ObjectionToKnexConvertingOperation");
5
+ const knexUtils_1 = require("../../utils/knexUtils");
4
6
  // `onIn`, `onNotIn` etc. of join callbacks. knex compiles the values before the
5
7
  // column, so the bindings of a raw column (like `ref('data:a').castInt()` on
6
8
  // MySQL or `fn.lower(ref('a'))`) end up after the values and the query uses the
7
9
  // wrong bindings. In that case the condition is built as raw sql with the
8
10
  // bindings in the right order. knex 3.2 fixed this for `whereIn` but not for
9
11
  // `onIn`.
10
- class WhereInOperation extends ObjectionToKnexConvertingOperation {
12
+ class WhereInOperation extends ObjectionToKnexConvertingOperation_1.ObjectionToKnexConvertingOperation {
11
13
  onBuildKnex(knexBuilder, builder) {
12
14
  const args = this.getKnexArgs(builder);
13
15
  const [column, values] = args;
@@ -22,7 +24,7 @@ class WhereInOperation extends ObjectionToKnexConvertingOperation {
22
24
  sql = `? ${not}in (${values.map(() => '?').join(', ')})`;
23
25
  bindings = [column, ...values];
24
26
  }
25
- else if (isKnexRaw(values)) {
27
+ else if ((0, knexUtils_1.isKnexRaw)(values)) {
26
28
  // knex doesn't wrap raw bindings in parentheses.
27
29
  sql = `? ${not}in (?)`;
28
30
  bindings = [column, values];
@@ -35,12 +37,12 @@ class WhereInOperation extends ObjectionToKnexConvertingOperation {
35
37
  return knexBuilder[this.opt.rawMethod](knex.raw(sql, bindings));
36
38
  }
37
39
  }
40
+ exports.WhereInOperation = WhereInOperation;
41
+ // A knex raw with bindings.
38
42
  function hasBindings(column) {
39
- return isKnexRaw(column) && Array.isArray(column.bindings) && column.bindings.length > 0;
43
+ const raw = column;
44
+ return (0, knexUtils_1.isKnexRaw)(raw) && Array.isArray(raw.bindings) && raw.bindings.length > 0;
40
45
  }
41
46
  function isEmptyArray(values) {
42
47
  return Array.isArray(values) && values.length === 0;
43
48
  }
44
- module.exports = {
45
- WhereInOperation,
46
- };
@@ -1,10 +1,12 @@
1
- 'use strict';
2
- const { QueryBuilderOperation } = require('../QueryBuilderOperation');
3
- const { RelationExpression } = require('../../RelationExpression');
4
- class EagerOperation extends QueryBuilderOperation {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EagerOperation = void 0;
4
+ const QueryBuilderOperation_1 = require("../QueryBuilderOperation");
5
+ const RelationExpression_1 = require("../../RelationExpression");
6
+ class EagerOperation extends QueryBuilderOperation_1.QueryBuilderOperation {
5
7
  constructor(name, opt) {
6
8
  super(name, opt);
7
- this.expression = RelationExpression.create();
9
+ this.expression = RelationExpression_1.RelationExpression.create();
8
10
  this.modifiersAtPath = [];
9
11
  this.graphOptions = this.opt.defaultGraphOptions;
10
12
  }
@@ -12,7 +14,9 @@ class EagerOperation extends QueryBuilderOperation {
12
14
  const expression = this.expression.clone();
13
15
  this.modifiersAtPath.forEach((modifier, i) => {
14
16
  const modifierName = getModifierName(i);
15
- expression.expressionsAtPath(modifier.path).forEach((expr) => {
17
+ expression
18
+ .expressionsAtPath(modifier.path)
19
+ .forEach((expr) => {
16
20
  expr.node.$modify.push(modifierName);
17
21
  });
18
22
  });
@@ -38,9 +42,7 @@ class EagerOperation extends QueryBuilderOperation {
38
42
  return clone;
39
43
  }
40
44
  }
45
+ exports.EagerOperation = EagerOperation;
41
46
  function getModifierName(index) {
42
47
  return `_f${index}_`;
43
48
  }
44
- module.exports = {
45
- EagerOperation,
46
- };
@@ -1,28 +1,28 @@
1
- 'use strict';
2
- const { EagerOperation } = require('./EagerOperation');
3
- const { RelationJoiner } = require('../../join/RelationJoiner');
4
- class JoinEagerOperation extends EagerOperation {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.JoinEagerOperation = void 0;
4
+ const EagerOperation_1 = require("./EagerOperation");
5
+ const RelationJoiner_1 = require("../../join/RelationJoiner");
6
+ class JoinEagerOperation extends EagerOperation_1.EagerOperation {
5
7
  constructor(name, opt) {
6
8
  super(name, opt);
7
9
  this.joiner = null;
8
10
  }
9
11
  onAdd(builder) {
10
12
  builder.findOptions({ callAfterFindDeeply: true });
11
- this.joiner = new RelationJoiner({
13
+ this.joiner = new RelationJoiner_1.RelationJoiner({
12
14
  modelClass: builder.modelClass(),
13
15
  });
14
16
  return true;
15
17
  }
16
18
  onBefore3(builder) {
17
- return this.joiner
18
- .setExpression(this.buildFinalExpression())
19
+ return this.joiner.setExpression(this.buildFinalExpression())
19
20
  .setModifiers(this.buildFinalModifiers(builder))
20
21
  .setOptions(this.graphOptions)
21
22
  .fetchColumnInfo(builder);
22
23
  }
23
24
  onBuild(builder) {
24
- this.joiner
25
- .setExpression(this.buildFinalExpression())
25
+ this.joiner.setExpression(this.buildFinalExpression())
26
26
  .setModifiers(this.buildFinalModifiers(builder))
27
27
  .setOptions(this.graphOptions)
28
28
  .build(builder);
@@ -36,6 +36,4 @@ class JoinEagerOperation extends EagerOperation {
36
36
  return clone;
37
37
  }
38
38
  }
39
- module.exports = {
40
- JoinEagerOperation,
41
- };
39
+ exports.JoinEagerOperation = JoinEagerOperation;
@@ -1,10 +1,10 @@
1
- 'use strict';
2
- const { WhereInEagerOperation } = require('./WhereInEagerOperation');
3
- class NaiveEagerOperation extends WhereInEagerOperation {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NaiveEagerOperation = void 0;
4
+ const WhereInEagerOperation_1 = require("./WhereInEagerOperation");
5
+ class NaiveEagerOperation extends WhereInEagerOperation_1.WhereInEagerOperation {
4
6
  batchSize() {
5
7
  return 1;
6
8
  }
7
9
  }
8
- module.exports = {
9
- NaiveEagerOperation,
10
- };
10
+ exports.NaiveEagerOperation = NaiveEagerOperation;
@@ -1,14 +1,49 @@
1
- 'use strict';
2
- const promiseUtils = require('../../../utils/promiseUtils');
3
- const { EagerOperation } = require('./EagerOperation');
4
- const { isMsSql, isOracle, isSqlite } = require('../../../utils/knexUtils');
5
- const { isObject, asArray, flatten, chunk } = require('../../../utils/objectUtils');
6
- const { ValidationErrorType } = require('../../../model/ValidationError');
7
- const { createModifier } = require('../../../utils/createModifier');
8
- const { RelationDoesNotExistError } = require('../../../model/RelationDoesNotExistError');
9
- const { RelationOwner } = require('../../../relations/RelationOwner');
10
- const { getReadConcurrency } = require('../../../model/modelConcurrency');
11
- class WhereInEagerOperation extends EagerOperation {
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.WhereInEagerOperation = void 0;
37
+ const promiseUtils = __importStar(require("../../../utils/promiseUtils"));
38
+ const EagerOperation_1 = require("./EagerOperation");
39
+ const knexUtils_1 = require("../../../utils/knexUtils");
40
+ const objectUtils_1 = require("../../../utils/objectUtils");
41
+ const ValidationError_1 = require("../../../model/ValidationError");
42
+ const createModifier_1 = require("../../../utils/createModifier");
43
+ const RelationDoesNotExistError_1 = require("../../../model/RelationDoesNotExistError");
44
+ const RelationOwner_1 = require("../../../relations/RelationOwner");
45
+ const modelConcurrency_1 = require("../../../model/modelConcurrency");
46
+ class WhereInEagerOperation extends EagerOperation_1.EagerOperation {
12
47
  constructor(name, opt) {
13
48
  super(name, opt);
14
49
  this.relationsToFetch = [];
@@ -18,16 +53,16 @@ class WhereInEagerOperation extends EagerOperation {
18
53
  if (this.graphOptions.maxBatchSize) {
19
54
  return this.graphOptions.maxBatchSize;
20
55
  }
21
- else if (isMsSql(knex)) {
56
+ else if ((0, knexUtils_1.isMsSql)(knex)) {
22
57
  // On MSSQL the parameter limit is actually 2100, but since I couldn't figure out
23
58
  // if the limit is for all parameters in a query or for individual clauses, we set
24
59
  // the limit to 2000 to leave 100 parameters for where clauses etc.
25
60
  return 2000;
26
61
  }
27
- else if (isOracle(knex)) {
62
+ else if ((0, knexUtils_1.isOracle)(knex)) {
28
63
  return 1000;
29
64
  }
30
- else if (isSqlite(knex)) {
65
+ else if ((0, knexUtils_1.isSqlite)(knex)) {
31
66
  // SQLITE_MAX_VARIABLE_NUMBER is 999 by default
32
67
  return 999;
33
68
  }
@@ -46,17 +81,19 @@ class WhereInEagerOperation extends EagerOperation {
46
81
  this.relationsToFetch = relationsToFetch;
47
82
  this.omitProps = selectedProps;
48
83
  }
84
+ // `result` is whatever the query returned: models, a model, or something else
85
+ // like a `count` result.
49
86
  async onAfter2(builder, result) {
50
87
  const modelClass = builder.resultModelClass();
51
88
  if (!result) {
52
89
  return result;
53
90
  }
54
- const models = asArray(result);
91
+ const models = (0, objectUtils_1.asArray)(result);
55
92
  // Check models to be actual objects, to filter out `count` results (#2397).
56
- if (!models.length || !isObject(models[0])) {
93
+ if (!models.length || !(0, objectUtils_1.isObject)(models[0])) {
57
94
  return result;
58
95
  }
59
- await promiseUtils.map(this.relationsToFetch, (it) => this.fetchRelation(builder, models, it.relation, it.childExpression), { concurrency: getReadConcurrency(modelClass, builder.unsafeKnex()) });
96
+ await promiseUtils.map(this.relationsToFetch, (it) => this.fetchRelation(builder, models, it.relation, it.childExpression), { concurrency: (0, modelConcurrency_1.getReadConcurrency)(modelClass, builder.unsafeKnex()) });
60
97
  const intOpt = builder.internalOptions();
61
98
  if (!this.omitProps.length || intOpt.keepImplicitJoinProps) {
62
99
  return result;
@@ -74,24 +111,25 @@ class WhereInEagerOperation extends EagerOperation {
74
111
  async fetchRelation(builder, models, relation, expr) {
75
112
  const modelClass = builder.resultModelClass();
76
113
  const batchSize = this.batchSize(builder.knex());
77
- const modelBatches = chunk(models, batchSize);
114
+ const modelBatches = (0, objectUtils_1.chunk)(models, batchSize);
78
115
  const result = await promiseUtils.map(modelBatches, (batch) => this.fetchRelationBatch(builder, batch, relation, expr), {
79
- concurrency: getReadConcurrency(modelClass, builder.unsafeKnex()),
116
+ concurrency: (0, modelConcurrency_1.getReadConcurrency)(modelClass, builder.unsafeKnex()),
80
117
  });
81
- return flatten(result);
118
+ return (0, objectUtils_1.flatten)(result);
82
119
  }
83
120
  fetchRelationBatch(builder, models, relation, expr) {
84
121
  if (this.shouldSkipFetched(models, relation, expr)) {
85
122
  return this.createSkippedQuery(builder, models, relation, expr);
86
123
  }
87
124
  const queryBuilder = this.createRelationQuery(builder, relation, expr);
88
- const findOperation = relation.find(queryBuilder, RelationOwner.create(models));
125
+ // `Relation` types the operations it creates as `RelationOperation`.
126
+ const findOperation = relation.find(queryBuilder, RelationOwner_1.RelationOwner.create(models));
89
127
  findOperation.alwaysReturnArray = true;
90
128
  findOperation.assignResultToOwner = true;
91
129
  findOperation.relationProperty = expr.node.$name;
92
130
  queryBuilder.addOperation(findOperation, []);
93
131
  for (const modifierName of expr.node.$modify) {
94
- const modifier = createModifier({
132
+ const modifier = (0, createModifier_1.createModifier)({
95
133
  modifier: modifierName,
96
134
  modelClass: relation.relatedModelClass,
97
135
  modifiers: this.buildFinalModifiers(builder),
@@ -103,7 +141,7 @@ class WhereInEagerOperation extends EagerOperation {
103
141
  const modelClass = builder.modelClass();
104
142
  if (err instanceof modelClass.ModifierNotFoundError) {
105
143
  throw modelClass.createValidationError({
106
- type: ValidationErrorType.RelationExpression,
144
+ type: ValidationError_1.ValidationErrorType.RelationExpression,
107
145
  message: `could not find modifier "${modifierName}" for relation "${relation.name}"`,
108
146
  });
109
147
  }
@@ -162,6 +200,7 @@ class WhereInEagerOperation extends EagerOperation {
162
200
  return clone;
163
201
  }
164
202
  }
203
+ exports.WhereInEagerOperation = WhereInEagerOperation;
165
204
  function findRelationsToFetch(modelClass, eagerExpression) {
166
205
  const relationsToFetch = [];
167
206
  try {
@@ -173,9 +212,9 @@ function findRelationsToFetch(modelClass, eagerExpression) {
173
212
  });
174
213
  }
175
214
  catch (err) {
176
- if (err instanceof RelationDoesNotExistError) {
215
+ if (err instanceof RelationDoesNotExistError_1.RelationDoesNotExistError) {
177
216
  throw modelClass.createValidationError({
178
- type: ValidationErrorType.RelationExpression,
217
+ type: ValidationError_1.ValidationErrorType.RelationExpression,
179
218
  message: `unknown relation "${err.relationName}" in an eager expression`,
180
219
  });
181
220
  }
@@ -222,6 +261,3 @@ function getRelatedModels(models, expr) {
222
261
  }
223
262
  return allRelated;
224
263
  }
225
- module.exports = {
226
- WhereInEagerOperation,
227
- };
@@ -1,19 +1,54 @@
1
- 'use strict';
2
- const postgresJsonApi = require('./postgresJsonApi');
3
- const mysqlJsonApi = require('./mysqlJsonApi');
4
- const { getJsonDialect } = require('../../../utils/postgresJsonPath');
5
- const { jsonCastsForDialect } = require('../../../utils/mysqlJsonPath');
6
- const { ObjectionToKnexConvertingOperation } = require('../ObjectionToKnexConvertingOperation');
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.WhereJsonHasOperation = void 0;
37
+ const postgresJsonApi = __importStar(require("./postgresJsonApi"));
38
+ const mysqlJsonApi = __importStar(require("./mysqlJsonApi"));
39
+ const postgresJsonPath_1 = require("../../../utils/postgresJsonPath");
40
+ const mysqlJsonPath_1 = require("../../../utils/mysqlJsonPath");
41
+ const ObjectionToKnexConvertingOperation_1 = require("../ObjectionToKnexConvertingOperation");
7
42
  // `whereJsonHasAny` and `whereJsonHasAll`.
8
- class WhereJsonHasOperation extends ObjectionToKnexConvertingOperation {
43
+ class WhereJsonHasOperation extends ObjectionToKnexConvertingOperation_1.ObjectionToKnexConvertingOperation {
9
44
  onBuildKnex(knexBuilder, builder) {
10
- const dialect = getJsonDialect(builder.unsafeKnex(), this.name);
45
+ const dialect = (0, postgresJsonPath_1.getJsonDialect)(builder.unsafeKnex(), this.name);
11
46
  const args = this.getKnexArgs(builder);
12
47
  let [sql, bindings] = dialect === 'mysql'
13
48
  ? mysqlJsonApi.whereJsonHas(args[0], this.opt.operator, args[1], builder.unsafeKnex())
14
49
  : postgresJsonApi.whereJsonFieldRightStringArrayOnLeftQuery(builder.knex(), args[0], this.opt.operator, args[1]);
15
50
  if (dialect === 'mysql') {
16
- sql = jsonCastsForDialect(sql, builder.unsafeKnex());
51
+ sql = (0, mysqlJsonPath_1.jsonCastsForDialect)(sql, builder.unsafeKnex());
17
52
  }
18
53
  if (this.opt.bool === 'or') {
19
54
  knexBuilder = knexBuilder.orWhereRaw(sql, bindings);
@@ -24,6 +59,4 @@ class WhereJsonHasOperation extends ObjectionToKnexConvertingOperation {
24
59
  return knexBuilder;
25
60
  }
26
61
  }
27
- module.exports = {
28
- WhereJsonHasOperation,
29
- };
62
+ exports.WhereJsonHasOperation = WhereJsonHasOperation;