@abedmurrar/objection 4.0.0-beta.4 → 4.0.0-beta.6

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 (31) hide show
  1. package/lib/queryBuilder/InternalOptions.js +4 -4
  2. package/lib/queryBuilder/QueryBuilder.js +161 -135
  3. package/lib/queryBuilder/QueryBuilderBase.js +203 -203
  4. package/lib/queryBuilder/QueryBuilderContext.js +6 -6
  5. package/lib/queryBuilder/QueryBuilderContextBase.js +12 -8
  6. package/lib/queryBuilder/QueryBuilderOperationSupport.js +30 -25
  7. package/lib/queryBuilder/QueryBuilderUserContext.js +4 -4
  8. package/lib/queryBuilder/StaticHookArguments.js +11 -11
  9. package/lib/queryBuilder/graph/GraphAction.js +7 -7
  10. package/lib/queryBuilder/graph/GraphData.js +4 -4
  11. package/lib/queryBuilder/graph/GraphFetcher.js +18 -17
  12. package/lib/queryBuilder/graph/GraphNodeDbExistence.js +45 -12
  13. package/lib/queryBuilder/graph/GraphOperation.js +4 -4
  14. package/lib/queryBuilder/graph/GraphOptions.js +5 -5
  15. package/lib/queryBuilder/graph/GraphUpsert.js +36 -36
  16. package/lib/queryBuilder/graph/delete/GraphDelete.js +8 -8
  17. package/lib/queryBuilder/graph/delete/GraphDeleteAction.js +46 -11
  18. package/lib/queryBuilder/graph/insert/GraphInsert.js +12 -12
  19. package/lib/queryBuilder/graph/insert/GraphInsertAction.js +59 -21
  20. package/lib/queryBuilder/graph/insert/JoinRowGraphInsertAction.js +49 -11
  21. package/lib/queryBuilder/graph/patch/GraphPatch.js +8 -8
  22. package/lib/queryBuilder/graph/patch/GraphPatchAction.js +52 -19
  23. package/lib/queryBuilder/graph/recursiveUpsert/GraphRecursiveUpsert.js +8 -8
  24. package/lib/queryBuilder/graph/recursiveUpsert/GraphRecursiveUpsertAction.js +54 -18
  25. package/lib/queryBuilder/operations/types.js +2 -2
  26. package/lib/queryBuilder/transformations/CompositeQueryTransformation.js +6 -6
  27. package/lib/queryBuilder/transformations/QueryTransformation.js +4 -4
  28. package/lib/queryBuilder/transformations/WrapMysqlModifySubqueryTransformation.js +11 -8
  29. package/lib/queryBuilder/transformations/index.js +8 -8
  30. package/lib/queryBuilder/whereScopes.js +15 -21
  31. package/package.json +1 -1
