Socket
Socket
Sign inDemoInstall

objection

Package Overview
Dependencies
Maintainers
2
Versions
201
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

objection - npm Package Compare versions

Comparing version 2.0.0-alpha.8 to 2.0.0-alpha.9

26

lib/model/Model.js

@@ -521,2 +521,18 @@ 'use strict';

static getRelatedFindQueryMutates() {
if (this.relatedFindQueryMutates) {
deprecate('Model.relatedFindQueryMutates is deprected and will be removed in 3.0.');
}
return this.relatedFindQueryMutates;
}
static getRelatedInsertQueryMutates() {
if (this.relatedInsertQueryMutates) {
deprecate('Model.relatedInsertQueryMutates is deprected and will be removed in 3.0.');
}
return this.relatedInsertQueryMutates;
}
static query(trx) {

@@ -541,3 +557,3 @@ const query = this.QueryBuilder.forClass(this).transacting(trx);

operation.assignResultToOwner = this.relatedFindQueryMutates;
operation.assignResultToOwner = this.getRelatedFindQueryMutates();
operation.alwaysReturnArray = !owner.isModels;

@@ -552,3 +568,3 @@ operation.alias = isSubQuery ? relation.name : null;

operation.assignResultToOwner = this.relatedInsertQueryMutates;
operation.assignResultToOwner = this.getRelatedInsertQueryMutates();
return operation;

@@ -828,4 +844,6 @@ })

Model.columnNameMappers = null;
Model.relatedFindQueryMutates = true;
Model.relatedInsertQueryMutates = true;
// Deprecated.
Model.relatedFindQueryMutates = false;
// Deprecated.
Model.relatedInsertQueryMutates = false;
Model.concurrency = null;

@@ -832,0 +850,0 @@

@@ -5,2 +5,3 @@ 'use strict';

const { GraphUpsert } = require('../graph/GraphUpsert');
const { RelationFindOperation } = require('../../relations/RelationFindOperation');

@@ -44,2 +45,8 @@ class UpsertGraphOperation extends QueryBuilderOperation {

onAfter1(builder) {
if (hasOtherSqlModifyingQueryBuilderCalls(builder)) {
throw new Error(
'upsertGraph query should contain no other query builder calls like `findById`, `where` or `$relatedQuery` that would affect the SQL. They have no effect.'
);
}
return this.upsert.run(builder);

@@ -55,4 +62,8 @@ }

function hasOtherSqlModifyingQueryBuilderCalls(builder) {
return builder.has(/where/) || builder.has(RelationFindOperation);
}
module.exports = {
UpsertGraphOperation
};

31

lib/relations/manyToMany/find/ManyToManyFindOperation.js

@@ -19,3 +19,2 @@ 'use strict';

const relatedModelClass = this.relation.relatedModelClass;
const joinTableOwnerProp = this.relation.joinTableOwnerProp;

@@ -39,14 +38,3 @@ this.maybeApplyAlias(builder);

if (this.owner.isModels) {
// We must select the owner join columns so that we know for which owner model the related
// models belong to after the requests.
for (let i = 0, l = joinTableOwnerProp.size; i < l; ++i) {
const joinTableOwnerRef = joinTableOwnerProp.ref(builder, i);
const propName = relatedModelClass.columnNameToPropertyName(this.ownerJoinColumnAlias[i]);
builder.select(joinTableOwnerRef.as(this.ownerJoinColumnAlias[i]));
// Mark them to be omitted later.
this.omitProps.push(propName);
}
if (this.assignResultToOwner && this.owner.isModels) {
this.selectMissingJoinColumns(builder);

@@ -98,2 +86,19 @@ }

}
selectMissingJoinColumns(builder) {
const { relatedModelClass, joinTableOwnerProp } = this.relation;
// We must select the owner join columns so that we know for which owner model the related
// models belong to after the requests.
for (let i = 0, l = joinTableOwnerProp.size; i < l; ++i) {
const joinTableOwnerRef = joinTableOwnerProp.ref(builder, i);
const propName = relatedModelClass.columnNameToPropertyName(this.ownerJoinColumnAlias[i]);
builder.select(joinTableOwnerRef.as(this.ownerJoinColumnAlias[i]));
// Mark them to be omitted later.
this.omitProps.push(propName);
}
super.selectMissingJoinColumns(builder);
}
}

@@ -100,0 +105,0 @@

@@ -22,3 +22,3 @@ 'use strict';

