@abedmurrar/objection 4.0.0-beta.5 → 4.0.0-beta.7

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 (61) hide show
  1. package/lib/initialize.js +4 -5
  2. package/lib/model/AjvValidator.js +24 -21
  3. package/lib/model/Model.js +116 -114
  4. package/lib/model/ModifierNotFoundError.js +4 -4
  5. package/lib/model/NotFoundError.js +4 -4
  6. package/lib/model/RelationDoesNotExistError.js +4 -4
  7. package/lib/model/ValidationError.js +8 -8
  8. package/lib/model/Validator.js +7 -6
  9. package/lib/model/getModel.js +4 -4
  10. package/lib/model/graph/ModelGraph.js +9 -7
  11. package/lib/model/graph/ModelGraphBuilder.js +24 -24
  12. package/lib/model/graph/ModelGraphEdge.js +4 -4
  13. package/lib/model/graph/ModelGraphNode.js +17 -11
  14. package/lib/model/inheritModel.js +3 -4
  15. package/lib/model/modelBindKnex.js +12 -13
  16. package/lib/model/modelClone.js +15 -16
  17. package/lib/model/modelColPropMap.js +7 -8
  18. package/lib/model/modelConcurrency.js +6 -7
  19. package/lib/model/modelId.js +4 -5
  20. package/lib/model/modelJsonAttributes.js +10 -11
  21. package/lib/model/modelParseRelations.js +5 -6
  22. package/lib/model/modelQueryProps.js +12 -13
  23. package/lib/model/modelSet.js +17 -18
  24. package/lib/model/modelTableMetadata.js +9 -10
  25. package/lib/model/modelToJson.js +13 -14
  26. package/lib/model/modelUtils.js +7 -7
  27. package/lib/model/modelValidate.js +5 -6
  28. package/lib/model/modelValues.js +10 -10
  29. package/lib/model/modelVisitor.js +3 -4
  30. package/lib/queryBuilder/InternalOptions.js +4 -4
  31. package/lib/queryBuilder/QueryBuilder.js +161 -135
  32. package/lib/queryBuilder/QueryBuilderBase.js +203 -203
  33. package/lib/queryBuilder/QueryBuilderContext.js +6 -6
  34. package/lib/queryBuilder/QueryBuilderContextBase.js +12 -8
  35. package/lib/queryBuilder/QueryBuilderOperationSupport.js +30 -25
  36. package/lib/queryBuilder/QueryBuilderUserContext.js +4 -4
  37. package/lib/queryBuilder/StaticHookArguments.js +11 -11
  38. package/lib/queryBuilder/graph/GraphAction.js +7 -7
  39. package/lib/queryBuilder/graph/GraphData.js +4 -4
  40. package/lib/queryBuilder/graph/GraphFetcher.js +18 -17
  41. package/lib/queryBuilder/graph/GraphNodeDbExistence.js +45 -12
  42. package/lib/queryBuilder/graph/GraphOperation.js +4 -4
  43. package/lib/queryBuilder/graph/GraphOptions.js +5 -5
  44. package/lib/queryBuilder/graph/GraphUpsert.js +36 -36
  45. package/lib/queryBuilder/graph/delete/GraphDelete.js +8 -8
  46. package/lib/queryBuilder/graph/delete/GraphDeleteAction.js +46 -11
  47. package/lib/queryBuilder/graph/insert/GraphInsert.js +12 -12
  48. package/lib/queryBuilder/graph/insert/GraphInsertAction.js +59 -21
  49. package/lib/queryBuilder/graph/insert/JoinRowGraphInsertAction.js +49 -11
  50. package/lib/queryBuilder/graph/patch/GraphPatch.js +8 -8
  51. package/lib/queryBuilder/graph/patch/GraphPatchAction.js +52 -19
  52. package/lib/queryBuilder/graph/recursiveUpsert/GraphRecursiveUpsert.js +8 -8
  53. package/lib/queryBuilder/graph/recursiveUpsert/GraphRecursiveUpsertAction.js +54 -18
  54. package/lib/queryBuilder/operations/types.js +2 -2
  55. package/lib/queryBuilder/transformations/CompositeQueryTransformation.js +6 -6
  56. package/lib/queryBuilder/transformations/QueryTransformation.js +4 -4
  57. package/lib/queryBuilder/transformations/WrapMysqlModifySubqueryTransformation.js +11 -8
  58. package/lib/queryBuilder/transformations/index.js +8 -8
  59. package/lib/queryBuilder/whereScopes.js +15 -21
  60. package/lib/transaction.js +44 -12
  61. package/package.json +1 -1
