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 1.6.9 to 1.6.11

8

lib/model/Model.js

@@ -728,2 +728,10 @@ 'use strict';

Object.defineProperties(Model, {
isObjectionModelClass: {
enumerable: false,
writable: false,
value: true
}
});
Object.defineProperties(Model.prototype, {

@@ -730,0 +738,0 @@ $isObjectionModel: {

8

lib/queryBuilder/graph/GraphOptions.js

@@ -165,4 +165,10 @@ 'use strict';

return option.indexOf(node.relationPathKey) !== -1;
} else if (typeof option === 'boolean') {
return option;
} else if (option === undefined) {
return false;
} else {
return !!option;
throw new Error(
`expected ${optionName} option value "${option}" to be an instance of boolean or array of strings`
);
}

@@ -169,0 +175,0 @@ }

@@ -96,4 +96,24 @@ 'use strict';

const deleteNodes = currentGraph.nodes.filter(currentNode => !graph.nodeForNode(currentNode));
const roots = findRoots(deleteNodes);
removeBranchesFromGraph(findRoots(deleteNodes), currentGraph);
// Don't delete relations the current graph doesn't even mention.
// So if the parent node doesn't even have the relation, it's not
// supposed to be deleted.
const rootsNotInRelation = roots.filter(deleteRoot => {
if (!deleteRoot.parentNode) {
return false;
}
const { relation } = deleteRoot.parentEdge;
const parentNode = graph.nodeForNode(deleteRoot.parentNode);
if (!parentNode) {
return false;
}
return parentNode.obj[relation.name] === undefined;
});
removeBranchesFromGraph(roots, currentGraph);
removeNodesFromGraph(new Set(rootsNotInRelation), currentGraph);
}

@@ -129,2 +149,6 @@

