@abedmurrar/objection 4.0.0-beta.1 → 4.0.0-beta.11
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 +1 -1
- package/lib/initialize.js +4 -5
- package/lib/model/AjvValidator.js +24 -21
- package/lib/model/Model.js +116 -114
- package/lib/model/ModifierNotFoundError.js +4 -4
- package/lib/model/NotFoundError.js +4 -4
- package/lib/model/RelationDoesNotExistError.js +4 -4
- package/lib/model/ValidationError.js +8 -8
- package/lib/model/Validator.js +7 -6
- package/lib/model/getModel.js +4 -4
- package/lib/model/graph/ModelGraph.js +9 -7
- package/lib/model/graph/ModelGraphBuilder.js +24 -24
- package/lib/model/graph/ModelGraphEdge.js +4 -4
- package/lib/model/graph/ModelGraphNode.js +17 -11
- package/lib/model/inheritModel.js +3 -4
- package/lib/model/modelBindKnex.js +12 -13
- package/lib/model/modelClone.js +15 -16
- package/lib/model/modelColPropMap.js +7 -8
- package/lib/model/modelConcurrency.js +6 -7
- package/lib/model/modelId.js +4 -5
- package/lib/model/modelJsonAttributes.js +10 -11
- package/lib/model/modelParseRelations.js +5 -6
- package/lib/model/modelQueryProps.js +12 -13
- package/lib/model/modelSet.js +17 -18
- package/lib/model/modelTableMetadata.js +9 -10
- package/lib/model/modelToJson.js +13 -14
- package/lib/model/modelUtils.js +7 -7
- package/lib/model/modelValidate.js +5 -6
- package/lib/model/modelValues.js +10 -10
- package/lib/model/modelVisitor.js +3 -4
- package/lib/objection.js +4 -26
- package/lib/queryBuilder/FunctionBuilder.js +35 -31
- package/lib/queryBuilder/InternalOptions.js +4 -4
- package/lib/queryBuilder/JoinBuilder.js +46 -45
- package/lib/queryBuilder/QueryBuilder.js +161 -135
- package/lib/queryBuilder/QueryBuilderBase.js +203 -203
- package/lib/queryBuilder/QueryBuilderContext.js +6 -6
- package/lib/queryBuilder/QueryBuilderContextBase.js +12 -8
- package/lib/queryBuilder/QueryBuilderOperationSupport.js +30 -25
- package/lib/queryBuilder/QueryBuilderUserContext.js +4 -4
- package/lib/queryBuilder/RawBuilder.js +15 -13
- package/lib/queryBuilder/ReferenceBuilder.js +25 -23
- package/lib/queryBuilder/RelationExpression.js +29 -20
- package/lib/queryBuilder/StaticHookArguments.js +11 -11
- package/lib/queryBuilder/ValueBuilder.js +20 -19
- package/lib/queryBuilder/expressions.js +8 -18
- package/lib/queryBuilder/functions/mysql.js +18 -42
- package/lib/queryBuilder/graph/GraphAction.js +7 -7
- package/lib/queryBuilder/graph/GraphData.js +4 -4
- package/lib/queryBuilder/graph/GraphFetcher.js +18 -17
- package/lib/queryBuilder/graph/GraphNodeDbExistence.js +45 -12
- package/lib/queryBuilder/graph/GraphOperation.js +4 -4
- package/lib/queryBuilder/graph/GraphOptions.js +5 -5
- package/lib/queryBuilder/graph/GraphUpsert.js +36 -36
- package/lib/queryBuilder/graph/delete/GraphDelete.js +8 -8
- package/lib/queryBuilder/graph/delete/GraphDeleteAction.js +46 -11
- package/lib/queryBuilder/graph/insert/GraphInsert.js +12 -12
- package/lib/queryBuilder/graph/insert/GraphInsertAction.js +59 -21
- package/lib/queryBuilder/graph/insert/JoinRowGraphInsertAction.js +49 -11
- package/lib/queryBuilder/graph/patch/GraphPatch.js +8 -8
- package/lib/queryBuilder/graph/patch/GraphPatchAction.js +52 -19
- package/lib/queryBuilder/graph/recursiveUpsert/GraphRecursiveUpsert.js +8 -8
- package/lib/queryBuilder/graph/recursiveUpsert/GraphRecursiveUpsertAction.js +54 -18
- package/lib/queryBuilder/join/JoinResultColumn.js +6 -4
- package/lib/queryBuilder/join/JoinResultParser.js +10 -8
- package/lib/queryBuilder/join/RelationJoiner.js +40 -35
- package/lib/queryBuilder/join/TableNode.js +7 -5
- package/lib/queryBuilder/join/TableTree.js +13 -9
- package/lib/queryBuilder/join/utils.js +8 -8
- package/lib/queryBuilder/operations/DelegateOperation.js +6 -6
- package/lib/queryBuilder/operations/DeleteOperation.js +11 -11
- package/lib/queryBuilder/operations/FindByIdOperation.js +8 -8
- package/lib/queryBuilder/operations/FindByIdsOperation.js +6 -6
- package/lib/queryBuilder/operations/FindOperation.js +23 -23
- package/lib/queryBuilder/operations/FirstOperation.js +6 -6
- package/lib/queryBuilder/operations/FromOperation.js +13 -13
- package/lib/queryBuilder/operations/InsertAndFetchOperation.js +12 -12
- package/lib/queryBuilder/operations/InsertGraphAndFetchOperation.js +10 -10
- package/lib/queryBuilder/operations/InsertGraphOperation.js +11 -11
- package/lib/queryBuilder/operations/InsertOperation.js +23 -22
- package/lib/queryBuilder/operations/InstanceDeleteOperation.js +12 -12
- package/lib/queryBuilder/operations/InstanceFindOperation.js +10 -10
- package/lib/queryBuilder/operations/InstanceInsertOperation.js +6 -6
- package/lib/queryBuilder/operations/InstanceUpdateOperation.js +14 -14
- package/lib/queryBuilder/operations/JoinRelatedOperation.js +13 -13
- package/lib/queryBuilder/operations/KnexOperation.js +6 -6
- package/lib/queryBuilder/operations/MergeOperation.js +11 -11
- package/lib/queryBuilder/operations/ObjectionToKnexConvertingOperation.js +26 -22
- package/lib/queryBuilder/operations/OnBuildKnexOperation.js +6 -6
- package/lib/queryBuilder/operations/OnBuildOperation.js +6 -6
- package/lib/queryBuilder/operations/OnErrorOperation.js +6 -6
- package/lib/queryBuilder/operations/QueryBuilderOperation.js +6 -4
- package/lib/queryBuilder/operations/RangeOperation.js +7 -6
- package/lib/queryBuilder/operations/RelateOperation.js +6 -6
- package/lib/queryBuilder/operations/ReturningOperation.js +8 -8
- package/lib/queryBuilder/operations/RunAfterOperation.js +6 -6
- package/lib/queryBuilder/operations/RunBeforeOperation.js +6 -6
- package/lib/queryBuilder/operations/UnrelateOperation.js +6 -6
- package/lib/queryBuilder/operations/UpdateAndFetchOperation.js +12 -12
- package/lib/queryBuilder/operations/UpdateOperation.js +24 -24
- package/lib/queryBuilder/operations/UpsertGraphAndFetchOperation.js +10 -10
- package/lib/queryBuilder/operations/UpsertGraphOperation.js +10 -10
- package/lib/queryBuilder/operations/WhereCompositeOperation.js +8 -8
- package/lib/queryBuilder/operations/WhereInOperation.js +11 -9
- package/lib/queryBuilder/operations/eager/EagerOperation.js +11 -9
- package/lib/queryBuilder/operations/eager/JoinEagerOperation.js +10 -12
- package/lib/queryBuilder/operations/eager/NaiveEagerOperation.js +6 -6
- package/lib/queryBuilder/operations/eager/WhereInEagerOperation.js +64 -28
- package/lib/queryBuilder/operations/jsonApi/WhereJsonHasOperation.js +45 -12
- package/lib/queryBuilder/operations/jsonApi/WhereJsonNotObjectOperation.js +45 -12
- package/lib/queryBuilder/operations/jsonApi/WhereJsonOperation.js +45 -12
- package/lib/queryBuilder/operations/jsonApi/WhereJsonOverlapsOperation.js +46 -13
- package/lib/queryBuilder/operations/jsonApi/mysqlJsonApi.js +22 -27
- package/lib/queryBuilder/operations/jsonApi/postgresJsonApi.js +51 -17
- package/lib/queryBuilder/operations/select/SelectOperation.js +12 -12
- package/lib/queryBuilder/operations/select/Selection.js +23 -19
- package/lib/queryBuilder/operations/types.js +8 -0
- package/lib/queryBuilder/operations/whereInComposite/WhereInCompositeMsSqlOperation.js +13 -12
- package/lib/queryBuilder/operations/whereInComposite/WhereInCompositeOperation.js +11 -11
- package/lib/queryBuilder/operations/whereInComposite/WhereInCompositeSqliteOperation.js +10 -10
- package/lib/queryBuilder/transformations/CompositeQueryTransformation.js +6 -6
- package/lib/queryBuilder/transformations/QueryTransformation.js +4 -4
- package/lib/queryBuilder/transformations/WrapMysqlModifySubqueryTransformation.js +11 -8
- package/lib/queryBuilder/transformations/index.js +8 -8
- package/lib/queryBuilder/whereScopes.js +15 -21
- package/lib/relations/RelationDeleteOperation.js +0 -2
- package/lib/relations/RelationFindOperation.js +0 -1
- package/lib/relations/RelationUpdateOperation.js +0 -1
- package/lib/relations/manyToMany/delete/ManyToManyDeleteOperationBase.js +0 -1
- package/lib/transaction.js +44 -12
- package/lib/utils/objectUtils.js +6 -1
- package/lib/utils/parseFieldExpression.js +4 -35
- package/lib/utils/promiseUtils/index.js +19 -9
- package/package.json +1 -1
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ModelGraph = void 0;
|
|
4
|
+
const ModelGraphBuilder_1 = require("./ModelGraphBuilder");
|
|
5
|
+
// The marker of the lazily calculated maps that haven't been calculated yet.
|
|
6
|
+
// The type is a brand so that it isn't confused with the maps.
|
|
3
7
|
const NOT_CALCULATED = {};
|
|
4
8
|
class ModelGraph {
|
|
5
9
|
constructor(nodes, edges) {
|
|
@@ -10,7 +14,7 @@ class ModelGraph {
|
|
|
10
14
|
this._nodesByIdPathKeys = NOT_CALCULATED;
|
|
11
15
|
}
|
|
12
16
|
static create(rootModelClass, roots) {
|
|
13
|
-
const builder = ModelGraphBuilder.buildGraph(rootModelClass, roots);
|
|
17
|
+
const builder = ModelGraphBuilder_1.ModelGraphBuilder.buildGraph(rootModelClass, roots);
|
|
14
18
|
return new ModelGraph(builder.nodes, builder.edges);
|
|
15
19
|
}
|
|
16
20
|
static createEmpty() {
|
|
@@ -35,9 +39,10 @@ class ModelGraph {
|
|
|
35
39
|
if (this._nodesByIdPathKeys === NOT_CALCULATED) {
|
|
36
40
|
this._nodesByIdPathKeys = createNodesByIdPathKeysMap(this.nodes);
|
|
37
41
|
}
|
|
38
|
-
return this._nodesByIdPathKeys.get(node.idPathKey) || null;
|
|
42
|
+
return (this._nodesByIdPathKeys.get(node.idPathKey) || null);
|
|
39
43
|
}
|
|
40
44
|
}
|
|
45
|
+
exports.ModelGraph = ModelGraph;
|
|
41
46
|
function createNodesByObjectsMap(nodes) {
|
|
42
47
|
const nodesByObjects = new Map();
|
|
43
48
|
for (const node of nodes) {
|
|
@@ -55,6 +60,3 @@ function createNodesByIdPathKeysMap(nodes) {
|
|
|
55
60
|
}
|
|
56
61
|
return nodesByIdPathKeys;
|
|
57
62
|
}
|
|
58
|
-
module.exports = {
|
|
59
|
-
ModelGraph,
|
|
60
|
-
};
|
|
@@ -1,8 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ModelGraphBuilder = void 0;
|
|
4
|
+
exports.createNotModelError = createNotModelError;
|
|
5
|
+
exports.forEachPropertyReference = forEachPropertyReference;
|
|
6
|
+
const objectUtils_1 = require("../../utils/objectUtils");
|
|
7
|
+
const ValidationError_1 = require("../../model/ValidationError");
|
|
8
|
+
const ModelGraphNode_1 = require("./ModelGraphNode");
|
|
9
|
+
const ModelGraphEdge_1 = require("./ModelGraphEdge");
|
|
6
10
|
class ModelGraphBuilder {
|
|
7
11
|
constructor() {
|
|
8
12
|
this.nodes = [];
|
|
@@ -18,7 +22,7 @@ class ModelGraphBuilder {
|
|
|
18
22
|
if (Array.isArray(roots)) {
|
|
19
23
|
this._buildNodes(rootModelClass, roots);
|
|
20
24
|
}
|
|
21
|
-
else if (isObject(roots)) {
|
|
25
|
+
else if ((0, objectUtils_1.isObject)(roots)) {
|
|
22
26
|
this._buildNode(rootModelClass, roots);
|
|
23
27
|
}
|
|
24
28
|
else {
|
|
@@ -28,20 +32,20 @@ class ModelGraphBuilder {
|
|
|
28
32
|
this._buildReferences();
|
|
29
33
|
}
|
|
30
34
|
_buildNodes(modelClass, objs, parentNode = null, relation = null) {
|
|
31
|
-
objs = asArray(objs);
|
|
35
|
+
objs = (0, objectUtils_1.asArray)(objs);
|
|
32
36
|
objs.forEach((obj, index) => {
|
|
33
37
|
this._buildNode(modelClass, obj, parentNode, relation, index);
|
|
34
38
|
});
|
|
35
39
|
}
|
|
36
40
|
_buildNode(modelClass, obj, parentNode = null, relation = null, index = null) {
|
|
37
|
-
obj = asSingle(obj);
|
|
38
|
-
if (!isObject(obj) || !obj.$isObjectionModel) {
|
|
41
|
+
obj = (0, objectUtils_1.asSingle)(obj);
|
|
42
|
+
if (!(0, objectUtils_1.isObject)(obj) || !obj.$isObjectionModel) {
|
|
39
43
|
throw createNotModelError(modelClass, obj);
|
|
40
44
|
}
|
|
41
|
-
const node = new ModelGraphNode(modelClass, obj);
|
|
45
|
+
const node = new ModelGraphNode_1.ModelGraphNode(modelClass, obj);
|
|
42
46
|
this.nodes.push(node);
|
|
43
47
|
if (parentNode) {
|
|
44
|
-
const edge = new ModelGraphEdge(ModelGraphEdge.Type.Relation, parentNode, node, relation, index);
|
|
48
|
+
const edge = new ModelGraphEdge_1.ModelGraphEdge(ModelGraphEdge_1.ModelGraphEdge.Type.Relation, parentNode, node, relation, index);
|
|
45
49
|
node.parentEdge = edge;
|
|
46
50
|
this._addEdge(parentNode, node, edge);
|
|
47
51
|
}
|
|
@@ -88,8 +92,8 @@ class ModelGraphBuilder {
|
|
|
88
92
|
if (!refNode) {
|
|
89
93
|
throw createReferenceNotFoundError(ref);
|
|
90
94
|
}
|
|
91
|
-
const edge = new ModelGraphEdge(ModelGraphEdge.Type.Reference, node, refNode);
|
|
92
|
-
edge.refType = ModelGraphEdge.ReferenceType.Object;
|
|
95
|
+
const edge = new ModelGraphEdge_1.ModelGraphEdge(ModelGraphEdge_1.ModelGraphEdge.Type.Reference, node, refNode);
|
|
96
|
+
edge.refType = ModelGraphEdge_1.ModelGraphEdge.ReferenceType.Object;
|
|
93
97
|
this._addEdge(node, refNode, edge);
|
|
94
98
|
}
|
|
95
99
|
}
|
|
@@ -100,8 +104,8 @@ class ModelGraphBuilder {
|
|
|
100
104
|
if (!refNode) {
|
|
101
105
|
throw createReferenceNotFoundError(ref);
|
|
102
106
|
}
|
|
103
|
-
const edge = new ModelGraphEdge(ModelGraphEdge.Type.Reference, node, refNode);
|
|
104
|
-
edge.refType = ModelGraphEdge.ReferenceType.Property;
|
|
107
|
+
const edge = new ModelGraphEdge_1.ModelGraphEdge(ModelGraphEdge_1.ModelGraphEdge.Type.Reference, node, refNode);
|
|
108
|
+
edge.refType = ModelGraphEdge_1.ModelGraphEdge.ReferenceType.Property;
|
|
105
109
|
edge.refMatch = refMatch;
|
|
106
110
|
edge.refOwnerDataPath = path.slice();
|
|
107
111
|
edge.refRelatedDataPath = refPath;
|
|
@@ -113,12 +117,13 @@ class ModelGraphBuilder {
|
|
|
113
117
|
this.edges.push(edge);
|
|
114
118
|
ownerNode.edges.push(edge);
|
|
115
119
|
relatedNode.edges.push(edge);
|
|
116
|
-
if (edge.type === ModelGraphEdge.Type.Reference) {
|
|
120
|
+
if (edge.type === ModelGraphEdge_1.ModelGraphEdge.Type.Reference) {
|
|
117
121
|
ownerNode.refEdges.push(edge);
|
|
118
122
|
relatedNode.refEdges.push(edge);
|
|
119
123
|
}
|
|
120
124
|
}
|
|
121
125
|
}
|
|
126
|
+
exports.ModelGraphBuilder = ModelGraphBuilder;
|
|
122
127
|
function forEachPropertyReference(obj, callback) {
|
|
123
128
|
const modelClass = obj.constructor;
|
|
124
129
|
const relationNames = modelClass.getRelationNames();
|
|
@@ -138,10 +143,10 @@ function visitStrings(value, path, visit) {
|
|
|
138
143
|
if (Array.isArray(value)) {
|
|
139
144
|
visitStringsInArray(value, path, visit);
|
|
140
145
|
}
|
|
141
|
-
else if (isObject(value) && !Buffer.isBuffer(value)) {
|
|
146
|
+
else if ((0, objectUtils_1.isObject)(value) && !Buffer.isBuffer(value)) {
|
|
142
147
|
visitStringsInObject(value, path, visit);
|
|
143
148
|
}
|
|
144
|
-
else if (isString(value)) {
|
|
149
|
+
else if ((0, objectUtils_1.isString)(value)) {
|
|
145
150
|
visit(value, path);
|
|
146
151
|
}
|
|
147
152
|
}
|
|
@@ -177,12 +182,7 @@ function createReferenceNotFoundError(ref) {
|
|
|
177
182
|
}
|
|
178
183
|
function createNotModelError(modelClass, value) {
|
|
179
184
|
throw modelClass.createValidationError({
|
|
180
|
-
type: ValidationErrorType.InvalidGraph,
|
|
185
|
+
type: ValidationError_1.ValidationErrorType.InvalidGraph,
|
|
181
186
|
message: `expected value "${value}" to be an instance of ${modelClass.name}`,
|
|
182
187
|
});
|
|
183
188
|
}
|
|
184
|
-
module.exports = {
|
|
185
|
-
ModelGraphBuilder,
|
|
186
|
-
createNotModelError,
|
|
187
|
-
forEachPropertyReference,
|
|
188
|
-
};
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ModelGraphEdge = void 0;
|
|
2
4
|
const Type = {
|
|
3
5
|
Relation: 'Relation',
|
|
4
6
|
Reference: 'Reference',
|
|
@@ -35,6 +37,4 @@ class ModelGraphEdge {
|
|
|
35
37
|
return node === this.relatedNode;
|
|
36
38
|
}
|
|
37
39
|
}
|
|
38
|
-
|
|
39
|
-
ModelGraphEdge,
|
|
40
|
-
};
|
|
40
|
+
exports.ModelGraphEdge = ModelGraphEdge;
|
|
@@ -1,6 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ModelGraphNode = void 0;
|
|
4
|
+
const ModelGraphEdge_1 = require("./ModelGraphEdge");
|
|
5
|
+
const objectUtils_1 = require("../../utils/objectUtils");
|
|
6
|
+
// The marker of the lazily calculated properties that haven't been calculated
|
|
7
|
+
// yet. The type is a brand so that it isn't confused with the calculated values.
|
|
4
8
|
const NOT_CALCULATED = {};
|
|
5
9
|
class ModelGraphNode {
|
|
6
10
|
constructor(modelClass, obj) {
|
|
@@ -99,7 +103,7 @@ class ModelGraphNode {
|
|
|
99
103
|
*/
|
|
100
104
|
get referencedNode() {
|
|
101
105
|
for (const edge of this.refEdges) {
|
|
102
|
-
if (edge.refType === ModelGraphEdge.ReferenceType.Object && edge.isOwnerNode(this)) {
|
|
106
|
+
if (edge.refType === ModelGraphEdge_1.ModelGraphEdge.ReferenceType.Object && edge.isOwnerNode(this)) {
|
|
103
107
|
return edge.relatedNode;
|
|
104
108
|
}
|
|
105
109
|
}
|
|
@@ -111,7 +115,7 @@ class ModelGraphNode {
|
|
|
111
115
|
get referencingNodes() {
|
|
112
116
|
const nodes = [];
|
|
113
117
|
for (const edge of this.refEdges) {
|
|
114
|
-
if (edge.refType === ModelGraphEdge.ReferenceType.Object && edge.isRelatedNode(this)) {
|
|
118
|
+
if (edge.refType === ModelGraphEdge_1.ModelGraphEdge.ReferenceType.Object && edge.isRelatedNode(this)) {
|
|
115
119
|
nodes.push(edge.ownerNode);
|
|
116
120
|
}
|
|
117
121
|
}
|
|
@@ -131,7 +135,7 @@ class ModelGraphNode {
|
|
|
131
135
|
}
|
|
132
136
|
_collectDescendantRelationNodes(nodes) {
|
|
133
137
|
for (const edge of this.edges) {
|
|
134
|
-
if (edge.type === ModelGraphEdge.Type.Relation && edge.isOwnerNode(this)) {
|
|
138
|
+
if (edge.type === ModelGraphEdge_1.ModelGraphEdge.Type.Relation && edge.isOwnerNode(this)) {
|
|
135
139
|
nodes.push(edge.relatedNode);
|
|
136
140
|
edge.relatedNode._collectDescendantRelationNodes(nodes);
|
|
137
141
|
}
|
|
@@ -157,12 +161,16 @@ class ModelGraphNode {
|
|
|
157
161
|
return [...this.parentNode.dataPath, this.relationName];
|
|
158
162
|
}
|
|
159
163
|
else {
|
|
160
|
-
return [
|
|
164
|
+
return [
|
|
165
|
+
...this.parentNode.dataPath,
|
|
166
|
+
this.relationName,
|
|
167
|
+
this.indexInRelation,
|
|
168
|
+
];
|
|
161
169
|
}
|
|
162
170
|
}
|
|
163
171
|
_createDataPathKey() {
|
|
164
172
|
const dataPathKey = this.dataPath.reduce((key, it) => {
|
|
165
|
-
if (isNumber(it)) {
|
|
173
|
+
if ((0, objectUtils_1.isNumber)(it)) {
|
|
166
174
|
return `${key}[${it}]`;
|
|
167
175
|
}
|
|
168
176
|
else {
|
|
@@ -196,6 +204,4 @@ class ModelGraphNode {
|
|
|
196
204
|
}
|
|
197
205
|
}
|
|
198
206
|
}
|
|
199
|
-
|
|
200
|
-
ModelGraphNode,
|
|
201
|
-
};
|
|
207
|
+
exports.ModelGraphNode = ModelGraphNode;
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.inheritModel = inheritModel;
|
|
2
4
|
const cache = new Map();
|
|
3
5
|
function inheritModel(modelClass) {
|
|
4
6
|
let inherit = cache.get(modelClass.name);
|
|
@@ -14,6 +16,3 @@ function createClassInheritor(className) {
|
|
|
14
16
|
return class ${className} extends BaseClass {}
|
|
15
17
|
`);
|
|
16
18
|
}
|
|
17
|
-
module.exports = {
|
|
18
|
-
inheritModel,
|
|
19
|
-
};
|
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.bindKnex = bindKnex;
|
|
4
|
+
const inheritModel_1 = require("./inheritModel");
|
|
5
|
+
const modelUtils_1 = require("./modelUtils");
|
|
6
|
+
const modelUtils_2 = require("./modelUtils");
|
|
5
7
|
function bindKnex(modelClass, knex) {
|
|
6
8
|
let BoundModelClass = getBoundModelFromCache(modelClass, knex);
|
|
7
9
|
if (BoundModelClass === null) {
|
|
8
|
-
BoundModelClass = inheritModel(modelClass);
|
|
10
|
+
BoundModelClass = (0, inheritModel_1.inheritModel)(modelClass);
|
|
9
11
|
BoundModelClass = copyHiddenProperties(modelClass, BoundModelClass);
|
|
10
12
|
BoundModelClass.knex(knex);
|
|
11
13
|
BoundModelClass = putBoundModelToCache(modelClass, BoundModelClass, knex);
|
|
@@ -25,7 +27,7 @@ function getCache(knex) {
|
|
|
25
27
|
return knex.$$objection.boundModels;
|
|
26
28
|
}
|
|
27
29
|
function createCache(knex) {
|
|
28
|
-
defineNonEnumerableProperty(knex, '$$objection', {
|
|
30
|
+
(0, modelUtils_2.defineNonEnumerableProperty)(knex, '$$objection', {
|
|
29
31
|
boundModels: new Map(),
|
|
30
32
|
});
|
|
31
33
|
}
|
|
@@ -37,10 +39,10 @@ function copyHiddenProperties(modelClass, BoundModelClass) {
|
|
|
37
39
|
if (!Object.hasOwn(modelClass, '$$validator')) {
|
|
38
40
|
modelClass.getValidator();
|
|
39
41
|
}
|
|
40
|
-
for (const prop of staticHiddenProps) {
|
|
42
|
+
for (const prop of modelUtils_1.staticHiddenProps) {
|
|
41
43
|
// $$relations and $$relationArray are handled in separately.
|
|
42
44
|
if (Object.hasOwn(modelClass, prop) && prop !== '$$relations' && prop !== '$$relationArray') {
|
|
43
|
-
defineNonEnumerableProperty(BoundModelClass, prop, modelClass[prop]);
|
|
45
|
+
(0, modelUtils_2.defineNonEnumerableProperty)(BoundModelClass, prop, modelClass[prop]);
|
|
44
46
|
}
|
|
45
47
|
}
|
|
46
48
|
return BoundModelClass;
|
|
@@ -60,10 +62,7 @@ function bindRelations(modelClass, BoundModelClass, knex) {
|
|
|
60
62
|
boundRelations[relation.name] = boundRelation;
|
|
61
63
|
boundRelationArray.push(boundRelation);
|
|
62
64
|
}
|
|
63
|
-
defineNonEnumerableProperty(BoundModelClass, '$$relations', boundRelations);
|
|
64
|
-
defineNonEnumerableProperty(BoundModelClass, '$$relationArray', boundRelationArray);
|
|
65
|
+
(0, modelUtils_2.defineNonEnumerableProperty)(BoundModelClass, '$$relations', boundRelations);
|
|
66
|
+
(0, modelUtils_2.defineNonEnumerableProperty)(BoundModelClass, '$$relationArray', boundRelationArray);
|
|
65
67
|
return BoundModelClass;
|
|
66
68
|
}
|
|
67
|
-
module.exports = {
|
|
68
|
-
bindKnex,
|
|
69
|
-
};
|
package/lib/model/modelClone.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
const
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.clone = clone;
|
|
4
|
+
const objectUtils_1 = require("../utils/objectUtils");
|
|
5
|
+
const modelUtils_1 = require("./modelUtils");
|
|
6
|
+
const modelUtils_2 = require("./modelUtils");
|
|
7
|
+
const internalPropUtils_1 = require("../utils/internalPropUtils");
|
|
6
8
|
function clone(model, shallow, stripInternal) {
|
|
7
9
|
let clone = null;
|
|
8
10
|
const omitFromJson = model.$omitFromJson();
|
|
@@ -28,7 +30,7 @@ function cloneSimple(model) {
|
|
|
28
30
|
for (let i = 0, l = keys.length; i < l; ++i) {
|
|
29
31
|
const key = keys[i];
|
|
30
32
|
const value = model[key];
|
|
31
|
-
if (isObject(value)) {
|
|
33
|
+
if ((0, objectUtils_1.isObject)(value)) {
|
|
32
34
|
clone[key] = cloneObject(value);
|
|
33
35
|
}
|
|
34
36
|
else {
|
|
@@ -49,10 +51,10 @@ function cloneWithOpt(model, shallow, stripInternal) {
|
|
|
49
51
|
delete clone[key];
|
|
50
52
|
continue;
|
|
51
53
|
}
|
|
52
|
-
if (stripInternal && isInternalProp(key)) {
|
|
54
|
+
if (stripInternal && (0, internalPropUtils_1.isInternalProp)(key)) {
|
|
53
55
|
continue;
|
|
54
56
|
}
|
|
55
|
-
if (isObject(value)) {
|
|
57
|
+
if ((0, objectUtils_1.isObject)(value)) {
|
|
56
58
|
clone[key] = cloneObject(value);
|
|
57
59
|
}
|
|
58
60
|
else {
|
|
@@ -72,14 +74,14 @@ function cloneObject(value) {
|
|
|
72
74
|
return Buffer.from(value);
|
|
73
75
|
}
|
|
74
76
|
else {
|
|
75
|
-
return cloneDeep(value);
|
|
77
|
+
return (0, objectUtils_1.cloneDeep)(value);
|
|
76
78
|
}
|
|
77
79
|
}
|
|
78
80
|
function cloneArray(value) {
|
|
79
81
|
const ret = new Array(value.length);
|
|
80
82
|
for (let i = 0, l = ret.length; i < l; ++i) {
|
|
81
83
|
const item = value[i];
|
|
82
|
-
if (isObject(item)) {
|
|
84
|
+
if ((0, objectUtils_1.isObject)(item)) {
|
|
83
85
|
ret[i] = cloneObject(item);
|
|
84
86
|
}
|
|
85
87
|
else {
|
|
@@ -89,14 +91,11 @@ function cloneArray(value) {
|
|
|
89
91
|
return ret;
|
|
90
92
|
}
|
|
91
93
|
function copyHiddenProps(model, clone) {
|
|
92
|
-
for (let i = 0, l = hiddenProps.length; i < l; ++i) {
|
|
93
|
-
const prop = hiddenProps[i];
|
|
94
|
+
for (let i = 0, l = modelUtils_1.hiddenProps.length; i < l; ++i) {
|
|
95
|
+
const prop = modelUtils_1.hiddenProps[i];
|
|
94
96
|
if (Object.hasOwn(model, prop)) {
|
|
95
|
-
defineNonEnumerableProperty(clone, prop, model[prop]);
|
|
97
|
+
(0, modelUtils_2.defineNonEnumerableProperty)(clone, prop, model[prop]);
|
|
96
98
|
}
|
|
97
99
|
}
|
|
98
100
|
return clone;
|
|
99
101
|
}
|
|
100
|
-
module.exports = {
|
|
101
|
-
clone,
|
|
102
|
-
};
|
|
@@ -1,12 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.columnNameToPropertyName = columnNameToPropertyName;
|
|
4
|
+
exports.propertyNameToColumnName = propertyNameToColumnName;
|
|
5
|
+
const objectUtils_1 = require("../utils/objectUtils");
|
|
3
6
|
function columnNameToPropertyName(modelClass, columnName) {
|
|
4
7
|
const model = new modelClass();
|
|
5
8
|
const addedProps = Object.keys(model.$parseDatabaseJson({}));
|
|
6
9
|
const row = {};
|
|
7
10
|
row[columnName] = null;
|
|
8
11
|
const props = Object.keys(model.$parseDatabaseJson(row));
|
|
9
|
-
const propertyName = difference(props, addedProps)[0];
|
|
12
|
+
const propertyName = (0, objectUtils_1.difference)(props, addedProps)[0];
|
|
10
13
|
return propertyName || columnName;
|
|
11
14
|
}
|
|
12
15
|
function propertyNameToColumnName(modelClass, propertyName) {
|
|
@@ -15,10 +18,6 @@ function propertyNameToColumnName(modelClass, propertyName) {
|
|
|
15
18
|
const obj = {};
|
|
16
19
|
obj[propertyName] = null;
|
|
17
20
|
const cols = Object.keys(model.$formatDatabaseJson(obj));
|
|
18
|
-
const columnName = difference(cols, addedCols)[0];
|
|
21
|
+
const columnName = (0, objectUtils_1.difference)(cols, addedCols)[0];
|
|
19
22
|
return columnName || propertyName;
|
|
20
23
|
}
|
|
21
|
-
module.exports = {
|
|
22
|
-
columnNameToPropertyName,
|
|
23
|
-
propertyNameToColumnName,
|
|
24
|
-
};
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.setDefaultGetConcurrency = setDefaultGetConcurrency;
|
|
4
|
+
exports.getReadConcurrency = getReadConcurrency;
|
|
5
|
+
const knexUtils_1 = require("../utils/knexUtils");
|
|
3
6
|
const DEFAULT_CONCURRENCY = 4;
|
|
4
7
|
let defaultGetConcurrency = null;
|
|
5
8
|
// Called by Model.js with Model.getConcurrency.
|
|
@@ -16,9 +19,5 @@ function getReadConcurrency(modelClass, knex) {
|
|
|
16
19
|
return modelClass.getConcurrency(knex);
|
|
17
20
|
}
|
|
18
21
|
// The mssql driver can't run concurrent queries.
|
|
19
|
-
return knex && isMsSql(knex) ? 1 : DEFAULT_CONCURRENCY;
|
|
22
|
+
return knex && (0, knexUtils_1.isMsSql)(knex) ? 1 : DEFAULT_CONCURRENCY;
|
|
20
23
|
}
|
|
21
|
-
module.exports = {
|
|
22
|
-
setDefaultGetConcurrency,
|
|
23
|
-
getReadConcurrency,
|
|
24
|
-
};
|
package/lib/model/modelId.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getSetId = getSetId;
|
|
4
|
+
exports.hasId = hasId;
|
|
2
5
|
function getSetId(model, maybeId) {
|
|
3
6
|
if (maybeId !== undefined) {
|
|
4
7
|
return setId(model, maybeId);
|
|
@@ -51,7 +54,3 @@ function getId(model) {
|
|
|
51
54
|
return model[idProp];
|
|
52
55
|
}
|
|
53
56
|
}
|
|
54
|
-
module.exports = {
|
|
55
|
-
getSetId,
|
|
56
|
-
hasId,
|
|
57
|
-
};
|
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseJsonAttributes = parseJsonAttributes;
|
|
4
|
+
exports.formatJsonAttributes = formatJsonAttributes;
|
|
5
|
+
exports.getJsonAttributes = getJsonAttributes;
|
|
6
|
+
const objectUtils_1 = require("../utils/objectUtils");
|
|
3
7
|
function parseJsonAttributes(json, modelClass) {
|
|
4
8
|
const jsonAttr = modelClass.getJsonAttributes();
|
|
5
9
|
if (jsonAttr.length) {
|
|
@@ -8,7 +12,7 @@ function parseJsonAttributes(json, modelClass) {
|
|
|
8
12
|
for (let i = 0, l = jsonAttr.length; i < l; ++i) {
|
|
9
13
|
const attr = jsonAttr[i];
|
|
10
14
|
const value = json[attr];
|
|
11
|
-
if (isString(value)) {
|
|
15
|
+
if ((0, objectUtils_1.isString)(value)) {
|
|
12
16
|
const parsed = tryParseJson(value);
|
|
13
17
|
// tryParseJson returns undefined if parsing failed.
|
|
14
18
|
if (parsed !== undefined) {
|
|
@@ -43,12 +47,12 @@ function getJsonAttributes(modelClass) {
|
|
|
43
47
|
const props = modelClass.getJsonSchema().properties || {};
|
|
44
48
|
for (const propName of Object.keys(props)) {
|
|
45
49
|
const prop = props[propName];
|
|
46
|
-
let types = asArray(prop.type).filter((it) => !!it);
|
|
50
|
+
let types = (0, objectUtils_1.asArray)(prop.type).filter((it) => !!it);
|
|
47
51
|
if (types.length === 0 && Array.isArray(prop.anyOf)) {
|
|
48
|
-
types = flatten(prop.anyOf.map((it) => it.type));
|
|
52
|
+
types = (0, objectUtils_1.flatten)(prop.anyOf.map((it) => it.type));
|
|
49
53
|
}
|
|
50
54
|
if (types.length === 0 && Array.isArray(prop.oneOf)) {
|
|
51
|
-
types = flatten(prop.oneOf.map((it) => it.type));
|
|
55
|
+
types = (0, objectUtils_1.flatten)(prop.oneOf.map((it) => it.type));
|
|
52
56
|
}
|
|
53
57
|
if (types.indexOf('object') !== -1 || types.indexOf('array') !== -1) {
|
|
54
58
|
jsonAttributes.push(propName);
|
|
@@ -65,8 +69,3 @@ function tryParseJson(maybeJsonStr) {
|
|
|
65
69
|
return undefined;
|
|
66
70
|
}
|
|
67
71
|
}
|
|
68
|
-
module.exports = {
|
|
69
|
-
parseJsonAttributes,
|
|
70
|
-
formatJsonAttributes,
|
|
71
|
-
getJsonAttributes,
|
|
72
|
-
};
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseRelationsIntoModelInstances = parseRelationsIntoModelInstances;
|
|
4
|
+
const objectUtils_1 = require("../utils/objectUtils");
|
|
3
5
|
function parseRelationsIntoModelInstances(model, json, options = {}) {
|
|
4
6
|
const relationNames = model.constructor.getRelationNames();
|
|
5
7
|
if (!options.cache && !hasRelation(json, relationNames)) {
|
|
@@ -61,7 +63,7 @@ function parseRelationArray(json, relation, options) {
|
|
|
61
63
|
}
|
|
62
64
|
}
|
|
63
65
|
function parseRelationObject(json, relation, options) {
|
|
64
|
-
if (isObject(json)) {
|
|
66
|
+
if ((0, objectUtils_1.isObject)(json)) {
|
|
65
67
|
const modelClass = relation.relatedModelClass;
|
|
66
68
|
let model = options.cache.get(json);
|
|
67
69
|
if (model === undefined) {
|
|
@@ -78,6 +80,3 @@ function parseRelationObject(json, relation, options) {
|
|
|
78
80
|
return json;
|
|
79
81
|
}
|
|
80
82
|
}
|
|
81
|
-
module.exports = {
|
|
82
|
-
parseRelationsIntoModelInstances,
|
|
83
|
-
};
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.splitQueryProps = splitQueryProps;
|
|
4
|
+
exports.mergeQueryProps = mergeQueryProps;
|
|
5
|
+
const objectUtils_1 = require("../utils/objectUtils");
|
|
6
|
+
const modelUtils_1 = require("./modelUtils");
|
|
7
|
+
const knexUtils_1 = require("../utils/knexUtils");
|
|
5
8
|
const QUERY_PROPS_PROPERTY = '$$queryProps';
|
|
6
9
|
// Removes query properties from `json` and stores them into a hidden property
|
|
7
10
|
// inside `model` so that they can be later merged back to `json`.
|
|
@@ -20,7 +23,7 @@ function splitQueryProps(model, json) {
|
|
|
20
23
|
modelProps[key] = value;
|
|
21
24
|
}
|
|
22
25
|
}
|
|
23
|
-
defineNonEnumerableProperty(model, QUERY_PROPS_PROPERTY, queryProps);
|
|
26
|
+
(0, modelUtils_1.defineNonEnumerableProperty)(model, QUERY_PROPS_PROPERTY, queryProps);
|
|
24
27
|
return modelProps;
|
|
25
28
|
}
|
|
26
29
|
else {
|
|
@@ -36,11 +39,11 @@ function hasQueryProps(json, keys) {
|
|
|
36
39
|
return false;
|
|
37
40
|
}
|
|
38
41
|
function isQueryProp(value) {
|
|
39
|
-
if (!isObject(value)) {
|
|
42
|
+
if (!(0, objectUtils_1.isObject)(value)) {
|
|
40
43
|
return false;
|
|
41
44
|
}
|
|
42
|
-
return (isKnexQueryBuilder(value) ||
|
|
43
|
-
isKnexRaw(value) ||
|
|
45
|
+
return ((0, knexUtils_1.isKnexQueryBuilder)(value) ||
|
|
46
|
+
(0, knexUtils_1.isKnexRaw)(value) ||
|
|
44
47
|
isKnexRawConvertable(value) ||
|
|
45
48
|
value.isObjectionQueryBuilderBase);
|
|
46
49
|
}
|
|
@@ -108,9 +111,5 @@ function buildKnexRawConvertable(convertable, builder) {
|
|
|
108
111
|
return convertable.toKnexRaw(builder);
|
|
109
112
|
}
|
|
110
113
|
function isKnexRawConvertable(queryProp) {
|
|
111
|
-
return isFunction(queryProp.toKnexRaw);
|
|
114
|
+
return (0, objectUtils_1.isFunction)(queryProp.toKnexRaw);
|
|
112
115
|
}
|
|
113
|
-
module.exports = {
|
|
114
|
-
splitQueryProps,
|
|
115
|
-
mergeQueryProps,
|
|
116
|
-
};
|
package/lib/model/modelSet.js
CHANGED
|
@@ -1,8 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.setFast = setFast;
|
|
4
|
+
exports.setJson = setJson;
|
|
5
|
+
exports.setDatabaseJson = setDatabaseJson;
|
|
6
|
+
exports.setRelated = setRelated;
|
|
7
|
+
exports.appendRelated = appendRelated;
|
|
8
|
+
const internalPropUtils_1 = require("../utils/internalPropUtils");
|
|
9
|
+
const modelQueryProps_1 = require("./modelQueryProps");
|
|
10
|
+
const objectUtils_1 = require("../utils/objectUtils");
|
|
11
|
+
const modelParseRelations_1 = require("./modelParseRelations");
|
|
6
12
|
function setJson(model, json, options) {
|
|
7
13
|
json = json || {};
|
|
8
14
|
options = options || {};
|
|
@@ -15,13 +21,13 @@ function setJson(model, json, options) {
|
|
|
15
21
|
// json can contain "query properties" like `raw` instances, query builders etc.
|
|
16
22
|
// We take them out of `json` and store them to a hidden property $$queryProps
|
|
17
23
|
// in the model instance for later use.
|
|
18
|
-
json = splitQueryProps(model, json);
|
|
24
|
+
json = (0, modelQueryProps_1.splitQueryProps)(model, json);
|
|
19
25
|
}
|
|
20
26
|
json = model.$parseJson(json, options);
|
|
21
27
|
json = model.$validate(json, options);
|
|
22
28
|
model.$set(json);
|
|
23
29
|
if (!options.skipParseRelations) {
|
|
24
|
-
parseRelationsIntoModelInstances(model, json, options);
|
|
30
|
+
(0, modelParseRelations_1.parseRelationsIntoModelInstances)(model, json, options);
|
|
25
31
|
}
|
|
26
32
|
return model;
|
|
27
33
|
}
|
|
@@ -46,9 +52,9 @@ function setFast(model, obj) {
|
|
|
46
52
|
for (let i = 0, l = keys.length; i < l; ++i) {
|
|
47
53
|
const key = keys[i];
|
|
48
54
|
const value = obj[key];
|
|
49
|
-
if ((value !== undefined || isPlainObject(obj)) &&
|
|
50
|
-
!isInternalProp(key) &&
|
|
51
|
-
!isFunction(value) &&
|
|
55
|
+
if ((value !== undefined || (0, objectUtils_1.isPlainObject)(obj)) &&
|
|
56
|
+
!(0, internalPropUtils_1.isInternalProp)(key) &&
|
|
57
|
+
!(0, objectUtils_1.isFunction)(value) &&
|
|
52
58
|
!readOnlyAttr.includes(key)) {
|
|
53
59
|
model[key] = value;
|
|
54
60
|
}
|
|
@@ -100,17 +106,10 @@ function appendRelated(model, relation, models) {
|
|
|
100
106
|
return model;
|
|
101
107
|
}
|
|
102
108
|
function ensureRelation(model, relation) {
|
|
103
|
-
if (isString(relation)) {
|
|
109
|
+
if ((0, objectUtils_1.isString)(relation)) {
|
|
104
110
|
return model.constructor.getRelation(relation);
|
|
105
111
|
}
|
|
106
112
|
else {
|
|
107
113
|
return relation;
|
|
108
114
|
}
|
|
109
115
|
}
|
|
110
|
-
module.exports = {
|
|
111
|
-
setFast,
|
|
112
|
-
setJson,
|
|
113
|
-
setDatabaseJson,
|
|
114
|
-
setRelated,
|
|
115
|
-
appendRelated,
|
|
116
|
-
};
|