From 3f0cbf20fc2f61d43fb3f60185c4ae09f38803e8 Mon Sep 17 00:00:00 2001 From: Satana Charuwichitratana Date: Sat, 6 Jan 2018 00:35:01 +0700 Subject: [PATCH] [@types/knex] Fixed search path incomplete typing (#22698) * [@types/knex] Added multiple searchPath support for 0.14.1 * [@types/knex] Fixed whitespace lint * [@types/knex] Fixed typedef-whitespace lint * [@types/knex] Fixed semicolon lint --- types/knex/index.d.ts | 9 ++-- types/knex/knex-tests.ts | 104 ++++++++++++++++++++------------------- types/knex/tsconfig.json | 2 +- types/knex/tslint.json | 6 +-- 4 files changed, 61 insertions(+), 60 deletions(-) diff --git a/types/knex/index.d.ts b/types/knex/index.d.ts index 792541d6dd..58dafaf788 100644 --- a/types/knex/index.d.ts +++ b/types/knex/index.d.ts @@ -1,9 +1,10 @@ -// Type definitions for Knex.js +// Type definitions for Knex.js 0.14 // Project: https://github.com/tgriesser/knex // Definitions by: Qubo // Baronfel // Pablo Rodríguez // Matt R. Wilson +// Satana Charuwichitratana // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.3 @@ -28,7 +29,7 @@ interface Knex extends Knex.QueryInterface { transaction(transactionScope: (trx: Knex.Transaction) => Promise | Bluebird | void): Bluebird; destroy(callback: Function): void; destroy(): Bluebird; - batchInsert(tableName : TableName, data: any[], chunkSize : number) : Knex.QueryBuilder; + batchInsert(tableName: TableName, data: any[], chunkSize: number): Knex.QueryBuilder; schema: Knex.SchemaBuilder; queryBuilder(): Knex.QueryBuilder; @@ -250,7 +251,7 @@ declare namespace Knex { } interface WithSchema { - (schema: string): QueryBuilder + (schema: string): QueryBuilder; } interface WithWrapped { @@ -523,7 +524,7 @@ declare namespace Knex { seeds?: SeedsConfig; acquireConnectionTimeout?: number; useNullAsDefault?: boolean; - searchPath?: string; + searchPath?: string | string[]; } interface ConnectionConfig { diff --git a/types/knex/knex-tests.ts b/types/knex/knex-tests.ts index 687b641b93..3f9f20ab72 100644 --- a/types/knex/knex-tests.ts +++ b/types/knex/knex-tests.ts @@ -118,8 +118,12 @@ var knex = Knex({ // searchPath var knex = Knex({ - client: 'pg', - searchPath: 'public', + client: 'pg', + searchPath: 'public', +}); +var knex = Knex({ + client: 'pg', + searchPath: ['public', 'private'], }); // useNullAsDefault @@ -159,7 +163,7 @@ knex.select('title', 'author', 'year').from('books'); knex.select().table('books'); knex.avg('sum_column1').from(function() { - this.sum('column1 as sum_column1').from('t1').groupBy('column1').as('t1') + this.sum('column1 as sum_column1').from('t1').groupBy('column1').as('t1'); }).as('ignored_alias'); knex.column('title', 'author', 'year').select().from('books'); @@ -174,7 +178,7 @@ knex('users').where({ knex('users').where('id', 1); knex('users').where(() => { - this.where('id', 1).orWhere('id', '>', 10) + this.where('id', 1).orWhere('id', '>', 10); }).orWhere({name: 'Tester'}); knex('users').where('votes', '>', 100); @@ -242,11 +246,11 @@ knex('users') .select('users.id', 'contacts.phone'); knex.select('*').from('users').join(knex('accounts').select('id', 'owner_id').as('accounts'), function() { - this.on('accounts.id', '=', 'users.account_id').orOn('accounts.owner_id', '=', 'users.id') + this.on('accounts.id', '=', 'users.account_id').orOn('accounts.owner_id', '=', 'users.id'); }); knex.select('*').from('users').join('accounts', function() { - this.on('accounts.id', '=', 'users.account_id').orOn('accounts.owner_id', '=', 'users.id') + this.on('accounts.id', '=', 'users.account_id').orOn('accounts.owner_id', '=', 'users.id'); }); knex.select('*').from('users').join('accounts', function(join: Knex.JoinClause) { @@ -262,121 +266,121 @@ knex.select('*').from('user').join('contacts', () => { }); knex.select('*').from('users').join('contacts', function() { - this.on('users.id', '=', 'contacts.id').onIn('contacts.id', [7, 15, 23, 41]) + this.on('users.id', '=', 'contacts.id').onIn('contacts.id', [7, 15, 23, 41]); }); knex.select('*').from('users').join('contacts', function() { - this.on('users.id', '=', 'contacts.id').andOnIn('contacts.id', [7, 15, 23, 41]) + this.on('users.id', '=', 'contacts.id').andOnIn('contacts.id', [7, 15, 23, 41]); }); knex.select('*').from('users').join('contacts', function() { - this.on('users.id', '=', 'contacts.id').orOnIn('contacts.id', [7, 15, 23, 41]) + this.on('users.id', '=', 'contacts.id').orOnIn('contacts.id', [7, 15, 23, 41]); }); knex.select('*').from('users').join('contacts', function() { - this.on('users.id', '=', 'contacts.id').onNotIn('contacts.id', [7, 15, 23, 41]) + this.on('users.id', '=', 'contacts.id').onNotIn('contacts.id', [7, 15, 23, 41]); }); knex.select('*').from('users').join('contacts', function() { - this.on('users.id', '=', 'contacts.id').andOnNotIn('contacts.id', [7, 15, 23, 41]) + this.on('users.id', '=', 'contacts.id').andOnNotIn('contacts.id', [7, 15, 23, 41]); }); knex.select('*').from('users').join('contacts', function() { - this.on('users.id', '=', 'contacts.id').orOnNotIn('contacts.id', [7, 15, 23, 41]) + this.on('users.id', '=', 'contacts.id').orOnNotIn('contacts.id', [7, 15, 23, 41]); }); knex.select('*').from('users').join('contacts', function() { - this.on('users.id', '=', 'contacts.id').onNull('contacts.email') + this.on('users.id', '=', 'contacts.id').onNull('contacts.email'); }); knex.select('*').from('users').join('contacts', function() { - this.on('users.id', '=', 'contacts.id').andOnNull('contacts.email') + this.on('users.id', '=', 'contacts.id').andOnNull('contacts.email'); }); knex.select('*').from('users').join('contacts', function() { - this.on('users.id', '=', 'contacts.id').orOnNull('contacts.email') + this.on('users.id', '=', 'contacts.id').orOnNull('contacts.email'); }); knex.select('*').from('users').join('contacts', function() { - this.on('users.id', '=', 'contacts.id').onNotNull('contacts.email') + this.on('users.id', '=', 'contacts.id').onNotNull('contacts.email'); }); knex.select('*').from('users').join('contacts', function() { - this.on('users.id', '=', 'contacts.id').andOnNotNull('contacts.email') + this.on('users.id', '=', 'contacts.id').andOnNotNull('contacts.email'); }); knex.select('*').from('users').join('contacts', function() { - this.on('users.id', '=', 'contacts.id').orOnNotNull('contacts.email') + this.on('users.id', '=', 'contacts.id').orOnNotNull('contacts.email'); }); knex.select('*').from('users').join('contacts', function() { this.on('users.id', '=', 'contacts.id').onExists(function() { this.select('*').from('accounts').whereRaw('users.account_id = accounts.id'); - }) + }); }); knex.select('*').from('users').join('contacts', function() { this.on('users.id', '=', 'contacts.id').andOnExists(function() { this.select('*').from('accounts').whereRaw('users.account_id = accounts.id'); - }) + }); }); knex.select('*').from('users').join('contacts', function() { this.on('users.id', '=', 'contacts.id').orOnExists(function() { this.select('*').from('accounts').whereRaw('users.account_id = accounts.id'); - }) + }); }); knex.select('*').from('users').join('contacts', function() { this.on('users.id', '=', 'contacts.id').onNotExists(function() { this.select('*').from('accounts').whereRaw('users.account_id = accounts.id'); - }) + }); }); knex.select('*').from('users').join('contacts', function() { this.on('users.id', '=', 'contacts.id').andOnNotExists(function() { this.select('*').from('accounts').whereRaw('users.account_id = accounts.id'); - }) + }); }); knex.select('*').from('users').join('contacts', function() { this.on('users.id', '=', 'contacts.id').orOnNotExists(function() { this.select('*').from('accounts').whereRaw('users.account_id = accounts.id'); - }) + }); }); knex.select('*').from('users').join('contacts', function() { - this.on('users.id', '=', 'contacts.id').onBetween('contacts.id', [5, 30]) + this.on('users.id', '=', 'contacts.id').onBetween('contacts.id', [5, 30]); }); knex.select('*').from('users').join('contacts', function() { - this.on('users.id', '=', 'contacts.id').andOnBetween('contacts.id', [5, 30]) + this.on('users.id', '=', 'contacts.id').andOnBetween('contacts.id', [5, 30]); }); knex.select('*').from('users').join('contacts', function() { - this.on('users.id', '=', 'contacts.id').orOnBetween('contacts.id', [5, 30]) + this.on('users.id', '=', 'contacts.id').orOnBetween('contacts.id', [5, 30]); }); knex.select('*').from('users').join('contacts', function() { - this.on('users.id', '=', 'contacts.id').onNotBetween('contacts.id', [5, 30]) + this.on('users.id', '=', 'contacts.id').onNotBetween('contacts.id', [5, 30]); }); knex.select('*').from('users').join('contacts', function() { - this.on('users.id', '=', 'contacts.id').andOnNotBetween('contacts.id', [5, 30]) + this.on('users.id', '=', 'contacts.id').andOnNotBetween('contacts.id', [5, 30]); }); knex.select('*').from('users').join('contacts', function() { - this.on('users.id', '=', 'contacts.id').orOnNotBetween('contacts.id', [5, 30]) + this.on('users.id', '=', 'contacts.id').orOnNotBetween('contacts.id', [5, 30]); }); knex.select('*').from('users').join('contacts', function() { this.on('users.id', '=', 'contacts.id').onNotExists(function() { this.select('*').from('accounts').whereRaw('users.account_id = accounts.id'); - }) + }); }); knex.select('*').from('users').join('accounts', (join: Knex.JoinClause) => { - join.on('accounts.id', '=', 'users.account_id').orOn('accounts.owner_id', '=', 'users.id') + join.on('accounts.id', '=', 'users.account_id').orOn('accounts.owner_id', '=', 'users.id'); }); knex.select('*').from('users').join('accounts', 'accounts.type', knex.raw('?', ['admin'])); @@ -388,7 +392,7 @@ knex.from('users').innerJoin('accounts', 'users.id', 'accounts.user_id'); knex.table('users').innerJoin('accounts', 'users.id', '=', 'accounts.user_id'); knex('users').innerJoin('accounts', function() { - this.on('accounts.id', '=', 'users.account_id').orOn('accounts.owner_id', '=', 'users.id') + this.on('accounts.id', '=', 'users.account_id').orOn('accounts.owner_id', '=', 'users.id'); }); knex('users').innerJoin('accounts', (join: Knex.JoinClause) => { @@ -398,53 +402,53 @@ knex('users').innerJoin('accounts', (join: Knex.JoinClause) => { knex.select('*').from('users').leftJoin('accounts', 'users.id', 'accounts.user_id'); knex.select('*').from('users').leftJoin('accounts', function() { - this.on('accounts.id', '=', 'users.account_id').orOn('accounts.owner_id', '=', 'users.id') + this.on('accounts.id', '=', 'users.account_id').orOn('accounts.owner_id', '=', 'users.id'); }); knex.select('*').from('users').leftJoin('accounts', (join: Knex.JoinClause) => { - join.on('accounts.id', '=', 'users.account_id').orOn('accounts.owner_id', '=', 'users.id') + join.on('accounts.id', '=', 'users.account_id').orOn('accounts.owner_id', '=', 'users.id'); }); knex.select('*').from('users').leftOuterJoin('accounts', 'users.id', 'accounts.user_id'); knex.select('*').from('users').leftOuterJoin('accounts', function() { - this.on('accounts.id', '=', 'users.account_id').orOn('accounts.owner_id', '=', 'users.id') + this.on('accounts.id', '=', 'users.account_id').orOn('accounts.owner_id', '=', 'users.id'); }); knex.select('*').from('users').rightJoin('accounts', 'users.id', 'accounts.user_id'); knex.select('*').from('users').rightJoin('accounts', function() { - this.on('accounts.id', '=', 'users.account_id').orOn('accounts.owner_id', '=', 'users.id') + this.on('accounts.id', '=', 'users.account_id').orOn('accounts.owner_id', '=', 'users.id'); }); knex.select('*').from('users').rightJoin('accounts', (join: Knex.JoinClause) => { - join.on('accounts.id', '=', 'users.account_id').orOn('accounts.owner_id', '=', 'users.id') + join.on('accounts.id', '=', 'users.account_id').orOn('accounts.owner_id', '=', 'users.id'); }); knex.select('*').from('users').rightOuterJoin('accounts', 'users.id', 'accounts.user_id'); knex.select('*').from('users').rightOuterJoin('accounts', function() { - this.on('accounts.id', '=', 'users.account_id').orOn('accounts.owner_id', '=', 'users.id') + this.on('accounts.id', '=', 'users.account_id').orOn('accounts.owner_id', '=', 'users.id'); }); knex.select('*').from('users').outerJoin('accounts', 'users.id', 'accounts.user_id'); knex.select('*').from('users').outerJoin('accounts', function() { - this.on('accounts.id', '=', 'users.account_id').orOn('accounts.owner_id', '=', 'users.id') + this.on('accounts.id', '=', 'users.account_id').orOn('accounts.owner_id', '=', 'users.id'); }); knex.select('*').from('users').outerJoin('accounts', (join: Knex.JoinClause) => { - join.on('accounts.id', '=', 'users.account_id').orOn('accounts.owner_id', '=', 'users.id') + join.on('accounts.id', '=', 'users.account_id').orOn('accounts.owner_id', '=', 'users.id'); }); knex.select('*').from('users').fullOuterJoin('accounts', 'users.id', 'accounts.user_id'); knex.select('*').from('users').fullOuterJoin('accounts', function() { - this.on('accounts.id', '=', 'users.account_id').orOn('accounts.owner_id', '=', 'users.id') + this.on('accounts.id', '=', 'users.account_id').orOn('accounts.owner_id', '=', 'users.id'); }); knex.select('*').from('users').fullOuterJoin('accounts', (join: Knex.JoinClause) => { - join.on('accounts.id', '=', 'users.account_id').orOn('accounts.owner_id', '=', 'users.id') + join.on('accounts.id', '=', 'users.account_id').orOn('accounts.owner_id', '=', 'users.id'); }); knex.select('*').from('users').crossJoin('accounts', 'users.id', 'accounts.user_id'); @@ -480,7 +484,7 @@ knex('books') .returning('id') .insert([{title: 'Great Gatsby'}, {title: 'Fahrenheit 451'}]); -knex.batchInsert('books', [{title:'Great Gatsby'}, {title: 'Fahrenheit 451'}], 200); +knex.batchInsert('books', [{title: 'Great Gatsby'}, {title: 'Fahrenheit 451'}], 200); knex.queryBuilder().table('books'); knex('books').where('published_date', '<', 2000).update({status: 'archived'}); @@ -546,15 +550,15 @@ knex.transaction(function(trx) { knex('tableName') .transacting(trx) .forShare() - .select('*') -}) + .select('*'); +}); const transactionReturnValue = knex.transaction(function(trx) { return knex("table") .insert({ foo: "bar" }) .returning(["id"]) - .then(function(result) { return result[0].id as number }) -}) + .then(function(result) { return result[0].id as number; }); +}); // Tests that the transaction has kept the type of its return value by referencing a method of number transactionReturnValue.then(value => value.toExponential); @@ -781,7 +785,7 @@ knex.select('name').from('users') console.log(rows); }) .catch(function(error) { - console.error(error) + console.error(error); }); knex.select('*').from('users').where({name: 'Tim'}) @@ -825,7 +829,7 @@ knex.select('name').from('users').limit(10).then(function (rows: any[]) { memo.names.push(row.name); memo.count++; return memo; - }, {count: 0, names: []}) + }, {count: 0, names: []}); }).then(function(obj: any) { console.log(obj); }).catch(function(e: Error) { diff --git a/types/knex/tsconfig.json b/types/knex/tsconfig.json index 8f0b7771d9..41e9ae905e 100644 --- a/types/knex/tsconfig.json +++ b/types/knex/tsconfig.json @@ -21,4 +21,4 @@ "index.d.ts", "knex-tests.ts" ] -} \ No newline at end of file +} diff --git a/types/knex/tslint.json b/types/knex/tslint.json index a41bf5d19a..cf7f07f094 100644 --- a/types/knex/tslint.json +++ b/types/knex/tslint.json @@ -65,15 +65,11 @@ "prefer-method-signature": false, "prefer-template": false, "radix": false, - "semicolon": false, "space-before-function-paren": false, "space-within-parens": false, "strict-export-declare-modifiers": false, "trim-file": false, "triple-equals": false, - "typedef-whitespace": false, - "unified-signatures": false, - "void-return": false, - "whitespace": false + "unified-signatures": false } }