@@ -1,20 +1,22 @@
1
- 'use strict';
2
- const { ModelGraph } = require('../../model/graph/ModelGraph');
3
- const { ModelGraphEdge } = require('../../model/graph/ModelGraphEdge');
4
- const { createNotModelError } = require('../../model/graph/ModelGraphBuilder');
5
- const { GraphFetcher } = require('../graph/GraphFetcher');
6
- const { GraphInsert } = require('./insert/GraphInsert');
7
- const { GraphPatch } = require('./patch/GraphPatch');
8
- const { GraphDelete } = require('./delete/GraphDelete');
9
- const { GraphRecursiveUpsert } = require('./recursiveUpsert/GraphRecursiveUpsert');
10
- const { GraphOptions } = require('./GraphOptions');
11
- const { ValidationErrorType } = require('../../model/ValidationError');
12
- const { RelationExpression } = require('../RelationExpression');
13
- const { GraphNodeDbExistence } = require('./GraphNodeDbExistence');
14
- const { GraphData } = require('./GraphData');
15
- const { uniqBy, asArray, isObject } = require('../../utils/objectUtils');
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GraphUpsert = void 0;
4
+ const ModelGraph_1 = require("../../model/graph/ModelGraph");
5
+ const ModelGraphEdge_1 = require("../../model/graph/ModelGraphEdge");
6
+ const ModelGraphBuilder_1 = require("../../model/graph/ModelGraphBuilder");
7
+ const GraphFetcher_1 = require("../graph/GraphFetcher");
8
+ const GraphInsert_1 = require("./insert/GraphInsert");
9
+ const GraphPatch_1 = require("./patch/GraphPatch");
10
+ const GraphDelete_1 = require("./delete/GraphDelete");
11
+ const GraphRecursiveUpsert_1 = require("./recursiveUpsert/GraphRecursiveUpsert");
12
+ const GraphOptions_1 = require("./GraphOptions");
13
+ const ValidationError_1 = require("../../model/ValidationError");
14
+ const RelationExpression_1 = require("../RelationExpression");
15
+ const GraphNodeDbExistence_1 = require("./GraphNodeDbExistence");
16
+ const GraphData_1 = require("./GraphData");
17
+ const objectUtils_1 = require("../../utils/objectUtils");
16
18
  class GraphUpsert {
17
- constructor({ rootModelClass, objects, upsertOptions }) {
19
+ constructor({ rootModelClass, objects, upsertOptions, }) {
18
20
  checkCanBeConvertedToModels(rootModelClass, objects);
19
21
  this.objects = rootModelClass.ensureModelArray(objects, GraphUpsert.modelOptions);
20
22
  this.isArray = Array.isArray(objects);
@@ -25,8 +27,8 @@ class GraphUpsert {
25
27
  }
26
28
  run(builder) {
27
29
  const modelClass = builder.modelClass();
28
- const graphOptions = new GraphOptions(this.upsertOpt);
29
- const graph = ModelGraph.create(modelClass, this.objects);
30
+ const graphOptions = new GraphOptions_1.GraphOptions(this.upsertOpt);
31
+ const graph = ModelGraph_1.ModelGraph.create(modelClass, this.objects);
30
32
  assignDbRefsAsRelateProps(graph);
31
33
  return createGraphData(builder, graphOptions, graph)
32
34
  .then(checkForErrors(builder))
@@ -35,10 +37,11 @@ class GraphUpsert {
35
37
  .then(returnResult(this.objects, this.isArray));
36
38
  }
37
39
  }
40
+ exports.GraphUpsert = GraphUpsert;
38
41
  function checkCanBeConvertedToModels(modelClass, objects) {
39
- asArray(objects).forEach((obj) => {
40
- if (!isObject(obj)) {
41
- throw createNotModelError(modelClass, obj);
42
+ (0, objectUtils_1.asArray)(objects).forEach((obj) => {
43
+ if (!(0, objectUtils_1.isObject)(obj)) {
44
+ throw (0, ModelGraphBuilder_1.createNotModelError)(modelClass, obj);
42
45
  }
43
46
  });
44
47
  }
@@ -47,25 +50,25 @@ function assignDbRefsAsRelateProps(graph) {
47
50
  if (!node.parentEdge || !node.parentEdge.relation || !node.isDbReference) {
48
51
  continue;
49
52
  }
50
- node.parentEdge.relation.setRelateProp(node.obj, asArray(node.dbReference));
53
+ node.parentEdge.relation.setRelateProp(node.obj, (0, objectUtils_1.asArray)(node.dbReference));
51
54
  }
52
55
  }
53
56
  async function createGraphData(builder, graphOptions, graph) {
54
57
  const currentGraph = await fetchCurrentGraph(builder, graphOptions, graph);
55
- const nodeDbExistence = await GraphNodeDbExistence.create({
58
+ const nodeDbExistence = await GraphNodeDbExistence_1.GraphNodeDbExistence.create({
56
59
  builder,
57
60
  graph,
58
61
  graphOptions,
59
62
  currentGraph,
60
63
  });
61
- return new GraphData({ graph, currentGraph, graphOptions, nodeDbExistence });
64
+ return new GraphData_1.GraphData({ graph, currentGraph, graphOptions, nodeDbExistence });
62
65
  }
63
66
  function fetchCurrentGraph(builder, graphOptions, graph) {
64
67
  if (graphOptions.isInsertOnly()) {
65
- return Promise.resolve(ModelGraph.createEmpty());
68
+ return Promise.resolve(ModelGraph_1.ModelGraph.createEmpty());
66
69
  }
67
70
  else {
68
- return GraphFetcher.fetchCurrentGraph({ builder, graph, graphOptions });
71
+ return GraphFetcher_1.GraphFetcher.fetchCurrentGraph({ builder, graph, graphOptions });
69
72
  }
70
73
  }
71
74
  // Remove branches from the graph that require no operations. For example
@@ -110,7 +113,7 @@ function pruneDeletedBranches(graphData) {
110
113
  }
111
114
  function findRoots(nodes) {
112
115
  const nodeSet = new Set(nodes);
113
- return uniqBy(nodes.filter((node) => {
116
+ return (0, objectUtils_1.uniqBy)(nodes.filter((node) => {
114
117
  let parentNode = node.parentNode;
115
118
  while (parentNode) {
116
119
  if (nodeSet.has(parentNode)) {
@@ -178,10 +181,10 @@ function checkForUnallowedRelationErrors(graphData, builder) {
178
181
  const allowedExpression = builder.allowedGraphExpression();
179
182
  if (allowedExpression) {
180
183
  const rootsObjs = graph.nodes.filter((node) => !node.parentEdge).map((node) => node.obj);
181
- const expression = RelationExpression.fromModelGraph(rootsObjs);
184
+ const expression = RelationExpression_1.RelationExpression.fromModelGraph(rootsObjs);
182
185
  if (!allowedExpression.isSubExpression(expression)) {
183
186
  throw builder.modelClass().createValidationError({
184
- type: ValidationErrorType.UnallowedRelation,
187
+ type: ValidationError_1.ValidationErrorType.UnallowedRelation,
185
188
  message: 'trying to upsert an unallowed relation',
186
189
  });
187
190
  }
@@ -192,9 +195,9 @@ function checkForUnallowedReferenceErrors(graphData, builder) {
192
195
  if (graphOptions.allowRefs()) {
193
196
  return;
194
197
  }
195
- if (graph.edges.some((edge) => edge.type === ModelGraphEdge.Type.Reference)) {
198
+ if (graph.edges.some((edge) => edge.type === ModelGraphEdge_1.ModelGraphEdge.Type.Reference)) {
196
199
  throw builder.modelClass().createValidationError({
197
- type: ValidationErrorType.InvalidGraph,
200
+ type: ValidationError_1.ValidationErrorType.InvalidGraph,
198
201
  message: '#ref references are not allowed in a graph by default. see the allowRefs insert/upsert graph option',
199
202
  });
200
203
  }
@@ -211,8 +214,8 @@ function checkForHasManyRelateErrors(graphData) {
211
214
  function executeOperations(builder) {
212
215
  return (graphData) => {
213
216
  const operations = graphData.graphOptions.isInsertOnly()
214
- ? [GraphInsert]
215
- : [GraphDelete, GraphInsert, GraphPatch, GraphRecursiveUpsert];
217
+ ? [GraphInsert_1.GraphInsert]
218
+ : [GraphDelete_1.GraphDelete, GraphInsert_1.GraphInsert, GraphPatch_1.GraphPatch, GraphRecursiveUpsert_1.GraphRecursiveUpsert];
216
219
  return operations.reduce((promise, Operation) => {
217
220
  const operation = new Operation(graphData);
218
221
  const actions = operation.createActions();
@@ -226,6 +229,3 @@ function executeActions(builder, actions) {
226
229
  function returnResult(objects, isArray) {
227
230
  return () => (isArray ? objects : objects[0]);
228
231
  }
229
- module.exports = {
230
- GraphUpsert,
231
- };
@@ -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;