@abedmurrar/objection 4.0.0-beta.1 → 4.0.0-beta.10
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,6 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WrapMysqlModifySubqueryTransformation = void 0;
|
|
4
|
+
const QueryTransformation_1 = require("./QueryTransformation");
|
|
5
|
+
const knexUtils_1 = require("../../utils/knexUtils");
|
|
4
6
|
/**
|
|
5
7
|
* Mysql doesn't allow queries like this:
|
|
6
8
|
*
|
|
@@ -13,7 +15,8 @@ const { isMySql } = require('../../utils/knexUtils');
|
|
|
13
15
|
*
|
|
14
16
|
* update foo set bar = 1 where id in (select * from (select id from foo))
|
|
15
17
|
*/
|
|
16
|
-
class WrapMysqlModifySubqueryTransformation extends QueryTransformation {
|
|
18
|
+
class WrapMysqlModifySubqueryTransformation extends QueryTransformation_1.QueryTransformation {
|
|
19
|
+
// In a join callback `parentQuery` is a `JoinBuilder`, which the loop below walks past.
|
|
17
20
|
onConvertQueryBuilderBase(query, parentQuery) {
|
|
18
21
|
const knex = parentQuery.unsafeKnex();
|
|
19
22
|
// Cannot detect anything if, for whatever reason, a knex instance
|
|
@@ -22,11 +25,12 @@ class WrapMysqlModifySubqueryTransformation extends QueryTransformation {
|
|
|
22
25
|
return query;
|
|
23
26
|
}
|
|
24
27
|
// This transformation only applies to MySQL.
|
|
25
|
-
if (!isMySql(knex)) {
|
|
28
|
+
if (!(0, knexUtils_1.isMySql)(knex)) {
|
|
26
29
|
return query;
|
|
27
30
|
}
|
|
28
31
|
// A subquery in a join callback belongs to the query of the join.
|
|
29
32
|
while (parentQuery && typeof parentQuery.isUpdate !== 'function') {
|
|
33
|
+
// The loop stops at the first parent query that is a `QueryBuilder`.
|
|
30
34
|
parentQuery = parentQuery.parentQuery();
|
|
31
35
|
}
|
|
32
36
|
// This transformation only applies to update and delete queries.
|
|
@@ -42,9 +46,11 @@ class WrapMysqlModifySubqueryTransformation extends QueryTransformation {
|
|
|
42
46
|
return query.modelClass().query().from(query.as('mysql_subquery_fix'));
|
|
43
47
|
}
|
|
44
48
|
}
|
|
49
|
+
exports.WrapMysqlModifySubqueryTransformation = WrapMysqlModifySubqueryTransformation;
|
|
45
50
|
function hasJoinsToTable(query, tableName) {
|
|
46
51
|
let found = false;
|
|
47
52
|
query.forEachOperation(query.constructor.JoinSelector, (op) => {
|
|
53
|
+
// The join operations are `KnexOperation`s, which have `args`.
|
|
48
54
|
if (op.args[0] === tableName) {
|
|
49
55
|
found = true;
|
|
50
56
|
return false;
|
|
@@ -52,6 +58,3 @@ function hasJoinsToTable(query, tableName) {
|
|
|
52
58
|
});
|
|
53
59
|
return found;
|
|
54
60
|
}
|
|
55
|
-
module.exports = {
|
|
56
|
-
WrapMysqlModifySubqueryTransformation,
|
|
57
|
-
};
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.transformation = void 0;
|
|
4
|
+
const CompositeQueryTransformation_1 = require("./CompositeQueryTransformation");
|
|
5
|
+
const WrapMysqlModifySubqueryTransformation_1 = require("./WrapMysqlModifySubqueryTransformation");
|
|
6
|
+
const transformation = new CompositeQueryTransformation_1.CompositeQueryTransformation([
|
|
7
|
+
new WrapMysqlModifySubqueryTransformation_1.WrapMysqlModifySubqueryTransformation(),
|
|
6
8
|
]);
|
|
7
|
-
|
|
8
|
-
transformation,
|
|
9
|
-
};
|
|
9
|
+
exports.transformation = transformation;
|
|
@@ -1,15 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
// conditions of the others. Without this, `$relatedQuery('pets').where(a).orWhere(b)`
|
|
9
|
-
// would produce `owner and a or b` and match other owners' pets.
|
|
10
|
-
//
|
|
11
|
-
// The scopes are only used when the knex query is built. The operation tree is
|
|
12
|
-
// never modified.
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.withWhereScope = withWhereScope;
|
|
4
|
+
exports.effectiveWhereScope = effectiveWhereScope;
|
|
5
|
+
exports.createWhereGrouping = createWhereGrouping;
|
|
6
|
+
const objectUtils_1 = require("../utils/objectUtils");
|
|
7
|
+
const knexUtils_1 = require("../utils/knexUtils");
|
|
13
8
|
const WhereSelector = /^(where|orWhere|andWhere|find\w+)/;
|
|
14
9
|
// Where operations that only ever produce a single predicate or predicates
|
|
15
10
|
// joined with `and`. A scope that only contains these (and no raw arguments)
|
|
@@ -63,6 +58,7 @@ function withWhereScope(builder, callback) {
|
|
|
63
58
|
builder._whereScope = previous;
|
|
64
59
|
}
|
|
65
60
|
}
|
|
61
|
+
// Returns the where scope token, or null.
|
|
66
62
|
function effectiveWhereScope(op) {
|
|
67
63
|
while (op) {
|
|
68
64
|
if (op.whereScope !== null) {
|
|
@@ -139,6 +135,7 @@ function buildOperationTree(builder, op, knexBuilder) {
|
|
|
139
135
|
}
|
|
140
136
|
function hasWhereAncestor(op) {
|
|
141
137
|
for (let parent = op.parentOperation; parent; parent = parent.parentOperation) {
|
|
138
|
+
// A null name is tested as 'null', as `test()` converts it to a string.
|
|
142
139
|
if (WhereSelector.test(parent.name)) {
|
|
143
140
|
return true;
|
|
144
141
|
}
|
|
@@ -159,13 +156,15 @@ function isAndOnlyTree(op) {
|
|
|
159
156
|
return andOnly;
|
|
160
157
|
}
|
|
161
158
|
function isAndOnly(op) {
|
|
162
|
-
|
|
159
|
+
// The operations that convert their arguments for knex have `args`.
|
|
160
|
+
return (AND_ONLY_OPERATIONS.has(op.name) && !containsRaw(op.args));
|
|
163
161
|
}
|
|
162
|
+
// `value` is a user value of any shape: operation arguments.
|
|
164
163
|
function containsRaw(value) {
|
|
165
164
|
if (Array.isArray(value)) {
|
|
166
165
|
return value.some(containsRaw);
|
|
167
166
|
}
|
|
168
|
-
else if (!isObject(value)) {
|
|
167
|
+
else if (!(0, objectUtils_1.isObject)(value)) {
|
|
169
168
|
return false;
|
|
170
169
|
}
|
|
171
170
|
else if (value.isObjectionReferenceBuilder) {
|
|
@@ -177,11 +176,11 @@ function containsRaw(value) {
|
|
|
177
176
|
// so only their arguments can contain anything.
|
|
178
177
|
return containsRaw(value._args);
|
|
179
178
|
}
|
|
180
|
-
else if (isKnexRaw(value) || isFunction(value.toKnexRaw)) {
|
|
179
|
+
else if ((0, knexUtils_1.isKnexRaw)(value) || (0, objectUtils_1.isFunction)(value.toKnexRaw)) {
|
|
181
180
|
// Raw sql (and anything that is converted into it) can contain anything.
|
|
182
181
|
return true;
|
|
183
182
|
}
|
|
184
|
-
else if (value.isObjectionQueryBuilderBase || isFunction(value.toSQL)) {
|
|
183
|
+
else if (value.isObjectionQueryBuilderBase || (0, objectUtils_1.isFunction)(value.toSQL)) {
|
|
185
184
|
// Subqueries are always wrapped in parentheses.
|
|
186
185
|
return false;
|
|
187
186
|
}
|
|
@@ -192,8 +191,3 @@ function containsRaw(value) {
|
|
|
192
191
|
return false;
|
|
193
192
|
}
|
|
194
193
|
}
|
|
195
|
-
module.exports = {
|
|
196
|
-
withWhereScope,
|
|
197
|
-
effectiveWhereScope,
|
|
198
|
-
createWhereGrouping,
|
|
199
|
-
};
|
|
@@ -5,7 +5,6 @@ const DeleteOperation_1 = require("../queryBuilder/operations/DeleteOperation");
|
|
|
5
5
|
const RelationFindOperation_1 = require("./RelationFindOperation");
|
|
6
6
|
class RelationDeleteOperation extends DeleteOperation_1.DeleteOperation {
|
|
7
7
|
constructor(name, opt) {
|
|
8
|
-
// @ts-expect-error The JavaScript QueryBuilderOperation's `name` is inferred as null.
|
|
9
8
|
super(name, opt);
|
|
10
9
|
this.relation = opt.relation;
|
|
11
10
|
this.owner = opt.owner;
|
|
@@ -14,7 +13,6 @@ class RelationDeleteOperation extends DeleteOperation_1.DeleteOperation {
|
|
|
14
13
|
super.onBuild(builder);
|
|
15
14
|
this.relation.findQuery(builder, this.owner);
|
|
16
15
|
}
|
|
17
|
-
// @ts-expect-error The JavaScript base class's toFindOperation() is inferred to return null.
|
|
18
16
|
toFindOperation() {
|
|
19
17
|
return new RelationFindOperation_1.RelationFindOperation('find', {
|
|
20
18
|
relation: this.relation,
|
|
@@ -4,7 +4,6 @@ exports.RelationFindOperation = void 0;
|
|
|
4
4
|
const FindOperation_1 = require("../queryBuilder/operations/FindOperation");
|
|
5
5
|
class RelationFindOperation extends FindOperation_1.FindOperation {
|
|
6
6
|
constructor(name, opt) {
|
|
7
|
-
// @ts-expect-error The JavaScript QueryBuilderOperation's `name` is inferred as null.
|
|
8
7
|
super(name, opt);
|
|
9
8
|
this.relation = opt.relation;
|
|
10
9
|
this.owner = opt.owner;
|
|
@@ -13,7 +13,6 @@ class RelationUpdateOperation extends UpdateOperation_1.UpdateOperation {
|
|
|
13
13
|
super.onBuild(builder);
|
|
14
14
|
this.relation.findQuery(builder, this.owner);
|
|
15
15
|
}
|
|
16
|
-
// @ts-expect-error The JavaScript base class's toFindOperation() is inferred to return null.
|
|
17
16
|
toFindOperation() {
|
|
18
17
|
return new RelationFindOperation_1.RelationFindOperation('find', {
|
|
19
18
|
relation: this.relation,
|
|
@@ -4,7 +4,6 @@ exports.ManyToManyDeleteOperationBase = void 0;
|
|
|
4
4
|
const DeleteOperation_1 = require("../../../queryBuilder/operations/DeleteOperation");
|
|
5
5
|
class ManyToManyDeleteOperationBase extends DeleteOperation_1.DeleteOperation {
|
|
6
6
|
constructor(name, opt) {
|
|
7
|
-
// @ts-expect-error The JavaScript QueryBuilderOperation's `name` is inferred as null.
|
|
8
7
|
super(name, opt);
|
|
9
8
|
this.relation = opt.relation;
|
|
10
9
|
this.owner = opt.owner;
|
package/lib/transaction.js
CHANGED
|
@@ -1,13 +1,48 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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.transaction = transaction;
|
|
37
|
+
const promiseUtils = __importStar(require("./utils/promiseUtils"));
|
|
38
|
+
const objectUtils_1 = require("./utils/objectUtils");
|
|
39
|
+
function transaction(...transactionArgs) {
|
|
5
40
|
// There must be at least one model class and the callback.
|
|
6
|
-
if (
|
|
41
|
+
if (transactionArgs.length < 2) {
|
|
7
42
|
return Promise.reject(new Error('objection.transaction: provide at least one Model class to bind to the transaction or a knex instance'));
|
|
8
43
|
}
|
|
9
|
-
let args = Array.from(
|
|
10
|
-
if (!isModelClass(args[0]) && isFunction(args[0].transaction)) {
|
|
44
|
+
let args = Array.from(transactionArgs);
|
|
45
|
+
if (!isModelClass(args[0]) && (0, objectUtils_1.isFunction)(args[0].transaction)) {
|
|
11
46
|
const knex = args[0];
|
|
12
47
|
args = args.slice(1);
|
|
13
48
|
return knex.transaction.apply(knex, args);
|
|
@@ -45,7 +80,7 @@ transaction.start = function (modelClassOrKnex) {
|
|
|
45
80
|
if (isModelClass(modelClassOrKnex)) {
|
|
46
81
|
knex = modelClassOrKnex.knex();
|
|
47
82
|
}
|
|
48
|
-
if (!knex || !isFunction(knex.transaction)) {
|
|
83
|
+
if (!knex || !(0, objectUtils_1.isFunction)(knex.transaction)) {
|
|
49
84
|
return Promise.reject(new Error('objection.transaction.start: first argument must be a model class or a knex instance'));
|
|
50
85
|
}
|
|
51
86
|
return new Promise((resolve, reject) => {
|
|
@@ -59,8 +94,5 @@ transaction.start = function (modelClassOrKnex) {
|
|
|
59
94
|
});
|
|
60
95
|
};
|
|
61
96
|
function isModelClass(maybeModel) {
|
|
62
|
-
return isFunction(maybeModel) && maybeModel.isObjectionModelClass;
|
|
97
|
+
return (0, objectUtils_1.isFunction)(maybeModel) && maybeModel.isObjectionModelClass;
|
|
63
98
|
}
|
|
64
|
-
module.exports = {
|
|
65
|
-
transaction,
|
|
66
|
-
};
|
package/lib/utils/objectUtils.js
CHANGED
|
@@ -25,7 +25,12 @@ exports.last = last;
|
|
|
25
25
|
exports.get = get;
|
|
26
26
|
exports.set = set;
|
|
27
27
|
const cloneDeep_1 = require("./cloneDeep");
|
|
28
|
-
|
|
28
|
+
// Re-exporting an imported binding makes tsc define the export as a getter,
|
|
29
|
+
// which puts this module's whole exports object in V8's slow dictionary mode
|
|
30
|
+
// and makes every `objectUtils.x()` call several times slower. A local
|
|
31
|
+
// constant is exported as a plain property instead.
|
|
32
|
+
const cloneDeep = cloneDeep_1.cloneDeep;
|
|
33
|
+
exports.cloneDeep = cloneDeep;
|
|
29
34
|
const SMALL_ARRAY_SIZE = 10;
|
|
30
35
|
function isEmpty(item) {
|
|
31
36
|
if (Array.isArray(item) || Buffer.isBuffer(item)) {
|
|
@@ -1,40 +1,9 @@
|
|
|
1
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
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
3
|
exports.parseFieldExpression = parseFieldExpression;
|
|
37
|
-
|
|
4
|
+
// A named import: `import * as` of a JavaScript module wraps it in an object
|
|
5
|
+
// of getters (tsc's __importStar), which is slow to call through.
|
|
6
|
+
const jsonFieldExpressionParser_1 = require("../queryBuilder/parsers/jsonFieldExpressionParser");
|
|
38
7
|
const cache = new Map();
|
|
39
8
|
function parseFieldExpression(expr) {
|
|
40
9
|
let parsedExpr = cache.get(expr);
|
|
@@ -42,7 +11,7 @@ function parseFieldExpression(expr) {
|
|
|
42
11
|
return parsedExpr;
|
|
43
12
|
}
|
|
44
13
|
else {
|
|
45
|
-
const parserOutput =
|
|
14
|
+
const parserOutput = (0, jsonFieldExpressionParser_1.parse)(expr);
|
|
46
15
|
parsedExpr = preprocessParsedExpression(parserOutput);
|
|
47
16
|
// We don't take a copy of the parsedExpr each time we
|
|
48
17
|
// use if from cache. Instead to make sure it's never
|
|
@@ -1,15 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.try = exports.
|
|
4
|
-
const isPromise_1 = require("./isPromise");
|
|
5
|
-
Object.defineProperty(exports, "isPromise", { enumerable: true, get: function () { return isPromise_1.isPromise; } });
|
|
3
|
+
exports.try = exports.mapAfterAllReturn = exports.map = exports.isPromise = exports.afterReturn = exports.after = void 0;
|
|
6
4
|
const after_1 = require("./after");
|
|
7
|
-
Object.defineProperty(exports, "after", { enumerable: true, get: function () { return after_1.after; } });
|
|
8
5
|
const afterReturn_1 = require("./afterReturn");
|
|
9
|
-
|
|
10
|
-
const mapAfterAllReturn_1 = require("./mapAfterAllReturn");
|
|
11
|
-
Object.defineProperty(exports, "mapAfterAllReturn", { enumerable: true, get: function () { return mapAfterAllReturn_1.mapAfterAllReturn; } });
|
|
6
|
+
const isPromise_1 = require("./isPromise");
|
|
12
7
|
const map_1 = require("./map");
|
|
13
|
-
|
|
8
|
+
const mapAfterAllReturn_1 = require("./mapAfterAllReturn");
|
|
14
9
|
const try_1 = require("./try");
|
|
15
|
-
|
|
10
|
+
// Re-exporting imported bindings makes tsc define the exports as getters,
|
|
11
|
+
// which puts this module's exports object in V8's slow dictionary mode and
|
|
12
|
+
// makes every call through it several times slower. Local constants are
|
|
13
|
+
// exported as plain properties instead.
|
|
14
|
+
const isPromise = isPromise_1.isPromise;
|
|
15
|
+
exports.isPromise = isPromise;
|
|
16
|
+
const after = after_1.after;
|
|
17
|
+
exports.after = after;
|
|
18
|
+
const afterReturn = afterReturn_1.afterReturn;
|
|
19
|
+
exports.afterReturn = afterReturn;
|
|
20
|
+
const mapAfterAllReturn = mapAfterAllReturn_1.mapAfterAllReturn;
|
|
21
|
+
exports.mapAfterAllReturn = mapAfterAllReturn;
|
|
22
|
+
const map = map_1.promiseMap;
|
|
23
|
+
exports.map = map;
|
|
24
|
+
const promiseTryExport = try_1.promiseTry;
|
|
25
|
+
exports.try = promiseTryExport;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@abedmurrar/objection",
|
|
3
|
-
"version": "4.0.0-beta.
|
|
3
|
+
"version": "4.0.0-beta.10",
|
|
4
4
|
"description": "An SQL-friendly ORM for Node.js. A fork of objection.js with strict TypeScript types and MySQL support.",
|
|
5
5
|
"main": "lib/objection.js",
|
|
6
6
|
"type": "commonjs",
|