@abedmurrar/objection 4.0.0-beta.1 → 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 (134) 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/RelationDeleteOperation.js +0 -2
  127. package/lib/relations/RelationFindOperation.js +0 -1
  128. package/lib/relations/RelationUpdateOperation.js +0 -1
  129. package/lib/relations/manyToMany/delete/ManyToManyDeleteOperationBase.js +0 -1
  130. package/lib/transaction.js +44 -12
  131. package/lib/utils/objectUtils.js +6 -1
  132. package/lib/utils/parseFieldExpression.js +4 -35
  133. package/lib/utils/promiseUtils/index.js +19 -9
  134. package/package.json +1 -1
@@ -1,15 +1,15 @@
1
- 'use strict';
2
- const { GraphOperation } = require('../GraphOperation');
3
- const { GraphDeleteAction } = require('./GraphDeleteAction');
4
- class GraphDelete extends GraphOperation {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GraphDelete = void 0;
4
+ const GraphOperation_1 = require("../GraphOperation");
5
+ const GraphDeleteAction_1 = require("./GraphDeleteAction");
6
+ class GraphDelete extends GraphOperation_1.GraphOperation {
5
7
  createActions() {
6
8
  return [
7
- new GraphDeleteAction(this.graphData, {
9
+ new GraphDeleteAction_1.GraphDeleteAction(this.graphData, {
8
10
  nodes: this.currentGraph.nodes.filter((currentNode) => this.graphOptions.shouldDeleteOrUnrelate(currentNode, this.graphData)),
9
11
  }),
10
12
  ];
11
13
  }
12
14
  }
13
- module.exports = {
14
- GraphDelete,
15
- };
15
+ exports.GraphDelete = GraphDelete;
@@ -1,8 +1,43 @@
1
- 'use strict';
2
- const { GraphAction } = require('../GraphAction');
3
- const { groupBy } = require('../../../utils/objectUtils');
4
- const promiseUtils = require('../../../utils/promiseUtils');
5
- class GraphDeleteAction extends GraphAction {
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.GraphDeleteAction = void 0;
37
+ const GraphAction_1 = require("../GraphAction");
38
+ const objectUtils_1 = require("../../../utils/objectUtils");
39
+ const promiseUtils = __importStar(require("../../../utils/promiseUtils"));
40
+ class GraphDeleteAction extends GraphAction_1.GraphAction {
6
41
  constructor(graphData, { nodes }) {
7
42
  super(graphData);
8
43
  // Nodes to delete.
@@ -25,13 +60,15 @@ class GraphDeleteAction extends GraphAction {
25
60
  });
26
61
  }
27
62
  _createDeleteBuilders(parentBuilder, nodesTodelete) {
28
- const nodesByRelation = groupBy(nodesTodelete, getRelation);
63
+ const nodesByRelation = (0, objectUtils_1.groupBy)(nodesTodelete, getRelation);
29
64
  const builders = [];
30
65
  nodesByRelation.forEach((nodes, relation) => {
31
- const nodesByParent = groupBy(nodes, getParent);
66
+ const nodesByParent = (0, objectUtils_1.groupBy)(nodes, getParent);
32
67
  nodesByParent.forEach((nodes, parentNode) => {
33
68
  const shouldUnrelate = this.graphOptions.shouldUnrelate(nodes[0], this.graphData);
34
- const builder = parentNode.obj.$relatedQuery(relation.name).childQueryOf(parentBuilder);
69
+ const builder = parentNode.obj
70
+ .$relatedQuery(relation.name)
71
+ .childQueryOf(parentBuilder);
35
72
  if (!relation.isObjectionBelongsToOneRelation) {
36
73
  // This is useless in case of BelongsToOneRelation.
37
74
  builder.findByIds(nodes.map((node) => node.obj.$id()));
@@ -45,12 +82,10 @@ class GraphDeleteAction extends GraphAction {
45
82
  return builders;
46
83
  }
47
84
  }
85
+ exports.GraphDeleteAction = GraphDeleteAction;
48
86
  function getRelation(node) {
49
87
  return node.parentEdge.relation;
50
88
  }
51
89
  function getParent(node) {
52
90
  return node.parentNode;
53
91
  }
54
- module.exports = {
55
- GraphDeleteAction,
56
- };
@@ -1,9 +1,11 @@
1
- 'use strict';
2
- const { JoinRowGraphInsertAction } = require('./JoinRowGraphInsertAction');
3
- const { GraphInsertAction } = require('./GraphInsertAction');
4
- const { GraphOperation } = require('../GraphOperation');
5
- const { ModelGraphEdge } = require('../../../model/graph/ModelGraphEdge');
6
- class GraphInsert extends GraphOperation {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GraphInsert = void 0;
4
+ const JoinRowGraphInsertAction_1 = require("./JoinRowGraphInsertAction");
5
+ const GraphInsertAction_1 = require("./GraphInsertAction");
6
+ const GraphOperation_1 = require("../GraphOperation");
7
+ const ModelGraphEdge_1 = require("../../../model/graph/ModelGraphEdge");
8
+ class GraphInsert extends GraphOperation_1.GraphOperation {
7
9
  constructor(...args) {
8
10
  super(...args);
9
11
  this.dependencies = this._createDependencyMap();
@@ -14,7 +16,7 @@ class GraphInsert extends GraphOperation {
14
16
  _createDependencyMap() {
15
17
  const dependencies = new Map();
16
18
  for (const edge of this.graph.edges) {
17
- if (edge.type == ModelGraphEdge.Type.Relation) {
19
+ if (edge.type == ModelGraphEdge_1.ModelGraphEdge.Type.Relation) {
18
20
  this._createRelationDependency(edge, dependencies);
19
21
  }
20
22
  else {
@@ -60,7 +62,7 @@ class GraphInsert extends GraphOperation {
60
62
  if (nodesToInsert.length === 0) {
61
63
  break;
62
64
  }
63
- actions.push(new GraphInsertAction(this.graphData, {
65
+ actions.push(new GraphInsertAction_1.GraphInsertAction(this.graphData, {
64
66
  nodes: nodesToInsert,
65
67
  dependencies: this.dependencies,
66
68
  }));
@@ -101,7 +103,7 @@ class GraphInsert extends GraphOperation {
101
103
  }
102
104
  _createJoinRowActions() {
103
105
  return [
104
- new JoinRowGraphInsertAction(this.graphData, {
106
+ new JoinRowGraphInsertAction_1.JoinRowGraphInsertAction(this.graphData, {
105
107
  nodes: this.graph.nodes.filter((node) => {
106
108
  return (this.currentGraph.nodeForNode(node) === null &&
107
109
  node.parentEdge &&
@@ -111,6 +113,4 @@ class GraphInsert extends GraphOperation {
111
113
  ];
112
114
  }
113
115
  }
114
- module.exports = {
115
- GraphInsert,
116
- };
116
+ exports.GraphInsert = GraphInsert;
@@ -1,8 +1,43 @@
1
- 'use strict';
2
- const { GraphAction } = require('../GraphAction');
3
- const { groupBy, chunk, get, set } = require('../../../utils/objectUtils');
4
- const { ModelGraphEdge } = require('../../../model/graph/ModelGraphEdge');
5
- const promiseUtils = require('../../../utils/promiseUtils');
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.GraphInsertAction = void 0;
37
+ const GraphAction_1 = require("../GraphAction");
38
+ const objectUtils_1 = require("../../../utils/objectUtils");
39
+ const ModelGraphEdge_1 = require("../../../model/graph/ModelGraphEdge");
40
+ const promiseUtils = __importStar(require("../../../utils/promiseUtils"));
6
41
  /**
7
42
  * Inserts a batch of nodes for a GraphInsert.
8
43
  *
@@ -11,7 +46,7 @@ const promiseUtils = require('../../../utils/promiseUtils');
11
46
  * batch inserts, so this class splits the inserts into further sub batches
12
47
  * when needed.
13
48
  */
14
- class GraphInsertAction extends GraphAction {
49
+ class GraphInsertAction extends GraphAction_1.GraphAction {
15
50
  constructor(graphData, { nodes, dependencies }) {
16
51
  super(graphData);
17
52
  // Nodes to insert.
@@ -21,14 +56,16 @@ class GraphInsertAction extends GraphAction {
21
56
  run(builder) {
22
57
  const batches = this._createInsertBatches(builder);
23
58
  const concurrency = this._getConcurrency(builder, this.nodes);
24
- return promiseUtils.map(batches, (batch) => this._insertBatch(builder, batch), { concurrency });
59
+ return promiseUtils.map(batches, (batch) => this._insertBatch(builder, batch), {
60
+ concurrency,
61
+ });
25
62
  }
26
63
  _createInsertBatches(builder) {
27
64
  const batches = [];
28
65
  const batchSize = this._getBatchSize(builder);
29
- const nodesByModelClass = groupBy(this.nodes, getModelClass);
66
+ const nodesByModelClass = (0, objectUtils_1.groupBy)(this.nodes, getModelClass);
30
67
  for (const nodes of nodesByModelClass.values()) {
31
- for (const nodeBatch of chunk(nodes, batchSize)) {
68
+ for (const nodeBatch of (0, objectUtils_1.chunk)(nodes, batchSize)) {
32
69
  batches.push(nodeBatch);
33
70
  }
34
71
  }
@@ -58,10 +95,10 @@ class GraphInsertAction extends GraphAction {
58
95
  }
59
96
  }
60
97
  _resolveDependency(dependencyNode, edge) {
61
- if (edge.type === ModelGraphEdge.Type.Relation && !edge.relation.joinTable) {
98
+ if (edge.type === ModelGraphEdge_1.ModelGraphEdge.Type.Relation && !edge.relation.joinTable) {
62
99
  this._resolveRelationDependency(dependencyNode, edge);
63
100
  }
64
- else if (edge.refType === ModelGraphEdge.ReferenceType.Property) {
101
+ else if (edge.refType === ModelGraphEdge_1.ModelGraphEdge.ReferenceType.Property) {
65
102
  this._resolvePropertyReferenceNode(dependencyNode, edge);
66
103
  }
67
104
  }
@@ -84,6 +121,7 @@ class GraphInsertAction extends GraphAction {
84
121
  }
85
122
  _resolvePropertyReferenceNode(dependencyNode, edge) {
86
123
  const dependentNode = edge.getOtherNode(dependencyNode);
124
+ // A property reference edge has the paths.
87
125
  let sourcePath;
88
126
  let targetPath;
89
127
  if (edge.isOwnerNode(dependencyNode)) {
@@ -94,20 +132,22 @@ class GraphInsertAction extends GraphAction {
94
132
  targetPath = edge.refOwnerDataPath;
95
133
  sourcePath = edge.refRelatedDataPath;
96
134
  }
97
- const sourceValue = get(dependencyNode.obj, sourcePath);
98
- const targetValue = get(dependentNode.obj, targetPath);
135
+ const sourceValue = (0, objectUtils_1.get)(dependencyNode.obj, sourcePath);
136
+ const targetValue = (0, objectUtils_1.get)(dependentNode.obj, targetPath);
99
137
  if (targetValue === edge.refMatch) {
100
- set(dependentNode.obj, targetPath, sourceValue);
138
+ (0, objectUtils_1.set)(dependentNode.obj, targetPath, sourceValue);
101
139
  }
102
140
  else {
103
- set(dependentNode.obj, targetPath, targetValue.replace(edge.refMatch, sourceValue));
141
+ // The reference is a part of a string: `replace()` converts the value to a string.
142
+ (0, objectUtils_1.set)(dependentNode.obj, targetPath, targetValue.replace(edge.refMatch, sourceValue));
104
143
  }
105
144
  }
106
145
  _omitManyToManyExtraProps(nodes) {
107
146
  for (const node of nodes) {
108
147
  if (node.parentEdge &&
109
- node.parentEdge.type === ModelGraphEdge.Type.Relation &&
148
+ node.parentEdge.type === ModelGraphEdge_1.ModelGraphEdge.Type.Relation &&
110
149
  node.parentEdge.relation.joinTableExtras.length > 0) {
150
+ // Only many to many relations have join table extras.
111
151
  node.parentEdge.relation.omitExtraProps([node.obj]);
112
152
  }
113
153
  }
@@ -119,7 +159,7 @@ class GraphInsertAction extends GraphAction {
119
159
  continue;
120
160
  }
121
161
  for (const edge of node.edges) {
122
- if (edge.type !== ModelGraphEdge.Type.Relation) {
162
+ if (edge.type !== ModelGraphEdge_1.ModelGraphEdge.Type.Relation) {
123
163
  continue;
124
164
  }
125
165
  const prop = edge.isOwnerNode(node) ? edge.relation.ownerProp : edge.relation.relatedProp;
@@ -153,7 +193,7 @@ class GraphInsertAction extends GraphAction {
153
193
  .query()
154
194
  .insert(nodes.map((node) => node.obj))
155
195
  .childQueryOf(parentBuilder)
156
- .copyFrom(parentBuilder, GraphAction.ReturningAllSelector)
196
+ .copyFrom(parentBuilder, GraphAction_1.GraphAction.ReturningAllSelector)
157
197
  .execute();
158
198
  });
159
199
  }
@@ -175,9 +215,7 @@ class GraphInsertAction extends GraphAction {
175
215
  }
176
216
  }
177
217
  }
218
+ exports.GraphInsertAction = GraphInsertAction;
178
219
  function getModelClass(node) {
179
220
  return node.modelClass;
180
221
  }
181
- module.exports = {
182
- GraphInsertAction,
183
- };
@@ -1,8 +1,43 @@
1
- 'use strict';
2
- const { GraphAction } = require('../GraphAction');
3
- const { groupBy, chunk } = require('../../../utils/objectUtils');
4
- const promiseUtils = require('../../../utils/promiseUtils');
5
- class JoinRowGraphInsertAction extends GraphAction {
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.JoinRowGraphInsertAction = void 0;
37
+ const GraphAction_1 = require("../GraphAction");
38
+ const objectUtils_1 = require("../../../utils/objectUtils");
39
+ const promiseUtils = __importStar(require("../../../utils/promiseUtils"));
40
+ class JoinRowGraphInsertAction extends GraphAction_1.GraphAction {
6
41
  constructor(graphData, { nodes }) {
7
42
  super(graphData);
8
43
  this.nodes = nodes;
@@ -10,14 +45,16 @@ class JoinRowGraphInsertAction extends GraphAction {
10
45
  run(builder) {
11
46
  const batches = this._createInsertBatches(builder);
12
47
  const concurrency = this._getConcurrency(builder, this.nodes);
13
- return promiseUtils.map(batches, (batch) => this._insertBatch(builder, batch), { concurrency });
48
+ return promiseUtils.map(batches, (batch) => this._insertBatch(builder, batch), {
49
+ concurrency,
50
+ });
14
51
  }
15
52
  _createInsertBatches(builder) {
16
53
  const batches = [];
17
54
  const batchSize = this._getBatchSize(builder);
18
- const nodesByModel = groupBy(this.nodes, (node) => getJoinTableModel(builder, node));
55
+ const nodesByModel = (0, objectUtils_1.groupBy)(this.nodes, (node) => getJoinTableModel(builder, node));
19
56
  for (const [joinTableModelClass, nodes] of nodesByModel.entries()) {
20
- for (const nodeBatch of chunk(nodes, batchSize)) {
57
+ for (const nodeBatch of (0, objectUtils_1.chunk)(nodes, batchSize)) {
21
58
  batches.push(this._createBatch(joinTableModelClass, nodeBatch));
22
59
  }
23
60
  }
@@ -36,6 +73,7 @@ class JoinRowGraphInsertAction extends GraphAction {
36
73
  }
37
74
  _createJoinTableObj(joinTableModelClass, node) {
38
75
  const { parentEdge, parentNode } = node;
76
+ // The nodes of this action are in many to many relations.
39
77
  const { relation } = parentEdge;
40
78
  this._resolveReferences(node);
41
79
  return joinTableModelClass.fromJson(relation.createJoinModel(relation.ownerProp.getProps(parentNode.obj), node.obj));
@@ -62,9 +100,9 @@ class JoinRowGraphInsertAction extends GraphAction {
62
100
  }
63
101
  }
64
102
  }
103
+ exports.JoinRowGraphInsertAction = JoinRowGraphInsertAction;
65
104
  function getJoinTableModel(builder, node) {
105
+ // A many to many relation always has a join model class. `getJoinModelClass()`
106
+ // also gets the missing knex as null if the builder has none.
66
107
  return node.parentEdge.relation.getJoinModelClass(builder.unsafeKnex());
67
108
  }
68
- module.exports = {
69
- JoinRowGraphInsertAction,
70
- };
@@ -1,15 +1,15 @@
1
- 'use strict';
2
- const { GraphOperation } = require('../GraphOperation');
3
- const { GraphPatchAction } = require('./GraphPatchAction');
4
- class GraphPatch extends GraphOperation {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GraphPatch = void 0;
4
+ const GraphOperation_1 = require("../GraphOperation");
5
+ const GraphPatchAction_1 = require("./GraphPatchAction");
6
+ class GraphPatch extends GraphOperation_1.GraphOperation {
5
7
  createActions() {
6
8
  return [
7
- new GraphPatchAction(this.graphData, {
9
+ new GraphPatchAction_1.GraphPatchAction(this.graphData, {
8
10
  nodes: this.graph.nodes.filter((node) => this.graphOptions.shouldPatchOrUpdateIgnoreDisable(node, this.graphData)),
9
11
  }),
10
12
  ];
11
13
  }
12
14
  }
13
- module.exports = {
14
- GraphPatch,
15
- };
15
+ exports.GraphPatch = GraphPatch;
@@ -1,10 +1,45 @@
1
- 'use strict';
2
- const { getModel } = require('../../../model/getModel');
3
- const { GraphAction } = require('../GraphAction');
4
- const { isInternalProp } = require('../../../utils/internalPropUtils');
5
- const { difference, isObject, jsonEquals } = require('../../../utils/objectUtils');
6
- const promiseUtils = require('../../../utils/promiseUtils');
7
- class GraphPatchAction extends GraphAction {
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.GraphPatchAction = void 0;
37
+ const getModel_1 = require("../../../model/getModel");
38
+ const GraphAction_1 = require("../GraphAction");
39
+ const internalPropUtils_1 = require("../../../utils/internalPropUtils");
40
+ const objectUtils_1 = require("../../../utils/objectUtils");
41
+ const promiseUtils = __importStar(require("../../../utils/promiseUtils"));
42
+ class GraphPatchAction extends GraphAction_1.GraphAction {
8
43
  constructor(graphData, { nodes }) {
9
44
  super(graphData);
10
45
  // Nodes to patch.
@@ -27,7 +62,7 @@ class GraphPatchAction extends GraphAction {
27
62
  const handleUpdate = () => {
28
63
  const { changedProps, unchangedProps } = this._findChanges(node);
29
64
  const allProps = [...changedProps, ...unchangedProps];
30
- const propsToUpdate = difference(shouldPatch || shouldUpdate
65
+ const propsToUpdate = (0, objectUtils_1.difference)(shouldPatch || shouldUpdate
31
66
  ? changedProps
32
67
  : [...changedPropsBecauseOfBelongsToOneInsert, ...changePropsBecauseOfBelongsToOneDelete],
33
68
  // Remove id properties from the props to update. With upsertGraph
@@ -36,12 +71,12 @@ class GraphPatchAction extends GraphAction {
36
71
  const update = propsToUpdate.length > 0;
37
72
  if (update) {
38
73
  // Don't update the fields that we know not to change.
39
- node.obj.$omitFromDatabaseJson(difference(allProps, propsToUpdate));
74
+ node.obj.$omitFromDatabaseJson((0, objectUtils_1.difference)(allProps, propsToUpdate));
40
75
  node.userData.updated = true;
41
76
  }
42
77
  return update;
43
78
  };
44
- const Model = getModel();
79
+ const Model = (0, getModel_1.getModel)();
45
80
  // See if the model defines a beforeUpdate or $beforeUpdate hook. If it does
46
81
  // not, we can check for updated properties now and drop out immediately if
47
82
  // there is nothing to update. Otherwise, we need to wait for the hook to be
@@ -62,7 +97,7 @@ class GraphPatchAction extends GraphAction {
62
97
  });
63
98
  const updateBuilder = this._createBuilder(node)
64
99
  .childQueryOf(builder, childQueryOptions())
65
- .copyFrom(builder, GraphAction.ReturningAllSelector);
100
+ .copyFrom(builder, GraphAction_1.GraphAction.ReturningAllSelector);
66
101
  if (hasBeforeUpdate) {
67
102
  updateBuilder.internalContext().runBefore.push((result, builder) => {
68
103
  // Call handleUpdate in the runBefore hook which runs after the
@@ -81,7 +116,7 @@ class GraphPatchAction extends GraphAction {
81
116
  updateBuilder.update(node.obj);
82
117
  }
83
118
  return updateBuilder.execute().then((result) => {
84
- if (isObject(result) && result.$isObjectionModel) {
119
+ if ((0, objectUtils_1.isObject)(result) && result.$isObjectionModel) {
85
120
  // Handle returning('*').
86
121
  node.obj.$set(result);
87
122
  }
@@ -140,7 +175,7 @@ class GraphPatchAction extends GraphAction {
140
175
  const unchangedProps = [];
141
176
  const changedProps = [];
142
177
  for (const prop of Object.keys(obj)) {
143
- if (isInternalProp(prop) || relationNames.includes(prop)) {
178
+ if ((0, internalPropUtils_1.isInternalProp)(prop) || relationNames.includes(prop)) {
144
179
  continue;
145
180
  }
146
181
  const value = obj[prop];
@@ -178,8 +213,8 @@ class GraphPatchAction extends GraphAction {
178
213
  }
179
214
  }
180
215
  _createRelatedBuilder(node) {
181
- return node.parentNode.obj
182
- .$relatedQuery(node.parentEdge.relation.name)
216
+ return node
217
+ .parentNode.obj.$relatedQuery(node.parentEdge.relation.name)
183
218
  .findById(node.obj.$id());
184
219
  }
185
220
  _createRootBuilder(node) {
@@ -188,6 +223,7 @@ class GraphPatchAction extends GraphAction {
188
223
  return currentObj ? currentObj.$query() : node.obj.$query();
189
224
  }
190
225
  }
226
+ exports.GraphPatchAction = GraphPatchAction;
191
227
  function childQueryOptions() {
192
228
  return {
193
229
  fork: true,
@@ -198,8 +234,5 @@ function nonStrictEquals(val1, val2) {
198
234
  if (val1 == val2) {
199
235
  return true;
200
236
  }
201
- return jsonEquals(val1, val2);
237
+ return (0, objectUtils_1.jsonEquals)(val1, val2);
202
238
  }
203
- module.exports = {
204
- GraphPatchAction,
205
- };
@@ -1,10 +1,12 @@
1
- 'use strict';
2
- const { GraphOperation } = require('../GraphOperation');
3
- const { GraphRecursiveUpsertAction } = require('./GraphRecursiveUpsertAction');
4
- class GraphRecursiveUpsert extends GraphOperation {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GraphRecursiveUpsert = void 0;
4
+ const GraphOperation_1 = require("../GraphOperation");
5
+ const GraphRecursiveUpsertAction_1 = require("./GraphRecursiveUpsertAction");
6
+ class GraphRecursiveUpsert extends GraphOperation_1.GraphOperation {
5
7
  createActions() {
6
8
  return [
7
- new GraphRecursiveUpsertAction(this.graphData, {
9
+ new GraphRecursiveUpsertAction_1.GraphRecursiveUpsertAction(this.graphData, {
8
10
  nodes: this.graph.nodes.filter((node) => {
9
11
  const shouldRelate = this.graphOptions.shouldRelate(node, this.graphData);
10
12
  return shouldRelate && hasRelations(node.obj);
@@ -13,6 +15,7 @@ class GraphRecursiveUpsert extends GraphOperation {
13
15
  ];
14
16
  }
15
17
  }
18
+ exports.GraphRecursiveUpsert = GraphRecursiveUpsert;
16
19
  function hasRelations(obj) {
17
20
  for (const relationName of obj.constructor.getRelationNames()) {
18
21
  if (obj[relationName] !== undefined) {
@@ -21,6 +24,3 @@ function hasRelations(obj) {
21
24
  }
22
25
  return false;
23
26
  }
24
- module.exports = {
25
- GraphRecursiveUpsert,
26
- };