@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,227 +1,188 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.snakeCaseKeys = exports.camelCaseKeys = void 0;
|
|
4
|
+
exports.snakeCase = snakeCase;
|
|
5
|
+
exports.camelCase = camelCase;
|
|
6
|
+
exports.snakeCaseMappers = snakeCaseMappers;
|
|
7
|
+
exports.knexSnakeCaseMappers = knexSnakeCaseMappers;
|
|
8
|
+
exports.knexIdentifierMappers = knexIdentifierMappers;
|
|
9
|
+
exports.knexIdentifierMapping = knexIdentifierMapping;
|
|
10
|
+
const objectUtils_1 = require("./objectUtils");
|
|
5
11
|
// Super fast memoize for single argument functions.
|
|
6
12
|
function memoize(func) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
return output;
|
|
18
|
-
};
|
|
13
|
+
const cache = new Map();
|
|
14
|
+
return (input) => {
|
|
15
|
+
let output = cache.get(input);
|
|
16
|
+
if (output === undefined) {
|
|
17
|
+
output = func(input);
|
|
18
|
+
cache.set(input, output);
|
|
19
|
+
}
|
|
20
|
+
return output;
|
|
21
|
+
};
|
|
19
22
|
}
|
|
20
|
-
|
|
21
23
|
// camelCase to snake_case converter that also works with non-ascii characters
|
|
22
24
|
// This is needed especially so that aliases containing the `:` character,
|
|
23
25
|
// objection uses internally, work.
|
|
24
|
-
function snakeCase(
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
upperCase = false,
|
|
28
|
-
underscoreBeforeDigits = false,
|
|
29
|
-
underscoreBetweenUppercaseLetters = false,
|
|
30
|
-
} = {},
|
|
31
|
-
) {
|
|
32
|
-
if (str.length === 0) {
|
|
33
|
-
return str;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
const upper = str.toUpperCase();
|
|
37
|
-
const lower = str.toLowerCase();
|
|
38
|
-
|
|
39
|
-
let out = lower[0];
|
|
40
|
-
|
|
41
|
-
for (let i = 1, l = str.length; i < l; ++i) {
|
|
42
|
-
const char = str[i];
|
|
43
|
-
const prevChar = str[i - 1];
|
|
44
|
-
|
|
45
|
-
const upperChar = upper[i];
|
|
46
|
-
const prevUpperChar = upper[i - 1];
|
|
47
|
-
|
|
48
|
-
const lowerChar = lower[i];
|
|
49
|
-
const prevLowerChar = lower[i - 1];
|
|
50
|
-
|
|
51
|
-
// If underScoreBeforeDigits is true then, well, insert an underscore
|
|
52
|
-
// before digits :). Only the first digit gets an underscore if
|
|
53
|
-
// there are multiple.
|
|
54
|
-
if (underscoreBeforeDigits && isDigit(char) && !isDigit(prevChar)) {
|
|
55
|
-
out += '_' + char;
|
|
56
|
-
continue;
|
|
26
|
+
function snakeCase(str, { upperCase = false, underscoreBeforeDigits = false, underscoreBetweenUppercaseLetters = false, } = {}) {
|
|
27
|
+
if (str.length === 0) {
|
|
28
|
+
return str;
|
|
57
29
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
prevChar
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
30
|
+
const upper = str.toUpperCase();
|
|
31
|
+
const lower = str.toLowerCase();
|
|
32
|
+
let out = lower[0];
|
|
33
|
+
for (let i = 1, l = str.length; i < l; ++i) {
|
|
34
|
+
const char = str[i];
|
|
35
|
+
const prevChar = str[i - 1];
|
|
36
|
+
const upperChar = upper[i];
|
|
37
|
+
const prevUpperChar = upper[i - 1];
|
|
38
|
+
const lowerChar = lower[i];
|
|
39
|
+
const prevLowerChar = lower[i - 1];
|
|
40
|
+
// If underScoreBeforeDigits is true then, well, insert an underscore
|
|
41
|
+
// before digits :). Only the first digit gets an underscore if
|
|
42
|
+
// there are multiple.
|
|
43
|
+
if (underscoreBeforeDigits && isDigit(char) && !isDigit(prevChar)) {
|
|
44
|
+
out += '_' + char;
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
// Test if `char` is an upper-case character and that the character
|
|
48
|
+
// actually has different upper and lower case versions.
|
|
49
|
+
if (char === upperChar && upperChar !== lowerChar) {
|
|
50
|
+
const prevCharacterIsUppercase = prevChar === prevUpperChar && prevUpperChar !== prevLowerChar;
|
|
51
|
+
// If underscoreBetweenUppercaseLetters is true, we always place an underscore
|
|
52
|
+
// before consecutive uppercase letters (e.g. "fooBAR" becomes "foo_b_a_r").
|
|
53
|
+
// Otherwise, we don't (e.g. "fooBAR" becomes "foo_bar").
|
|
54
|
+
if (underscoreBetweenUppercaseLetters || !prevCharacterIsUppercase) {
|
|
55
|
+
out += '_' + lowerChar;
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
out += lowerChar;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
out += char;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
if (upperCase) {
|
|
66
|
+
return out.toUpperCase();
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
return out;
|
|
75
70
|
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
if (upperCase) {
|
|
79
|
-
return out.toUpperCase();
|
|
80
|
-
} else {
|
|
81
|
-
return out;
|
|
82
|
-
}
|
|
83
71
|
}
|
|
84
|
-
|
|
85
72
|
// snake_case to camelCase converter that simply reverses
|
|
86
73
|
// the actions done by `snakeCase` function.
|
|
87
74
|
function camelCase(str, { upperCase = false } = {}) {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
if (upperCase && isAllUpperCaseSnakeCase(str)) {
|
|
93
|
-
// Only convert to lower case if the string is all upper
|
|
94
|
-
// case snake_case. This allowes camelCase strings to go
|
|
95
|
-
// through without changing.
|
|
96
|
-
str = str.toLowerCase();
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
let out = str[0];
|
|
100
|
-
|
|
101
|
-
for (let i = 1, l = str.length; i < l; ++i) {
|
|
102
|
-
const char = str[i];
|
|
103
|
-
const prevChar = str[i - 1];
|
|
104
|
-
|
|
105
|
-
if (char !== '_') {
|
|
106
|
-
if (prevChar === '_') {
|
|
107
|
-
out += char.toUpperCase();
|
|
108
|
-
} else {
|
|
109
|
-
out += char;
|
|
110
|
-
}
|
|
75
|
+
if (str.length === 0) {
|
|
76
|
+
return str;
|
|
111
77
|
}
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
78
|
+
if (upperCase && isAllUpperCaseSnakeCase(str)) {
|
|
79
|
+
// Only convert to lower case if the string is all upper
|
|
80
|
+
// case snake_case. This allowes camelCase strings to go
|
|
81
|
+
// through without changing.
|
|
82
|
+
str = str.toLowerCase();
|
|
83
|
+
}
|
|
84
|
+
let out = str[0];
|
|
85
|
+
for (let i = 1, l = str.length; i < l; ++i) {
|
|
86
|
+
const char = str[i];
|
|
87
|
+
const prevChar = str[i - 1];
|
|
88
|
+
if (char !== '_') {
|
|
89
|
+
if (prevChar === '_') {
|
|
90
|
+
out += char.toUpperCase();
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
out += char;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return out;
|
|
115
98
|
}
|
|
116
|
-
|
|
117
99
|
function isAllUpperCaseSnakeCase(str) {
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
100
|
+
for (let i = 1, l = str.length; i < l; ++i) {
|
|
101
|
+
const char = str[i];
|
|
102
|
+
if (char !== '_' && char !== char.toUpperCase()) {
|
|
103
|
+
return false;
|
|
104
|
+
}
|
|
123
105
|
}
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
return true;
|
|
106
|
+
return true;
|
|
127
107
|
}
|
|
128
|
-
|
|
129
108
|
function isDigit(char) {
|
|
130
|
-
|
|
109
|
+
return char >= '0' && char <= '9';
|
|
131
110
|
}
|
|
132
|
-
|
|
133
111
|
// Returns a function that splits the inputs string into pieces using `separator`,
|
|
134
112
|
// only calls `mapper` for the last part and concatenates the string back together.
|
|
135
113
|
// If no separators are found, `mapper` is called for the entire string.
|
|
136
114
|
function mapLastPart(mapper, separator) {
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
115
|
+
return (str) => {
|
|
116
|
+
if (!str)
|
|
117
|
+
return str;
|
|
118
|
+
const idx = str.lastIndexOf(separator);
|
|
119
|
+
const mapped = mapper(str.slice(idx + separator.length));
|
|
120
|
+
return str.slice(0, idx + separator.length) + mapped;
|
|
121
|
+
};
|
|
143
122
|
}
|
|
144
|
-
|
|
145
123
|
// Returns a function that takes an object as an input and maps the object's keys
|
|
146
124
|
// using `mapper`. If the input is not an object, the input is returned unchanged.
|
|
147
125
|
function keyMapper(mapper) {
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
return out;
|
|
162
|
-
};
|
|
126
|
+
return (obj) => {
|
|
127
|
+
if (!(0, objectUtils_1.isObject)(obj) || Array.isArray(obj)) {
|
|
128
|
+
return obj;
|
|
129
|
+
}
|
|
130
|
+
const keys = Object.keys(obj);
|
|
131
|
+
const out = {};
|
|
132
|
+
for (let i = 0, l = keys.length; i < l; ++i) {
|
|
133
|
+
const key = keys[i];
|
|
134
|
+
out[mapper(key)] = obj[key];
|
|
135
|
+
}
|
|
136
|
+
return out;
|
|
137
|
+
};
|
|
163
138
|
}
|
|
164
|
-
|
|
165
139
|
function snakeCaseMappers(opt = {}) {
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
140
|
+
return {
|
|
141
|
+
parse: keyMapper(memoize((str) => camelCase(str, opt))),
|
|
142
|
+
format: keyMapper(memoize((str) => snakeCase(str, opt))),
|
|
143
|
+
};
|
|
170
144
|
}
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
},
|
|
195
|
-
};
|
|
145
|
+
function knexIdentifierMappers({ parse, format, idSeparator = ':', } = {}) {
|
|
146
|
+
// Without `parse` or `format`, the mappers throw when they're used, as they
|
|
147
|
+
// did in the JavaScript code.
|
|
148
|
+
const formatId = memoize(mapLastPart(format, idSeparator));
|
|
149
|
+
const parseId = memoize(mapLastPart(parse, idSeparator));
|
|
150
|
+
const parseKeys = keyMapper(parseId);
|
|
151
|
+
return {
|
|
152
|
+
wrapIdentifier(identifier, origWrap) {
|
|
153
|
+
return origWrap(formatId(identifier));
|
|
154
|
+
},
|
|
155
|
+
postProcessResponse(result) {
|
|
156
|
+
if (Array.isArray(result)) {
|
|
157
|
+
const output = new Array(result.length);
|
|
158
|
+
for (let i = 0, l = result.length; i < l; ++i) {
|
|
159
|
+
output[i] = parseKeys(result[i]);
|
|
160
|
+
}
|
|
161
|
+
return output;
|
|
162
|
+
}
|
|
163
|
+
else {
|
|
164
|
+
return parseKeys(result);
|
|
165
|
+
}
|
|
166
|
+
},
|
|
167
|
+
};
|
|
196
168
|
}
|
|
197
|
-
|
|
198
169
|
function knexSnakeCaseMappers(opt = {}) {
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
170
|
+
return knexIdentifierMappers({
|
|
171
|
+
parse: (str) => camelCase(str, opt),
|
|
172
|
+
format: (str) => snakeCase(str, opt),
|
|
173
|
+
});
|
|
203
174
|
}
|
|
204
|
-
|
|
205
175
|
function knexIdentifierMapping(colToProp) {
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
});
|
|
176
|
+
const propToCol = Object.keys(colToProp).reduce((propToCol, column) => {
|
|
177
|
+
propToCol[colToProp[column]] = column;
|
|
178
|
+
return propToCol;
|
|
179
|
+
}, {});
|
|
180
|
+
return knexIdentifierMappers({
|
|
181
|
+
parse: (column) => colToProp[column] || column,
|
|
182
|
+
format: (prop) => propToCol[prop] || prop,
|
|
183
|
+
});
|
|
215
184
|
}
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
snakeCaseMappers,
|
|
221
|
-
knexSnakeCaseMappers,
|
|
222
|
-
knexIdentifierMappers,
|
|
223
|
-
knexIdentifierMapping,
|
|
224
|
-
|
|
225
|
-
camelCaseKeys: keyMapper(memoize(camelCase)),
|
|
226
|
-
snakeCaseKeys: keyMapper(memoize(snakeCase)),
|
|
227
|
-
};
|
|
185
|
+
const camelCaseKeys = keyMapper(memoize(camelCase));
|
|
186
|
+
exports.camelCaseKeys = camelCaseKeys;
|
|
187
|
+
const snakeCaseKeys = keyMapper(memoize(snakeCase));
|
|
188
|
+
exports.snakeCaseKeys = snakeCaseKeys;
|
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isInternalProp = isInternalProp;
|
|
3
4
|
const INTERNAL_PROP_PREFIX = '$';
|
|
4
|
-
|
|
5
5
|
function isInternalProp(propName) {
|
|
6
|
-
|
|
6
|
+
return propName[0] === INTERNAL_PROP_PREFIX;
|
|
7
7
|
}
|
|
8
|
-
|
|
9
|
-
module.exports = {
|
|
10
|
-
isInternalProp,
|
|
11
|
-
};
|
package/lib/utils/knexUtils.js
CHANGED
|
@@ -1,76 +1,81 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getDialect = getDialect;
|
|
4
|
+
exports.isPostgres = isPostgres;
|
|
5
|
+
exports.isMySql = isMySql;
|
|
6
|
+
exports.isMariaDb = isMariaDb;
|
|
7
|
+
exports.getMariaDbVersion = getMariaDbVersion;
|
|
8
|
+
exports.isSqlite = isSqlite;
|
|
9
|
+
exports.isMsSql = isMsSql;
|
|
10
|
+
exports.isOracle = isOracle;
|
|
11
|
+
exports.isKnexQueryBuilder = isKnexQueryBuilder;
|
|
12
|
+
exports.isKnexJoinBuilder = isKnexJoinBuilder;
|
|
13
|
+
exports.isKnexRaw = isKnexRaw;
|
|
14
|
+
const objectUtils_1 = require("../utils/objectUtils");
|
|
5
15
|
function getDialect(knex) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
null
|
|
14
|
-
);
|
|
16
|
+
const type = typeof knex;
|
|
17
|
+
const knexLike = knex;
|
|
18
|
+
return ((knex !== null &&
|
|
19
|
+
(type === 'object' || type === 'function') &&
|
|
20
|
+
knexLike.client &&
|
|
21
|
+
knexLike.client.dialect) ||
|
|
22
|
+
null);
|
|
15
23
|
}
|
|
16
|
-
|
|
17
24
|
function isPostgres(knex) {
|
|
18
|
-
|
|
25
|
+
return getDialect(knex) === 'postgresql';
|
|
19
26
|
}
|
|
20
|
-
|
|
21
27
|
function isOracle(knex) {
|
|
22
|
-
|
|
23
|
-
|
|
28
|
+
const dialect = getDialect(knex);
|
|
29
|
+
return dialect === 'oracledb';
|
|
24
30
|
}
|
|
25
|
-
|
|
26
31
|
function isMySql(knex) {
|
|
27
|
-
|
|
28
|
-
|
|
32
|
+
const dialect = getDialect(knex);
|
|
33
|
+
return dialect === 'mysql' || dialect === 'mysql2';
|
|
34
|
+
}
|
|
35
|
+
// knex reports MariaDB as the `mysql` dialect. It's recognized from knex's
|
|
36
|
+
// `mariadb` client, or from a `version` like '11.4.0-MariaDB' in the knex config
|
|
37
|
+
// when the mysql2 driver is used. knex finds out about MariaDB itself only
|
|
38
|
+
// after connecting, which would build the first queries differently than the
|
|
39
|
+
// later ones, so that isn't used.
|
|
40
|
+
function isMariaDb(knex) {
|
|
41
|
+
if (!isMySql(knex)) {
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
// isMySql() returned true, so the client exists.
|
|
45
|
+
const client = knex.client;
|
|
46
|
+
return client.driverName === 'mariadb' || /mariadb/i.test(configVersion(client));
|
|
47
|
+
}
|
|
48
|
+
// The MariaDB version as [major, minor], when it's known from the knex config.
|
|
49
|
+
function getMariaDbVersion(knex) {
|
|
50
|
+
if (!isMariaDb(knex)) {
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
const match = /^(\d+)\.(\d+)/.exec(configVersion(knex.client));
|
|
54
|
+
return match ? [Number(match[1]), Number(match[2])] : null;
|
|
55
|
+
}
|
|
56
|
+
function configVersion(client) {
|
|
57
|
+
const version = client.config && client.config.version;
|
|
58
|
+
return typeof version === 'string' ? version : '';
|
|
29
59
|
}
|
|
30
|
-
|
|
31
60
|
function isSqlite(knex) {
|
|
32
|
-
|
|
61
|
+
return getDialect(knex) === 'sqlite3';
|
|
33
62
|
}
|
|
34
|
-
|
|
35
63
|
function isMsSql(knex) {
|
|
36
|
-
|
|
64
|
+
return getDialect(knex) === 'mssql';
|
|
37
65
|
}
|
|
38
|
-
|
|
39
66
|
function isKnexQueryBuilder(value) {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
'client' in value
|
|
46
|
-
);
|
|
67
|
+
return (hasConstructor(value) &&
|
|
68
|
+
(0, objectUtils_1.isFunction)(value.select) &&
|
|
69
|
+
(0, objectUtils_1.isFunction)(value.column) &&
|
|
70
|
+
value.select === value.column &&
|
|
71
|
+
'client' in value);
|
|
47
72
|
}
|
|
48
|
-
|
|
49
73
|
function isKnexJoinBuilder(value) {
|
|
50
|
-
|
|
74
|
+
return hasConstructor(value) && value.grouping === 'join' && 'joinType' in value;
|
|
51
75
|
}
|
|
52
|
-
|
|
53
76
|
function isKnexRaw(value) {
|
|
54
|
-
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
function isKnexTransaction(knex) {
|
|
58
|
-
return !!getDialect(knex) && isFunction(knex.commit) && isFunction(knex.rollback);
|
|
77
|
+
return hasConstructor(value) && value.isRawInstance && 'client' in value;
|
|
59
78
|
}
|
|
60
|
-
|
|
61
79
|
function hasConstructor(value) {
|
|
62
|
-
|
|
80
|
+
return (0, objectUtils_1.isObject)(value) && (0, objectUtils_1.isFunction)(value.constructor);
|
|
63
81
|
}
|
|
64
|
-
|
|
65
|
-
module.exports = {
|
|
66
|
-
getDialect,
|
|
67
|
-
isPostgres,
|
|
68
|
-
isMySql,
|
|
69
|
-
isSqlite,
|
|
70
|
-
isMsSql,
|
|
71
|
-
isOracle,
|
|
72
|
-
isKnexQueryBuilder,
|
|
73
|
-
isKnexJoinBuilder,
|
|
74
|
-
isKnexRaw,
|
|
75
|
-
isKnexTransaction,
|
|
76
|
-
};
|
package/lib/utils/mixin.js
CHANGED
|
@@ -1,25 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.compose = compose;
|
|
4
|
+
exports.mixin = mixin;
|
|
5
|
+
const objectUtils_1 = require("./objectUtils");
|
|
6
|
+
function mixin(...mixinArgs) {
|
|
7
|
+
const args = (0, objectUtils_1.flatten)(mixinArgs);
|
|
8
|
+
const mixins = args.slice(1);
|
|
9
|
+
return mixins.reduce((Class, mixinFunc) => {
|
|
10
|
+
return mixinFunc(Class);
|
|
11
|
+
}, args[0]);
|
|
12
12
|
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
return mixin(Class, mixins);
|
|
19
|
-
};
|
|
13
|
+
function compose(...composeArgs) {
|
|
14
|
+
const mixins = (0, objectUtils_1.flatten)(composeArgs);
|
|
15
|
+
return function (Class) {
|
|
16
|
+
return mixin(Class, mixins);
|
|
17
|
+
};
|
|
20
18
|
}
|
|
21
|
-
|
|
22
|
-
module.exports = {
|
|
23
|
-
compose,
|
|
24
|
-
mixin,
|
|
25
|
-
};
|