@@ -1,6 +1,8 @@
1
- 'use strict';
2
- const { QueryBuilderContextBase } = require('./QueryBuilderContextBase');
3
- class QueryBuilderContext extends QueryBuilderContextBase {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.QueryBuilderContext = void 0;
4
+ const QueryBuilderContextBase_1 = require("./QueryBuilderContextBase");
5
+ class QueryBuilderContext extends QueryBuilderContextBase_1.QueryBuilderContextBase {
4
6
  constructor(builder) {
5
7
  super(builder);
6
8
  this.runBefore = [];
@@ -15,6 +17,4 @@ class QueryBuilderContext extends QueryBuilderContextBase {
15
17
  return ctx;
16
18
  }
17
19
  }
18
- module.exports = {
19
- QueryBuilderContext,
20
- };
20
+ exports.QueryBuilderContext = QueryBuilderContext;
@@ -1,15 +1,21 @@
1
- 'use strict';
2
- const { InternalOptions } = require('./InternalOptions');
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.QueryBuilderContextBase = void 0;
4
+ const InternalOptions_1 = require("./InternalOptions");
3
5
  class QueryBuilderContextBase {
4
6
  constructor(builder) {
5
- this.userContext = builder ? new builder.constructor.QueryBuilderUserContext(builder) : null;
6
- this.options = builder ? new this.constructor.InternalOptions() : null;
7
+ // `userContext` and `options` are only null in the copy that `clone()`
8
+ // creates, which assigns them right away.
9
+ this.userContext = (builder
10
+ ? new builder.constructor.QueryBuilderUserContext(builder)
11
+ : null);
12
+ this.options = (builder ? new this.constructor.InternalOptions() : null);
7
13
  this.knex = null;
8
14
  this.aliasMap = null;
9
15
  this.tableMap = null;
10
16
  }
11
17
  static get InternalOptions() {
12
- return InternalOptions;
18
+ return InternalOptions_1.InternalOptions;
13
19
  }
14
20
  clone() {
15
21
  const ctx = new this.constructor();
@@ -21,6 +27,4 @@ class QueryBuilderContextBase {
21
27
  return ctx;
22
28
  }
23
29
  }
24
- module.exports = {
25
- QueryBuilderContextBase,
26
- };
30
+ exports.QueryBuilderContextBase = QueryBuilderContextBase;
@@ -1,9 +1,11 @@
1
- 'use strict';
2
- const { isString, isFunction, isRegExp, mergeMaps, last } = require('../utils/objectUtils');
3
- const { QueryBuilderContextBase } = require('./QueryBuilderContextBase');
4
- const { QueryBuilderUserContext } = require('./QueryBuilderUserContext');
5
- const { deprecate } = require('../utils/deprecate');
6
- const { effectiveWhereScope, createWhereGrouping } = require('./whereScopes');
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.QueryBuilderOperationSupport = void 0;
4
+ const objectUtils_1 = require("../utils/objectUtils");
5
+ const QueryBuilderContextBase_1 = require("./QueryBuilderContextBase");
6
+ const QueryBuilderUserContext_1 = require("./QueryBuilderUserContext");
7
+ const deprecate_1 = require("../utils/deprecate");
8
+ const whereScopes_1 = require("./whereScopes");
7
9
  const AllSelector = () => true;
8
10
  const SelectSelector = /^(select|columns|column|distinct|count|countDistinct|min|max|sum|sumDistinct|avg|avgDistinct)$/;
9
11
  const WhereSelector = /^(where|orWhere|andWhere|find\w+)/;
@@ -31,10 +33,10 @@ class QueryBuilderOperationSupport {
31
33
  return AllSelector;
32
34
  }
33
35
  static get QueryBuilderContext() {
34
- return QueryBuilderContextBase;
36
+ return QueryBuilderContextBase_1.QueryBuilderContextBase;
35
37
  }
36
38
  static get QueryBuilderUserContext() {
37
- return QueryBuilderUserContext;
39
+ return QueryBuilderUserContext_1.QueryBuilderUserContext;
38
40
  }
39
41
  static get SelectSelector() {
40
42
  return SelectSelector;
@@ -107,7 +109,7 @@ class QueryBuilderOperationSupport {
107
109
  const tableName = getTableName(modelClassOrTableName);
108
110
  const ctx = this.internalContext();
109
111
  const tableMap = ctx.tableMap;
110
- if (isString(newTableName)) {
112
+ if ((0, objectUtils_1.isString)(newTableName)) {
111
113
  ctx.tableMap = tableMap || new Map();
112
114
  ctx.tableMap.set(tableName, newTableName);
113
115
  return this;
@@ -120,7 +122,7 @@ class QueryBuilderOperationSupport {
120
122
  const tableName = getTableName(modelClassOrTableName);
121
123
  const ctx = this.internalContext();
122
124
  const aliasMap = ctx.aliasMap;
123
- if (isString(alias)) {
125
+ if ((0, objectUtils_1.isString)(alias)) {
124
126
  ctx.aliasMap = aliasMap || new Map();
125
127
  ctx.aliasMap.set(tableName, alias);
126
128
  return this;
@@ -157,8 +159,8 @@ class QueryBuilderOperationSupport {
157
159
  if (this._isPartialQuery) {
158
160
  // Merge alias and table name maps for "partial" subqueries.
159
161
  const ctx = this.internalContext();
160
- ctx.aliasMap = mergeMaps(query.internalContext().aliasMap, ctx.aliasMap);
161
- ctx.tableMap = mergeMaps(query.internalContext().tableMap, ctx.tableMap);
162
+ ctx.aliasMap = (0, objectUtils_1.mergeMaps)(query.internalContext().aliasMap, ctx.aliasMap);
163
+ ctx.tableMap = (0, objectUtils_1.mergeMaps)(query.internalContext().tableMap, ctx.tableMap);
162
164
  }
163
165
  this._parentQuery = query;
164
166
  if (this.unsafeKnex() === null) {
@@ -205,6 +207,7 @@ class QueryBuilderOperationSupport {
205
207
  const operationsToReplace = [];
206
208
  const operationsToRemove = [];
207
209
  findQuery.forEachOperation((op) => op.hasToFindOperation(), (op) => {
210
+ // Only `QueryBuilder`s are turned into find queries.
208
211
  const findOp = op.toFindOperation(findQuery);
209
212
  if (!findOp) {
210
213
  operationsToRemove.push(op);
@@ -242,7 +245,7 @@ class QueryBuilderOperationSupport {
242
245
  for (const op of operationsToAdd) {
243
246
  const opClone = op.clone();
244
247
  // The scope may come from a parent operation that is not copied.
245
- opClone.whereScope = effectiveWhereScope(op);
248
+ opClone.whereScope = (0, whereScopes_1.effectiveWhereScope)(op);
246
249
  // We may be moving nested operations to the root. Clear
247
250
  // any links to the parent operations.
248
251
  opClone.parentOperation = null;
@@ -283,6 +286,7 @@ class QueryBuilderOperationSupport {
283
286
  }, false);
284
287
  return every;
285
288
  }
289
+ // Returns whatever the hook returns.
286
290
  callOperationMethod(operation, hookName, args) {
287
291
  try {
288
292
  operation.removeChildOperationsByHookName(hookName);
@@ -296,6 +300,7 @@ class QueryBuilderOperationSupport {
296
300
  this._activeOperations.pop();
297
301
  }
298
302
  }
303
+ // Returns whatever the hook returns.
299
304
  async callAsyncOperationMethod(operation, hookName, args) {
300
305
  operation.removeChildOperationsByHookName(hookName);
301
306
  this._activeOperations.push({
@@ -323,7 +328,7 @@ class QueryBuilderOperationSupport {
323
328
  operation.whereScope = this._whereScope;
324
329
  }
325
330
  if (this._activeOperations.length) {
326
- const { operation: parentOperation, hookName } = last(this._activeOperations);
331
+ const { operation: parentOperation, hookName } = (0, objectUtils_1.last)(this._activeOperations);
327
332
  parentOperation.addChildOperation(hookName, operation);
328
333
  }
329
334
  else {
@@ -382,7 +387,7 @@ class QueryBuilderOperationSupport {
382
387
  });
383
388
  }
384
389
  executeOnBuildKnex(knexBuilder) {
385
- const whereGrouping = createWhereGrouping(this);
390
+ const whereGrouping = (0, whereScopes_1.createWhereGrouping)(this);
386
391
  this.forEachOperation(true, (op) => {
387
392
  if (whereGrouping !== null && whereGrouping.isGrouped(op)) {
388
393
  knexBuilder = whereGrouping.build(op, knexBuilder);
@@ -403,11 +408,12 @@ class QueryBuilderOperationSupport {
403
408
  return this.toString();
404
409
  }
405
410
  skipUndefined() {
406
- deprecate('skipUndefined() is deprecated and will be removed in objection 4.0');
411
+ (0, deprecate_1.deprecate)('skipUndefined() is deprecated and will be removed in objection 4.0');
407
412
  this.internalOptions().skipUndefined = true;
408
413
  return this;
409
414
  }
410
415
  }
416
+ exports.QueryBuilderOperationSupport = QueryBuilderOperationSupport;
411
417
  // Operation selectors are `true` (every operation), a regex or a string that
412
418
  // is matched against the operation name, an operation class, or a predicate.
413
419
  // Queries walk their operations many times, so the selector is classified
@@ -422,17 +428,18 @@ function selectorKind(operationSelector) {
422
428
  if (operationSelector === true) {
423
429
  return SELECT_ALL;
424
430
  }
425
- else if (isRegExp(operationSelector)) {
431
+ else if ((0, objectUtils_1.isRegExp)(operationSelector)) {
426
432
  return SELECT_REGEX;
427
433
  }
428
- else if (isString(operationSelector)) {
434
+ else if ((0, objectUtils_1.isString)(operationSelector)) {
429
435
  return SELECT_NAME;
430
436
  }
431
- else if (isFunction(operationSelector) &&
432
- operationSelector.isObjectionQueryBuilderOperationClass) {
437
+ else if ((0, objectUtils_1.isFunction)(operationSelector) &&
438
+ operationSelector
439
+ .isObjectionQueryBuilderOperationClass) {
433
440
  return SELECT_CLASS;
434
441
  }
435
- else if (isFunction(operationSelector)) {
442
+ else if ((0, objectUtils_1.isFunction)(operationSelector)) {
436
443
  return SELECT_PREDICATE;
437
444
  }
438
445
  else {
@@ -444,6 +451,7 @@ function matchesSelector(op, kind, operationSelector) {
444
451
  case SELECT_ALL:
445
452
  return true;
446
453
  case SELECT_REGEX:
454
+ // A null name is tested as 'null', as `test()` converts it to a string.
447
455
  return operationSelector.test(op.name);
448
456
  case SELECT_NAME:
449
457
  return op.name === operationSelector;
@@ -472,13 +480,10 @@ function visitOperations(operations, kind, operationSelector, callback, match) {
472
480
  return true;
473
481
  }
474
482
  function getTableName(modelClassOrTableName) {
475
- if (isString(modelClassOrTableName)) {
483
+ if ((0, objectUtils_1.isString)(modelClassOrTableName)) {
476
484
  return modelClassOrTableName;
477
485
  }
478
486
  else {
479
487
  return modelClassOrTableName.getTableName();
480
488
  }
481
489
  }
482
- module.exports = {
483
- QueryBuilderOperationSupport,
484
- };
@@ -1,4 +1,6 @@
1
- 'use strict';
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.QueryBuilderUserContext = void 0;
2
4
  const SYMBOL_BUILDER = Symbol();
3
5
  class QueryBuilderUserContext {
4
6
  constructor(builder) {
@@ -20,6 +22,4 @@ class QueryBuilderUserContext {
20
22
  return ctx;
21
23
  }
22
24
  }
23
- module.exports = {
24
- QueryBuilderUserContext,
25
- };
25
+ exports.QueryBuilderUserContext = QueryBuilderUserContext;
@@ -1,5 +1,9 @@
1
- 'use strict';
2
- const { asArray } = require('../utils/objectUtils');
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.StaticHookArguments = void 0;
4
+ exports.markDefaultStaticHook = markDefaultStaticHook;
5
+ exports.hasStaticHook = hasStaticHook;
6
+ const objectUtils_1 = require("../utils/objectUtils");
3
7
  const BUILDER_SYMBOL = Symbol();
4
8
  // The static hooks of `Model`, which do nothing. Queries skip creating the
5
9
  // arguments and calling the hook when a model class hasn't overridden it.
@@ -19,7 +23,7 @@ class StaticHookArguments {
19
23
  value: builder,
20
24
  });
21
25
  Object.defineProperty(this, 'result', {
22
- value: asArray(result),
26
+ value: (0, objectUtils_1.asArray)(result),
23
27
  });
24
28
  }
25
29
  static create(args) {
@@ -27,7 +31,7 @@ class StaticHookArguments {
27
31
  }
28
32
  get asFindQuery() {
29
33
  return () => {
30
- return this[BUILDER_SYMBOL].toFindQuery().clearWithGraphFetched().runAfter(asArray);
34
+ return this[BUILDER_SYMBOL].toFindQuery().clearWithGraphFetched().runAfter(objectUtils_1.asArray);
31
35
  };
32
36
  }
33
37
  get context() {
@@ -57,7 +61,7 @@ class StaticHookArguments {
57
61
  get items() {
58
62
  const op = this[BUILDER_SYMBOL].findOperation(hasItems);
59
63
  if (op) {
60
- return asArray(getItems(op));
64
+ return (0, objectUtils_1.asArray)(getItems(op));
61
65
  }
62
66
  else {
63
67
  return [];
@@ -66,7 +70,7 @@ class StaticHookArguments {
66
70
  get inputItems() {
67
71
  const op = this[BUILDER_SYMBOL].findOperation(hasInputItems);
68
72
  if (op) {
69
- return asArray(getInputItems(op));
73
+ return (0, objectUtils_1.asArray)(getInputItems(op));
70
74
  }
71
75
  else {
72
76
  return [];
@@ -91,6 +95,7 @@ class StaticHookArguments {
91
95
  };
92
96
  }
93
97
  }
98
+ exports.StaticHookArguments = StaticHookArguments;
94
99
  function getRelation(op) {
95
100
  return op.relation;
96
101
  }
@@ -115,8 +120,3 @@ function getInputItems(op) {
115
120
  function hasInputItems(op) {
116
121
  return !!getInputItems(op);
117
122
  }
118
- module.exports = {
119
- StaticHookArguments,
120
- markDefaultStaticHook,
121
- hasStaticHook,
122
- };
@@ -1,5 +1,7 @@
1
- 'use strict';
2
- const { isPostgres } = require('../../utils/knexUtils');
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GraphAction = void 0;
4
+ const knexUtils_1 = require("../../utils/knexUtils");
3
5
  const POSTGRES_MAX_INSERT_BATCH_SIZE = 100;
4
6
  const MAX_CONCURRENCY = 100;
5
7
  class GraphAction {
@@ -9,7 +11,7 @@ class GraphAction {
9
11
  static get ReturningAllSelector() {
10
12
  return (op) => {
11
13
  // Only select `returning('*')` operation.
12
- return op.name === 'returning' && op.args.includes('*');
14
+ return (op.name === 'returning' && op.args.includes('*'));
13
15
  };
14
16
  }
15
17
  static getConcurrency(builder, nodes) {
@@ -33,7 +35,7 @@ class GraphAction {
33
35
  return GraphAction.getConcurrency(builder, nodes);
34
36
  }
35
37
  _getBatchSize(builder) {
36
- return isPostgres(builder.unsafeKnex()) ? POSTGRES_MAX_INSERT_BATCH_SIZE : 1;
38
+ return (0, knexUtils_1.isPostgres)(builder.unsafeKnex()) ? POSTGRES_MAX_INSERT_BATCH_SIZE : 1;
37
39
  }
38
40
  _resolveReferences(node) {
39
41
  if (node.isReference) {
@@ -49,6 +51,4 @@ class GraphAction {
49
51
  }
50
52
  }
51
53
  }
52
- module.exports = {
53
- GraphAction,
54
- };
54
+ exports.GraphAction = GraphAction;
@@ -1,4 +1,6 @@
1
- 'use strict';
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GraphData = void 0;
2
4
  class GraphData {
3
5
  constructor({ graph, currentGraph, graphOptions, nodeDbExistence }) {
4
6
  this.graph = graph;
@@ -7,6 +9,4 @@ class GraphData {
7
9
  this.nodeDbExistence = nodeDbExistence;
8
10
  }
9
11
  }
10
- module.exports = {
11
- GraphData,
12
- };
12
+ exports.GraphData = GraphData;
@@ -1,21 +1,23 @@
1
- 'use strict';
2
- const { asArray, groupBy } = require('../../utils/objectUtils');
3
- const { ModelGraph } = require('../../model/graph/ModelGraph');
4
- const { FetchStrategy } = require('./GraphOptions');
5
- const { RelationExpression } = require('../RelationExpression');
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GraphFetcher = void 0;
4
+ const objectUtils_1 = require("../../utils/objectUtils");
5
+ const ModelGraph_1 = require("../../model/graph/ModelGraph");
6
+ const GraphOptions_1 = require("./GraphOptions");
7
+ const RelationExpression_1 = require("../RelationExpression");
6
8
  class GraphFetcher {
7
9
  /**
8
10
  * Given a graph and options, fetches the current state of that graph
9
11
  * from the database and returns it as a ModelGraph instance.
10
12
  */
11
- static async fetchCurrentGraph({ builder, graph, graphOptions }) {
13
+ static async fetchCurrentGraph({ builder, graph, graphOptions, }) {
12
14
  const { rootObjects } = graph;
13
15
  const rootIds = getRootIds(rootObjects);
14
16
  const modelClass = builder.modelClass();
15
17
  if (rootIds.length === 0) {
16
- return Promise.resolve(ModelGraph.create(modelClass, []));
18
+ return Promise.resolve(ModelGraph_1.ModelGraph.create(modelClass, []));
17
19
  }
18
- const eagerExpr = RelationExpression.fromModelGraph(rootObjects);
20
+ const eagerExpr = RelationExpression_1.RelationExpression.fromModelGraph(rootObjects);
19
21
  const models = await modelClass
20
22
  .query()
21
23
  .childQueryOf(builder, childQueryOptions())
@@ -24,11 +26,12 @@ class GraphFetcher {
24
26
  .findByIds(rootIds)
25
27
  .withGraphFetched(eagerExpr)
26
28
  .internalOptions(fetchQueryInternalOptions());
27
- return ModelGraph.create(modelClass, models);
29
+ return ModelGraph_1.ModelGraph.create(modelClass, models);
28
30
  }
29
31
  }
32
+ exports.GraphFetcher = GraphFetcher;
30
33
  function getRootIds(rootObjects) {
31
- return asArray(rootObjects)
34
+ return (0, objectUtils_1.asArray)(rootObjects)
32
35
  .filter((it) => it.$hasId())
33
36
  .map((root) => root.$id());
34
37
  }
@@ -57,7 +60,7 @@ function buildFetchQuerySelects(graph, graphOptions, eagerExpr) {
57
60
  };
58
61
  }
59
62
  function groupNodesByRelationPath(graph, eagerExpr) {
60
- const nodesByRelationPath = groupBy(graph.nodes, (node) => node.relationPathKey);
63
+ const nodesByRelationPath = (0, objectUtils_1.groupBy)(graph.nodes, (node) => node.relationPathKey);
61
64
  // Not all relation paths have nodes. Relations with nulls or empty arrays
62
65
  // don't have nodes, but will still need to be fetched. Add these to the
63
66
  // map as empty arrays.
@@ -69,10 +72,10 @@ function groupNodesByRelationPath(graph, eagerExpr) {
69
72
  return nodesByRelationPath;
70
73
  }
71
74
  function createFetchSelectModifier(nodes, graphOptions) {
72
- if (graphOptions.isFetchStrategy(FetchStrategy.OnlyIdentifiers)) {
75
+ if (graphOptions.isFetchStrategy(GraphOptions_1.FetchStrategy.OnlyIdentifiers)) {
73
76
  return createIdentifierSelector();
74
77
  }
75
- else if (graphOptions.isFetchStrategy(FetchStrategy.OnlyNeeded)) {
78
+ else if (graphOptions.isFetchStrategy(GraphOptions_1.FetchStrategy.OnlyNeeded)) {
76
79
  return createInputColumnSelector(nodes);
77
80
  }
78
81
  else {
@@ -101,7 +104,7 @@ function createInputColumnSelector(nodes) {
101
104
  }
102
105
  }
103
106
  const selectArr = Array.from(selects.values());
104
- const idColumns = asArray(builder.fullIdColumn());
107
+ const idColumns = (0, objectUtils_1.asArray)(builder.fullIdColumn());
105
108
  for (const idColumn of idColumns) {
106
109
  if (!selectArr.includes(idColumn)) {
107
110
  // Always select the identifers.
@@ -142,6 +145,7 @@ function fetchQueryInternalOptions() {
142
145
  keepImplicitJoinProps: true,
143
146
  };
144
147
  }
148
+ // `eagerExprNode` is a relation expression node: `$childNames` and a property per child.
145
149
  function forEachPath(eagerExprNode, cb, path = []) {
146
150
  for (const relation of eagerExprNode.$childNames) {
147
151
  path.push(relation);
@@ -150,6 +154,3 @@ function forEachPath(eagerExprNode, cb, path = []) {
150
154
  path.pop();
151
155
  }
152
156
  }
153
- module.exports = {
154
- GraphFetcher,
155
- };
@@ -1,7 +1,42 @@
1
- 'use strict';
2
- const { GraphData } = require('./GraphData');
3
- const { GraphAction } = require('./GraphAction');
4
- 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.GraphNodeDbExistence = void 0;
37
+ const GraphData_1 = require("./GraphData");
38
+ const GraphAction_1 = require("./GraphAction");
39
+ const promiseUtils = __importStar(require("../../utils/promiseUtils"));
5
40
  /**
6
41
  * This weird little class is responsible for checking (and maintaining information)
7
42
  * whether certain nodes exist in the database.
@@ -19,12 +54,12 @@ class GraphNodeDbExistence {
19
54
  * creates an instance of GraphNodeDbExistence that can be used to
20
55
  * synchronously check if a node exist in the database.
21
56
  */
22
- static async create({ builder, graph, graphOptions, currentGraph }) {
57
+ static async create({ builder, graph, graphOptions, currentGraph, }) {
23
58
  if (graphOptions.isInsertOnly()) {
24
59
  // With insertGraph, we never want to do anything but inserts.
25
60
  return GraphNodeDbExistence.createEveryNodeExistsExistence();
26
61
  }
27
- const graphData = new GraphData({
62
+ const graphData = new GraphData_1.GraphData({
28
63
  graph,
29
64
  graphOptions,
30
65
  currentGraph,
@@ -54,6 +89,7 @@ class GraphNodeDbExistence {
54
89
  return !idMap.has(node.obj.$idKey());
55
90
  }
56
91
  }
92
+ exports.GraphNodeDbExistence = GraphNodeDbExistence;
57
93
  function createMayNotExistMap(graphData) {
58
94
  const { graph, currentGraph, graphOptions } = graphData;
59
95
  const mayNotExist = new Map();
@@ -94,11 +130,11 @@ function hasNodeById(currentGraph, nodeToFind) {
94
130
  idProps.every((idProp) => node.obj[idProp] === nodeToFind.obj[idProp]));
95
131
  });
96
132
  }
97
- async function createDontExistMap({ builder, mayNotExist, mayNotExistNodes }) {
133
+ async function createDontExistMap({ builder, mayNotExist, mayNotExistNodes, }) {
98
134
  const dontExist = cloneExistenceMap(mayNotExist);
99
135
  const existenceCheckQueries = createExistenceCheckQueries({ builder, mayNotExist });
100
136
  const results = await promiseUtils.map(existenceCheckQueries, (builder) => builder.execute(), {
101
- concurrency: GraphAction.getConcurrency(builder, mayNotExistNodes),
137
+ concurrency: GraphAction_1.GraphAction.getConcurrency(builder, mayNotExistNodes),
102
138
  });
103
139
  // Remove all items from the mayNotExist map that we have just proven to exist
104
140
  // by executing the existenceCheckQueries.
@@ -113,7 +149,7 @@ async function createDontExistMap({ builder, mayNotExist, mayNotExistNodes }) {
113
149
  // Now only items that don't exist in the db are left in this map.
114
150
  return dontExist;
115
151
  }
116
- function createExistenceCheckQueries({ builder, mayNotExist }) {
152
+ function createExistenceCheckQueries({ builder, mayNotExist, }) {
117
153
  const builders = [];
118
154
  for (const [modelClass, idMap] of mayNotExist.entries()) {
119
155
  const ids = Array.from(idMap.values());
@@ -141,6 +177,3 @@ function cloneExistenceMap(exixtenseMap) {
141
177
  }
142
178
  return clone;
143
179
  }
144
- module.exports = {
145
- GraphNodeDbExistence,
146
- };
@@ -1,4 +1,6 @@
1
- 'use strict';
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GraphOperation = void 0;
2
4
  class GraphOperation {
3
5
  constructor(graphData) {
4
6
  this.graphData = graphData;
@@ -16,6 +18,4 @@ class GraphOperation {
16
18
  return [];
17
19
  }
18
20
  }
19
- module.exports = {
20
- GraphOperation,
21
- };
21
+ exports.GraphOperation = GraphOperation;
@@ -1,4 +1,6 @@
1
- 'use strict';
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FetchStrategy = exports.GraphOptions = void 0;
2
4
  const NO_RELATE = 'noRelate';
3
5
  const NO_UNRELATE = 'noUnrelate';
4
6
  const NO_INSERT = 'noInsert';
@@ -15,6 +17,7 @@ const FetchStrategy = {
15
17
  Everything: 'Everything',
16
18
  OnlyNeeded: 'OnlyNeeded',
17
19
  };
20
+ exports.FetchStrategy = FetchStrategy;
18
21
  class GraphOptions {
19
22
  constructor(options) {
20
23
  if (options instanceof GraphOptions) {
@@ -147,6 +150,7 @@ class GraphOptions {
147
150
  }
148
151
  }
149
152
  }
153
+ exports.GraphOptions = GraphOptions;
150
154
  function getCurrentNode(node, graphData) {
151
155
  if (!graphData || !node) {
152
156
  return null;
@@ -159,7 +163,3 @@ function getNode(currentNode, graph) {
159
163
  }
160
164
  return graph.nodeForNode(currentNode);
161
165
  }
162
- module.exports = {
163
- GraphOptions,
164
- FetchStrategy,
165
- };