objection 3.0.0-alpha.2 → 3.0.0-alpha.6
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 +2 -1
- package/lib/relations/RelationOwner.js +2 -0
- package/lib/utils/objectUtils.js +19 -3
- package/package.json +2 -6
- package/typings/objection/index.d.ts +31 -9
package/README.md
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
[](https://github.com/Vincit/objection.js)
|
|
2
|
+
[](https://gitter.im/Vincit/objection.js?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
|
2
3
|
|
|
3
4
|
# [Objection.js](https://vincit.github.io/objection.js)
|
|
4
5
|
|
package/lib/utils/objectUtils.js
CHANGED
|
@@ -189,7 +189,6 @@ function once(func) {
|
|
|
189
189
|
|
|
190
190
|
function flatten(arrays) {
|
|
191
191
|
const out = [];
|
|
192
|
-
let outIdx = 0;
|
|
193
192
|
|
|
194
193
|
for (let i = 0, l = arrays.length; i < l; ++i) {
|
|
195
194
|
const value = arrays[i];
|
|
@@ -225,6 +224,11 @@ function set(obj, path, value) {
|
|
|
225
224
|
|
|
226
225
|
for (let i = 0, l = path.length - 1; i < l; ++i) {
|
|
227
226
|
const key = path[i];
|
|
227
|
+
|
|
228
|
+
if (!isSafeKey(key)) {
|
|
229
|
+
return inputObj;
|
|
230
|
+
}
|
|
231
|
+
|
|
228
232
|
let child = obj[key];
|
|
229
233
|
|
|
230
234
|
if (!isObject(child)) {
|
|
@@ -243,7 +247,11 @@ function set(obj, path, value) {
|
|
|
243
247
|
}
|
|
244
248
|
|
|
245
249
|
if (path.length > 0 && isObject(obj)) {
|
|
246
|
-
|
|
250
|
+
const key = path[path.length - 1];
|
|
251
|
+
|
|
252
|
+
if (isSafeKey(key)) {
|
|
253
|
+
obj[key] = value;
|
|
254
|
+
}
|
|
247
255
|
}
|
|
248
256
|
|
|
249
257
|
return inputObj;
|
|
@@ -253,7 +261,11 @@ function zipObject(keys, values) {
|
|
|
253
261
|
const out = {};
|
|
254
262
|
|
|
255
263
|
for (let i = 0, l = keys.length; i < l; ++i) {
|
|
256
|
-
|
|
264
|
+
const key = keys[i];
|
|
265
|
+
|
|
266
|
+
if (isSafeKey(key)) {
|
|
267
|
+
out[key] = values[i];
|
|
268
|
+
}
|
|
257
269
|
}
|
|
258
270
|
|
|
259
271
|
return out;
|
|
@@ -357,6 +369,10 @@ function compareStrict(val1, val2) {
|
|
|
357
369
|
return val1 === val2;
|
|
358
370
|
}
|
|
359
371
|
|
|
372
|
+
function isSafeKey(key) {
|
|
373
|
+
return isNumber(key) || (isString(key) && key !== '__proto__');
|
|
374
|
+
}
|
|
375
|
+
|
|
360
376
|
module.exports = {
|
|
361
377
|
isEmpty,
|
|
362
378
|
isString,
|
package/package.json
CHANGED
|
@@ -1,16 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "objection",
|
|
3
|
-
"version": "3.0.0-alpha.
|
|
3
|
+
"version": "3.0.0-alpha.6",
|
|
4
4
|
"description": "An SQL-friendly ORM for Node.js",
|
|
5
5
|
"main": "lib/objection.js",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"test": "npm run eslint && mocha --slow 10 --timeout 15000 --reporter spec --recursive tests --exclude \"tests/unit/relations/files/**\"",
|
|
9
|
-
"test-travis": "nyc mocha --slow 100 --timeout 60000 --reporter spec --recursive tests --exclude \"tests/unit/relations/files/**\" && npm run test-typings",
|
|
10
9
|
"test-fast": "mocha --slow 10 --timeout 15000 --reporter spec --recursive tests --bail --exclude \"tests/unit/relations/files/**\"",
|
|
11
|
-
"test-opt": "mocha --slow 10 --timeout 15000 --reporter spec --recursive tests --bail --trace_opt --trace_deopt --exclude \"tests/unit/relations/files/**\"",
|
|
12
|
-
"test-debug": "mocha --slow 10 --timeout 15000 --reporter spec --recursive tests --inspect-brk --exclude \"tests/unit/relations/files/**\"",
|
|
13
|
-
"test-sqlite": "cross-env DATABASES=sqlite3 mocha --slow 10 --timeout 15000 --reporter spec --recursive tests --exclude \"tests/unit/relations/files/**\"",
|
|
14
10
|
"test-typings": "tsc",
|
|
15
11
|
"coveralls": "cat ./testCoverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js",
|
|
16
12
|
"perf": "mocha --slow 60000 --timeout 60000 --reporter spec --recursive perf",
|
|
@@ -85,7 +81,7 @@
|
|
|
85
81
|
"pg": "^8.6.0",
|
|
86
82
|
"prettier": "2.3.2",
|
|
87
83
|
"sqlite3": "^5.0.2",
|
|
88
|
-
"typescript": "^4.
|
|
84
|
+
"typescript": "^4.4.4",
|
|
89
85
|
"vuepress": "1.8.2"
|
|
90
86
|
},
|
|
91
87
|
"nyc": {
|
|
@@ -306,6 +306,11 @@ declare namespace Objection {
|
|
|
306
306
|
*/
|
|
307
307
|
type SingleQueryBuilder<T extends { SingleQueryBuilderType: any }> = T['SingleQueryBuilderType'];
|
|
308
308
|
|
|
309
|
+
/**
|
|
310
|
+
* Gets the single or undefined item query builder type for a query builder.
|
|
311
|
+
*/
|
|
312
|
+
type MaybeSingleQueryBuilder<QB extends AnyQueryBuilder> = QB['MaybeSingleQueryBuilderType'];
|
|
313
|
+
|
|
309
314
|
/**
|
|
310
315
|
* Gets the multi-item query builder type for a query builder.
|
|
311
316
|
*/
|
|
@@ -566,7 +571,7 @@ declare namespace Objection {
|
|
|
566
571
|
|
|
567
572
|
interface FirstMethod {
|
|
568
573
|
<QB extends AnyQueryBuilder>(this: QB): QB extends ArrayQueryBuilder<QB>
|
|
569
|
-
?
|
|
574
|
+
? MaybeSingleQueryBuilder<QB>
|
|
570
575
|
: QB;
|
|
571
576
|
}
|
|
572
577
|
|
|
@@ -589,10 +594,6 @@ declare namespace Objection {
|
|
|
589
594
|
(arg: T): QB;
|
|
590
595
|
}
|
|
591
596
|
|
|
592
|
-
interface OptionalOneArgMethod<T, QB extends AnyQueryBuilder> {
|
|
593
|
-
(arg?: T): QB;
|
|
594
|
-
}
|
|
595
|
-
|
|
596
597
|
interface StringReturningMethod {
|
|
597
598
|
(): string;
|
|
598
599
|
}
|
|
@@ -798,7 +799,13 @@ declare namespace Objection {
|
|
|
798
799
|
[key: string]: any;
|
|
799
800
|
}
|
|
800
801
|
|
|
801
|
-
export
|
|
802
|
+
export interface CatchablePromiseLike<R> extends PromiseLike<R> {
|
|
803
|
+
catch<FR = never>(
|
|
804
|
+
onrejected?: ((reason: any) => FR | PromiseLike<FR>) | undefined | null
|
|
805
|
+
): Promise<R | FR>;
|
|
806
|
+
}
|
|
807
|
+
|
|
808
|
+
export class QueryBuilder<M extends Model, R = M[]> implements CatchablePromiseLike<R> {
|
|
802
809
|
static forClass: ForClassMethod;
|
|
803
810
|
|
|
804
811
|
select: SelectMethod<this>;
|
|
@@ -969,9 +976,9 @@ declare namespace Objection {
|
|
|
969
976
|
groupBy: GroupByMethod<this>;
|
|
970
977
|
groupByRaw: RawInterface<this>;
|
|
971
978
|
|
|
972
|
-
findById(id: MaybeCompositeId):
|
|
979
|
+
findById(id: MaybeCompositeId): MaybeSingleQueryBuilder<this>;
|
|
973
980
|
findByIds(ids: MaybeCompositeId[]): this;
|
|
974
|
-
findOne: WhereMethod<
|
|
981
|
+
findOne: WhereMethod<MaybeSingleQueryBuilder<this>>;
|
|
975
982
|
|
|
976
983
|
execute(): Promise<R>;
|
|
977
984
|
castTo<MC extends Model>(modelClass: ModelConstructor<MC>): QueryBuilderType<MC>;
|
|
@@ -1047,7 +1054,10 @@ declare namespace Objection {
|
|
|
1047
1054
|
// Deprecated
|
|
1048
1055
|
allowUpsert: AllowGraphMethod<this>;
|
|
1049
1056
|
|
|
1050
|
-
throwIfNotFound:
|
|
1057
|
+
throwIfNotFound: (
|
|
1058
|
+
arg?: any
|
|
1059
|
+
) => R extends Model | undefined ? SingleQueryBuilder<QueryBuilder<M, M>> : this;
|
|
1060
|
+
|
|
1051
1061
|
returning: ReturningMethod;
|
|
1052
1062
|
forUpdate: IdentityMethod<this>;
|
|
1053
1063
|
forShare: IdentityMethod<this>;
|
|
@@ -1156,10 +1166,22 @@ declare namespace Objection {
|
|
|
1156
1166
|
|
|
1157
1167
|
ArrayQueryBuilderType: QueryBuilder<M, M[]>;
|
|
1158
1168
|
SingleQueryBuilderType: QueryBuilder<M, M>;
|
|
1169
|
+
MaybeSingleQueryBuilderType: QueryBuilder<M, M | undefined>;
|
|
1159
1170
|
NumberQueryBuilderType: QueryBuilder<M, number>;
|
|
1160
1171
|
PageQueryBuilderType: QueryBuilder<M, Page<M>>;
|
|
1172
|
+
|
|
1173
|
+
then<R1 = R, R2 = never>(
|
|
1174
|
+
onfulfilled?: ((value: R) => R1 | PromiseLike<R1>) | undefined | null,
|
|
1175
|
+
onrejected?: ((reason: any) => R2 | PromiseLike<R2>) | undefined | null
|
|
1176
|
+
): Promise<R1 | R2>;
|
|
1177
|
+
|
|
1178
|
+
catch<FR = never>(
|
|
1179
|
+
onrejected?: ((reason: any) => FR | PromiseLike<FR>) | undefined | null
|
|
1180
|
+
): Promise<R | FR>;
|
|
1161
1181
|
}
|
|
1162
1182
|
|
|
1183
|
+
type X<T> = Promise<T>;
|
|
1184
|
+
|
|
1163
1185
|
interface FetchGraphOptions {
|
|
1164
1186
|
transaction?: TransactionOrKnex;
|
|
1165
1187
|
skipFetched?: boolean;
|