removeNodesFromGraph(nodesToRemove, graph);
}
function removeNodesFromGraph(nodesToRemove, graph) {
const edgesToRemove = new Set();

@@ -131,0 +155,0 @@

@@ -255,4 +255,12 @@ 'use strict';

Object.defineProperties(QueryBuilderOperation, {
isObjectionQueryBuilderOperationClass: {
enumerable: false,
writable: false,
value: true
}
});
module.exports = {
QueryBuilderOperation
};

15

lib/queryBuilder/operations/UpdateAndFetchOperation.js

@@ -29,7 +29,7 @@ 'use strict';

onBuild(builder) {
super.onBuild(builder);
if (!this.skipIdWhere) {
builder.findById(this.id);
}
super.onBuild(builder);
}

@@ -43,7 +43,12 @@

// Clone `this` query builder so that we get the correct
// operation factories in case of `$relatedQuery` etc.
return builder
.modelClass()
.query()
.emptyInstance()
.childQueryOf(builder)
.findById(this.id)
.modify(builder => {
if (!this.skipIdWhere) {
builder.findById(this.id);
}
})
.castTo(builder.resultModelClass())

@@ -50,0 +55,0 @@ .then(fetched => {

@@ -1002,5 +1002,3 @@ /*

console.warn(
`Duplicate relation "${
expr.$name
}" in a relation expression. You should use "a.[b, c]" instead of "[a.b, a.c]". This will cause an error in objection 2.0`
`Duplicate relation "${expr.$name}" in a relation expression. You should use "a.[b, c]" instead of "[a.b, a.c]". This will cause an error in objection 2.0`
);

@@ -1007,0 +1005,0 @@

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

clone() {
const builder = new this.constructor(this.modelClass());
const builder = this.emptyInstance();

@@ -459,2 +459,8 @@ // Call the super class's clone implementation.

return builder;
}
emptyInstance() {
const builder = new this.constructor(this.modelClass());
builder._findOperationFactory = this._findOperationFactory;

@@ -548,4 +554,4 @@ builder._insertOperationFactory = this._insertOperationFactory;

return countQuery.then(
result => (result[0] && result[0].count ? parseInt(result[0].count, 10) : 0)
return countQuery.then(result =>
result[0] && result[0].count ? parseInt(result[0].count, 10) : 0
);

@@ -988,3 +994,3 @@ }

range(...args) {
return this.addOperation(new RangeOperation('range'), args);
return this.clear(RangeOperation).addOperation(new RangeOperation('range'), args);
}

@@ -1197,5 +1203,3 @@

type: ValidationErrorType.RelationExpression,
message: `Duplicate relation name "${
err.relationName
}" in relation expression "${exp}". Use "a.[b, c]" instead of "[a.b, a.c]".`
message: `Duplicate relation name "${err.relationName}" in relation expression "${exp}". Use "a.[b, c]" instead of "[a.b, a.c]".`
});

@@ -1202,0 +1206,0 @@ } else {

@@ -299,2 +299,6 @@ 'use strict';

clearHaving(...args) {
return this.addOperation(new KnexOperation('clearHaving'), args);
}
orHaving(...args) {

@@ -301,0 +305,0 @@ return this.addOperation(new KnexOperation('orHaving'), args);

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

const { isSubclassOf } = require('../utils/classUtils');
const { isString, isFunction, isRegExp, last } = require('../utils/objectUtils');
const { QueryBuilderOperation } = require('./operations/QueryBuilderOperation');
const { QueryBuilderContextBase } = require('./QueryBuilderContextBase');

@@ -472,3 +470,6 @@ const { QueryBuilderUserContext } = require('./QueryBuilderUserContext');

return op => op.name === operationSelector;
} else if (isSubclassOf(operationSelector, QueryBuilderOperation)) {
} else if (
isFunction(operationSelector) &&
operationSelector.isObjectionQueryBuilderOperationClass
) {
return op => op.is(operationSelector);

@@ -475,0 +476,0 @@ } else if (isFunction(operationSelector)) {

@@ -80,4 +80,4 @@ 'use strict';

: this.modelClass
? builder.tableRefFor(this.modelClass.getTableName())
: null;
? builder.tableRefFor(this.modelClass.getTableName())
: null;

@@ -84,0 +84,0 @@ if (table) {

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

return builder.modify(this.modify);
return this.applyModify(builder);
}

@@ -111,3 +111,3 @@

) {
let relatedJoinSelect = relatedJoinSelectQuery.modify(this.modify).as(relatedTableAlias);
let relatedJoinSelect = this.applyModify(relatedJoinSelectQuery).as(relatedTableAlias);

@@ -114,0 +114,0 @@ if (relatedJoinSelect.isSelectAll()) {

'use strict';
const { RelationProperty } = require('./RelationProperty');
const getModel = () => require('../model/Model').Model;

@@ -12,3 +11,2 @@ const { RelationFindOperation } = require('./RelationFindOperation');

const { ref } = require('../queryBuilder/ReferenceBuilder');
const { isSubclassOf } = require('../utils/classUtils');
const { resolveModel } = require('../utils/resolveModel');

@@ -134,2 +132,6 @@ const { get, isFunction } = require('../utils/objectUtils');

return this.applyModify(builder);
}
applyModify(builder) {
try {

@@ -156,10 +158,10 @@ return builder.modify(this.modify);

) {
let relatedSelect = relatedJoinSelectQuery.modify(this.modify).as(relatedTableAlias);
let relatedJoinSelect = this.applyModify(relatedJoinSelectQuery).as(relatedTableAlias);
if (relatedSelect.isSelectAll()) {
if (relatedJoinSelect.isSelectAll()) {
// No need to join a subquery if the query is `select * from "RelatedTable"`.
relatedSelect = aliasedTableName(relatedTable, relatedTableAlias);
relatedJoinSelect = aliasedTableName(relatedTable, relatedTableAlias);
}
return builder[joinOperation](relatedSelect, join => {
return builder[joinOperation](relatedJoinSelect, join => {
const relatedProp = this.relatedProp;

@@ -250,2 +252,10 @@ const ownerProp = this.ownerProp;

Object.defineProperties(Relation, {
isObjectionRelationClass: {
enumerable: false,
writable: false,
value: true
}
});
Object.defineProperties(Relation.prototype, {

@@ -270,3 +280,3 @@ isObjectionRelation: {

function checkOwnerModelClass(ctx) {
if (!isSubclassOf(ctx.ownerModelClass, getModel())) {
if (!isFunction(ctx.ownerModelClass) || !ctx.ownerModelClass.isObjectionModelClass) {
throw ctx.createError(`Relation's owner is not a subclass of Model`);

@@ -307,3 +317,3 @@ }

if (!isSubclassOf(ctx.mapping.relation, Relation)) {
if (!isFunction(ctx.mapping.relation) || !ctx.mapping.relation.isObjectionRelationClass) {
throw ctx.createError('relation is not a subclass of Relation');

@@ -342,5 +352,3 @@ }

throw ctx.createError(
`join: relation name and join property '${
ctx.name
}' cannot have the same name. If you cannot change one or the other, you can use $parseDatabaseJson and $formatDatabaseJson methods to convert the column name.`
`join: relation name and join property '${ctx.name}' cannot have the same name. If you cannot change one or the other, you can use $parseDatabaseJson and $formatDatabaseJson methods to convert the column name.`
);

@@ -364,5 +372,3 @@ }

throw ctx.createError(
`join: either \`from\` or \`to\` must point to the owner model table and the other one to the related table. It might be that specified table '${
err.tableName
}' is not correct`
`join: either \`from\` or \`to\` must point to the owner model table and the other one to the related table. It might be that specified table '${err.tableName}' is not correct`
);

@@ -369,0 +375,0 @@ } else if (err instanceof RelationProperty.InvalidReferenceError) {

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

this._propSetters = paths.map(it => createSetter(it.path));
this._patchers = refs.map(it => createPatcher(it));
this._patchers = refs.map((it, i) => createPatcher(it, paths[i].path));
}

@@ -231,5 +231,5 @@

function createPatcher(ref) {
function createPatcher(ref, path) {
if (ref.isPlainColumnRef) {
return (patch, value) => (patch[ref.column] = value);
return (patch, value) => (patch[path[0]] = value);
} else {

@@ -236,0 +236,0 @@ // Objection `patch`, `update` etc. methods understand field expressions.

'use strict';
const Bluebird = require('bluebird');
const { Model } = require('./model/Model');
const promiseUtils = require('./utils/promiseUtils');
const { isSubclassOf } = require('./utils/classUtils');
const { isFunction } = require('./utils/objectUtils');

@@ -21,3 +19,3 @@

if (!isSubclassOf(args[0], Model) && isFunction(args[0].transaction)) {
if (!isModelClass(args[0]) && isFunction(args[0].transaction)) {
let knex = args[0];

@@ -39,3 +37,3 @@ args = args.slice(1);

for (i = 0; i < modelClasses.length; ++i) {
if (!isSubclassOf(modelClasses[i], Model)) {
if (!isModelClass(modelClasses[i])) {
return Bluebird.reject(

@@ -82,3 +80,3 @@ new Error('objection.transaction: all but the last argument should be Model subclasses')

if (isSubclassOf(modelClassOrKnex, Model)) {
if (isModelClass(modelClassOrKnex)) {
knex = modelClassOrKnex.knex();

@@ -110,4 +108,8 @@ }

function isModelClass(maybeModel) {
return isFunction(maybeModel) && maybeModel.isObjectionModelClass;
}
module.exports = {
transaction
};

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

throw new Error(
`one of the identifier columns [${ids}] is null or undefined. Have you specified the correct identifier column for the model '${
modelClass.name
}' using the 'idColumn' property?`
`one of the identifier columns [${ids}] is null or undefined. Have you specified the correct identifier column for the model '${modelClass.name}' using the 'idColumn' property?`
);

@@ -14,0 +12,0 @@ }

'use strict';
const { isFunction } = require('./objectUtils');
function isSubclassOf(Constructor, SuperConstructor) {
if (!isFunction(SuperConstructor)) {
return false;
}
while (isFunction(Constructor)) {
if (Constructor === SuperConstructor) {
return true;
}
Constructor = Object.getPrototypeOf(Constructor);
}
return false;
}
function inherit(Constructor, BaseConstructor) {

@@ -30,4 +12,3 @@ Constructor.prototype = Object.create(BaseConstructor.prototype);

module.exports = {
isSubclassOf,
inherit
};
'use strict';
const path = require('path');
const { once, isString, isFunction } = require('../utils/objectUtils');
const { isSubclassOf } = require('../utils/classUtils');
const { isString, isFunction } = require('../utils/objectUtils');
const getModel = once(() => require('../model/Model').Model);
class ResolveError extends Error {}

@@ -19,7 +17,7 @@

} else {
if (isFunction(modelRef) && !isSubclassOf(modelRef, getModel())) {
if (isFunction(modelRef) && !isModelClass(modelRef)) {
modelRef = modelRef();
}
if (!isSubclassOf(modelRef, getModel())) {
if (!isModelClass(modelRef)) {
throw new ResolveError(

@@ -62,3 +60,2 @@ `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.`

function requireModel(modelPath) {
const Model = getModel();
/**

@@ -73,5 +70,5 @@ * Wrap path string in template literal to prevent

if (isSubclassOf(mod, Model)) {
if (isModelClass(mod)) {
modelClass = mod;
} else if (isSubclassOf(mod.default, Model)) {
} else if (isModelClass(mod.default)) {
// Babel 6 style of exposing default export.

@@ -83,3 +80,3 @@ modelClass = mod.default;

if (isSubclassOf(exp, Model)) {
if (isModelClass(exp)) {
if (modelClass !== null) {

@@ -96,3 +93,3 @@ throw new ResolveError(

if (!isSubclassOf(modelClass, Model)) {
if (!isModelClass(modelClass)) {
throw new ResolveError(`${modelPath} is an invalid file path to a model class`);

@@ -108,4 +105,8 @@ }

function isModelClass(maybeModel) {
return isFunction(maybeModel) && maybeModel.isObjectionModelClass;
}
module.exports = {
resolveModel
};
{
"name": "objection",
"version": "1.6.9",
"version": "1.6.11",
"description": "An SQL-friendly ORM for Node.js",

@@ -64,4 +64,4 @@ "main": "lib/objection.js",

"dependencies": {
"ajv": "^6.1.1",
"bluebird": "^3.5.3",
"ajv": "^6.10.0",
"bluebird": "^3.5.5",
"lodash": "^4.17.11"

@@ -73,23 +73,23 @@ },

"devDependencies": {
"@babel/polyfill": "^7.2.5",
"@types/node": "^10.0.6",
"@babel/polyfill": "^7.4.4",
"@types/node": "^12.7.5",
"babel-eslint": "^10.0.1",
"chai": "^4.2.0",
"chai-subset": "^1.6.0",
"coveralls": "^3.0.2",
"cross-env": "^5.2.0",
"eslint": "^5.9.0",
"eslint-plugin-prettier": "^3.0.0",
"coveralls": "^3.0.3",
"cross-env": "^6.0.0",
"eslint": "^5.16.0",
"eslint-plugin-prettier": "^3.1.0",
"expect.js": "^0.3.1",
"fs-extra": "^7.0.1",
"fs-extra": "^8.1.0",
"glob": "^7.1.3",
"knex": "0.16.4-next2",
"mocha": "^5.2.0",
"mysql": "^2.16.0",
"nyc": "^13.3.0",
"pg": "^7.6.1",
"prettier": "1.13.6",
"sqlite3": "^4.0.0",
"typescript": "^3.3.3",
"vuepress": "0.14.10"
"knex": "^0.17.0",
"mocha": "^6.2.0",
"mysql": "^2.17.1",
"nyc": "^14.1.1",
"pg": "^7.11.0",
"prettier": "1.18.2",
"sqlite3": "^4.0.8",
"typescript": "^3.4.5",
"vuepress": "1.1.0"
},

@@ -96,0 +96,0 @@ "nyc": {

@@ -32,5 +32,10 @@ // Type definitions for Objection.js

const snakeCaseMappers: () => ColumnNameMappers;
const knexSnakeCaseMappers: () => KnexMappers;
const snakeCaseMappers: (opt?: SnakeCaseMappersOptions) => ColumnNameMappers;
const knexSnakeCaseMappers: (opt?: SnakeCaseMappersOptions) => KnexMappers;
export interface SnakeCaseMappersOptions {
upperCase?: boolean;
underscoreBeforeDigits?: boolean;
}
interface LiteralObject {

@@ -272,3 +277,5 @@ [key: string]: Value;

? DeepPartialGraphArray<T[number]>
: T extends Model ? DeepPartialGraphModel<T> : T;
: T extends Model
? DeepPartialGraphModel<T>
: T;

@@ -345,3 +352,3 @@ export interface InsertGraphOptions {

interface JoinRelation {
<QM extends Model>(relationName: string, opt?: RelationOptions): QueryBuilder<QM, QM[]>;
<QM extends Model>(expr: RelationExpression, opt?: RelationOptions): QueryBuilder<QM, QM[]>;
}

@@ -721,3 +728,3 @@

type PartialUpdate<QM extends Model> = {
[P in keyof QM]?: QM[P] | Raw | Reference | QueryBuilder<any, any[]>
[P in keyof QM]?: QM[P] | Raw | Reference | QueryBuilder<any, any[]>;
};

@@ -731,4 +738,3 @@

findById(id: Id): QueryBuilderYieldingOneOrNone<QM>;
findById(idOrIds: IdOrIds): this;
findById(idOrIds: IdOrIds): QueryBuilderYieldingOneOrNone<QM>;
findByIds(ids: Id[] | Id[][]): this;

@@ -810,3 +816,6 @@ /** findOne is shorthand for .where(...whereArgs).first() */

): this;
whereInComposite(column: ColumnRef | ColumnRef[], values: Value[] | QueryBuilder<any, any[]>): this;
whereInComposite(
column: ColumnRef | ColumnRef[],
values: Value[] | QueryBuilder<any, any[]>
): this;

@@ -920,3 +929,3 @@ whereJsonSupersetOf: WhereJson<QM, RM, RV>;

alias(alias: string): this;
aliasFor(modelClassOrTableName: string | ModelClass<any>, alias:string): this;
aliasFor(modelClassOrTableName: string | ModelClass<any>, alias: string): this;
tableRefFor(modelClass: ModelClass<any>): string;

@@ -1109,4 +1118,4 @@ tableNameFor(modelClass: ModelClass<any>): string;

// Union
union: SetOperations<QM>;
unionAll: SetOperations<QM>;
union: Union<QM>;
unionAll: Union<QM>;
intersect: SetOperations<QM>;

@@ -1307,15 +1316,58 @@

interface OrderBy<QM extends Model, RM, RV> {
(column: ColumnRef, direction?: string): QueryBuilder<QM, RM, RV>;
(column: ColumnRef, order?: string): QueryBuilder<QM, RM, RV>;
(columns: ({ column: ColumnRef; order?: string } | string)[]): QueryBuilder<QM, RM, RV>;
}
interface SetOperations<QM extends Model> {
type QBOrCallback<QM extends Model> =
| QueryBuilder<QM, QM[]>
| ((this: QueryBuilder<QM, QM[]>, queryBuilder: QueryBuilder<QM, QM[]>) => void);
interface Union<QM extends Model> extends BaseSetOperations<QM> {
(...args: QBOrCallback<QM>[]): QueryBuilder<QM, QM[]>;
(arg1: QBOrCallback<QM>, wrap?: boolean): QueryBuilder<QM, QM[]>;
(arg1: QBOrCallback<QM>, arg2: QBOrCallback<QM>, wrap?: boolean): QueryBuilder<QM, QM[]>;
(
callback: (this: QueryBuilder<QM, QM[]>, queryBuilder: QueryBuilder<QM, QM[]>) => void,
arg1: QBOrCallback<QM>,
arg2: QBOrCallback<QM>,
arg3: QBOrCallback<QM>,
wrap?: boolean
): QueryBuilder<QM, QM[]>;
(
callbacks: ((this: QueryBuilder<QM, QM[]>, queryBuilder: QueryBuilder<QM, QM[]>) => void)[],
arg1: QBOrCallback<QM>,
arg2: QBOrCallback<QM>,
arg3: QBOrCallback<QM>,
arg4: QBOrCallback<QM>,
wrap?: boolean
): QueryBuilder<QM, QM[]>;
(
arg1: QBOrCallback<QM>,
arg2: QBOrCallback<QM>,
arg3: QBOrCallback<QM>,
arg4: QBOrCallback<QM>,
arg5: QBOrCallback<QM>,
wrap?: boolean
): QueryBuilder<QM, QM[]>;
(
arg1: QBOrCallback<QM>,
arg2: QBOrCallback<QM>,
arg3: QBOrCallback<QM>,
arg4: QBOrCallback<QM>,
arg5: QBOrCallback<QM>,
arg6: QBOrCallback<QM>,
wrap?: boolean
): QueryBuilder<QM, QM[]>;
(
arg1: QBOrCallback<QM>,
arg2: QBOrCallback<QM>,
arg3: QBOrCallback<QM>,
arg4: QBOrCallback<QM>,
arg5: QBOrCallback<QM>,
arg6: QBOrCallback<QM>,
arg7: QBOrCallback<QM>,
wrap?: boolean
): QueryBuilder<QM, QM[]>;
}
interface SetOperations<QM extends Model> extends BaseSetOperations<QM> {
(
...callbacks: ((this: QueryBuilder<QM, QM[]>, queryBuilder: QueryBuilder<QM, QM[]>) => void)[]

@@ -1325,2 +1377,13 @@ ): QueryBuilder<QM, QM[]>;

interface BaseSetOperations<QM extends Model> {
(
callback: (this: QueryBuilder<QM, QM[]>, queryBuilder: QueryBuilder<QM, QM[]>) => void,
wrap?: boolean
): QueryBuilder<QM, QM[]>;
(
callbacks: ((this: QueryBuilder<QM, QM[]>, queryBuilder: QueryBuilder<QM, QM[]>) => void)[],
wrap?: boolean
): QueryBuilder<QM, QM[]>;
}
// commons

@@ -1345,4 +1408,23 @@

// The following is from https://gist.github.com/enriched/c84a2a99f886654149908091a3183e15
type JsonSchemaFormatType =
| 'date-time'
| 'time'
| 'date'
| 'email'
| 'idn-email'
| 'hostname'
| 'idn-hostname'
| 'ipv4'
| 'ipv6'
| 'uri'
| 'uri-reference'
| 'iri'
| 'iri-reference'
| 'uri-template'
| 'json-pointer'
| 'relative-json-pointer'
| 'regex';
// The following is extended version of interface from https://gist.github.com/enriched/c84a2a99f886654149908091a3183e15
/*

@@ -1487,3 +1569,7 @@ * MIT License

type?: string | string[];
/**
* fallback raw string for custom formats,
* or formats that aren't in the standard yet
*/
format?: JsonSchemaFormatType | string;
/////////////////////////////////////////////////

@@ -1490,0 +1576,0 @@ // Combining Schemas

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