if (this.owner.isModels) {
if (this.assignResultToOwner && this.owner.isModels) {
this.selectMissingJoinColumns(builder);

@@ -25,0 +25,0 @@ }

{
"name": "objection",
"version": "2.0.0-alpha.8",
"version": "2.0.0-alpha.9",
"description": "An SQL-friendly ORM for Node.js",

@@ -90,3 +90,3 @@ "main": "lib/objection.js",

"sqlite3": "^4.1.0",
"typescript": "3.5.3",
"typescript": "^3.6.3",
"vuepress": "1.0.4"

@@ -93,0 +93,0 @@ },

@@ -121,5 +121,4 @@ /// <reference types="node" />

type Raw = RawBuilder;
type Raw = RawBuilder | knex.Raw;
type Operator = string;
type NonPrimitiveValue = Raw | ReferenceBuilder | ValueBuilder | AnyQueryBuilder;
type ColumnRef = string | Raw | ReferenceBuilder;

@@ -140,3 +139,3 @@ type TableRef = ColumnRef | AnyQueryBuilder;

type Value = NonPrimitiveValue | PrimitiveValue;
type Expression<T> = T | Raw | ReferenceBuilder | ValueBuilder | AnyQueryBuilder;

@@ -147,4 +146,4 @@ type Id = string | number;

interface ValueObject {
[key: string]: Value;
interface ExpressionObject {
[key: string]: Expression<PrimitiveValue>;
}

@@ -166,3 +165,4 @@

| string
| object;
| string[]
| Record<string, Expression<PrimitiveValue>>;
type OrderByDirection = 'asc' | 'desc' | 'ASC' | 'DESC';

@@ -187,10 +187,15 @@

/**
* Removes `undefined` from a type.
*/
type Defined<T> = Exclude<T, undefined>;
/**
* Any object that has some of the properties of model class T match this type.
*/
type PartialModelObject<T extends Model> = {
[K in NonFunctionPropertyNames<T>]?: Exclude<T[K], undefined> extends Model
[K in NonFunctionPropertyNames<T>]?: Defined<T[K]> extends Model
? T[K]
: Exclude<T[K], undefined> extends Array<infer I>
? (I extends Model ? I[] : (T[K] | NonPrimitiveValue))
: (T[K] | NonPrimitiveValue);
: Defined<T[K]> extends Array<infer I>
? (I extends Model ? I[] : Expression<T[K]>)
: Expression<T[K]>;
};

@@ -210,10 +215,9 @@

*/
type PartialModelGraph<T> = {
[K in NonFunctionPropertyNames<T>]?: Exclude<T[K], undefined> extends Model
? PartialModelGraph<Exclude<T[K], undefined>>
: Exclude<T[K], undefined> extends Array<infer I>
? (I extends Model ? PartialModelGraph<I>[] : (T[K] | NonPrimitiveValue))
: (T[K] | NonPrimitiveValue);
} &
GraphParameters;
type PartialModelGraph<M, T = M & GraphParameters> = {
[K in NonFunctionPropertyNames<T>]?: Defined<T[K]> extends Model
? PartialModelGraph<Defined<T[K]>>
: Defined<T[K]> extends Array<infer I>
? (I extends Model ? PartialModelGraph<I>[] : Expression<T[K]>)
: Expression<T[K]>;
};

@@ -235,5 +239,5 @@ /**

{
[K in keyof T]?: Exclude<T[K], undefined> extends Model
[K in keyof T]?: Defined<T[K]> extends Model
? never
: Exclude<T[K], undefined> extends Array<infer I>
: Defined<T[K]> extends Array<infer I>
? (I extends Model ? never : K)

@@ -250,11 +254,10 @@ : T[K] extends Function

*/
type ModelRelations<T extends Model> = Exclude<
type ModelRelations<T extends Model> = Defined<
{
[K in keyof T]?: Exclude<T[K], undefined> extends Model
[K in keyof T]?: Defined<T[K]> extends Model
? K
: Exclude<T[K], undefined> extends Array<infer I>
: Defined<T[K]> extends Array<infer I>
? (I extends Model ? K : never)
: never;
}[keyof T],
undefined
}[keyof T]
>;

@@ -320,8 +323,13 @@

// These must come first so that we get autocomplete.
<QBP extends QB>(col: ModelProps<ModelType<QBP>>, op: Operator, value: Value): QB;
<QBP extends QB>(col: ModelProps<ModelType<QBP>>, value: Value): QB;
<QBP extends QB>(
col: ModelProps<ModelType<QBP>>,
op: Operator,
expr: Expression<PrimitiveValue>
): QB;
(col: ColumnRef, op: Operator, value: Value): QB;
(col: ColumnRef, value: Value): QB;
<QBP extends QB>(col: ModelProps<ModelType<QBP>>, expr: Expression<PrimitiveValue>): QB;
(col: ColumnRef, op: Operator, expr: Expression<PrimitiveValue>): QB;
(col: ColumnRef, expr: Expression<PrimitiveValue>): QB;
(condition: boolean): QB;

@@ -353,7 +361,7 @@ (cb: CallbackVoid<QB>): QB;

// These must come first so that we get autocomplete.
<QBP extends QB>(col: ModelProps<ModelType<QBP>>, value: Value): QB;
<QBP extends QB>(col: ModelProps<ModelType<QBP>>, expr: Expression<PrimitiveValue>): QB;
<QBP extends QB>(col: ModelProps<ModelType<QBP>>, cb: CallbackVoid<QB>): QB;
<QBP extends QB>(col: ModelProps<ModelType<QBP>>, qb: AnyQueryBuilder): QB;
(col: ColumnRef | ColumnRef[], value: Value[]): QB;
(col: ColumnRef | ColumnRef[], expr: Expression<PrimitiveValue>[]): QB;
(col: ColumnRef | ColumnRef[], cb: CallbackVoid<QB>): QB;

@@ -364,3 +372,3 @@ (col: ColumnRef | ColumnRef[], qb: AnyQueryBuilder): QB;

interface WhereBetweenMethod<QB extends AnyQueryBuilder> {
(column: ColumnRef, range: [Value, Value]): QB;
(column: ColumnRef, range: [Expression<PrimitiveValue>, Expression<PrimitiveValue>]): QB;
}

@@ -405,5 +413,6 @@

interface WhereCompositeMethod<QB extends AnyQueryBuilder> {
(column: ColumnRef, value: Value): QB;
(column: ColumnRef, op: Operator, value: Value): QB;
(column: ColumnRef[], value: Value[]): QB;
(column: ColumnRef[], op: Operator, expr: Expression<PrimitiveValue>[]): QB;
(column: ColumnRef, expr: Expression<PrimitiveValue>): QB;
(column: ColumnRef, op: Operator, expr: Expression<PrimitiveValue>): QB;
(column: ColumnRef[], expr: Expression<PrimitiveValue>[]): QB;
(column: ColumnRef[], qb: AnyQueryBuilder): QB;

@@ -413,5 +422,5 @@ }

interface WhereInCompositeMethod<QB extends AnyQueryBuilder> {
(column: ColumnRef, value: Value[]): QB;
(column: ColumnRef, expr: Expression<PrimitiveValue>[]): QB;
(column: ColumnRef, qb: AnyQueryBuilder): QB;
(column: ColumnRef[], value: Value[][]): QB;
(column: ColumnRef[], expr: Expression<PrimitiveValue>[][]): QB;
(column: ColumnRef[], qb: AnyQueryBuilder): QB;

@@ -575,9 +584,9 @@ }

interface RelateMethod<QB extends AnyQueryBuilder> {
<RelatedModel extends Model>(
ids: MaybeCompositeId | Partial<RelatedModel> | Partial<RelatedModel>[]
(
ids:
| MaybeCompositeId
| MaybeCompositeId[]
| PartialModelObject<ModelType<QB>>
| PartialModelObject<ModelType<QB>>[]
): NumberQueryBuilder<QB>;
<RelatedModel extends Model>(
ids: MaybeCompositeId | Partial<RelatedModel> | Partial<RelatedModel>[]
): NumberQueryBuilder<QB>;
}

@@ -771,11 +780,11 @@

this: QB,
graph: PartialModelGraph<ModelType<QB>>,
graph: PartialModelGraph<ModelType<QB>>[],
options?: UpsertGraphOptions
): SingleQueryBuilder<QB>;
): ArrayQueryBuilder<QB>;
<QB extends AnyQueryBuilder>(
this: QB,
graph: PartialModelGraph<ModelType<QB>>[],
graph: PartialModelGraph<ModelType<QB>>,
options?: UpsertGraphOptions
): ArrayQueryBuilder<QB>;
): SingleQueryBuilder<QB>;
}

