@abedmurrar/objection 0.0.0-stage → 4.0.0-alpha.0
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/LICENSE +23 -0
- package/README.md +69 -2
- package/lib/.eslintrc.json +8 -0
- package/lib/initialize.js +14 -0
- package/lib/model/AjvValidator.js +325 -0
- package/lib/model/Model.js +942 -0
- package/lib/model/ModifierNotFoundError.js +12 -0
- package/lib/model/NotFoundError.js +23 -0
- package/lib/model/RelationDoesNotExistError.js +14 -0
- package/lib/model/ValidationError.js +54 -0
- package/lib/model/Validator.js +26 -0
- package/lib/model/getModel.js +9 -0
- package/lib/model/graph/ModelGraph.js +80 -0
- package/lib/model/graph/ModelGraphBuilder.js +241 -0
- package/lib/model/graph/ModelGraphEdge.js +52 -0
- package/lib/model/graph/ModelGraphNode.js +240 -0
- package/lib/model/inheritModel.js +28 -0
- package/lib/model/modelBindKnex.js +83 -0
- package/lib/model/modelClone.js +121 -0
- package/lib/model/modelColPropMap.js +34 -0
- package/lib/model/modelId.js +62 -0
- package/lib/model/modelJsonAttributes.js +92 -0
- package/lib/model/modelParseRelations.js +82 -0
- package/lib/model/modelQueryProps.js +147 -0
- package/lib/model/modelSet.js +136 -0
- package/lib/model/modelTableMetadata.js +83 -0
- package/lib/model/modelToJson.js +187 -0
- package/lib/model/modelUtils.js +47 -0
- package/lib/model/modelValidate.js +48 -0
- package/lib/model/modelValues.js +126 -0
- package/lib/model/modelVisitor.js +41 -0
- package/lib/objection.js +114 -0
- package/lib/queryBuilder/FunctionBuilder.js +339 -0
- package/lib/queryBuilder/InternalOptions.js +29 -0
- package/lib/queryBuilder/JoinBuilder.js +157 -0
- package/lib/queryBuilder/QueryBuilder.js +1398 -0
- package/lib/queryBuilder/QueryBuilderBase.js +884 -0
- package/lib/queryBuilder/QueryBuilderContext.js +27 -0
- package/lib/queryBuilder/QueryBuilderContextBase.js +35 -0
- package/lib/queryBuilder/QueryBuilderOperationSupport.js +558 -0
- package/lib/queryBuilder/QueryBuilderUserContext.js +31 -0
- package/lib/queryBuilder/RawBuilder.js +93 -0
- package/lib/queryBuilder/ReferenceBuilder.js +284 -0
- package/lib/queryBuilder/RelationExpression.js +431 -0
- package/lib/queryBuilder/StaticHookArguments.js +134 -0
- package/lib/queryBuilder/ValueBuilder.js +127 -0
- package/lib/queryBuilder/expressions.js +151 -0
- package/lib/queryBuilder/functions/mysql.js +817 -0
- package/lib/queryBuilder/graph/GraphAction.js +69 -0
- package/lib/queryBuilder/graph/GraphData.js +14 -0
- package/lib/queryBuilder/graph/GraphFetcher.js +191 -0
- package/lib/queryBuilder/graph/GraphNodeDbExistence.js +184 -0
- package/lib/queryBuilder/graph/GraphOperation.js +27 -0
- package/lib/queryBuilder/graph/GraphOptions.js +207 -0
- package/lib/queryBuilder/graph/GraphUpsert.js +305 -0
- package/lib/queryBuilder/graph/delete/GraphDelete.js +20 -0
- package/lib/queryBuilder/graph/delete/GraphDeleteAction.js +74 -0
- package/lib/queryBuilder/graph/insert/GraphInsert.js +145 -0
- package/lib/queryBuilder/graph/insert/GraphInsertAction.js +225 -0
- package/lib/queryBuilder/graph/insert/JoinRowGraphInsertAction.js +92 -0
- package/lib/queryBuilder/graph/patch/GraphPatch.js +20 -0
- package/lib/queryBuilder/graph/patch/GraphPatchAction.js +258 -0
- package/lib/queryBuilder/graph/recursiveUpsert/GraphRecursiveUpsert.js +31 -0
- package/lib/queryBuilder/graph/recursiveUpsert/GraphRecursiveUpsertAction.js +126 -0
- package/lib/queryBuilder/join/JoinResultColumn.js +23 -0
- package/lib/queryBuilder/join/JoinResultParser.js +119 -0
- package/lib/queryBuilder/join/RelationJoiner.js +341 -0
- package/lib/queryBuilder/join/TableNode.js +163 -0
- package/lib/queryBuilder/join/TableTree.js +85 -0
- package/lib/queryBuilder/join/utils.js +25 -0
- package/lib/queryBuilder/operations/DelegateOperation.js +141 -0
- package/lib/queryBuilder/operations/DeleteOperation.js +51 -0
- package/lib/queryBuilder/operations/FindByIdOperation.js +37 -0
- package/lib/queryBuilder/operations/FindByIdsOperation.js +29 -0
- package/lib/queryBuilder/operations/FindOperation.js +164 -0
- package/lib/queryBuilder/operations/FirstOperation.js +27 -0
- package/lib/queryBuilder/operations/FromOperation.js +110 -0
- package/lib/queryBuilder/operations/InsertAndFetchOperation.js +49 -0
- package/lib/queryBuilder/operations/InsertGraphAndFetchOperation.js +45 -0
- package/lib/queryBuilder/operations/InsertGraphOperation.js +108 -0
- package/lib/queryBuilder/operations/InsertOperation.js +206 -0
- package/lib/queryBuilder/operations/InstanceDeleteOperation.js +46 -0
- package/lib/queryBuilder/operations/InstanceFindOperation.js +21 -0
- package/lib/queryBuilder/operations/InstanceInsertOperation.js +24 -0
- package/lib/queryBuilder/operations/InstanceUpdateOperation.js +59 -0
- package/lib/queryBuilder/operations/JoinRelatedOperation.js +103 -0
- package/lib/queryBuilder/operations/KnexOperation.js +14 -0
- package/lib/queryBuilder/operations/MergeOperation.js +56 -0
- package/lib/queryBuilder/operations/ObjectionToKnexConvertingOperation.js +192 -0
- package/lib/queryBuilder/operations/OnBuildKnexOperation.js +29 -0
- package/lib/queryBuilder/operations/OnBuildOperation.js +29 -0
- package/lib/queryBuilder/operations/OnErrorOperation.js +29 -0
- package/lib/queryBuilder/operations/QueryBuilderOperation.js +297 -0
- package/lib/queryBuilder/operations/RangeOperation.js +47 -0
- package/lib/queryBuilder/operations/RelateOperation.js +27 -0
- package/lib/queryBuilder/operations/ReturningOperation.js +30 -0
- package/lib/queryBuilder/operations/RunAfterOperation.js +29 -0
- package/lib/queryBuilder/operations/RunBeforeOperation.js +29 -0
- package/lib/queryBuilder/operations/UnrelateOperation.js +23 -0
- package/lib/queryBuilder/operations/UpdateAndFetchOperation.js +80 -0
- package/lib/queryBuilder/operations/UpdateOperation.js +155 -0
- package/lib/queryBuilder/operations/UpsertGraphAndFetchOperation.js +45 -0
- package/lib/queryBuilder/operations/UpsertGraphOperation.js +66 -0
- package/lib/queryBuilder/operations/WhereCompositeOperation.js +57 -0
- package/lib/queryBuilder/operations/WhereInOperation.js +48 -0
- package/lib/queryBuilder/operations/eager/EagerOperation.js +61 -0
- package/lib/queryBuilder/operations/eager/JoinEagerOperation.js +51 -0
- package/lib/queryBuilder/operations/eager/NaiveEagerOperation.js +13 -0
- package/lib/queryBuilder/operations/eager/WhereInEagerOperation.js +285 -0
- package/lib/queryBuilder/operations/jsonApi/WhereJsonHasOperation.js +36 -0
- package/lib/queryBuilder/operations/jsonApi/WhereJsonNotObjectOperation.js +53 -0
- package/lib/queryBuilder/operations/jsonApi/WhereJsonOperation.js +31 -0
- package/lib/queryBuilder/operations/jsonApi/WhereJsonOverlapsOperation.js +31 -0
- package/lib/queryBuilder/operations/jsonApi/mysqlJsonApi.js +167 -0
- package/lib/queryBuilder/operations/jsonApi/postgresJsonApi.js +164 -0
- package/lib/queryBuilder/operations/select/SelectOperation.js +66 -0
- package/lib/queryBuilder/operations/select/Selection.js +123 -0
- package/lib/queryBuilder/operations/whereInComposite/WhereInCompositeMsSqlOperation.js +117 -0
- package/lib/queryBuilder/operations/whereInComposite/WhereInCompositeOperation.js +100 -0
- package/lib/queryBuilder/operations/whereInComposite/WhereInCompositeSqliteOperation.js +104 -0
- package/lib/queryBuilder/parsers/jsonFieldExpressionParser.js +886 -0
- package/lib/queryBuilder/parsers/jsonFieldExpressionParser.pegjs +97 -0
- package/lib/queryBuilder/parsers/relationExpressionParser.js +1042 -0
- package/lib/queryBuilder/parsers/relationExpressionParser.pegjs +141 -0
- package/lib/queryBuilder/transformations/CompositeQueryTransformation.js +22 -0
- package/lib/queryBuilder/transformations/QueryTransformation.js +11 -0
- package/lib/queryBuilder/transformations/WrapMysqlModifySubqueryTransformation.js +71 -0
- package/lib/queryBuilder/transformations/index.js +15 -0
- package/lib/queryBuilder/whereScopes.js +227 -0
- package/lib/relations/Relation.js +401 -0
- package/lib/relations/RelationDeleteOperation.js +29 -0
- package/lib/relations/RelationFindOperation.js +149 -0
- package/lib/relations/RelationInsertOperation.js +33 -0
- package/lib/relations/RelationOwner.js +236 -0
- package/lib/relations/RelationProperty.js +247 -0
- package/lib/relations/RelationUpdateOperation.js +30 -0
- package/lib/relations/belongsToOne/BelongsToOneDeleteOperation.js +23 -0
- package/lib/relations/belongsToOne/BelongsToOneInsertOperation.js +44 -0
- package/lib/relations/belongsToOne/BelongsToOneRelateOperation.js +50 -0
- package/lib/relations/belongsToOne/BelongsToOneRelation.js +53 -0
- package/lib/relations/belongsToOne/BelongsToOneUnrelateOperation.js +61 -0
- package/lib/relations/hasMany/HasManyInsertOperation.js +61 -0
- package/lib/relations/hasMany/HasManyRelateOperation.js +64 -0
- package/lib/relations/hasMany/HasManyRelation.js +49 -0
- package/lib/relations/hasMany/HasManyUnrelateOperation.js +33 -0
- package/lib/relations/hasOne/HasOneRelation.js +13 -0
- package/lib/relations/hasOneThrough/HasOneThroughRelation.js +13 -0
- package/lib/relations/manyToMany/ManyToManyModifyMixin.js +105 -0
- package/lib/relations/manyToMany/ManyToManyRelation.js +507 -0
- package/lib/relations/manyToMany/ManyToManySqliteModifyMixin.js +36 -0
- package/lib/relations/manyToMany/delete/ManyToManyDeleteOperation.js +10 -0
- package/lib/relations/manyToMany/delete/ManyToManyDeleteOperationBase.js +26 -0
- package/lib/relations/manyToMany/delete/ManyToManyDeleteSqliteOperation.js +12 -0
- package/lib/relations/manyToMany/find/ManyToManyFindOperation.js +105 -0
- package/lib/relations/manyToMany/insert/ManyToManyInsertOperation.js +52 -0
- package/lib/relations/manyToMany/relate/ManyToManyRelateOperation.js +81 -0
- package/lib/relations/manyToMany/unrelate/ManyToManyUnrelateOperation.js +14 -0
- package/lib/relations/manyToMany/unrelate/ManyToManyUnrelateOperationBase.js +34 -0
- package/lib/relations/manyToMany/unrelate/ManyToManyUnrelateSqliteOperation.js +16 -0
- package/lib/relations/manyToMany/update/ManyToManyUpdateOperation.js +10 -0
- package/lib/relations/manyToMany/update/ManyToManyUpdateOperationBase.js +82 -0
- package/lib/relations/manyToMany/update/ManyToManyUpdateSqliteOperation.js +12 -0
- package/lib/transaction.js +96 -0
- package/lib/utils/assert.js +25 -0
- package/lib/utils/buildUtils.js +21 -0
- package/lib/utils/classUtils.js +13 -0
- package/lib/utils/clone.js +2329 -0
- package/lib/utils/createModifier.js +42 -0
- package/lib/utils/deprecate.js +15 -0
- package/lib/utils/identifierMapping.js +227 -0
- package/lib/utils/internalPropUtils.js +11 -0
- package/lib/utils/knexUtils.js +76 -0
- package/lib/utils/mixin.js +25 -0
- package/lib/utils/mysqlJsonPath.js +55 -0
- package/lib/utils/normalizeIds.js +144 -0
- package/lib/utils/objectUtils.js +416 -0
- package/lib/utils/parseFieldExpression.js +51 -0
- package/lib/utils/postgresJsonPath.js +110 -0
- package/lib/utils/promiseUtils/after.js +17 -0
- package/lib/utils/promiseUtils/afterReturn.js +17 -0
- package/lib/utils/promiseUtils/index.js +17 -0
- package/lib/utils/promiseUtils/isPromise.js +11 -0
- package/lib/utils/promiseUtils/map.js +110 -0
- package/lib/utils/promiseUtils/mapAfterAllReturn.js +29 -0
- package/lib/utils/promiseUtils/try.js +22 -0
- package/lib/utils/resolveModel.js +107 -0
- package/lib/utils/tmpColumnUtils.js +16 -0
- package/package.json +86 -4
- package/typings/objection/index.d.ts +4104 -0
- package/typings/objection/relation-expression.d.ts +237 -0
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { isPromise } = require('./isPromise');
|
|
4
|
+
|
|
5
|
+
// Works like Bluebird.map.
|
|
6
|
+
function promiseMap(items, mapper, opt) {
|
|
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
|
+
}
|
|
16
|
+
|
|
17
|
+
function mapZero() {
|
|
18
|
+
return Promise.resolve([]);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function mapOne(items, mapper) {
|
|
22
|
+
try {
|
|
23
|
+
const maybePromise = mapper(items[0], 0);
|
|
24
|
+
|
|
25
|
+
if (isPromise(maybePromise)) {
|
|
26
|
+
return maybePromise.then(wrapArray);
|
|
27
|
+
} else {
|
|
28
|
+
return Promise.resolve(wrapArray(maybePromise));
|
|
29
|
+
}
|
|
30
|
+
} catch (err) {
|
|
31
|
+
return Promise.reject(err);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function wrapArray(item) {
|
|
36
|
+
return [item];
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function mapMany(items, mapper, opt = {}) {
|
|
40
|
+
return new Promise((resolve, reject) => {
|
|
41
|
+
const concurrency = opt.concurrency || Number.MAX_SAFE_INTEGER;
|
|
42
|
+
|
|
43
|
+
const ctx = {
|
|
44
|
+
reject,
|
|
45
|
+
resolve,
|
|
46
|
+
rejected: false,
|
|
47
|
+
index: 0,
|
|
48
|
+
numFinished: 0,
|
|
49
|
+
results: new Array(items.length),
|
|
50
|
+
items,
|
|
51
|
+
mapper,
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
while (ctx.index < concurrency && ctx.index < items.length && !ctx.rejected) {
|
|
55
|
+
executeNext(ctx);
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function executeNext(ctx) {
|
|
61
|
+
try {
|
|
62
|
+
if (ctx.rejected) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const index = ctx.index++;
|
|
67
|
+
const item = ctx.items[index];
|
|
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));
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return null;
|
|
79
|
+
} catch (err) {
|
|
80
|
+
onError(ctx, err);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function afterExecute(ctx, result, index) {
|
|
85
|
+
if (ctx.rejected) {
|
|
86
|
+
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
|
+
}
|
|
102
|
+
|
|
103
|
+
function onError(ctx, err) {
|
|
104
|
+
ctx.rejected = true;
|
|
105
|
+
ctx.reject(err);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
module.exports = {
|
|
109
|
+
promiseMap,
|
|
110
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { isPromise } = require('./isPromise');
|
|
4
|
+
|
|
5
|
+
// Map `arr` with `mapper` and after that return `returnValue`. If none of
|
|
6
|
+
// the mapped values is a promise, return synchronously for performance
|
|
7
|
+
// reasons.
|
|
8
|
+
function mapAfterAllReturn(arr, mapper, returnValue) {
|
|
9
|
+
const results = new Array(arr.length);
|
|
10
|
+
let containsPromise = false;
|
|
11
|
+
|
|
12
|
+
for (let i = 0, l = arr.length; i < l; ++i) {
|
|
13
|
+
results[i] = mapper(arr[i]);
|
|
14
|
+
|
|
15
|
+
if (isPromise(results[i])) {
|
|
16
|
+
containsPromise = true;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
if (containsPromise) {
|
|
21
|
+
return Promise.all(results).then(() => returnValue);
|
|
22
|
+
} else {
|
|
23
|
+
return returnValue;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
module.exports = {
|
|
28
|
+
mapAfterAllReturn,
|
|
29
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { isPromise } = require('./isPromise');
|
|
4
|
+
|
|
5
|
+
// Works like Bluebird.try.
|
|
6
|
+
function promiseTry(callback) {
|
|
7
|
+
try {
|
|
8
|
+
const maybePromise = callback();
|
|
9
|
+
|
|
10
|
+
if (isPromise(maybePromise)) {
|
|
11
|
+
return maybePromise;
|
|
12
|
+
} else {
|
|
13
|
+
return Promise.resolve(maybePromise);
|
|
14
|
+
}
|
|
15
|
+
} catch (err) {
|
|
16
|
+
return Promise.reject(err);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
module.exports = {
|
|
21
|
+
promiseTry,
|
|
22
|
+
};
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const path = require('path');
|
|
4
|
+
const { isString, isFunction } = require('../utils/objectUtils');
|
|
5
|
+
|
|
6
|
+
class ResolveError extends Error {}
|
|
7
|
+
|
|
8
|
+
function resolveModel(modelRef, modelPaths, errorPrefix) {
|
|
9
|
+
try {
|
|
10
|
+
if (isString(modelRef)) {
|
|
11
|
+
if (isAbsolutePath(modelRef)) {
|
|
12
|
+
return requireModel(modelRef);
|
|
13
|
+
} else if (modelPaths) {
|
|
14
|
+
return requireUsingModelPaths(modelRef, modelPaths);
|
|
15
|
+
}
|
|
16
|
+
} else {
|
|
17
|
+
if (isFunction(modelRef) && !isModelClass(modelRef)) {
|
|
18
|
+
modelRef = modelRef();
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
if (!isModelClass(modelRef)) {
|
|
22
|
+
throw new ResolveError(
|
|
23
|
+
`is not a subclass of Model or a file path to a module that exports one. You may be dealing with a require loop. See the documentation section about require loops.`,
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return modelRef;
|
|
28
|
+
}
|
|
29
|
+
} catch (err) {
|
|
30
|
+
if (err instanceof ResolveError) {
|
|
31
|
+
throw new Error(`${errorPrefix}: ${err.message}`);
|
|
32
|
+
} else {
|
|
33
|
+
throw err;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function requireUsingModelPaths(modelRef, modelPaths) {
|
|
39
|
+
let firstError = null;
|
|
40
|
+
|
|
41
|
+
for (const modelPath of modelPaths) {
|
|
42
|
+
try {
|
|
43
|
+
return requireModel(path.join(modelPath, modelRef));
|
|
44
|
+
} catch (err) {
|
|
45
|
+
if (firstError === null) {
|
|
46
|
+
firstError = err;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if (firstError) {
|
|
52
|
+
throw firstError;
|
|
53
|
+
} else {
|
|
54
|
+
throw new ResolveError(`could not resolve ${modelRef} using modelPaths`);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function requireModel(modelPath) {
|
|
59
|
+
/**
|
|
60
|
+
* Wrap path string in template literal to prevent
|
|
61
|
+
* warnings about Objection.JS being an expression
|
|
62
|
+
* in webpack builds.
|
|
63
|
+
* @link https://github.com/webpack/webpack/issues/196
|
|
64
|
+
*/
|
|
65
|
+
let mod = require(`${path.resolve(modelPath)}`);
|
|
66
|
+
let modelClass = null;
|
|
67
|
+
|
|
68
|
+
if (isModelClass(mod)) {
|
|
69
|
+
modelClass = mod;
|
|
70
|
+
} else if (isModelClass(mod.default)) {
|
|
71
|
+
// Babel 6 style of exposing default export.
|
|
72
|
+
modelClass = mod.default;
|
|
73
|
+
} else {
|
|
74
|
+
Object.keys(mod).forEach((exportName) => {
|
|
75
|
+
const exp = mod[exportName];
|
|
76
|
+
|
|
77
|
+
if (isModelClass(exp)) {
|
|
78
|
+
if (modelClass !== null) {
|
|
79
|
+
throw new ResolveError(
|
|
80
|
+
`path ${modelPath} exports multiple models. Don't know which one to choose.`,
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
modelClass = exp;
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (!isModelClass(modelClass)) {
|
|
90
|
+
throw new ResolveError(`${modelPath} is an invalid file path to a model class`);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return modelClass;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function isAbsolutePath(pth) {
|
|
97
|
+
return path.normalize(pth + '/') === path.normalize(path.resolve(pth) + '/');
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function isModelClass(maybeModel) {
|
|
101
|
+
return isFunction(maybeModel) && maybeModel.isObjectionModelClass;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
module.exports = {
|
|
105
|
+
resolveModel,
|
|
106
|
+
isModelClass,
|
|
107
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const OWNER_JOIN_COLUMN_ALIAS_PREFIX = 'objectiontmpjoin';
|
|
4
|
+
|
|
5
|
+
function getTempColumn(index) {
|
|
6
|
+
return `${OWNER_JOIN_COLUMN_ALIAS_PREFIX}${index}`;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
function isTempColumn(col) {
|
|
10
|
+
return col.startsWith(OWNER_JOIN_COLUMN_ALIAS_PREFIX);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
module.exports = {
|
|
14
|
+
getTempColumn,
|
|
15
|
+
isTempColumn,
|
|
16
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,88 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@abedmurrar/objection",
|
|
3
|
-
"version": "0.0.0
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "4.0.0-alpha.0",
|
|
4
|
+
"description": "An SQL-friendly ORM for Node.js. A fork of objection.js with strict TypeScript types and MySQL support.",
|
|
5
|
+
"main": "lib/objection.js",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"test": "npm run eslint && mocha --slow 10 --timeout 15000 --reporter spec --recursive tests --exclude \"tests/unit/relations/files/**\" && npm run test:typings",
|
|
9
|
+
"test:fast": "mocha --slow 10 --timeout 15000 --reporter spec --recursive tests --bail --exclude \"tests/unit/relations/files/**\"",
|
|
10
|
+
"test:typings": "node scripts/generate-fn-typings.js --check && tsc && tsc -p tests/ts/tsconfig.loose.json && node scripts/typings-errors.js",
|
|
11
|
+
"test:typings:ts7": "npx -y -p typescript@7 tsc -p tests/ts/tsconfig.ts7.json",
|
|
12
|
+
"bench:typings": "node scripts/typings-bench.js",
|
|
13
|
+
"prettier": "prettier --write \"{examples,lib,tests,testUtils,typings,doc}/**/*.{js,ts}\"",
|
|
14
|
+
"eslint": "eslint --format codeframe \"examples/**/*.js\" \"lib/**/*.js\" \"tests/**/*.js\"",
|
|
15
|
+
"docs:dev": "vuepress dev doc",
|
|
16
|
+
"docs:build": "vuepress build doc",
|
|
17
|
+
"release": "node scripts/release.js",
|
|
18
|
+
"prepublishOnly": "npm run eslint && npm run test:typings"
|
|
19
|
+
},
|
|
20
|
+
"publishConfig": {
|
|
21
|
+
"access": "public",
|
|
22
|
+
"registry": "https://registry.npmjs.org/"
|
|
23
|
+
},
|
|
24
|
+
"author": {
|
|
25
|
+
"name": "Abed Murrar",
|
|
26
|
+
"url": "https://github.com/abedmurrar"
|
|
27
|
+
},
|
|
28
|
+
"contributors": [
|
|
29
|
+
"Sami Koskimäki <sami@jakso.me> (https://github.com/koskimas)",
|
|
30
|
+
"Mikael Lepistö <mikael.lepisto@vincit.com> (https://github.com/elhigu)",
|
|
31
|
+
"Matthew McEachen <matthew-objection@photostructure.com> (https://github.com/mceachen)",
|
|
32
|
+
"Jürg Lehni <juerg@scratchdisk.com> (https://github.com/lehni)",
|
|
33
|
+
"Igor Savin <kibertoad@gmail.com> (https://github.com/kibertoad)"
|
|
34
|
+
],
|
|
35
|
+
"repository": {
|
|
36
|
+
"type": "git",
|
|
37
|
+
"url": "git+https://github.com/abedmurrar/objection.js.git"
|
|
38
|
+
},
|
|
39
|
+
"bugs": {
|
|
40
|
+
"url": "https://github.com/abedmurrar/objection.js/issues"
|
|
41
|
+
},
|
|
42
|
+
"homepage": "https://github.com/abedmurrar/objection.js#readme",
|
|
43
|
+
"engines": {
|
|
44
|
+
"node": ">=14.0.0"
|
|
45
|
+
},
|
|
46
|
+
"keywords": [
|
|
47
|
+
"orm",
|
|
48
|
+
"knex",
|
|
49
|
+
"sql",
|
|
50
|
+
"query",
|
|
51
|
+
"query builder",
|
|
52
|
+
"postgresql",
|
|
53
|
+
"mysql",
|
|
54
|
+
"sqlite3"
|
|
55
|
+
],
|
|
56
|
+
"files": [
|
|
57
|
+
"README.md",
|
|
58
|
+
"LICENSE",
|
|
59
|
+
"lib/*",
|
|
60
|
+
"typings/*"
|
|
61
|
+
],
|
|
62
|
+
"types": "./typings/objection/index.d.ts",
|
|
63
|
+
"dependencies": {
|
|
64
|
+
"ajv": "^8.20.0",
|
|
65
|
+
"ajv-formats": "^3.0.1",
|
|
66
|
+
"db-errors": "^0.2.3"
|
|
67
|
+
},
|
|
68
|
+
"peerDependencies": {
|
|
69
|
+
"knex": ">=3.1.0"
|
|
70
|
+
},
|
|
71
|
+
"devDependencies": {
|
|
72
|
+
"@types/node": "^22.15.3",
|
|
73
|
+
"chai": "^4.3.10",
|
|
74
|
+
"chai-subset": "^1.6.0",
|
|
75
|
+
"eslint": "^8.54.0",
|
|
76
|
+
"eslint-formatter-codeframe": "^7.32.1",
|
|
77
|
+
"eslint-plugin-prettier": "^5.3.1",
|
|
78
|
+
"expect.js": "^0.3.1",
|
|
79
|
+
"knex": "^3.3.0",
|
|
80
|
+
"mocha": "^11.2.2",
|
|
81
|
+
"mysql2": "^3.24.6",
|
|
82
|
+
"pg": "^8.15.6",
|
|
83
|
+
"prettier": "3.5.3",
|
|
84
|
+
"sqlite3": "^5.1.7",
|
|
85
|
+
"typescript": "~5.8.3",
|
|
86
|
+
"vuepress": "1.9.10"
|
|
87
|
+
}
|
|
88
|
+
}
|