@abedmurrar/objection 4.0.0-alpha.0 → 4.0.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +103 -67
- package/lib/index.mjs +6 -0
- package/lib/initialize.js +6 -9
- package/lib/model/AjvValidator.js +235 -282
- package/lib/model/Model.js +653 -823
- package/lib/model/ModifierNotFoundError.js +5 -7
- package/lib/model/NotFoundError.js +14 -18
- package/lib/model/RelationDoesNotExistError.js +6 -9
- package/lib/model/ValidationError.js +33 -41
- package/lib/model/Validator.js +15 -21
- package/lib/model/getModel.js +1 -3
- package/lib/model/graph/ModelGraph.js +44 -64
- package/lib/model/graph/ModelGraphBuilder.js +164 -217
- package/lib/model/graph/ModelGraphEdge.js +31 -43
- package/lib/model/graph/ModelGraphNode.js +192 -231
- package/lib/model/inheritModel.js +9 -18
- package/lib/model/modelBindKnex.js +48 -62
- package/lib/model/modelClone.js +79 -98
- package/lib/model/modelColPropMap.js +16 -26
- package/lib/model/modelConcurrency.js +24 -0
- package/lib/model/modelId.js +44 -49
- package/lib/model/modelJsonAttributes.js +56 -76
- package/lib/model/modelParseRelations.js +68 -67
- package/lib/model/modelQueryProps.js +76 -107
- package/lib/model/modelSet.js +92 -112
- package/lib/model/modelTableMetadata.js +60 -72
- package/lib/model/modelToJson.js +120 -150
- package/lib/model/modelUtils.js +30 -37
- package/lib/model/modelValidate.js +34 -42
- package/lib/model/modelValues.js +78 -91
- package/lib/model/modelVisitor.js +22 -29
- package/lib/objection.js +42 -67
- package/lib/queryBuilder/FunctionBuilder.js +231 -279
- package/lib/queryBuilder/InternalOptions.js +19 -24
- package/lib/queryBuilder/JoinBuilder.js +116 -149
- package/lib/queryBuilder/QueryBuilder.js +1009 -1271
- package/lib/queryBuilder/QueryBuilderBase.js +647 -865
- package/lib/queryBuilder/QueryBuilderContext.js +14 -21
- package/lib/queryBuilder/QueryBuilderContextBase.js +20 -29
- package/lib/queryBuilder/QueryBuilderOperationSupport.js +462 -536
- package/lib/queryBuilder/QueryBuilderUserContext.js +19 -25
- package/lib/queryBuilder/RawBuilder.js +58 -73
- package/lib/queryBuilder/ReferenceBuilder.js +232 -270
- package/lib/queryBuilder/RelationExpression.js +322 -380
- package/lib/queryBuilder/StaticHookArguments.js +94 -106
- package/lib/queryBuilder/ValueBuilder.js +100 -112
- package/lib/queryBuilder/expressions.js +86 -116
- package/lib/queryBuilder/functions/mysql.js +642 -697
- package/lib/queryBuilder/graph/GraphAction.js +44 -59
- package/lib/queryBuilder/graph/GraphData.js +7 -9
- package/lib/queryBuilder/graph/GraphFetcher.js +115 -151
- package/lib/queryBuilder/graph/GraphNodeDbExistence.js +114 -152
- package/lib/queryBuilder/graph/GraphOperation.js +16 -22
- package/lib/queryBuilder/graph/GraphOptions.js +143 -185
- package/lib/queryBuilder/graph/GraphUpsert.js +167 -241
- package/lib/queryBuilder/graph/delete/GraphDelete.js +8 -13
- package/lib/queryBuilder/graph/delete/GraphDeleteAction.js +44 -62
- package/lib/queryBuilder/graph/insert/GraphInsert.js +99 -128
- package/lib/queryBuilder/graph/insert/GraphInsertAction.js +151 -193
- package/lib/queryBuilder/graph/insert/JoinRowGraphInsertAction.js +57 -79
- package/lib/queryBuilder/graph/patch/GraphPatch.js +8 -13
- package/lib/queryBuilder/graph/patch/GraphPatchAction.js +181 -234
- package/lib/queryBuilder/graph/recursiveUpsert/GraphRecursiveUpsert.js +16 -21
- package/lib/queryBuilder/graph/recursiveUpsert/GraphRecursiveUpsertAction.js +80 -110
- package/lib/queryBuilder/join/JoinResultColumn.js +14 -18
- package/lib/queryBuilder/join/JoinResultParser.js +88 -101
- package/lib/queryBuilder/join/RelationJoiner.js +205 -288
- package/lib/queryBuilder/join/TableNode.js +117 -144
- package/lib/queryBuilder/join/TableTree.js +60 -76
- package/lib/queryBuilder/join/utils.js +10 -16
- package/lib/queryBuilder/operations/DelegateOperation.js +93 -133
- package/lib/queryBuilder/operations/DeleteOperation.js +33 -37
- package/lib/queryBuilder/operations/FindByIdOperation.js +20 -28
- package/lib/queryBuilder/operations/FindByIdsOperation.js +17 -23
- package/lib/queryBuilder/operations/FindOperation.js +114 -131
- package/lib/queryBuilder/operations/FirstOperation.js +14 -19
- package/lib/queryBuilder/operations/FromOperation.js +69 -88
- package/lib/queryBuilder/operations/InsertAndFetchOperation.js +28 -39
- package/lib/queryBuilder/operations/InsertGraphAndFetchOperation.js +25 -35
- package/lib/queryBuilder/operations/InsertGraphOperation.js +77 -98
- package/lib/queryBuilder/operations/InsertOperation.js +132 -165
- package/lib/queryBuilder/operations/InstanceDeleteOperation.js +27 -36
- package/lib/queryBuilder/operations/InstanceFindOperation.js +9 -13
- package/lib/queryBuilder/operations/InstanceInsertOperation.js +13 -17
- package/lib/queryBuilder/operations/InstanceUpdateOperation.js +32 -46
- package/lib/queryBuilder/operations/JoinRelatedOperation.js +66 -86
- package/lib/queryBuilder/operations/KnexOperation.js +4 -7
- package/lib/queryBuilder/operations/MergeOperation.js +32 -45
- package/lib/queryBuilder/operations/ObjectionToKnexConvertingOperation.js +131 -150
- package/lib/queryBuilder/operations/OnBuildKnexOperation.js +17 -23
- package/lib/queryBuilder/operations/OnBuildOperation.js +17 -23
- package/lib/queryBuilder/operations/OnErrorOperation.js +17 -23
- package/lib/queryBuilder/operations/QueryBuilderOperation.js +231 -270
- package/lib/queryBuilder/operations/RangeOperation.js +30 -40
- package/lib/queryBuilder/operations/RelateOperation.js +14 -21
- package/lib/queryBuilder/operations/ReturningOperation.js +12 -18
- package/lib/queryBuilder/operations/RunAfterOperation.js +17 -23
- package/lib/queryBuilder/operations/RunBeforeOperation.js +17 -23
- package/lib/queryBuilder/operations/UnrelateOperation.js +12 -17
- package/lib/queryBuilder/operations/UpdateAndFetchOperation.js +48 -65
- package/lib/queryBuilder/operations/UpdateOperation.js +104 -129
- package/lib/queryBuilder/operations/UpsertGraphAndFetchOperation.js +25 -35
- package/lib/queryBuilder/operations/UpsertGraphOperation.js +36 -55
- package/lib/queryBuilder/operations/WhereCompositeOperation.js +30 -39
- package/lib/queryBuilder/operations/WhereInOperation.js +34 -36
- package/lib/queryBuilder/operations/eager/EagerOperation.js +37 -52
- package/lib/queryBuilder/operations/eager/JoinEagerOperation.js +34 -44
- package/lib/queryBuilder/operations/eager/NaiveEagerOperation.js +4 -7
- package/lib/queryBuilder/operations/eager/WhereInEagerOperation.js +193 -251
- package/lib/queryBuilder/operations/jsonApi/WhereJsonHasOperation.js +18 -25
- package/lib/queryBuilder/operations/jsonApi/WhereJsonNotObjectOperation.js +25 -41
- package/lib/queryBuilder/operations/jsonApi/WhereJsonOperation.js +19 -20
- package/lib/queryBuilder/operations/jsonApi/WhereJsonOverlapsOperation.js +23 -21
- package/lib/queryBuilder/operations/jsonApi/mysqlJsonApi.js +106 -118
- package/lib/queryBuilder/operations/jsonApi/postgresJsonApi.js +79 -108
- package/lib/queryBuilder/operations/select/SelectOperation.js +37 -53
- package/lib/queryBuilder/operations/select/Selection.js +94 -105
- package/lib/queryBuilder/operations/whereInComposite/WhereInCompositeMsSqlOperation.js +68 -101
- package/lib/queryBuilder/operations/whereInComposite/WhereInCompositeOperation.js +65 -75
- package/lib/queryBuilder/operations/whereInComposite/WhereInCompositeSqliteOperation.js +75 -84
- package/lib/queryBuilder/parsers/jsonFieldExpressionParser.js +760 -859
- package/lib/queryBuilder/parsers/relationExpressionParser.js +840 -952
- package/lib/queryBuilder/transformations/CompositeQueryTransformation.js +10 -15
- package/lib/queryBuilder/transformations/QueryTransformation.js +4 -6
- package/lib/queryBuilder/transformations/WrapMysqlModifySubqueryTransformation.js +35 -49
- package/lib/queryBuilder/transformations/index.js +3 -9
- package/lib/queryBuilder/whereScopes.js +158 -186
- package/lib/relations/Relation.js +293 -375
- package/lib/relations/RelationDeleteOperation.js +24 -28
- package/lib/relations/RelationFindOperation.js +108 -138
- package/lib/relations/RelationInsertOperation.js +24 -32
- package/lib/relations/RelationOwner.js +175 -209
- package/lib/relations/RelationProperty.js +186 -223
- package/lib/relations/RelationUpdateOperation.js +23 -29
- package/lib/relations/belongsToOne/BelongsToOneDeleteOperation.js +16 -21
- package/lib/relations/belongsToOne/BelongsToOneInsertOperation.js +30 -41
- package/lib/relations/belongsToOne/BelongsToOneRelateOperation.js +36 -47
- package/lib/relations/belongsToOne/BelongsToOneRelation.js +42 -50
- package/lib/relations/belongsToOne/BelongsToOneUnrelateOperation.js +43 -58
- package/lib/relations/hasMany/HasManyInsertOperation.js +40 -56
- package/lib/relations/hasMany/HasManyRelateOperation.js +45 -61
- package/lib/relations/hasMany/HasManyRelation.js +38 -46
- package/lib/relations/hasMany/HasManyUnrelateOperation.js +25 -32
- package/lib/relations/hasOne/HasOneRelation.js +9 -12
- package/lib/relations/hasOneThrough/HasOneThroughRelation.js +9 -12
- package/lib/relations/manyToMany/ManyToManyModifyMixin.js +73 -95
- package/lib/relations/manyToMany/ManyToManyRelation.js +374 -473
- package/lib/relations/manyToMany/ManyToManySqliteModifyMixin.js +23 -30
- package/lib/relations/manyToMany/delete/ManyToManyDeleteOperation.js +8 -10
- package/lib/relations/manyToMany/delete/ManyToManyDeleteOperationBase.js +20 -25
- package/lib/relations/manyToMany/delete/ManyToManyDeleteSqliteOperation.js +8 -12
- package/lib/relations/manyToMany/find/ManyToManyFindOperation.js +77 -100
- package/lib/relations/manyToMany/insert/ManyToManyInsertOperation.js +37 -49
- package/lib/relations/manyToMany/relate/ManyToManyRelateOperation.js +58 -74
- package/lib/relations/manyToMany/unrelate/ManyToManyUnrelateOperation.js +10 -13
- package/lib/relations/manyToMany/unrelate/ManyToManyUnrelateOperationBase.js +26 -33
- package/lib/relations/manyToMany/unrelate/ManyToManyUnrelateSqliteOperation.js +10 -15
- package/lib/relations/manyToMany/update/ManyToManyUpdateOperation.js +8 -10
- package/lib/relations/manyToMany/update/ManyToManyUpdateOperationBase.js +61 -78
- package/lib/relations/manyToMany/update/ManyToManyUpdateSqliteOperation.js +8 -12
- package/lib/transaction.js +53 -83
- package/lib/utils/assert.js +15 -21
- package/lib/utils/buildUtils.js +17 -19
- package/lib/utils/classUtils.js +7 -11
- package/lib/utils/cloneDeep.js +365 -0
- package/lib/utils/createModifier.js +36 -41
- package/lib/utils/deprecate.js +8 -12
- package/lib/utils/identifierMapping.js +153 -192
- package/lib/utils/internalPropUtils.js +4 -8
- package/lib/utils/knexUtils.js +61 -56
- package/lib/utils/mixin.js +16 -23
- package/lib/utils/mysqlJsonPath.js +55 -40
- package/lib/utils/normalizeIds.js +110 -127
- package/lib/utils/objectUtils.js +236 -338
- package/lib/utils/parseFieldExpression.js +66 -44
- package/lib/utils/postgresJsonPath.js +48 -62
- package/lib/utils/promiseUtils/after.js +10 -13
- package/lib/utils/promiseUtils/afterReturn.js +10 -13
- package/lib/utils/promiseUtils/index.js +15 -17
- package/lib/utils/promiseUtils/isPromise.js +6 -9
- package/lib/utils/promiseUtils/map.js +75 -89
- package/lib/utils/promiseUtils/mapAfterAllReturn.js +17 -23
- package/lib/utils/promiseUtils/try.js +15 -18
- package/lib/utils/resolveModel.js +91 -94
- package/lib/utils/tmpColumnUtils.js +4 -13
- package/package.json +50 -23
- package/typings/objection/index.d.mts +362 -0
- package/typings/objection/index.d.ts +36 -9
- package/lib/.eslintrc.json +0 -8
- package/lib/queryBuilder/parsers/jsonFieldExpressionParser.pegjs +0 -97
- package/lib/queryBuilder/parsers/relationExpressionParser.pegjs +0 -141
- package/lib/utils/clone.js +0 -2329
|
@@ -1,51 +1,73 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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.parseFieldExpression = parseFieldExpression;
|
|
37
|
+
const jsonFieldExpressionParser = __importStar(require("../queryBuilder/parsers/jsonFieldExpressionParser"));
|
|
4
38
|
const cache = new Map();
|
|
5
|
-
|
|
6
39
|
function parseFieldExpression(expr) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
return parsedExpr;
|
|
22
|
-
}
|
|
40
|
+
let parsedExpr = cache.get(expr);
|
|
41
|
+
if (parsedExpr !== undefined) {
|
|
42
|
+
return parsedExpr;
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
const parserOutput = jsonFieldExpressionParser.parse(expr);
|
|
46
|
+
parsedExpr = preprocessParsedExpression(parserOutput);
|
|
47
|
+
// We don't take a copy of the parsedExpr each time we
|
|
48
|
+
// use if from cache. Instead to make sure it's never
|
|
49
|
+
// mutated we deep-freeze it.
|
|
50
|
+
parsedExpr = freezeParsedExpr(parsedExpr);
|
|
51
|
+
cache.set(expr, parsedExpr);
|
|
52
|
+
return parsedExpr;
|
|
53
|
+
}
|
|
23
54
|
}
|
|
24
|
-
|
|
25
55
|
function preprocessParsedExpression(parsedExpr) {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
return parsedExpr;
|
|
56
|
+
const columnParts = parsedExpr.columnName.split('.').map((part) => part.trim());
|
|
57
|
+
parsedExpr.column = columnParts[columnParts.length - 1];
|
|
58
|
+
if (columnParts.length >= 2) {
|
|
59
|
+
parsedExpr.table = columnParts.slice(0, columnParts.length - 1).join('.');
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
parsedExpr.table = null;
|
|
63
|
+
}
|
|
64
|
+
return parsedExpr;
|
|
36
65
|
}
|
|
37
|
-
|
|
38
66
|
function freezeParsedExpr(parsedExpr) {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
return parsedExpr;
|
|
67
|
+
for (const access of parsedExpr.access) {
|
|
68
|
+
Object.freeze(access);
|
|
69
|
+
}
|
|
70
|
+
Object.freeze(parsedExpr.access);
|
|
71
|
+
Object.freeze(parsedExpr);
|
|
72
|
+
return parsedExpr;
|
|
47
73
|
}
|
|
48
|
-
|
|
49
|
-
module.exports = {
|
|
50
|
-
parseFieldExpression,
|
|
51
|
-
};
|
|
@@ -1,7 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.toPgTextArray = toPgTextArray;
|
|
4
|
+
exports.toPgStringLiteral = toPgStringLiteral;
|
|
5
|
+
exports.toPgJsonPathLiteral = toPgJsonPathLiteral;
|
|
6
|
+
exports.toPgQuotedColumn = toPgQuotedColumn;
|
|
7
|
+
exports.getJsonDialect = getJsonDialect;
|
|
8
|
+
const knexUtils_1 = require("./knexUtils");
|
|
5
9
|
// Characters that force an element of a postgres text array literal to be
|
|
6
10
|
// double quoted: the array syntax characters, whitespace and control chars.
|
|
7
11
|
const ARRAY_ELEMENT_NEEDS_QUOTES = /[{}",\\\s\x00-\x1f\x7f]|^$|^null$/i;
|
|
@@ -10,30 +14,26 @@ const ARRAY_ELEMENT_NEEDS_QUOTES = /[{}",\\\s\x00-\x1f\x7f]|^$|^null$/i;
|
|
|
10
14
|
const NEEDS_ESCAPE_STRING = /[\\\x00-\x1f\x7f]/;
|
|
11
15
|
const POSTGRES_DIALECTS = ['postgresql', 'redshift'];
|
|
12
16
|
const MYSQL_DIALECTS = ['mysql', 'mysql2'];
|
|
13
|
-
|
|
14
17
|
/**
|
|
15
18
|
* Converts the `access` part of a parsed field expression into a postgres
|
|
16
19
|
* text array literal like `{a,b,1}`. Elements are quoted and escaped so that
|
|
17
20
|
* keys containing array syntax characters can't change the path.
|
|
18
21
|
*/
|
|
19
22
|
function toPgTextArray(access) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
return `{${elements.join(',')}}`;
|
|
23
|
+
const elements = access.map((it) => {
|
|
24
|
+
if (it.type === 'array' && Number.isInteger(it.ref)) {
|
|
25
|
+
return String(it.ref);
|
|
26
|
+
}
|
|
27
|
+
const ref = String(it.ref);
|
|
28
|
+
if (ARRAY_ELEMENT_NEEDS_QUOTES.test(ref)) {
|
|
29
|
+
return `"${ref.replace(/[\\"]/g, '\\$&')}"`;
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
return ref;
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
return `{${elements.join(',')}}`;
|
|
35
36
|
}
|
|
36
|
-
|
|
37
37
|
/**
|
|
38
38
|
* Converts a string into a postgres string literal that is safe to embed
|
|
39
39
|
* into a knex raw query. Single quotes are doubled and `?` characters are
|
|
@@ -45,42 +45,37 @@ function toPgTextArray(access) {
|
|
|
45
45
|
* backslash ever ends up next to a `?` (knex would eat it).
|
|
46
46
|
*/
|
|
47
47
|
function toPgStringLiteral(str) {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
return sql.replace(/\?/g, '\\?');
|
|
48
|
+
let sql = str.replace(/'/g, "''");
|
|
49
|
+
if (NEEDS_ESCAPE_STRING.test(sql)) {
|
|
50
|
+
sql = sql.replace(/[\\\x00-\x1f\x7f]/g, (char) => {
|
|
51
|
+
return '\\' + char.charCodeAt(0).toString(8).padStart(3, '0');
|
|
52
|
+
});
|
|
53
|
+
sql = `E'${sql}'`;
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
sql = `'${sql}'`;
|
|
57
|
+
}
|
|
58
|
+
return sql.replace(/\?/g, '\\?');
|
|
61
59
|
}
|
|
62
|
-
|
|
63
60
|
/**
|
|
64
61
|
* Converts the `access` part of a parsed field expression into a string
|
|
65
62
|
* literal that can be used as the right hand side of `#>`, `#>>` and as the
|
|
66
63
|
* path argument of `jsonb_set`.
|
|
67
64
|
*/
|
|
68
65
|
function toPgJsonPathLiteral(access) {
|
|
69
|
-
|
|
66
|
+
return toPgStringLiteral(toPgTextArray(access));
|
|
70
67
|
}
|
|
71
|
-
|
|
72
68
|
/**
|
|
73
69
|
* Quotes a (possibly table qualified) column name like `Table.column` as
|
|
74
70
|
* `"Table"."column"` for postgres.
|
|
75
71
|
*/
|
|
76
72
|
function toPgQuotedColumn(columnName) {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
73
|
+
return columnName
|
|
74
|
+
.split('.')
|
|
75
|
+
.map((part) => `"${part.replace(/"/g, '""')}"`)
|
|
76
|
+
.join('.')
|
|
77
|
+
.replace(/\?/g, '\\?');
|
|
82
78
|
}
|
|
83
|
-
|
|
84
79
|
/**
|
|
85
80
|
* Returns the flavor of JSON SQL to generate for field expressions: `'postgres'`
|
|
86
81
|
* or `'mysql'`. Other databases throw, since postgres SQL is invalid at best and
|
|
@@ -88,23 +83,14 @@ function toPgQuotedColumn(columnName) {
|
|
|
88
83
|
* when the query has no knex instance bound yet, in which case postgres is used.
|
|
89
84
|
*/
|
|
90
85
|
function getJsonDialect(knex, expression) {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
}
|
|
86
|
+
const dialect = knex ? (0, knexUtils_1.getDialect)(knex) : null;
|
|
87
|
+
if (dialect === null || POSTGRES_DIALECTS.includes(dialect)) {
|
|
88
|
+
return 'postgres';
|
|
89
|
+
}
|
|
90
|
+
else if (MYSQL_DIALECTS.includes(dialect)) {
|
|
91
|
+
return 'mysql';
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
throw new Error(`JSON field expressions are only supported on postgres and mysql. Tried to use "${expression}" with dialect "${dialect}".`);
|
|
95
|
+
}
|
|
102
96
|
}
|
|
103
|
-
|
|
104
|
-
module.exports = {
|
|
105
|
-
toPgTextArray,
|
|
106
|
-
toPgStringLiteral,
|
|
107
|
-
toPgJsonPathLiteral,
|
|
108
|
-
toPgQuotedColumn,
|
|
109
|
-
getJsonDialect,
|
|
110
|
-
};
|
|
@@ -1,17 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.after = after;
|
|
4
|
+
const isPromise_1 = require("./isPromise");
|
|
5
5
|
// Call `func` after `obj` has been resolved. Call `func` synchronously if
|
|
6
6
|
// `obj` is not a promise for performance reasons.
|
|
7
7
|
function after(obj, func) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
8
|
+
if ((0, isPromise_1.isPromise)(obj)) {
|
|
9
|
+
return obj.then(func);
|
|
10
|
+
}
|
|
11
|
+
else {
|
|
12
|
+
return func(obj);
|
|
13
|
+
}
|
|
13
14
|
}
|
|
14
|
-
|
|
15
|
-
module.exports = {
|
|
16
|
-
after,
|
|
17
|
-
};
|
|
@@ -1,17 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.afterReturn = afterReturn;
|
|
4
|
+
const isPromise_1 = require("./isPromise");
|
|
5
5
|
// Return `returnValue` after `obj` has been resolved. Return `returnValue`
|
|
6
6
|
// synchronously if `obj` is not a promise for performance reasons.
|
|
7
7
|
function afterReturn(obj, returnValue) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
8
|
+
if ((0, isPromise_1.isPromise)(obj)) {
|
|
9
|
+
return obj.then(() => returnValue);
|
|
10
|
+
}
|
|
11
|
+
else {
|
|
12
|
+
return returnValue;
|
|
13
|
+
}
|
|
13
14
|
}
|
|
14
|
-
|
|
15
|
-
module.exports = {
|
|
16
|
-
afterReturn,
|
|
17
|
-
};
|
|
@@ -1,17 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
try: promiseTry,
|
|
17
|
-
};
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.try = exports.map = exports.mapAfterAllReturn = exports.afterReturn = exports.after = exports.isPromise = void 0;
|
|
4
|
+
const isPromise_1 = require("./isPromise");
|
|
5
|
+
Object.defineProperty(exports, "isPromise", { enumerable: true, get: function () { return isPromise_1.isPromise; } });
|
|
6
|
+
const after_1 = require("./after");
|
|
7
|
+
Object.defineProperty(exports, "after", { enumerable: true, get: function () { return after_1.after; } });
|
|
8
|
+
const afterReturn_1 = require("./afterReturn");
|
|
9
|
+
Object.defineProperty(exports, "afterReturn", { enumerable: true, get: function () { return afterReturn_1.afterReturn; } });
|
|
10
|
+
const mapAfterAllReturn_1 = require("./mapAfterAllReturn");
|
|
11
|
+
Object.defineProperty(exports, "mapAfterAllReturn", { enumerable: true, get: function () { return mapAfterAllReturn_1.mapAfterAllReturn; } });
|
|
12
|
+
const map_1 = require("./map");
|
|
13
|
+
Object.defineProperty(exports, "map", { enumerable: true, get: function () { return map_1.promiseMap; } });
|
|
14
|
+
const try_1 = require("./try");
|
|
15
|
+
Object.defineProperty(exports, "try", { enumerable: true, get: function () { return try_1.promiseTry; } });
|
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isPromise = isPromise;
|
|
4
|
+
const objectUtils_1 = require("../objectUtils");
|
|
5
|
+
// The `T &` keeps an `any` argument `any`.
|
|
5
6
|
function isPromise(obj) {
|
|
6
|
-
|
|
7
|
+
return (0, objectUtils_1.isObject)(obj) && (0, objectUtils_1.isFunction)(obj.then);
|
|
7
8
|
}
|
|
8
|
-
|
|
9
|
-
module.exports = {
|
|
10
|
-
isPromise,
|
|
11
|
-
};
|
|
@@ -1,110 +1,96 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.promiseMap = promiseMap;
|
|
4
|
+
const isPromise_1 = require("./isPromise");
|
|
5
5
|
// Works like Bluebird.map.
|
|
6
6
|
function promiseMap(items, mapper, opt) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
7
|
+
switch (items.length) {
|
|
8
|
+
case 0:
|
|
9
|
+
return mapZero();
|
|
10
|
+
case 1:
|
|
11
|
+
return mapOne(items, mapper);
|
|
12
|
+
default:
|
|
13
|
+
return mapMany(items, mapper, opt);
|
|
14
|
+
}
|
|
15
15
|
}
|
|
16
|
-
|
|
17
16
|
function mapZero() {
|
|
18
|
-
|
|
17
|
+
return Promise.resolve([]);
|
|
19
18
|
}
|
|
20
|
-
|
|
21
19
|
function mapOne(items, mapper) {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
20
|
+
try {
|
|
21
|
+
const maybePromise = mapper(items[0], 0);
|
|
22
|
+
if ((0, isPromise_1.isPromise)(maybePromise)) {
|
|
23
|
+
return maybePromise.then(wrapArray);
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
return Promise.resolve(wrapArray(maybePromise));
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
catch (err) {
|
|
30
|
+
return Promise.reject(err);
|
|
29
31
|
}
|
|
30
|
-
} catch (err) {
|
|
31
|
-
return Promise.reject(err);
|
|
32
|
-
}
|
|
33
32
|
}
|
|
34
|
-
|
|
35
33
|
function wrapArray(item) {
|
|
36
|
-
|
|
34
|
+
return [item];
|
|
37
35
|
}
|
|
38
|
-
|
|
39
36
|
function mapMany(items, mapper, opt = {}) {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
}
|
|
57
|
-
});
|
|
37
|
+
return new Promise((resolve, reject) => {
|
|
38
|
+
const concurrency = opt.concurrency || Number.MAX_SAFE_INTEGER;
|
|
39
|
+
const ctx = {
|
|
40
|
+
reject,
|
|
41
|
+
resolve,
|
|
42
|
+
rejected: false,
|
|
43
|
+
index: 0,
|
|
44
|
+
numFinished: 0,
|
|
45
|
+
results: new Array(items.length),
|
|
46
|
+
items,
|
|
47
|
+
mapper,
|
|
48
|
+
};
|
|
49
|
+
while (ctx.index < concurrency && ctx.index < items.length && !ctx.rejected) {
|
|
50
|
+
executeNext(ctx);
|
|
51
|
+
}
|
|
52
|
+
});
|
|
58
53
|
}
|
|
59
|
-
|
|
60
54
|
function executeNext(ctx) {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
55
|
+
try {
|
|
56
|
+
if (ctx.rejected) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
const index = ctx.index++;
|
|
60
|
+
const item = ctx.items[index];
|
|
61
|
+
const maybePromise = ctx.mapper(item, index);
|
|
62
|
+
if ((0, isPromise_1.isPromise)(maybePromise)) {
|
|
63
|
+
// `catch` is called on the result of `then`, so the value is used as a
|
|
64
|
+
// promise. Promises and query builders have both.
|
|
65
|
+
maybePromise
|
|
66
|
+
.then((result) => afterExecute(ctx, result, index))
|
|
67
|
+
.catch((err) => onError(ctx, err));
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
process.nextTick(() => afterExecute(ctx, maybePromise, index));
|
|
71
|
+
}
|
|
72
|
+
return null;
|
|
64
73
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
const maybePromise = ctx.mapper(item, index);
|
|
69
|
-
|
|
70
|
-
if (isPromise(maybePromise)) {
|
|
71
|
-
maybePromise
|
|
72
|
-
.then((result) => afterExecute(ctx, result, index))
|
|
73
|
-
.catch((err) => onError(ctx, err));
|
|
74
|
-
} else {
|
|
75
|
-
process.nextTick(() => afterExecute(ctx, maybePromise, index));
|
|
74
|
+
catch (err) {
|
|
75
|
+
onError(ctx, err);
|
|
76
|
+
return undefined;
|
|
76
77
|
}
|
|
77
|
-
|
|
78
|
-
return null;
|
|
79
|
-
} catch (err) {
|
|
80
|
-
onError(ctx, err);
|
|
81
|
-
}
|
|
82
78
|
}
|
|
83
|
-
|
|
84
79
|
function afterExecute(ctx, result, index) {
|
|
85
|
-
|
|
80
|
+
if (ctx.rejected) {
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
ctx.results[index] = result;
|
|
84
|
+
ctx.numFinished++;
|
|
85
|
+
if (ctx.numFinished === ctx.items.length) {
|
|
86
|
+
ctx.resolve(ctx.results);
|
|
87
|
+
}
|
|
88
|
+
if (ctx.index < ctx.items.length) {
|
|
89
|
+
executeNext(ctx);
|
|
90
|
+
}
|
|
86
91
|
return null;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
ctx.results[index] = result;
|
|
90
|
-
ctx.numFinished++;
|
|
91
|
-
|
|
92
|
-
if (ctx.numFinished === ctx.items.length) {
|
|
93
|
-
ctx.resolve(ctx.results);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
if (ctx.index < ctx.items.length) {
|
|
97
|
-
executeNext(ctx);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
return null;
|
|
101
92
|
}
|
|
102
|
-
|
|
103
93
|
function onError(ctx, err) {
|
|
104
|
-
|
|
105
|
-
|
|
94
|
+
ctx.rejected = true;
|
|
95
|
+
ctx.reject(err);
|
|
106
96
|
}
|
|
107
|
-
|
|
108
|
-
module.exports = {
|
|
109
|
-
promiseMap,
|
|
110
|
-
};
|
|
@@ -1,29 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.mapAfterAllReturn = mapAfterAllReturn;
|
|
4
|
+
const isPromise_1 = require("./isPromise");
|
|
5
5
|
// Map `arr` with `mapper` and after that return `returnValue`. If none of
|
|
6
6
|
// the mapped values is a promise, return synchronously for performance
|
|
7
7
|
// reasons.
|
|
8
8
|
function mapAfterAllReturn(arr, mapper, returnValue) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
9
|
+
const results = new Array(arr.length);
|
|
10
|
+
let containsPromise = false;
|
|
11
|
+
for (let i = 0, l = arr.length; i < l; ++i) {
|
|
12
|
+
results[i] = mapper(arr[i]);
|
|
13
|
+
if ((0, isPromise_1.isPromise)(results[i])) {
|
|
14
|
+
containsPromise = true;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
if (containsPromise) {
|
|
18
|
+
return Promise.all(results).then(() => returnValue);
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
return returnValue;
|
|
17
22
|
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
if (containsPromise) {
|
|
21
|
-
return Promise.all(results).then(() => returnValue);
|
|
22
|
-
} else {
|
|
23
|
-
return returnValue;
|
|
24
|
-
}
|
|
25
23
|
}
|
|
26
|
-
|
|
27
|
-
module.exports = {
|
|
28
|
-
mapAfterAllReturn,
|
|
29
|
-
};
|
|
@@ -1,22 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.promiseTry = promiseTry;
|
|
4
|
+
const isPromise_1 = require("./isPromise");
|
|
5
5
|
// Works like Bluebird.try.
|
|
6
6
|
function promiseTry(callback) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
7
|
+
try {
|
|
8
|
+
const maybePromise = callback();
|
|
9
|
+
if ((0, isPromise_1.isPromise)(maybePromise)) {
|
|
10
|
+
return maybePromise;
|
|
11
|
+
}
|
|
12
|
+
else {
|
|
13
|
+
return Promise.resolve(maybePromise);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
catch (err) {
|
|
17
|
+
return Promise.reject(err);
|
|
14
18
|
}
|
|
15
|
-
} catch (err) {
|
|
16
|
-
return Promise.reject(err);
|
|
17
|
-
}
|
|
18
19
|
}
|
|
19
|
-
|
|
20
|
-
module.exports = {
|
|
21
|
-
promiseTry,
|
|
22
|
-
};
|