@@ -1015,2 +1024,4 @@

truncate(): Promise<void>;
// Deprecated

@@ -1261,3 +1272,3 @@ eager: EagerMethod<this>;

export interface RelationMappings {
[relationName: string]: RelationMapping;
[relationName: string]: RelationMapping<any>;
}

@@ -1267,6 +1278,9 @@

type ModelClassSpecifier = ModelClassFactory | AnyModelClass | string;
type RelationMappingHook = (model: Model, context: QueryContext) => Promise<void> | void;
type RelationMappingHook<M extends Model> = (
model: M,
context: QueryContext
) => Promise<void> | void;
type RelationMappingColumnRef = string | ReferenceBuilder | (string | ReferenceBuilder)[];
export interface RelationMapping<M extends Model = Model> {
export interface RelationMapping<M extends Model> {
relation: RelationType;

@@ -1277,3 +1291,3 @@ modelClass: ModelClassSpecifier;

filter?: Modifier<M['QueryBuilderType']>;
beforeInsert?: RelationMappingHook;
beforeInsert?: RelationMappingHook<M>;
}

@@ -1284,11 +1298,11 @@

to: RelationMappingColumnRef;
through?: RelationThrough;
through?: RelationThrough<any>;
}
export interface RelationThrough {
export interface RelationThrough<M extends Model> {
from: RelationMappingColumnRef;
to: RelationMappingColumnRef;
extra?: string[] | object;
extra?: string[] | Record<string, string>;
modelClass?: ModelClassSpecifier;
beforeInsert?: RelationMappingHook;
beforeInsert?: RelationMappingHook<M>;
}

@@ -1295,0 +1309,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc