@abedmurrar/objection 4.0.0-alpha.0 → 4.0.0-beta.1

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 (192) hide show
  1. package/README.md +103 -67
  2. package/lib/index.mjs +6 -0
  3. package/lib/initialize.js +6 -9
  4. package/lib/model/AjvValidator.js +235 -282
  5. package/lib/model/Model.js +653 -823
  6. package/lib/model/ModifierNotFoundError.js +5 -7
  7. package/lib/model/NotFoundError.js +14 -18
  8. package/lib/model/RelationDoesNotExistError.js +6 -9
  9. package/lib/model/ValidationError.js +33 -41
  10. package/lib/model/Validator.js +15 -21
  11. package/lib/model/getModel.js +1 -3
  12. package/lib/model/graph/ModelGraph.js +44 -64
  13. package/lib/model/graph/ModelGraphBuilder.js +164 -217
  14. package/lib/model/graph/ModelGraphEdge.js +31 -43
  15. package/lib/model/graph/ModelGraphNode.js +192 -231
  16. package/lib/model/inheritModel.js +9 -18
  17. package/lib/model/modelBindKnex.js +48 -62
  18. package/lib/model/modelClone.js +79 -98
  19. package/lib/model/modelColPropMap.js +16 -26
  20. package/lib/model/modelConcurrency.js +24 -0
  21. package/lib/model/modelId.js +44 -49
  22. package/lib/model/modelJsonAttributes.js +56 -76
  23. package/lib/model/modelParseRelations.js +68 -67
  24. package/lib/model/modelQueryProps.js +76 -107
  25. package/lib/model/modelSet.js +92 -112
  26. package/lib/model/modelTableMetadata.js +60 -72
  27. package/lib/model/modelToJson.js +120 -150
  28. package/lib/model/modelUtils.js +30 -37
  29. package/lib/model/modelValidate.js +34 -42
  30. package/lib/model/modelValues.js +78 -91
  31. package/lib/model/modelVisitor.js +22 -29
  32. package/lib/objection.js +42 -67
  33. package/lib/queryBuilder/FunctionBuilder.js +231 -279
  34. package/lib/queryBuilder/InternalOptions.js +19 -24
  35. package/lib/queryBuilder/JoinBuilder.js +116 -149
  36. package/lib/queryBuilder/QueryBuilder.js +1009 -1271
  37. package/lib/queryBuilder/QueryBuilderBase.js +647 -865
  38. package/lib/queryBuilder/QueryBuilderContext.js +14 -21
  39. package/lib/queryBuilder/QueryBuilderContextBase.js +20 -29
  40. package/lib/queryBuilder/QueryBuilderOperationSupport.js +462 -536
  41. package/lib/queryBuilder/QueryBuilderUserContext.js +19 -25
  42. package/lib/queryBuilder/RawBuilder.js +58 -73
  43. package/lib/queryBuilder/ReferenceBuilder.js +232 -270
  44. package/lib/queryBuilder/RelationExpression.js +322 -380
  45. package/lib/queryBuilder/StaticHookArguments.js +94 -106
  46. package/lib/queryBuilder/ValueBuilder.js +100 -112
  47. package/lib/queryBuilder/expressions.js +86 -116
  48. package/lib/queryBuilder/functions/mysql.js +642 -697
  49. package/lib/queryBuilder/graph/GraphAction.js +44 -59
  50. package/lib/queryBuilder/graph/GraphData.js +7 -9
  51. package/lib/queryBuilder/graph/GraphFetcher.js +115 -151
  52. package/lib/queryBuilder/graph/GraphNodeDbExistence.js +114 -152
  53. package/lib/queryBuilder/graph/GraphOperation.js +16 -22
  54. package/lib/queryBuilder/graph/GraphOptions.js +143 -185
  55. package/lib/queryBuilder/graph/GraphUpsert.js +167 -241
  56. package/lib/queryBuilder/graph/delete/GraphDelete.js +8 -13
  57. package/lib/queryBuilder/graph/delete/GraphDeleteAction.js +44 -62
  58. package/lib/queryBuilder/graph/insert/GraphInsert.js +99 -128
  59. package/lib/queryBuilder/graph/insert/GraphInsertAction.js +151 -193
  60. package/lib/queryBuilder/graph/insert/JoinRowGraphInsertAction.js +57 -79
  61. package/lib/queryBuilder/graph/patch/GraphPatch.js +8 -13
  62. package/lib/queryBuilder/graph/patch/GraphPatchAction.js +181 -234
  63. package/lib/queryBuilder/graph/recursiveUpsert/GraphRecursiveUpsert.js +16 -21
  64. package/lib/queryBuilder/graph/recursiveUpsert/GraphRecursiveUpsertAction.js +80 -110
  65. package/lib/queryBuilder/join/JoinResultColumn.js +14 -18
  66. package/lib/queryBuilder/join/JoinResultParser.js +88 -101
  67. package/lib/queryBuilder/join/RelationJoiner.js +205 -288
  68. package/lib/queryBuilder/join/TableNode.js +117 -144
  69. package/lib/queryBuilder/join/TableTree.js +60 -76
  70. package/lib/queryBuilder/join/utils.js +10 -16
  71. package/lib/queryBuilder/operations/DelegateOperation.js +93 -133
  72. package/lib/queryBuilder/operations/DeleteOperation.js +33 -37
  73. package/lib/queryBuilder/operations/FindByIdOperation.js +20 -28
  74. package/lib/queryBuilder/operations/FindByIdsOperation.js +17 -23
  75. package/lib/queryBuilder/operations/FindOperation.js +114 -131
  76. package/lib/queryBuilder/operations/FirstOperation.js +14 -19
  77. package/lib/queryBuilder/operations/FromOperation.js +69 -88
  78. package/lib/queryBuilder/operations/InsertAndFetchOperation.js +28 -39
  79. package/lib/queryBuilder/operations/InsertGraphAndFetchOperation.js +25 -35
  80. package/lib/queryBuilder/operations/InsertGraphOperation.js +77 -98
  81. package/lib/queryBuilder/operations/InsertOperation.js +132 -165
  82. package/lib/queryBuilder/operations/InstanceDeleteOperation.js +27 -36
  83. package/lib/queryBuilder/operations/InstanceFindOperation.js +9 -13
  84. package/lib/queryBuilder/operations/InstanceInsertOperation.js +13 -17
  85. package/lib/queryBuilder/operations/InstanceUpdateOperation.js +32 -46
  86. package/lib/queryBuilder/operations/JoinRelatedOperation.js +66 -86
  87. package/lib/queryBuilder/operations/KnexOperation.js +4 -7
  88. package/lib/queryBuilder/operations/MergeOperation.js +32 -45
  89. package/lib/queryBuilder/operations/ObjectionToKnexConvertingOperation.js +131 -150
  90. package/lib/queryBuilder/operations/OnBuildKnexOperation.js +17 -23
  91. package/lib/queryBuilder/operations/OnBuildOperation.js +17 -23
  92. package/lib/queryBuilder/operations/OnErrorOperation.js +17 -23
  93. package/lib/queryBuilder/operations/QueryBuilderOperation.js +231 -270
  94. package/lib/queryBuilder/operations/RangeOperation.js +30 -40
  95. package/lib/queryBuilder/operations/RelateOperation.js +14 -21
  96. package/lib/queryBuilder/operations/ReturningOperation.js +12 -18
  97. package/lib/queryBuilder/operations/RunAfterOperation.js +17 -23
  98. package/lib/queryBuilder/operations/RunBeforeOperation.js +17 -23
  99. package/lib/queryBuilder/operations/UnrelateOperation.js +12 -17
  100. package/lib/queryBuilder/operations/UpdateAndFetchOperation.js +48 -65
  101. package/lib/queryBuilder/operations/UpdateOperation.js +104 -129
  102. package/lib/queryBuilder/operations/UpsertGraphAndFetchOperation.js +25 -35
  103. package/lib/queryBuilder/operations/UpsertGraphOperation.js +36 -55
  104. package/lib/queryBuilder/operations/WhereCompositeOperation.js +30 -39
  105. package/lib/queryBuilder/operations/WhereInOperation.js +34 -36
  106. package/lib/queryBuilder/operations/eager/EagerOperation.js +37 -52
  107. package/lib/queryBuilder/operations/eager/JoinEagerOperation.js +34 -44
  108. package/lib/queryBuilder/operations/eager/NaiveEagerOperation.js +4 -7
  109. package/lib/queryBuilder/operations/eager/WhereInEagerOperation.js +193 -251
  110. package/lib/queryBuilder/operations/jsonApi/WhereJsonHasOperation.js +18 -25
  111. package/lib/queryBuilder/operations/jsonApi/WhereJsonNotObjectOperation.js +25 -41
  112. package/lib/queryBuilder/operations/jsonApi/WhereJsonOperation.js +19 -20
  113. package/lib/queryBuilder/operations/jsonApi/WhereJsonOverlapsOperation.js +23 -21
  114. package/lib/queryBuilder/operations/jsonApi/mysqlJsonApi.js +106 -118
  115. package/lib/queryBuilder/operations/jsonApi/postgresJsonApi.js +79 -108
  116. package/lib/queryBuilder/operations/select/SelectOperation.js +37 -53
  117. package/lib/queryBuilder/operations/select/Selection.js +94 -105
  118. package/lib/queryBuilder/operations/whereInComposite/WhereInCompositeMsSqlOperation.js +68 -101
  119. package/lib/queryBuilder/operations/whereInComposite/WhereInCompositeOperation.js +65 -75
  120. package/lib/queryBuilder/operations/whereInComposite/WhereInCompositeSqliteOperation.js +75 -84
  121. package/lib/queryBuilder/parsers/jsonFieldExpressionParser.js +760 -859
  122. package/lib/queryBuilder/parsers/relationExpressionParser.js +840 -952
  123. package/lib/queryBuilder/transformations/CompositeQueryTransformation.js +10 -15
  124. package/lib/queryBuilder/transformations/QueryTransformation.js +4 -6
  125. package/lib/queryBuilder/transformations/WrapMysqlModifySubqueryTransformation.js +35 -49
  126. package/lib/queryBuilder/transformations/index.js +3 -9
  127. package/lib/queryBuilder/whereScopes.js +158 -186
  128. package/lib/relations/Relation.js +293 -375
  129. package/lib/relations/RelationDeleteOperation.js +24 -28
  130. package/lib/relations/RelationFindOperation.js +108 -138
  131. package/lib/relations/RelationInsertOperation.js +24 -32
  132. package/lib/relations/RelationOwner.js +175 -209
  133. package/lib/relations/RelationProperty.js +186 -223
  134. package/lib/relations/RelationUpdateOperation.js +23 -29
  135. package/lib/relations/belongsToOne/BelongsToOneDeleteOperation.js +16 -21
  136. package/lib/relations/belongsToOne/BelongsToOneInsertOperation.js +30 -41
  137. package/lib/relations/belongsToOne/BelongsToOneRelateOperation.js +36 -47
  138. package/lib/relations/belongsToOne/BelongsToOneRelation.js +42 -50
  139. package/lib/relations/belongsToOne/BelongsToOneUnrelateOperation.js +43 -58
  140. package/lib/relations/hasMany/HasManyInsertOperation.js +40 -56
  141. package/lib/relations/hasMany/HasManyRelateOperation.js +45 -61
  142. package/lib/relations/hasMany/HasManyRelation.js +38 -46
  143. package/lib/relations/hasMany/HasManyUnrelateOperation.js +25 -32
  144. package/lib/relations/hasOne/HasOneRelation.js +9 -12
  145. package/lib/relations/hasOneThrough/HasOneThroughRelation.js +9 -12
  146. package/lib/relations/manyToMany/ManyToManyModifyMixin.js +73 -95
  147. package/lib/relations/manyToMany/ManyToManyRelation.js +374 -473
  148. package/lib/relations/manyToMany/ManyToManySqliteModifyMixin.js +23 -30
  149. package/lib/relations/manyToMany/delete/ManyToManyDeleteOperation.js +8 -10
  150. package/lib/relations/manyToMany/delete/ManyToManyDeleteOperationBase.js +20 -25
  151. package/lib/relations/manyToMany/delete/ManyToManyDeleteSqliteOperation.js +8 -12
  152. package/lib/relations/manyToMany/find/ManyToManyFindOperation.js +77 -100
  153. package/lib/relations/manyToMany/insert/ManyToManyInsertOperation.js +37 -49
  154. package/lib/relations/manyToMany/relate/ManyToManyRelateOperation.js +58 -74
  155. package/lib/relations/manyToMany/unrelate/ManyToManyUnrelateOperation.js +10 -13
  156. package/lib/relations/manyToMany/unrelate/ManyToManyUnrelateOperationBase.js +26 -33
  157. package/lib/relations/manyToMany/unrelate/ManyToManyUnrelateSqliteOperation.js +10 -15
  158. package/lib/relations/manyToMany/update/ManyToManyUpdateOperation.js +8 -10
  159. package/lib/relations/manyToMany/update/ManyToManyUpdateOperationBase.js +61 -78
  160. package/lib/relations/manyToMany/update/ManyToManyUpdateSqliteOperation.js +8 -12
  161. package/lib/transaction.js +53 -83
  162. package/lib/utils/assert.js +15 -21
  163. package/lib/utils/buildUtils.js +17 -19
  164. package/lib/utils/classUtils.js +7 -11
  165. package/lib/utils/cloneDeep.js +365 -0
  166. package/lib/utils/createModifier.js +36 -41
  167. package/lib/utils/deprecate.js +8 -12
  168. package/lib/utils/identifierMapping.js +153 -192
  169. package/lib/utils/internalPropUtils.js +4 -8
  170. package/lib/utils/knexUtils.js +61 -56
  171. package/lib/utils/mixin.js +16 -23
  172. package/lib/utils/mysqlJsonPath.js +55 -40
  173. package/lib/utils/normalizeIds.js +110 -127
  174. package/lib/utils/objectUtils.js +236 -338
  175. package/lib/utils/parseFieldExpression.js +66 -44
  176. package/lib/utils/postgresJsonPath.js +48 -62
  177. package/lib/utils/promiseUtils/after.js +10 -13
  178. package/lib/utils/promiseUtils/afterReturn.js +10 -13
  179. package/lib/utils/promiseUtils/index.js +15 -17
  180. package/lib/utils/promiseUtils/isPromise.js +6 -9
  181. package/lib/utils/promiseUtils/map.js +75 -89
  182. package/lib/utils/promiseUtils/mapAfterAllReturn.js +17 -23
  183. package/lib/utils/promiseUtils/try.js +15 -18
  184. package/lib/utils/resolveModel.js +91 -94
  185. package/lib/utils/tmpColumnUtils.js +4 -13
  186. package/package.json +50 -23
  187. package/typings/objection/index.d.mts +362 -0
  188. package/typings/objection/index.d.ts +36 -9
  189. package/lib/.eslintrc.json +0 -8
  190. package/lib/queryBuilder/parsers/jsonFieldExpressionParser.pegjs +0 -97
  191. package/lib/queryBuilder/parsers/relationExpressionParser.pegjs +0 -141
  192. package/lib/utils/clone.js +0 -2329
@@ -1,9 +1,7 @@
1
1
  'use strict';
2
-
3
2
  const { GraphData } = require('./GraphData');
4
3
  const { GraphAction } = require('./GraphAction');
5
4
  const promiseUtils = require('../../utils/promiseUtils');
6
-
7
5
  /**
8
6
  * This weird little class is responsible for checking (and maintaining information)
9
7
  * whether certain nodes exist in the database.
@@ -12,173 +10,137 @@ const promiseUtils = require('../../utils/promiseUtils');
12
10
  * option is true.
13
11
  */
14
12
  class GraphNodeDbExistence {
15
- static createEveryNodeExistsExistence() {
16
- return new GraphNodeDbExistence(new Map());
17
- }
18
-
19
- /**
20
- * Goes through the graphs and identifies nodes that may not exist in the db
21
- * (nodes that have an id, but are not found in `currentGraph`) and
22
- * creates an instance of GraphNodeDbExistence that can be used to
23
- * synchronously check if a node exist in the database.
24
- */
25
- static async create({ builder, graph, graphOptions, currentGraph }) {
26
- if (graphOptions.isInsertOnly()) {
27
- // With insertGraph, we never want to do anything but inserts.
28
- return GraphNodeDbExistence.createEveryNodeExistsExistence();
13
+ static createEveryNodeExistsExistence() {
14
+ return new GraphNodeDbExistence(new Map());
29
15
  }
30
-
31
- const graphData = new GraphData({
32
- graph,
33
- graphOptions,
34
- currentGraph,
35
- // We don't yet have an instance of GraphNodeDbExistence since we are
36
- // creating one. We can (and should) safely use an instance that
37
- // assumes that all nodes exist in the db for the purposes of this
38
- // method.
39
- nodeDbExistence: GraphNodeDbExistence.createEveryNodeExistsExistence(),
40
- });
41
-
42
- const { mayNotExist, mayNotExistNodes } = createMayNotExistMap(graphData);
43
-
44
- if (mayNotExist.size == 0) {
45
- // Early exit if we found no items for which we should check their
46
- // existence in the db.
47
- return GraphNodeDbExistence.createEveryNodeExistsExistence();
16
+ /**
17
+ * Goes through the graphs and identifies nodes that may not exist in the db
18
+ * (nodes that have an id, but are not found in `currentGraph`) and
19
+ * creates an instance of GraphNodeDbExistence that can be used to
20
+ * synchronously check if a node exist in the database.
21
+ */
22
+ static async create({ builder, graph, graphOptions, currentGraph }) {
23
+ if (graphOptions.isInsertOnly()) {
24
+ // With insertGraph, we never want to do anything but inserts.
25
+ return GraphNodeDbExistence.createEveryNodeExistsExistence();
26
+ }
27
+ const graphData = new GraphData({
28
+ graph,
29
+ graphOptions,
30
+ currentGraph,
31
+ // We don't yet have an instance of GraphNodeDbExistence since we are
32
+ // creating one. We can (and should) safely use an instance that
33
+ // assumes that all nodes exist in the db for the purposes of this
34
+ // method.
35
+ nodeDbExistence: GraphNodeDbExistence.createEveryNodeExistsExistence(),
36
+ });
37
+ const { mayNotExist, mayNotExistNodes } = createMayNotExistMap(graphData);
38
+ if (mayNotExist.size == 0) {
39
+ // Early exit if we found no items for which we should check their
40
+ // existence in the db.
41
+ return GraphNodeDbExistence.createEveryNodeExistsExistence();
42
+ }
43
+ const dontExist = await createDontExistMap({ builder, mayNotExist, mayNotExistNodes });
44
+ return new GraphNodeDbExistence(dontExist);
45
+ }
46
+ constructor(dontExist) {
47
+ this.dontExist = dontExist;
48
48
  }
49
-
50
- const dontExist = await createDontExistMap({ builder, mayNotExist, mayNotExistNodes });
51
-
52
- return new GraphNodeDbExistence(dontExist);
53
- }
54
-
55
- constructor(dontExist) {
56
- this.dontExist = dontExist;
57
- }
58
-
59
- doesNodeExistInDb(node) {
60
- const idMap = this.dontExist.get(node.modelClass);
61
-
62
- if (!idMap) {
63
- return true;
49
+ doesNodeExistInDb(node) {
50
+ const idMap = this.dontExist.get(node.modelClass);
51
+ if (!idMap) {
52
+ return true;
53
+ }
54
+ return !idMap.has(node.obj.$idKey());
64
55
  }
65
-
66
- return !idMap.has(node.obj.$idKey());
67
- }
68
56
  }
69
-
70
57
  function createMayNotExistMap(graphData) {
71
- const { graph, currentGraph, graphOptions } = graphData;
72
-
73
- const mayNotExist = new Map();
74
- const mayNotExistNodes = [];
75
-
76
- for (const node of graph.nodes) {
77
- if (
78
- // As an optimization, only consider nodes for which `insertMissing` is true.
79
- // We only need the information for those nodes.
80
- graphOptions.shouldInsertMissing(node) &&
81
- // Only consider nodes that will be related. We don't consider nodes that
82
- // would get inserted with an id. Those will still result in a unique
83
- // constraint error.
84
- graphOptions.shouldRelate(node, graphData) &&
85
- // Relate nodes may not have an id if they are `#ref` nodes. Only consider
86
- // nodes that have an id so that we can check the existence.
87
- node.hasId &&
88
- // We can ignore nodes if they are found anywhere in the graph. `shouldRelate`
89
- // only checks if the node is found in the same relation.
90
- !hasNodeById(currentGraph, node)
91
- ) {
92
- if (!mayNotExist.has(node.modelClass)) {
93
- mayNotExist.set(node.modelClass, new Map());
94
- }
95
-
96
- mayNotExist.get(node.modelClass).set(node.obj.$idKey(), node.obj.$id());
97
- mayNotExistNodes.push(node);
58
+ const { graph, currentGraph, graphOptions } = graphData;
59
+ const mayNotExist = new Map();
60
+ const mayNotExistNodes = [];
61
+ for (const node of graph.nodes) {
62
+ if (
63
+ // As an optimization, only consider nodes for which `insertMissing` is true.
64
+ // We only need the information for those nodes.
65
+ graphOptions.shouldInsertMissing(node) &&
66
+ // Only consider nodes that will be related. We don't consider nodes that
67
+ // would get inserted with an id. Those will still result in a unique
68
+ // constraint error.
69
+ graphOptions.shouldRelate(node, graphData) &&
70
+ // Relate nodes may not have an id if they are `#ref` nodes. Only consider
71
+ // nodes that have an id so that we can check the existence.
72
+ node.hasId &&
73
+ // We can ignore nodes if they are found anywhere in the graph. `shouldRelate`
74
+ // only checks if the node is found in the same relation.
75
+ !hasNodeById(currentGraph, node)) {
76
+ if (!mayNotExist.has(node.modelClass)) {
77
+ mayNotExist.set(node.modelClass, new Map());
78
+ }
79
+ mayNotExist.get(node.modelClass).set(node.obj.$idKey(), node.obj.$id());
80
+ mayNotExistNodes.push(node);
81
+ }
98
82
  }
99
- }
100
-
101
- return {
102
- mayNotExist,
103
- mayNotExistNodes,
104
- };
83
+ return {
84
+ mayNotExist,
85
+ mayNotExistNodes,
86
+ };
105
87
  }
106
-
107
88
  function hasNodeById(currentGraph, nodeToFind) {
108
- const { modelClass } = nodeToFind;
109
-
110
- const tableToFind = modelClass.getTableName();
111
- const idProps = modelClass.getIdPropertyArray();
112
-
113
- return currentGraph.nodes.some((node) => {
114
- return (
115
- node.modelClass.getTableName() === tableToFind &&
116
- idProps.every((idProp) => node.obj[idProp] === nodeToFind.obj[idProp])
117
- );
118
- });
89
+ const { modelClass } = nodeToFind;
90
+ const tableToFind = modelClass.getTableName();
91
+ const idProps = modelClass.getIdPropertyArray();
92
+ return currentGraph.nodes.some((node) => {
93
+ return (node.modelClass.getTableName() === tableToFind &&
94
+ idProps.every((idProp) => node.obj[idProp] === nodeToFind.obj[idProp]));
95
+ });
119
96
  }
120
-
121
97
  async function createDontExistMap({ builder, mayNotExist, mayNotExistNodes }) {
122
- const dontExist = cloneExistenceMap(mayNotExist);
123
- const existenceCheckQueries = createExistenceCheckQueries({ builder, mayNotExist });
124
-
125
- const results = await promiseUtils.map(existenceCheckQueries, (builder) => builder.execute(), {
126
- concurrency: GraphAction.getConcurrency(builder, mayNotExistNodes),
127
- });
128
-
129
- // Remove all items from the mayNotExist map that we have just proven to exist
130
- // by executing the existenceCheckQueries.
131
- for (const modelResult of results) {
132
- for (const item of modelResult) {
133
- const modelClass = item.constructor;
134
- const idMap = dontExist.get(modelClass);
135
- // Exist, remove from the map.
136
- idMap.delete(item.$idKey());
98
+ const dontExist = cloneExistenceMap(mayNotExist);
99
+ const existenceCheckQueries = createExistenceCheckQueries({ builder, mayNotExist });
100
+ const results = await promiseUtils.map(existenceCheckQueries, (builder) => builder.execute(), {
101
+ concurrency: GraphAction.getConcurrency(builder, mayNotExistNodes),
102
+ });
103
+ // Remove all items from the mayNotExist map that we have just proven to exist
104
+ // by executing the existenceCheckQueries.
105
+ for (const modelResult of results) {
106
+ for (const item of modelResult) {
107
+ const modelClass = item.constructor;
108
+ const idMap = dontExist.get(modelClass);
109
+ // Exist, remove from the map.
110
+ idMap.delete(item.$idKey());
111
+ }
137
112
  }
138
- }
139
-
140
- // Now only items that don't exist in the db are left in this map.
141
- return dontExist;
113
+ // Now only items that don't exist in the db are left in this map.
114
+ return dontExist;
142
115
  }
143
-
144
116
  function createExistenceCheckQueries({ builder, mayNotExist }) {
145
- const builders = [];
146
-
147
- for (const [modelClass, idMap] of mayNotExist.entries()) {
148
- const ids = Array.from(idMap.values());
149
-
150
- // Create one query per model class (table) to fetch the identifiers
151
- // of the nodes that may not exist. These queries should be super fast
152
- // since they come straight from the index.
153
- builders.push(
154
- modelClass
155
- .query()
156
- .childQueryOf(builder, childQueryOptions())
157
- .findByIds(ids)
158
- .select(modelClass.getIdColumnArray()),
159
- );
160
- }
161
-
162
- return builders;
117
+ const builders = [];
118
+ for (const [modelClass, idMap] of mayNotExist.entries()) {
119
+ const ids = Array.from(idMap.values());
120
+ // Create one query per model class (table) to fetch the identifiers
121
+ // of the nodes that may not exist. These queries should be super fast
122
+ // since they come straight from the index.
123
+ builders.push(modelClass
124
+ .query()
125
+ .childQueryOf(builder, childQueryOptions())
126
+ .findByIds(ids)
127
+ .select(modelClass.getIdColumnArray()));
128
+ }
129
+ return builders;
163
130
  }
164
-
165
131
  function childQueryOptions() {
166
- return {
167
- fork: true,
168
- isInternalQuery: true,
169
- };
132
+ return {
133
+ fork: true,
134
+ isInternalQuery: true,
135
+ };
170
136
  }
171
-
172
137
  function cloneExistenceMap(exixtenseMap) {
173
- const clone = new Map(exixtenseMap);
174
-
175
- for (const modelClass of clone.keys()) {
176
- clone.set(modelClass, new Map(clone.get(modelClass)));
177
- }
178
-
179
- return clone;
138
+ const clone = new Map(exixtenseMap);
139
+ for (const modelClass of clone.keys()) {
140
+ clone.set(modelClass, new Map(clone.get(modelClass)));
141
+ }
142
+ return clone;
180
143
  }
181
-
182
144
  module.exports = {
183
- GraphNodeDbExistence,
145
+ GraphNodeDbExistence,
184
146
  };
@@ -1,27 +1,21 @@
1
1
  'use strict';
2
-
3
2
  class GraphOperation {
4
- constructor(graphData) {
5
- this.graphData = graphData;
6
- }
7
-
8
- get graph() {
9
- return this.graphData.graph;
10
- }
11
-
12
- get currentGraph() {
13
- return this.graphData.currentGraph;
14
- }
15
-
16
- get graphOptions() {
17
- return this.graphData.graphOptions;
18
- }
19
-
20
- createActions() {
21
- return [];
22
- }
3
+ constructor(graphData) {
4
+ this.graphData = graphData;
5
+ }
6
+ get graph() {
7
+ return this.graphData.graph;
8
+ }
9
+ get currentGraph() {
10
+ return this.graphData.currentGraph;
11
+ }
12
+ get graphOptions() {
13
+ return this.graphData.graphOptions;
14
+ }
15
+ createActions() {
16
+ return [];
17
+ }
23
18
  }
24
-
25
19
  module.exports = {
26
- GraphOperation,
20
+ GraphOperation,
27
21
  };