@abedmurrar/objection 4.0.0-alpha.0 → 4.0.0-beta.0
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.
- package/README.md +103 -67
- package/lib/index.mjs +6 -0
- package/lib/initialize.js +6 -9
- package/lib/model/AjvValidator.js +235 -282
- package/lib/model/Model.js +653 -823
- package/lib/model/ModifierNotFoundError.js +5 -7
- package/lib/model/NotFoundError.js +14 -18
- package/lib/model/RelationDoesNotExistError.js +6 -9
- package/lib/model/ValidationError.js +33 -41
- package/lib/model/Validator.js +15 -21
- package/lib/model/getModel.js +1 -3
- package/lib/model/graph/ModelGraph.js +44 -64
- package/lib/model/graph/ModelGraphBuilder.js +164 -217
- package/lib/model/graph/ModelGraphEdge.js +31 -43
- package/lib/model/graph/ModelGraphNode.js +192 -231
- package/lib/model/inheritModel.js +9 -18
- package/lib/model/modelBindKnex.js +48 -62
- package/lib/model/modelClone.js +79 -98
- package/lib/model/modelColPropMap.js +16 -26
- package/lib/model/modelConcurrency.js +24 -0
- package/lib/model/modelId.js +44 -49
- package/lib/model/modelJsonAttributes.js +56 -76
- package/lib/model/modelParseRelations.js +68 -67
- package/lib/model/modelQueryProps.js +76 -107
- package/lib/model/modelSet.js +92 -112
- package/lib/model/modelTableMetadata.js +60 -72
- package/lib/model/modelToJson.js +120 -150
- package/lib/model/modelUtils.js +30 -37
- package/lib/model/modelValidate.js +34 -42
- package/lib/model/modelValues.js +78 -91
- package/lib/model/modelVisitor.js +22 -29
- package/lib/objection.js +42 -67
- package/lib/queryBuilder/FunctionBuilder.js +231 -279
- package/lib/queryBuilder/InternalOptions.js +19 -24
- package/lib/queryBuilder/JoinBuilder.js +116 -149
- package/lib/queryBuilder/QueryBuilder.js +1009 -1271
- package/lib/queryBuilder/QueryBuilderBase.js +647 -865
- package/lib/queryBuilder/QueryBuilderContext.js +14 -21
- package/lib/queryBuilder/QueryBuilderContextBase.js +20 -29
- package/lib/queryBuilder/QueryBuilderOperationSupport.js +462 -536
- package/lib/queryBuilder/QueryBuilderUserContext.js +19 -25
- package/lib/queryBuilder/RawBuilder.js +58 -73
- package/lib/queryBuilder/ReferenceBuilder.js +232 -270
- package/lib/queryBuilder/RelationExpression.js +322 -380
- package/lib/queryBuilder/StaticHookArguments.js +94 -106
- package/lib/queryBuilder/ValueBuilder.js +100 -112
- package/lib/queryBuilder/expressions.js +86 -116
- package/lib/queryBuilder/functions/mysql.js +642 -697
- package/lib/queryBuilder/graph/GraphAction.js +44 -59
- package/lib/queryBuilder/graph/GraphData.js +7 -9
- package/lib/queryBuilder/graph/GraphFetcher.js +115 -151
- package/lib/queryBuilder/graph/GraphNodeDbExistence.js +114 -152
- package/lib/queryBuilder/graph/GraphOperation.js +16 -22
- package/lib/queryBuilder/graph/GraphOptions.js +143 -185
- package/lib/queryBuilder/graph/GraphUpsert.js +167 -241
- package/lib/queryBuilder/graph/delete/GraphDelete.js +8 -13
- package/lib/queryBuilder/graph/delete/GraphDeleteAction.js +44 -62
- package/lib/queryBuilder/graph/insert/GraphInsert.js +99 -128
- package/lib/queryBuilder/graph/insert/GraphInsertAction.js +151 -193
- package/lib/queryBuilder/graph/insert/JoinRowGraphInsertAction.js +57 -79
- package/lib/queryBuilder/graph/patch/GraphPatch.js +8 -13
- package/lib/queryBuilder/graph/patch/GraphPatchAction.js +181 -234
- package/lib/queryBuilder/graph/recursiveUpsert/GraphRecursiveUpsert.js +16 -21
- package/lib/queryBuilder/graph/recursiveUpsert/GraphRecursiveUpsertAction.js +80 -110
- package/lib/queryBuilder/join/JoinResultColumn.js +14 -18
- package/lib/queryBuilder/join/JoinResultParser.js +88 -101
- package/lib/queryBuilder/join/RelationJoiner.js +205 -288
- package/lib/queryBuilder/join/TableNode.js +117 -144
- package/lib/queryBuilder/join/TableTree.js +60 -76
- package/lib/queryBuilder/join/utils.js +10 -16
- package/lib/queryBuilder/operations/DelegateOperation.js +93 -133
- package/lib/queryBuilder/operations/DeleteOperation.js +33 -37
- package/lib/queryBuilder/operations/FindByIdOperation.js +20 -28
- package/lib/queryBuilder/operations/FindByIdsOperation.js +17 -23
- package/lib/queryBuilder/operations/FindOperation.js +114 -131
- package/lib/queryBuilder/operations/FirstOperation.js +14 -19
- package/lib/queryBuilder/operations/FromOperation.js +69 -88
- package/lib/queryBuilder/operations/InsertAndFetchOperation.js +28 -39
- package/lib/queryBuilder/operations/InsertGraphAndFetchOperation.js +25 -35
- package/lib/queryBuilder/operations/InsertGraphOperation.js +77 -98
- package/lib/queryBuilder/operations/InsertOperation.js +132 -165
- package/lib/queryBuilder/operations/InstanceDeleteOperation.js +27 -36
- package/lib/queryBuilder/operations/InstanceFindOperation.js +9 -13
- package/lib/queryBuilder/operations/InstanceInsertOperation.js +13 -17
- package/lib/queryBuilder/operations/InstanceUpdateOperation.js +32 -46
- package/lib/queryBuilder/operations/JoinRelatedOperation.js +66 -86
- package/lib/queryBuilder/operations/KnexOperation.js +4 -7
- package/lib/queryBuilder/operations/MergeOperation.js +32 -45
- package/lib/queryBuilder/operations/ObjectionToKnexConvertingOperation.js +131 -150
- package/lib/queryBuilder/operations/OnBuildKnexOperation.js +17 -23
- package/lib/queryBuilder/operations/OnBuildOperation.js +17 -23
- package/lib/queryBuilder/operations/OnErrorOperation.js +17 -23
- package/lib/queryBuilder/operations/QueryBuilderOperation.js +231 -270
- package/lib/queryBuilder/operations/RangeOperation.js +30 -40
- package/lib/queryBuilder/operations/RelateOperation.js +14 -21
- package/lib/queryBuilder/operations/ReturningOperation.js +12 -18
- package/lib/queryBuilder/operations/RunAfterOperation.js +17 -23
- package/lib/queryBuilder/operations/RunBeforeOperation.js +17 -23
- package/lib/queryBuilder/operations/UnrelateOperation.js +12 -17
- package/lib/queryBuilder/operations/UpdateAndFetchOperation.js +48 -65
- package/lib/queryBuilder/operations/UpdateOperation.js +104 -129
- package/lib/queryBuilder/operations/UpsertGraphAndFetchOperation.js +25 -35
- package/lib/queryBuilder/operations/UpsertGraphOperation.js +36 -55
- package/lib/queryBuilder/operations/WhereCompositeOperation.js +30 -39
- package/lib/queryBuilder/operations/WhereInOperation.js +34 -36
- package/lib/queryBuilder/operations/eager/EagerOperation.js +37 -52
- package/lib/queryBuilder/operations/eager/JoinEagerOperation.js +34 -44
- package/lib/queryBuilder/operations/eager/NaiveEagerOperation.js +4 -7
- package/lib/queryBuilder/operations/eager/WhereInEagerOperation.js +193 -251
- package/lib/queryBuilder/operations/jsonApi/WhereJsonHasOperation.js +18 -25
- package/lib/queryBuilder/operations/jsonApi/WhereJsonNotObjectOperation.js +25 -41
- package/lib/queryBuilder/operations/jsonApi/WhereJsonOperation.js +19 -20
- package/lib/queryBuilder/operations/jsonApi/WhereJsonOverlapsOperation.js +23 -21
- package/lib/queryBuilder/operations/jsonApi/mysqlJsonApi.js +106 -118
- package/lib/queryBuilder/operations/jsonApi/postgresJsonApi.js +79 -108
- package/lib/queryBuilder/operations/select/SelectOperation.js +37 -53
- package/lib/queryBuilder/operations/select/Selection.js +94 -105
- package/lib/queryBuilder/operations/whereInComposite/WhereInCompositeMsSqlOperation.js +68 -101
- package/lib/queryBuilder/operations/whereInComposite/WhereInCompositeOperation.js +65 -75
- package/lib/queryBuilder/operations/whereInComposite/WhereInCompositeSqliteOperation.js +75 -84
- package/lib/queryBuilder/parsers/jsonFieldExpressionParser.js +760 -859
- package/lib/queryBuilder/parsers/relationExpressionParser.js +840 -952
- package/lib/queryBuilder/transformations/CompositeQueryTransformation.js +10 -15
- package/lib/queryBuilder/transformations/QueryTransformation.js +4 -6
- package/lib/queryBuilder/transformations/WrapMysqlModifySubqueryTransformation.js +35 -49
- package/lib/queryBuilder/transformations/index.js +3 -9
- package/lib/queryBuilder/whereScopes.js +158 -186
- package/lib/relations/Relation.js +279 -363
- package/lib/relations/RelationDeleteOperation.js +16 -22
- package/lib/relations/RelationFindOperation.js +100 -133
- package/lib/relations/RelationInsertOperation.js +19 -27
- package/lib/relations/RelationOwner.js +167 -204
- package/lib/relations/RelationProperty.js +177 -217
- package/lib/relations/RelationUpdateOperation.js +16 -23
- package/lib/relations/belongsToOne/BelongsToOneDeleteOperation.js +11 -16
- package/lib/relations/belongsToOne/BelongsToOneInsertOperation.js +24 -35
- package/lib/relations/belongsToOne/BelongsToOneRelateOperation.js +30 -41
- package/lib/relations/belongsToOne/BelongsToOneRelation.js +33 -41
- package/lib/relations/belongsToOne/BelongsToOneUnrelateOperation.js +38 -53
- package/lib/relations/hasMany/HasManyInsertOperation.js +35 -51
- package/lib/relations/hasMany/HasManyRelateOperation.js +38 -54
- package/lib/relations/hasMany/HasManyRelation.js +30 -38
- package/lib/relations/hasMany/HasManyUnrelateOperation.js +19 -26
- package/lib/relations/hasOne/HasOneRelation.js +4 -7
- package/lib/relations/hasOneThrough/HasOneThroughRelation.js +4 -7
- package/lib/relations/manyToMany/ManyToManyModifyMixin.js +67 -90
- package/lib/relations/manyToMany/ManyToManyRelation.js +349 -451
- package/lib/relations/manyToMany/ManyToManySqliteModifyMixin.js +19 -26
- package/lib/relations/manyToMany/delete/ManyToManyDeleteOperation.js +3 -5
- package/lib/relations/manyToMany/delete/ManyToManyDeleteOperationBase.js +14 -20
- package/lib/relations/manyToMany/delete/ManyToManyDeleteSqliteOperation.js +3 -7
- package/lib/relations/manyToMany/find/ManyToManyFindOperation.js +71 -94
- package/lib/relations/manyToMany/insert/ManyToManyInsertOperation.js +31 -43
- package/lib/relations/manyToMany/relate/ManyToManyRelateOperation.js +50 -67
- package/lib/relations/manyToMany/unrelate/ManyToManyUnrelateOperation.js +4 -7
- package/lib/relations/manyToMany/unrelate/ManyToManyUnrelateOperationBase.js +20 -27
- package/lib/relations/manyToMany/unrelate/ManyToManyUnrelateSqliteOperation.js +5 -10
- package/lib/relations/manyToMany/update/ManyToManyUpdateOperation.js +3 -5
- package/lib/relations/manyToMany/update/ManyToManyUpdateOperationBase.js +55 -72
- package/lib/relations/manyToMany/update/ManyToManyUpdateSqliteOperation.js +3 -7
- package/lib/transaction.js +53 -83
- package/lib/utils/assert.js +15 -21
- package/lib/utils/buildUtils.js +17 -19
- package/lib/utils/classUtils.js +7 -11
- package/lib/utils/cloneDeep.js +365 -0
- package/lib/utils/createModifier.js +36 -41
- package/lib/utils/deprecate.js +8 -12
- package/lib/utils/identifierMapping.js +153 -192
- package/lib/utils/internalPropUtils.js +4 -8
- package/lib/utils/knexUtils.js +61 -56
- package/lib/utils/mixin.js +16 -23
- package/lib/utils/mysqlJsonPath.js +55 -40
- package/lib/utils/normalizeIds.js +110 -127
- package/lib/utils/objectUtils.js +236 -338
- package/lib/utils/parseFieldExpression.js +66 -44
- package/lib/utils/postgresJsonPath.js +48 -62
- package/lib/utils/promiseUtils/after.js +10 -13
- package/lib/utils/promiseUtils/afterReturn.js +10 -13
- package/lib/utils/promiseUtils/index.js +15 -17
- package/lib/utils/promiseUtils/isPromise.js +6 -9
- package/lib/utils/promiseUtils/map.js +75 -89
- package/lib/utils/promiseUtils/mapAfterAllReturn.js +17 -23
- package/lib/utils/promiseUtils/try.js +15 -18
- package/lib/utils/resolveModel.js +91 -94
- package/lib/utils/tmpColumnUtils.js +4 -13
- package/package.json +50 -23
- package/typings/objection/index.d.mts +362 -0
- package/typings/objection/index.d.ts +36 -9
- package/lib/.eslintrc.json +0 -8
- package/lib/queryBuilder/parsers/jsonFieldExpressionParser.pegjs +0 -97
- package/lib/queryBuilder/parsers/relationExpressionParser.pegjs +0 -141
- package/lib/utils/clone.js +0 -2329
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
-
|
|
3
2
|
class ModifierNotFoundError extends Error {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
constructor(modifierName) {
|
|
4
|
+
super(`Unable to determine modify function from provided value: "${modifierName}".`);
|
|
5
|
+
this.modifierName = modifierName;
|
|
6
|
+
}
|
|
8
7
|
}
|
|
9
|
-
|
|
10
8
|
module.exports = {
|
|
11
|
-
|
|
9
|
+
ModifierNotFoundError,
|
|
12
10
|
};
|
|
@@ -1,23 +1,19 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
-
|
|
3
2
|
class NotFoundError extends Error {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
});
|
|
18
|
-
}
|
|
3
|
+
constructor({ modelClass, data = {}, statusCode = 404, ...rest } = {}) {
|
|
4
|
+
super(rest.message || 'NotFoundError');
|
|
5
|
+
this.type = 'NotFound';
|
|
6
|
+
this.name = this.constructor.name;
|
|
7
|
+
this.data = { ...rest, ...data };
|
|
8
|
+
this.statusCode = statusCode;
|
|
9
|
+
// Add as non-enumerable in case people are passing instances of
|
|
10
|
+
// this error directly to `JSON.stringify`.
|
|
11
|
+
Object.defineProperty(this, 'modelClass', {
|
|
12
|
+
value: modelClass,
|
|
13
|
+
enumerable: false,
|
|
14
|
+
});
|
|
15
|
+
}
|
|
19
16
|
}
|
|
20
|
-
|
|
21
17
|
module.exports = {
|
|
22
|
-
|
|
18
|
+
NotFoundError,
|
|
23
19
|
};
|
|
@@ -1,14 +1,11 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
-
|
|
3
2
|
class RelationDoesNotExistError extends Error {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
3
|
+
constructor(relationName) {
|
|
4
|
+
super(`unknown relation "${relationName}" in a relation expression`);
|
|
5
|
+
this.name = this.constructor.name;
|
|
6
|
+
this.relationName = relationName;
|
|
7
|
+
}
|
|
10
8
|
}
|
|
11
|
-
|
|
12
9
|
module.exports = {
|
|
13
|
-
|
|
10
|
+
RelationDoesNotExistError,
|
|
14
11
|
};
|
|
@@ -1,54 +1,46 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
-
|
|
3
2
|
const { asArray, isString } = require('../utils/objectUtils');
|
|
4
|
-
|
|
5
3
|
const ValidationErrorType = {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
4
|
+
ModelValidation: 'ModelValidation',
|
|
5
|
+
RelationExpression: 'RelationExpression',
|
|
6
|
+
UnallowedRelation: 'UnallowedRelation',
|
|
7
|
+
InvalidGraph: 'InvalidGraph',
|
|
10
8
|
};
|
|
11
|
-
|
|
12
9
|
class ValidationError extends Error {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
enumerable: false,
|
|
30
|
-
});
|
|
31
|
-
}
|
|
10
|
+
static get Type() {
|
|
11
|
+
return ValidationErrorType;
|
|
12
|
+
}
|
|
13
|
+
constructor({ type, message, modelClass, data = {}, statusCode = 400 }) {
|
|
14
|
+
super(message || errorsToMessage(data));
|
|
15
|
+
this.name = this.constructor.name;
|
|
16
|
+
this.type = type;
|
|
17
|
+
this.data = data;
|
|
18
|
+
this.statusCode = statusCode;
|
|
19
|
+
// Add as non-enumerable in case people are passing instances of
|
|
20
|
+
// this error directly to `JSON.stringify`.
|
|
21
|
+
Object.defineProperty(this, 'modelClass', {
|
|
22
|
+
value: modelClass,
|
|
23
|
+
enumerable: false,
|
|
24
|
+
});
|
|
25
|
+
}
|
|
32
26
|
}
|
|
33
|
-
|
|
34
27
|
function errorsToMessage(data) {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
28
|
+
return Object.keys(data)
|
|
29
|
+
.reduce((messages, key) => {
|
|
30
|
+
messages.push(`${key}: ${asArray(data[key]).map(message).join(', ')}`);
|
|
31
|
+
return messages;
|
|
39
32
|
}, [])
|
|
40
|
-
|
|
33
|
+
.join(', ');
|
|
41
34
|
}
|
|
42
|
-
|
|
43
35
|
function message(it) {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
36
|
+
if (isString(it)) {
|
|
37
|
+
return it;
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
return it.message;
|
|
41
|
+
}
|
|
49
42
|
}
|
|
50
|
-
|
|
51
43
|
module.exports = {
|
|
52
|
-
|
|
53
|
-
|
|
44
|
+
ValidationError,
|
|
45
|
+
ValidationErrorType,
|
|
54
46
|
};
|
package/lib/model/Validator.js
CHANGED
|
@@ -1,26 +1,20 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
-
|
|
3
2
|
class Validator {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
afterValidate({ model, json, options }) {
|
|
20
|
-
model.$afterValidate(json, options);
|
|
21
|
-
}
|
|
3
|
+
constructor(...args) {
|
|
4
|
+
this.constructor.init(this, ...args);
|
|
5
|
+
}
|
|
6
|
+
static init() { }
|
|
7
|
+
beforeValidate({ model, json, options }) {
|
|
8
|
+
model.$beforeValidate(null, json, options);
|
|
9
|
+
}
|
|
10
|
+
validate() {
|
|
11
|
+
/* istanbul ignore next */
|
|
12
|
+
throw new Error('not implemented');
|
|
13
|
+
}
|
|
14
|
+
afterValidate({ model, json, options }) {
|
|
15
|
+
model.$afterValidate(json, options);
|
|
16
|
+
}
|
|
22
17
|
}
|
|
23
|
-
|
|
24
18
|
module.exports = {
|
|
25
|
-
|
|
19
|
+
Validator,
|
|
26
20
|
};
|
package/lib/model/getModel.js
CHANGED
|
@@ -1,80 +1,60 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
-
|
|
3
2
|
const { ModelGraphBuilder } = require('./ModelGraphBuilder');
|
|
4
3
|
const NOT_CALCULATED = {};
|
|
5
|
-
|
|
6
4
|
class ModelGraph {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
this._nodesByIdPathKeys = NOT_CALCULATED;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
static create(rootModelClass, roots) {
|
|
17
|
-
const builder = ModelGraphBuilder.buildGraph(rootModelClass, roots);
|
|
18
|
-
return new ModelGraph(builder.nodes, builder.edges);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
static createEmpty() {
|
|
22
|
-
return new ModelGraph([], []);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
get rootObjects() {
|
|
26
|
-
return this.nodes.filter((node) => !node.parentEdge).map((node) => node.obj);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
nodeForObject(obj) {
|
|
30
|
-
if (!obj) {
|
|
31
|
-
return null;
|
|
5
|
+
constructor(nodes, edges) {
|
|
6
|
+
this.nodes = nodes;
|
|
7
|
+
this.edges = edges;
|
|
8
|
+
// These are calculated lazily.
|
|
9
|
+
this._nodesByObjects = NOT_CALCULATED;
|
|
10
|
+
this._nodesByIdPathKeys = NOT_CALCULATED;
|
|
32
11
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
12
|
+
static create(rootModelClass, roots) {
|
|
13
|
+
const builder = ModelGraphBuilder.buildGraph(rootModelClass, roots);
|
|
14
|
+
return new ModelGraph(builder.nodes, builder.edges);
|
|
36
15
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
nodeForNode(node) {
|
|
42
|
-
if (!node) {
|
|
43
|
-
return null;
|
|
16
|
+
static createEmpty() {
|
|
17
|
+
return new ModelGraph([], []);
|
|
44
18
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
19
|
+
get rootObjects() {
|
|
20
|
+
return this.nodes.filter((node) => !node.parentEdge).map((node) => node.obj);
|
|
21
|
+
}
|
|
22
|
+
nodeForObject(obj) {
|
|
23
|
+
if (!obj) {
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
if (this._nodesByObjects === NOT_CALCULATED) {
|
|
27
|
+
this._nodesByObjects = createNodesByObjectsMap(this.nodes);
|
|
28
|
+
}
|
|
29
|
+
return this._nodesByObjects.get(obj) || null;
|
|
30
|
+
}
|
|
31
|
+
nodeForNode(node) {
|
|
32
|
+
if (!node) {
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
if (this._nodesByIdPathKeys === NOT_CALCULATED) {
|
|
36
|
+
this._nodesByIdPathKeys = createNodesByIdPathKeysMap(this.nodes);
|
|
37
|
+
}
|
|
38
|
+
return this._nodesByIdPathKeys.get(node.idPathKey) || null;
|
|
48
39
|
}
|
|
49
|
-
|
|
50
|
-
return this._nodesByIdPathKeys.get(node.idPathKey) || null;
|
|
51
|
-
}
|
|
52
40
|
}
|
|
53
|
-
|
|
54
41
|
function createNodesByObjectsMap(nodes) {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
return nodesByObjects;
|
|
42
|
+
const nodesByObjects = new Map();
|
|
43
|
+
for (const node of nodes) {
|
|
44
|
+
nodesByObjects.set(node.obj, node);
|
|
45
|
+
}
|
|
46
|
+
return nodesByObjects;
|
|
62
47
|
}
|
|
63
|
-
|
|
64
48
|
function createNodesByIdPathKeysMap(nodes) {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
nodesByIdPathKeys.set(idPathKey, node);
|
|
49
|
+
const nodesByIdPathKeys = new Map();
|
|
50
|
+
for (const node of nodes) {
|
|
51
|
+
const idPathKey = node.idPathKey;
|
|
52
|
+
if (idPathKey !== null) {
|
|
53
|
+
nodesByIdPathKeys.set(idPathKey, node);
|
|
54
|
+
}
|
|
72
55
|
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
return nodesByIdPathKeys;
|
|
56
|
+
return nodesByIdPathKeys;
|
|
76
57
|
}
|
|
77
|
-
|
|
78
58
|
module.exports = {
|
|
79
|
-
|
|
59
|
+
ModelGraph,
|
|
80
60
|
};
|