@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,6 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.QueryBuilderContext = void 0;
|
|
4
|
+
const QueryBuilderContextBase_1 = require("./QueryBuilderContextBase");
|
|
5
|
+
class QueryBuilderContext extends QueryBuilderContextBase_1.QueryBuilderContextBase {
|
|
4
6
|
constructor(builder) {
|
|
5
7
|
super(builder);
|
|
6
8
|
this.runBefore = [];
|
|
@@ -15,6 +17,4 @@ class QueryBuilderContext extends QueryBuilderContextBase {
|
|
|
15
17
|
return ctx;
|
|
16
18
|
}
|
|
17
19
|
}
|
|
18
|
-
|
|
19
|
-
QueryBuilderContext,
|
|
20
|
-
};
|
|
20
|
+
exports.QueryBuilderContext = QueryBuilderContext;
|
|
@@ -1,15 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.QueryBuilderContextBase = void 0;
|
|
4
|
+
const InternalOptions_1 = require("./InternalOptions");
|
|
3
5
|
class QueryBuilderContextBase {
|
|
4
6
|
constructor(builder) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
+
// `userContext` and `options` are only null in the copy that `clone()`
|
|
8
|
+
// creates, which assigns them right away.
|
|
9
|
+
this.userContext = (builder
|
|
10
|
+
? new builder.constructor.QueryBuilderUserContext(builder)
|
|
11
|
+
: null);
|
|
12
|
+
this.options = (builder ? new this.constructor.InternalOptions() : null);
|
|
7
13
|
this.knex = null;
|
|
8
14
|
this.aliasMap = null;
|
|
9
15
|
this.tableMap = null;
|
|
10
16
|
}
|
|
11
17
|
static get InternalOptions() {
|
|
12
|
-
return InternalOptions;
|
|
18
|
+
return InternalOptions_1.InternalOptions;
|
|
13
19
|
}
|
|
14
20
|
clone() {
|
|
15
21
|
const ctx = new this.constructor();
|
|
@@ -21,6 +27,4 @@ class QueryBuilderContextBase {
|
|
|
21
27
|
return ctx;
|
|
22
28
|
}
|
|
23
29
|
}
|
|
24
|
-
|
|
25
|
-
QueryBuilderContextBase,
|
|
26
|
-
};
|
|
30
|
+
exports.QueryBuilderContextBase = QueryBuilderContextBase;
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.QueryBuilderOperationSupport = void 0;
|
|
4
|
+
const objectUtils_1 = require("../utils/objectUtils");
|
|
5
|
+
const QueryBuilderContextBase_1 = require("./QueryBuilderContextBase");
|
|
6
|
+
const QueryBuilderUserContext_1 = require("./QueryBuilderUserContext");
|
|
7
|
+
const deprecate_1 = require("../utils/deprecate");
|
|
8
|
+
const whereScopes_1 = require("./whereScopes");
|
|
7
9
|
const AllSelector = () => true;
|
|
8
10
|
const SelectSelector = /^(select|columns|column|distinct|count|countDistinct|min|max|sum|sumDistinct|avg|avgDistinct)$/;
|
|
9
11
|
const WhereSelector = /^(where|orWhere|andWhere|find\w+)/;
|
|
@@ -31,10 +33,10 @@ class QueryBuilderOperationSupport {
|
|
|
31
33
|
return AllSelector;
|
|
32
34
|
}
|
|
33
35
|
static get QueryBuilderContext() {
|
|
34
|
-
return QueryBuilderContextBase;
|
|
36
|
+
return QueryBuilderContextBase_1.QueryBuilderContextBase;
|
|
35
37
|
}
|
|
36
38
|
static get QueryBuilderUserContext() {
|
|
37
|
-
return QueryBuilderUserContext;
|
|
39
|
+
return QueryBuilderUserContext_1.QueryBuilderUserContext;
|
|
38
40
|
}
|
|
39
41
|
static get SelectSelector() {
|
|
40
42
|
return SelectSelector;
|
|
@@ -107,7 +109,7 @@ class QueryBuilderOperationSupport {
|
|
|
107
109
|
const tableName = getTableName(modelClassOrTableName);
|
|
108
110
|
const ctx = this.internalContext();
|
|
109
111
|
const tableMap = ctx.tableMap;
|
|
110
|
-
if (isString(newTableName)) {
|
|
112
|
+
if ((0, objectUtils_1.isString)(newTableName)) {
|
|
111
113
|
ctx.tableMap = tableMap || new Map();
|
|
112
114
|
ctx.tableMap.set(tableName, newTableName);
|
|
113
115
|
return this;
|
|
@@ -120,7 +122,7 @@ class QueryBuilderOperationSupport {
|
|
|
120
122
|
const tableName = getTableName(modelClassOrTableName);
|
|
121
123
|
const ctx = this.internalContext();
|
|
122
124
|
const aliasMap = ctx.aliasMap;
|
|
123
|
-
if (isString(alias)) {
|
|
125
|
+
if ((0, objectUtils_1.isString)(alias)) {
|
|
124
126
|
ctx.aliasMap = aliasMap || new Map();
|
|
125
127
|
ctx.aliasMap.set(tableName, alias);
|
|
126
128
|
return this;
|
|
@@ -157,8 +159,8 @@ class QueryBuilderOperationSupport {
|
|
|
157
159
|
if (this._isPartialQuery) {
|
|
158
160
|
// Merge alias and table name maps for "partial" subqueries.
|
|
159
161
|
const ctx = this.internalContext();
|
|
160
|
-
ctx.aliasMap = mergeMaps(query.internalContext().aliasMap, ctx.aliasMap);
|
|
161
|
-
ctx.tableMap = mergeMaps(query.internalContext().tableMap, ctx.tableMap);
|
|
162
|
+
ctx.aliasMap = (0, objectUtils_1.mergeMaps)(query.internalContext().aliasMap, ctx.aliasMap);
|
|
163
|
+
ctx.tableMap = (0, objectUtils_1.mergeMaps)(query.internalContext().tableMap, ctx.tableMap);
|
|
162
164
|
}
|
|
163
165
|
this._parentQuery = query;
|
|
164
166
|
if (this.unsafeKnex() === null) {
|
|
@@ -205,6 +207,7 @@ class QueryBuilderOperationSupport {
|
|
|
205
207
|
const operationsToReplace = [];
|
|
206
208
|
const operationsToRemove = [];
|
|
207
209
|
findQuery.forEachOperation((op) => op.hasToFindOperation(), (op) => {
|
|
210
|
+
// Only `QueryBuilder`s are turned into find queries.
|
|
208
211
|
const findOp = op.toFindOperation(findQuery);
|
|
209
212
|
if (!findOp) {
|
|
210
213
|
operationsToRemove.push(op);
|
|
@@ -242,7 +245,7 @@ class QueryBuilderOperationSupport {
|
|
|
242
245
|
for (const op of operationsToAdd) {
|
|
243
246
|
const opClone = op.clone();
|
|
244
247
|
// The scope may come from a parent operation that is not copied.
|
|
245
|
-
opClone.whereScope = effectiveWhereScope(op);
|
|
248
|
+
opClone.whereScope = (0, whereScopes_1.effectiveWhereScope)(op);
|
|
246
249
|
// We may be moving nested operations to the root. Clear
|
|
247
250
|
// any links to the parent operations.
|
|
248
251
|
opClone.parentOperation = null;
|
|
@@ -283,6 +286,7 @@ class QueryBuilderOperationSupport {
|
|
|
283
286
|
}, false);
|
|
284
287
|
return every;
|
|
285
288
|
}
|
|
289
|
+
// Returns whatever the hook returns.
|
|
286
290
|
callOperationMethod(operation, hookName, args) {
|
|
287
291
|
try {
|
|
288
292
|
operation.removeChildOperationsByHookName(hookName);
|
|
@@ -296,6 +300,7 @@ class QueryBuilderOperationSupport {
|
|
|
296
300
|
this._activeOperations.pop();
|
|
297
301
|
}
|
|
298
302
|
}
|
|
303
|
+
// Returns whatever the hook returns.
|
|
299
304
|
async callAsyncOperationMethod(operation, hookName, args) {
|
|
300
305
|
operation.removeChildOperationsByHookName(hookName);
|
|
301
306
|
this._activeOperations.push({
|
|
@@ -323,7 +328,7 @@ class QueryBuilderOperationSupport {
|
|
|
323
328
|
operation.whereScope = this._whereScope;
|
|
324
329
|
}
|
|
325
330
|
if (this._activeOperations.length) {
|
|
326
|
-
const { operation: parentOperation, hookName } = last(this._activeOperations);
|
|
331
|
+
const { operation: parentOperation, hookName } = (0, objectUtils_1.last)(this._activeOperations);
|
|
327
332
|
parentOperation.addChildOperation(hookName, operation);
|
|
328
333
|
}
|
|
329
334
|
else {
|
|
@@ -382,7 +387,7 @@ class QueryBuilderOperationSupport {
|
|
|
382
387
|
});
|
|
383
388
|
}
|
|
384
389
|
executeOnBuildKnex(knexBuilder) {
|
|
385
|
-
const whereGrouping = createWhereGrouping(this);
|
|
390
|
+
const whereGrouping = (0, whereScopes_1.createWhereGrouping)(this);
|
|
386
391
|
this.forEachOperation(true, (op) => {
|
|
387
392
|
if (whereGrouping !== null && whereGrouping.isGrouped(op)) {
|
|
388
393
|
knexBuilder = whereGrouping.build(op, knexBuilder);
|
|
@@ -403,11 +408,12 @@ class QueryBuilderOperationSupport {
|
|
|
403
408
|
return this.toString();
|
|
404
409
|
}
|
|
405
410
|
skipUndefined() {
|
|
406
|
-
deprecate('skipUndefined() is deprecated and will be removed in objection 4.0');
|
|
411
|
+
(0, deprecate_1.deprecate)('skipUndefined() is deprecated and will be removed in objection 4.0');
|
|
407
412
|
this.internalOptions().skipUndefined = true;
|
|
408
413
|
return this;
|
|
409
414
|
}
|
|
410
415
|
}
|
|
416
|
+
exports.QueryBuilderOperationSupport = QueryBuilderOperationSupport;
|
|
411
417
|
// Operation selectors are `true` (every operation), a regex or a string that
|
|
412
418
|
// is matched against the operation name, an operation class, or a predicate.
|
|
413
419
|
// Queries walk their operations many times, so the selector is classified
|
|
@@ -422,17 +428,18 @@ function selectorKind(operationSelector) {
|
|
|
422
428
|
if (operationSelector === true) {
|
|
423
429
|
return SELECT_ALL;
|
|
424
430
|
}
|
|
425
|
-
else if (isRegExp(operationSelector)) {
|
|
431
|
+
else if ((0, objectUtils_1.isRegExp)(operationSelector)) {
|
|
426
432
|
return SELECT_REGEX;
|
|
427
433
|
}
|
|
428
|
-
else if (isString(operationSelector)) {
|
|
434
|
+
else if ((0, objectUtils_1.isString)(operationSelector)) {
|
|
429
435
|
return SELECT_NAME;
|
|
430
436
|
}
|
|
431
|
-
else if (isFunction(operationSelector) &&
|
|
432
|
-
operationSelector
|
|
437
|
+
else if ((0, objectUtils_1.isFunction)(operationSelector) &&
|
|
438
|
+
operationSelector
|
|
439
|
+
.isObjectionQueryBuilderOperationClass) {
|
|
433
440
|
return SELECT_CLASS;
|
|
434
441
|
}
|
|
435
|
-
else if (isFunction(operationSelector)) {
|
|
442
|
+
else if ((0, objectUtils_1.isFunction)(operationSelector)) {
|
|
436
443
|
return SELECT_PREDICATE;
|
|
437
444
|
}
|
|
438
445
|
else {
|
|
@@ -444,6 +451,7 @@ function matchesSelector(op, kind, operationSelector) {
|
|
|
444
451
|
case SELECT_ALL:
|
|
445
452
|
return true;
|
|
446
453
|
case SELECT_REGEX:
|
|
454
|
+
// A null name is tested as 'null', as `test()` converts it to a string.
|
|
447
455
|
return operationSelector.test(op.name);
|
|
448
456
|
case SELECT_NAME:
|
|
449
457
|
return op.name === operationSelector;
|
|
@@ -472,13 +480,10 @@ function visitOperations(operations, kind, operationSelector, callback, match) {
|
|
|
472
480
|
return true;
|
|
473
481
|
}
|
|
474
482
|
function getTableName(modelClassOrTableName) {
|
|
475
|
-
if (isString(modelClassOrTableName)) {
|
|
483
|
+
if ((0, objectUtils_1.isString)(modelClassOrTableName)) {
|
|
476
484
|
return modelClassOrTableName;
|
|
477
485
|
}
|
|
478
486
|
else {
|
|
479
487
|
return modelClassOrTableName.getTableName();
|
|
480
488
|
}
|
|
481
489
|
}
|
|
482
|
-
module.exports = {
|
|
483
|
-
QueryBuilderOperationSupport,
|
|
484
|
-
};
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.QueryBuilderUserContext = void 0;
|
|
2
4
|
const SYMBOL_BUILDER = Symbol();
|
|
3
5
|
class QueryBuilderUserContext {
|
|
4
6
|
constructor(builder) {
|
|
@@ -20,6 +22,4 @@ class QueryBuilderUserContext {
|
|
|
20
22
|
return ctx;
|
|
21
23
|
}
|
|
22
24
|
}
|
|
23
|
-
|
|
24
|
-
QueryBuilderUserContext,
|
|
25
|
-
};
|
|
25
|
+
exports.QueryBuilderUserContext = QueryBuilderUserContext;
|
|
@@ -1,7 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RawBuilder = void 0;
|
|
4
|
+
exports.normalizeRawArgs = normalizeRawArgs;
|
|
5
|
+
exports.raw = raw;
|
|
6
|
+
const objectUtils_1 = require("../utils/objectUtils");
|
|
7
|
+
const buildUtils_1 = require("../utils/buildUtils");
|
|
8
|
+
const expressions_1 = require("./expressions");
|
|
5
9
|
class RawBuilder {
|
|
6
10
|
constructor(sql, args) {
|
|
7
11
|
this._sql = `${sql}`;
|
|
@@ -18,7 +22,7 @@ class RawBuilder {
|
|
|
18
22
|
toKnexRaw(builder) {
|
|
19
23
|
let args = null;
|
|
20
24
|
let sql = this._sql;
|
|
21
|
-
if (this._args.length === 1 && isPlainObject(this._args[0])) {
|
|
25
|
+
if (this._args.length === 1 && (0, objectUtils_1.isPlainObject)(this._args[0])) {
|
|
22
26
|
args = buildObject(this._args[0], builder);
|
|
23
27
|
if (this._as) {
|
|
24
28
|
args.__alias__ = this._as;
|
|
@@ -35,6 +39,7 @@ class RawBuilder {
|
|
|
35
39
|
return builder.knex().raw(sql, args);
|
|
36
40
|
}
|
|
37
41
|
}
|
|
42
|
+
exports.RawBuilder = RawBuilder;
|
|
38
43
|
Object.defineProperties(RawBuilder.prototype, {
|
|
39
44
|
isObjectionRawBuilder: {
|
|
40
45
|
enumerable: false,
|
|
@@ -42,13 +47,15 @@ Object.defineProperties(RawBuilder.prototype, {
|
|
|
42
47
|
value: true,
|
|
43
48
|
},
|
|
44
49
|
});
|
|
45
|
-
addExpressionMethods(RawBuilder.prototype);
|
|
50
|
+
(0, expressions_1.addExpressionMethods)(RawBuilder.prototype);
|
|
51
|
+
// `buildArg()` turns objection builders into knex ones. Everything else is a
|
|
52
|
+
// value that knex binds as it is.
|
|
46
53
|
function buildArray(arr, builder) {
|
|
47
|
-
return arr.map((it) => buildArg(it, builder));
|
|
54
|
+
return arr.map((it) => (0, buildUtils_1.buildArg)(it, builder));
|
|
48
55
|
}
|
|
49
56
|
function buildObject(obj, builder) {
|
|
50
57
|
return Object.keys(obj).reduce((args, key) => {
|
|
51
|
-
args[key] = buildArg(obj[key], builder);
|
|
58
|
+
args[key] = (0, buildUtils_1.buildArg)(obj[key], builder);
|
|
52
59
|
return args;
|
|
53
60
|
}, {});
|
|
54
61
|
}
|
|
@@ -71,8 +78,3 @@ function raw(...argsIn) {
|
|
|
71
78
|
const { sql, args } = normalizeRawArgs(argsIn);
|
|
72
79
|
return new RawBuilder(sql, args);
|
|
73
80
|
}
|
|
74
|
-
module.exports = {
|
|
75
|
-
RawBuilder,
|
|
76
|
-
normalizeRawArgs,
|
|
77
|
-
raw,
|
|
78
|
-
};
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ref = exports.ReferenceBuilder = void 0;
|
|
4
|
+
const parseFieldExpression_1 = require("../utils/parseFieldExpression");
|
|
5
|
+
const objectUtils_1 = require("../utils/objectUtils");
|
|
6
|
+
const knexUtils_1 = require("../utils/knexUtils");
|
|
7
|
+
const postgresJsonPath_1 = require("../utils/postgresJsonPath");
|
|
8
|
+
const mysqlJsonPath_1 = require("../utils/mysqlJsonPath");
|
|
9
|
+
const expressions_1 = require("./expressions");
|
|
8
10
|
class ReferenceBuilder {
|
|
9
11
|
constructor(expr) {
|
|
10
12
|
this._expr = expr;
|
|
@@ -22,6 +24,8 @@ class ReferenceBuilder {
|
|
|
22
24
|
this._parseExpression(expr);
|
|
23
25
|
}
|
|
24
26
|
}
|
|
27
|
+
// `_expr`, `_parsedExpr` and `_column` are only null inside `clone()`, which
|
|
28
|
+
// sets them right after creating the clone.
|
|
25
29
|
get parsedExpr() {
|
|
26
30
|
return this._parsedExpr;
|
|
27
31
|
}
|
|
@@ -132,13 +136,13 @@ class ReferenceBuilder {
|
|
|
132
136
|
return builder.knex().raw(...this._createRawArgs(builder));
|
|
133
137
|
}
|
|
134
138
|
_parseExpression(expr) {
|
|
135
|
-
this._parsedExpr = parseFieldExpression(expr);
|
|
139
|
+
this._parsedExpr = (0, parseFieldExpression_1.parseFieldExpression)(expr);
|
|
136
140
|
this._column = this._parsedExpr.column;
|
|
137
141
|
this._table = this._parsedExpr.table;
|
|
138
142
|
}
|
|
139
143
|
_createRawArgs(builder) {
|
|
140
144
|
const knex = builder.unsafeKnex();
|
|
141
|
-
const mysql = isMySql(knex);
|
|
145
|
+
const mysql = (0, knexUtils_1.isMySql)(knex);
|
|
142
146
|
const bindings = [];
|
|
143
147
|
let sql = this._createReferenceSql(builder, bindings);
|
|
144
148
|
sql = this._maybeCast(sql, mysql, knex);
|
|
@@ -152,20 +156,20 @@ class ReferenceBuilder {
|
|
|
152
156
|
if (access.length === 0) {
|
|
153
157
|
return '??';
|
|
154
158
|
}
|
|
155
|
-
if (getJsonDialect(builder.unsafeKnex(), this._expr) === 'mysql') {
|
|
156
|
-
bindings.push(toMySqlJsonPath(access));
|
|
159
|
+
if ((0, postgresJsonPath_1.getJsonDialect)(builder.unsafeKnex(), this._expr) === 'mysql') {
|
|
160
|
+
bindings.push((0, mysqlJsonPath_1.toMySqlJsonPath)(access));
|
|
157
161
|
// Casts need the unquoted value: `abc` instead of the JSON string `"abc"`.
|
|
158
162
|
if (this._cast) {
|
|
159
163
|
return 'JSON_UNQUOTE(JSON_EXTRACT(??, ?))';
|
|
160
164
|
}
|
|
161
165
|
// MariaDB's JSON_EXTRACT() returns the JSON with spaces, so it would never
|
|
162
166
|
// be equal to a value like `val({ a: 1 })`, which is compact.
|
|
163
|
-
return isMariaDb(builder.unsafeKnex())
|
|
167
|
+
return (0, knexUtils_1.isMariaDb)(builder.unsafeKnex())
|
|
164
168
|
? 'JSON_COMPACT(JSON_EXTRACT(??, ?))'
|
|
165
169
|
: 'JSON_EXTRACT(??, ?)';
|
|
166
170
|
}
|
|
167
171
|
const extractor = this._cast ? '#>>' : '#>';
|
|
168
|
-
return `??${extractor}${toPgJsonPathLiteral(access)}`;
|
|
172
|
+
return `??${extractor}${(0, postgresJsonPath_1.toPgJsonPathLiteral)(access)}`;
|
|
169
173
|
}
|
|
170
174
|
_maybeCast(sql, mysql, knex) {
|
|
171
175
|
if (!this._cast) {
|
|
@@ -176,17 +180,17 @@ class ReferenceBuilder {
|
|
|
176
180
|
}
|
|
177
181
|
const isJsonField = this._parsedExpr.access.length > 0;
|
|
178
182
|
// MySQL can't cast to a boolean.
|
|
179
|
-
if (isBooleanType(this._cast)) {
|
|
183
|
+
if ((0, mysqlJsonPath_1.isBooleanType)(this._cast)) {
|
|
180
184
|
return isJsonField ? `(${sql} IN ('true', '1'))` : `(${sql} <> 0)`;
|
|
181
185
|
}
|
|
182
|
-
const type = toMySqlCastType(this._cast);
|
|
186
|
+
const type = (0, mysqlJsonPath_1.toMySqlCastType)(this._cast);
|
|
183
187
|
// `JSON_UNQUOTE()` already returns text. Casting it would change its collation
|
|
184
188
|
// from the case sensitive one `->>` also uses.
|
|
185
189
|
if (isJsonField && type === 'CHAR') {
|
|
186
190
|
return sql;
|
|
187
191
|
}
|
|
188
192
|
if (type === 'JSON') {
|
|
189
|
-
return toJsonSql(sql, knex);
|
|
193
|
+
return (0, mysqlJsonPath_1.toJsonSql)(sql, knex);
|
|
190
194
|
}
|
|
191
195
|
return `CAST(${sql} AS ${type})`;
|
|
192
196
|
}
|
|
@@ -195,7 +199,7 @@ class ReferenceBuilder {
|
|
|
195
199
|
return sql;
|
|
196
200
|
}
|
|
197
201
|
else if (mysql) {
|
|
198
|
-
return toJsonSql(sql, knex);
|
|
202
|
+
return (0, mysqlJsonPath_1.toJsonSql)(sql, knex);
|
|
199
203
|
}
|
|
200
204
|
else {
|
|
201
205
|
return `to_jsonb(${sql})`;
|
|
@@ -224,6 +228,7 @@ class ReferenceBuilder {
|
|
|
224
228
|
}
|
|
225
229
|
}
|
|
226
230
|
}
|
|
231
|
+
exports.ReferenceBuilder = ReferenceBuilder;
|
|
227
232
|
Object.defineProperties(ReferenceBuilder.prototype, {
|
|
228
233
|
isObjectionReferenceBuilder: {
|
|
229
234
|
enumerable: false,
|
|
@@ -231,16 +236,13 @@ Object.defineProperties(ReferenceBuilder.prototype, {
|
|
|
231
236
|
value: true,
|
|
232
237
|
},
|
|
233
238
|
});
|
|
234
|
-
addExpressionMethods(ReferenceBuilder.prototype);
|
|
239
|
+
(0, expressions_1.addExpressionMethods)(ReferenceBuilder.prototype);
|
|
235
240
|
const ref = (reference) => {
|
|
236
|
-
if (isObject(reference) && reference.isObjectionReferenceBuilder) {
|
|
241
|
+
if ((0, objectUtils_1.isObject)(reference) && reference.isObjectionReferenceBuilder) {
|
|
237
242
|
return reference;
|
|
238
243
|
}
|
|
239
244
|
else {
|
|
240
245
|
return new ReferenceBuilder(reference);
|
|
241
246
|
}
|
|
242
247
|
};
|
|
243
|
-
|
|
244
|
-
ReferenceBuilder,
|
|
245
|
-
ref,
|
|
246
|
-
};
|
|
248
|
+
exports.ref = ref;
|
|
@@ -1,15 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DuplicateRelationError = exports.RelationExpressionParseError = exports.RelationExpression = void 0;
|
|
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 relationExpressionParser_1 = require("./parsers/relationExpressionParser");
|
|
7
|
+
const objectUtils_1 = require("../utils/objectUtils");
|
|
8
|
+
const RelationDoesNotExistError_1 = require("../model/RelationDoesNotExistError");
|
|
5
9
|
class RelationExpressionParseError extends Error {
|
|
6
10
|
}
|
|
11
|
+
exports.RelationExpressionParseError = RelationExpressionParseError;
|
|
7
12
|
class DuplicateRelationError extends RelationExpressionParseError {
|
|
8
13
|
constructor(relationName) {
|
|
9
14
|
super();
|
|
10
15
|
this.relationName = relationName;
|
|
11
16
|
}
|
|
12
17
|
}
|
|
18
|
+
exports.DuplicateRelationError = DuplicateRelationError;
|
|
13
19
|
class RelationExpression {
|
|
14
20
|
constructor(node = newNode(), recursionDepth = 0) {
|
|
15
21
|
this.node = node;
|
|
@@ -18,7 +24,7 @@ class RelationExpression {
|
|
|
18
24
|
// Create a relation expression from a string, a pojo or another
|
|
19
25
|
// RelationExpression instance.
|
|
20
26
|
static create(expr) {
|
|
21
|
-
if (isObject(expr)) {
|
|
27
|
+
if ((0, objectUtils_1.isObject)(expr)) {
|
|
22
28
|
if (expr.isObjectionRelationExpression) {
|
|
23
29
|
return expr;
|
|
24
30
|
}
|
|
@@ -26,7 +32,7 @@ class RelationExpression {
|
|
|
26
32
|
return new RelationExpression(normalizeNode(expr));
|
|
27
33
|
}
|
|
28
34
|
}
|
|
29
|
-
else if (isString(expr)) {
|
|
35
|
+
else if ((0, objectUtils_1.isString)(expr)) {
|
|
30
36
|
if (expr.trim().length === 0) {
|
|
31
37
|
return new RelationExpression();
|
|
32
38
|
}
|
|
@@ -58,7 +64,7 @@ class RelationExpression {
|
|
|
58
64
|
}
|
|
59
65
|
}
|
|
60
66
|
get maxRecursionDepth() {
|
|
61
|
-
if (isNumber(this.node.$recursive)) {
|
|
67
|
+
if ((0, objectUtils_1.isNumber)(this.node.$recursive)) {
|
|
62
68
|
return this.node.$recursive;
|
|
63
69
|
}
|
|
64
70
|
else {
|
|
@@ -143,7 +149,7 @@ class RelationExpression {
|
|
|
143
149
|
const node = this.node[childName];
|
|
144
150
|
const relation = modelClass.getRelationUnsafe(node.$relation);
|
|
145
151
|
if (!relation) {
|
|
146
|
-
throw new RelationDoesNotExistError(node.$relation);
|
|
152
|
+
throw new RelationDoesNotExistError_1.RelationDoesNotExistError(node.$relation);
|
|
147
153
|
}
|
|
148
154
|
const childExpr = new RelationExpression(node);
|
|
149
155
|
cb(childExpr, relation);
|
|
@@ -156,6 +162,7 @@ class RelationExpression {
|
|
|
156
162
|
clone() {
|
|
157
163
|
return new RelationExpression(cloneNode(this.node), this.recursionDepth);
|
|
158
164
|
}
|
|
165
|
+
// `null` for an empty expression.
|
|
159
166
|
toString() {
|
|
160
167
|
return toString(this.node);
|
|
161
168
|
}
|
|
@@ -166,6 +173,7 @@ class RelationExpression {
|
|
|
166
173
|
return this.toPojo();
|
|
167
174
|
}
|
|
168
175
|
}
|
|
176
|
+
exports.RelationExpression = RelationExpression;
|
|
169
177
|
const parseCache = new Map();
|
|
170
178
|
function parse(str) {
|
|
171
179
|
const cachedNode = parseCache.get(str);
|
|
@@ -173,7 +181,7 @@ function parse(str) {
|
|
|
173
181
|
return cloneNode(cachedNode);
|
|
174
182
|
}
|
|
175
183
|
else {
|
|
176
|
-
const node =
|
|
184
|
+
const node = (0, relationExpressionParser_1.parse)(str);
|
|
177
185
|
parseCache.set(str, cloneNode(node));
|
|
178
186
|
return node;
|
|
179
187
|
}
|
|
@@ -194,10 +202,12 @@ function getChildNames(node) {
|
|
|
194
202
|
}
|
|
195
203
|
function toString(node) {
|
|
196
204
|
const childNames = node.$childNames;
|
|
197
|
-
let childExpr = childNames
|
|
205
|
+
let childExpr = childNames
|
|
206
|
+
.map((childName) => node[childName])
|
|
207
|
+
.map(toString);
|
|
198
208
|
let str = node.$relation;
|
|
199
209
|
if (node.$recursive) {
|
|
200
|
-
if (isNumber(node.$recursive)) {
|
|
210
|
+
if ((0, objectUtils_1.isNumber)(node.$recursive)) {
|
|
201
211
|
str += '.^' + node.$recursive;
|
|
202
212
|
}
|
|
203
213
|
else {
|
|
@@ -277,8 +287,10 @@ function normalizeNode(node = null, name = null, allRecusive = false) {
|
|
|
277
287
|
$childNames: normalizeChildNames(node),
|
|
278
288
|
};
|
|
279
289
|
for (const childName of normalized.$childNames) {
|
|
290
|
+
// `node` isn't null here, since a null node has no child names.
|
|
280
291
|
const childNode = node[childName];
|
|
281
|
-
if (isObject(childNode) || childNode === true) {
|
|
292
|
+
if ((0, objectUtils_1.isObject)(childNode) || childNode === true) {
|
|
293
|
+
// `true` is a node without any properties, like `{}`.
|
|
282
294
|
normalized[childName] = normalizeNode(childNode, childName);
|
|
283
295
|
}
|
|
284
296
|
}
|
|
@@ -312,6 +324,7 @@ function findExpressionsAtPath(target, path, results) {
|
|
|
312
324
|
}
|
|
313
325
|
else {
|
|
314
326
|
for (const childName of path.node.$childNames) {
|
|
327
|
+
// Not null, since `childName` is a child of `path`.
|
|
315
328
|
const pathChild = path.childExpression(childName);
|
|
316
329
|
const targetChild = target.childExpression(childName);
|
|
317
330
|
if (targetChild) {
|
|
@@ -325,13 +338,13 @@ function mergeNodes(node1, node2) {
|
|
|
325
338
|
const node = {
|
|
326
339
|
$name: node1.$name,
|
|
327
340
|
$relation: node1.$relation,
|
|
328
|
-
$modify: union(node1.$modify, node2.$modify),
|
|
341
|
+
$modify: (0, objectUtils_1.union)(node1.$modify, node2.$modify),
|
|
329
342
|
$recursive: mergeRecursion(node1.$recursive, node2.$recursive),
|
|
330
343
|
$allRecursive: node1.$allRecursive || node2.$allRecursive,
|
|
331
344
|
$childNames: null,
|
|
332
345
|
};
|
|
333
346
|
if (!node.$recursive && !node.$allRecursive) {
|
|
334
|
-
node.$childNames = union(node1.$childNames, node2.$childNames);
|
|
347
|
+
node.$childNames = (0, objectUtils_1.union)(node1.$childNames, node2.$childNames);
|
|
335
348
|
for (const childName of node.$childNames) {
|
|
336
349
|
const child1 = node1[childName];
|
|
337
350
|
const child2 = node2[childName];
|
|
@@ -346,13 +359,14 @@ function mergeNodes(node1, node2) {
|
|
|
346
359
|
else {
|
|
347
360
|
node.$childNames = [];
|
|
348
361
|
}
|
|
362
|
+
// `$childNames` was set above.
|
|
349
363
|
return node;
|
|
350
364
|
}
|
|
351
365
|
function mergeRecursion(rec1, rec2) {
|
|
352
366
|
if (rec1 === true || rec2 === true) {
|
|
353
367
|
return true;
|
|
354
368
|
}
|
|
355
|
-
else if (isNumber(rec1) && isNumber(rec2)) {
|
|
369
|
+
else if ((0, objectUtils_1.isNumber)(rec1) && (0, objectUtils_1.isNumber)(rec2)) {
|
|
356
370
|
return Math.max(rec1, rec2);
|
|
357
371
|
}
|
|
358
372
|
else {
|
|
@@ -366,8 +380,3 @@ Object.defineProperties(RelationExpression.prototype, {
|
|
|
366
380
|
value: true,
|
|
367
381
|
},
|
|
368
382
|
});
|
|
369
|
-
module.exports = {
|
|
370
|
-
RelationExpression,
|
|
371
|
-
RelationExpressionParseError,
|
|
372
|
-
DuplicateRelationError,
|
|
373
|
-
};
|
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.StaticHookArguments = void 0;
|
|
4
|
+
exports.markDefaultStaticHook = markDefaultStaticHook;
|
|
5
|
+
exports.hasStaticHook = hasStaticHook;
|
|
6
|
+
const objectUtils_1 = require("../utils/objectUtils");
|
|
3
7
|
const BUILDER_SYMBOL = Symbol();
|
|
4
8
|
// The static hooks of `Model`, which do nothing. Queries skip creating the
|
|
5
9
|
// arguments and calling the hook when a model class hasn't overridden it.
|
|
@@ -19,7 +23,7 @@ class StaticHookArguments {
|
|
|
19
23
|
value: builder,
|
|
20
24
|
});
|
|
21
25
|
Object.defineProperty(this, 'result', {
|
|
22
|
-
value: asArray(result),
|
|
26
|
+
value: (0, objectUtils_1.asArray)(result),
|
|
23
27
|
});
|
|
24
28
|
}
|
|
25
29
|
static create(args) {
|
|
@@ -27,7 +31,7 @@ class StaticHookArguments {
|
|
|
27
31
|
}
|
|
28
32
|
get asFindQuery() {
|
|
29
33
|
return () => {
|
|
30
|
-
return this[BUILDER_SYMBOL].toFindQuery().clearWithGraphFetched().runAfter(asArray);
|
|
34
|
+
return this[BUILDER_SYMBOL].toFindQuery().clearWithGraphFetched().runAfter(objectUtils_1.asArray);
|
|
31
35
|
};
|
|
32
36
|
}
|
|
33
37
|
get context() {
|
|
@@ -57,7 +61,7 @@ class StaticHookArguments {
|
|
|
57
61
|
get items() {
|
|
58
62
|
const op = this[BUILDER_SYMBOL].findOperation(hasItems);
|
|
59
63
|
if (op) {
|
|
60
|
-
return asArray(getItems(op));
|
|
64
|
+
return (0, objectUtils_1.asArray)(getItems(op));
|
|
61
65
|
}
|
|
62
66
|
else {
|
|
63
67
|
return [];
|
|
@@ -66,7 +70,7 @@ class StaticHookArguments {
|
|
|
66
70
|
get inputItems() {
|
|
67
71
|
const op = this[BUILDER_SYMBOL].findOperation(hasInputItems);
|
|
68
72
|
if (op) {
|
|
69
|
-
return asArray(getInputItems(op));
|
|
73
|
+
return (0, objectUtils_1.asArray)(getInputItems(op));
|
|
70
74
|
}
|
|
71
75
|
else {
|
|
72
76
|
return [];
|
|
@@ -91,6 +95,7 @@ class StaticHookArguments {
|
|
|
91
95
|
};
|
|
92
96
|
}
|
|
93
97
|
}
|
|
98
|
+
exports.StaticHookArguments = StaticHookArguments;
|
|
94
99
|
function getRelation(op) {
|
|
95
100
|
return op.relation;
|
|
96
101
|
}
|
|
@@ -115,8 +120,3 @@ function getInputItems(op) {
|
|
|
115
120
|
function hasInputItems(op) {
|
|
116
121
|
return !!getInputItems(op);
|
|
117
122
|
}
|
|
118
|
-
module.exports = {
|
|
119
|
-
StaticHookArguments,
|
|
120
|
-
markDefaultStaticHook,
|
|
121
|
-
hasStaticHook,
|
|
122
|
-
};
|