From bb1d194eaec37289f4474bb25cab14a3a8c79b92 Mon Sep 17 00:00:00 2001 From: Dan Chao Date: Fri, 2 Nov 2018 12:16:46 -0700 Subject: [PATCH 1/8] add typings for cassanknex --- types/cassanknex/cassanknex-tests.ts | 74 ++++++++++ types/cassanknex/index.d.ts | 204 +++++++++++++++++++++++++++ types/cassanknex/tsconfig.json | 24 ++++ types/cassanknex/tslint.json | 14 ++ 4 files changed, 316 insertions(+) create mode 100644 types/cassanknex/cassanknex-tests.ts create mode 100644 types/cassanknex/index.d.ts create mode 100644 types/cassanknex/tsconfig.json create mode 100644 types/cassanknex/tslint.json diff --git a/types/cassanknex/cassanknex-tests.ts b/types/cassanknex/cassanknex-tests.ts new file mode 100644 index 0000000000..45e4ba3261 --- /dev/null +++ b/types/cassanknex/cassanknex-tests.ts @@ -0,0 +1,74 @@ +import * as cassanknex from "cassanknex"; + +const knex = cassanknex({ + connection: { + contactPoints: ['127.0.0.1'] + } +}); + +knex.on('ready', (err) => { +}); + +interface BirdRow { + type: string; + canFly: boolean; +} + +const qb = knex("animals") + .insert({ + type: 'Stork', + canFly: true + }) + .into('birds'); + +qb.exec((err, res) => { +}); + +qb.eachRow((n, row) => { +}, (err) => { +}); + +interface FooRow { + id: string; + foo: string; + bar: number; + baz: string[]; +} + +const query2 = knex("keyspace") + .select("id", "foo", "bar", "baz") + .ttl('foo') + .where("id", "=", "1") + .orWhere("id", "in", ["2", "3"]) + .orWhere("baz", "=", ["bar"]) + .andWhere("foo", "IN", ["baz", "bar"]) + .limit(10) + .from("table"); + +query2.stream({ + readable () { + const row = this.read(); + }, + end () {}, + error () {} +}); + +const values = { + id: "foo", + bar: 13, + baz: ["foo", "bar"] +}; + +const query3 = knex("cassanKnexy") + .insert(values) + .usingTimestamp(250000) + .usingTTL(50000) + .into("columnFamily"); + +const [cql, params] = [query3.cql(), query3.bindings()]; + +const query4 = knex("cassanKnexy") + .update("columnFamily") + .add("bar", { foo: "baz" }) // "bar" is a map + .remove("foo", ["bar"]) // "foo" is a set + .where("id", "=", 1); diff --git a/types/cassanknex/index.d.ts b/types/cassanknex/index.d.ts new file mode 100644 index 0000000000..5f5dc72b8c --- /dev/null +++ b/types/cassanknex/index.d.ts @@ -0,0 +1,204 @@ +// Type definitions for cassanknex 1.19 +// Project: https://github.com/azuqua/cassanknex +// Definitions by: Daniel Chao +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.8 + +/// + +import { EventEmitter } from "events"; +import { Client, ClientOptions, types, ResultCallback } from "cassandra-driver"; +import * as Long from "long"; +import { Readable } from "stream"; + +declare function CassanKnex (options?: CassanKnex.DriverOptions): CassanKnex.CassanKnex; + +export = CassanKnex; + +/** + * Will return the `never` type if `T[K]` is not a member of `Type`, for all `T[K]`. + */ +type TypeMatchedValue = T[K] extends Type ? This : never; + +type MappedDict = { + [key: string]: B +}; + +type InRestriction = 'in' | 'IN'; + +type ComparisonRestriction = '=' | '<' | '>' | '<=' | '>='; + +declare namespace CassanKnex { + interface DriverOptions { + debug?: boolean; + connection?: Client | ClientOptions; + } + + interface CassanKnex extends EventEmitter { + (keyspace?: string): QueryBuilderRoot; + } + + type SelectAsClause = { + [P in keyof T]: string; + }; + + interface StreamParams { + readable: (this: Readable) => any; + end: (this: Readable) => any; + error: (err: Error) => any; + } + + interface QueryBuilderRoot { + insert (values: Partial | T): InsertQueryBuilder; + select (...columns: Array): SelectQueryBuilder; + select (values: SelectAsClause): SelectQueryBuilder; + update (table: string): UpdateQueryBuilder; + delete (): DeleteQueryBuilder; + alterColumnFamily (columnFamily: string): AlterColumnFamilyQueryBuilder; + createColumnFamily (columnFamily: string): CreateColumnFamilyQueryBuilder; + createColumnFamilyIfNotExists (columnFamily: string): CreateColumnFamilyQueryBuilder; + createIndex (columnFamily: string, indexName: string, column: keyof T): QueryBuilder; + createIndexCustom (columnFamily: string, indexName: string, column: keyof T): QueryBuilder & CreateableIndexBuilder; + createType (typeName: string): CreateTypeQueryBuilder; + createTypeIfNotExists (typeName: string): CreateTypeQueryBuilder; + dropColumnFamily (columnFamily: string): QueryBuilder; + dropColumnFamilyIfExists (columnFamily: string): QueryBuilder; + dropType (): QueryBuilder; + dropTypeIfExists (): QueryBuilder; + truncate (columnFamily: string): QueryBuilder; + alterKeyspace (keyspace: string): KeyspaceQueryBuilder; + createKeyspace (keyspace: string): KeyspaceQueryBuilder; + createKeyspaceIfNotExists (keyspace: string): KeyspaceQueryBuilder; + dropKeyspace (): QueryBuilder; + dropKeyspaceIfExists (): QueryBuilder; + } + + interface QueryBuilder { + cql (): string; + bindings (): any[]; + exec (cb: ResultCallback): undefined; + eachRow (onEachRow: (n: number, row: types.Row) => any, onError: (err: Error) => any): undefined; + stream (params: StreamParams): undefined; + } + + interface FieldValueQueryBuilder { + decimal (columnName: K): TypeMatchedValue; + boolean (columnName: K): TypeMatchedValue; + blob (columnName: K): TypeMatchedValue; + timestamp (columnName: K): TypeMatchedValue; + date (columnName: K): TypeMatchedValue; + inet (columnName: K): TypeMatchedValue; + bigint (columnName: K): TypeMatchedValue; + counter (columnName: K): TypeMatchedValue; + double (columnName: K): TypeMatchedValue; + int (columnName: K): TypeMatchedValue; + float (columnName: K): TypeMatchedValue; + map (columnName: K, a: A, b: B): TypeMatchedValue, this>; + ascii (columnName: K): TypeMatchedValue; + text (columnName: K): TypeMatchedValue; + timeuuid (columnName: K): TypeMatchedValue; + uuid (columnName: K): TypeMatchedValue; + varchar (columnName: K): TypeMatchedValue; + list (columnName: K, typeName: string): TypeMatchedValue; + primary (primaryKey: string): this; + set (columnName: K, a: A): TypeMatchedValue, this>; + } + + interface CreateableColumnFamilyBuilder { + withCaching (): this; + withCompression (): this; + withCompaction (): this; + withClusteringOrderBy (value: K, direction: 'desc' | 'asc'): this; + } + + interface CreateableIndexBuilder { + withOptions (opts: MappedDict): this; + } + + interface KeyspaceableQueryBuilder { + withNetworkTopologyStrategy (strategy: MappedDict): this; + withSimpleStrategy (replicas: number): this; + withDurableWrites (durableWrites: boolean): this; + } + + interface InsertableQueryBuilder { + into (table: string): this; + ifNotExists (): this; + } + + interface TtlableQueryBuilder { + usingTimestamp (timestamp: number): this; + usingTTL (ttl: number): this; + } + + interface WhereableQueryBuilder { + where (lhs: K, comparison: InRestriction, rhs: Array): this; + where (lhs: K, comparison: ComparisonRestriction, rhs: T[K]): this; + orWhere (lhs: K, comparison: InRestriction, rhs: Array): this; + orWhere (lhs: K, comparison: ComparisonRestriction, rhs: T[K]): this; + andWhere (lhs: K, comparison: InRestriction, rhs: Array): this; + andWhere (lhs: K, comparison: ComparisonRestriction, rhs: T[K]): this; + tokenWhere (lhs: K, comparison: InRestriction, rhs: Array): this; + tokenWhere (lhs: K, comparison: ComparisonRestriction, rhs: T[K]): this; + ttl (columnName: K): this; + } + + interface IfableQueryBuilder { + if (lhs: K, comparison: ComparisonRestriction, rhs: T[K] | null): this; + } + + interface LimitableQueryBuilder { + limit (limit: number): this; + limitPerPartition (limit: number): this; + } + + interface FromableQueryBuilder { + from (table: string): this; + } + + interface UpdateableQueryBuilder { + set (key: K, value: T[K]): this; + set (object: Partial): this; + add (key: K, value: { [str: string]: T[K] }): TypeMatchedValue, this>; + add (key: K, value: Array): TypeMatchedValue, this>; + add (object: Partial): this; + remove (key: K, value: Array): this; + remove (object: Partial): this; + increment (column: keyof T, amount: number): this; + increment (object: Partial): this; + decrement (column: keyof T, amount: number): this; + decrement (object: Partial): this; + } + + interface AlterableQueryBuilder { + drop (...columns: K[]): this; + rename (column: K, newColumn: K): this; + alter (column: K, newType: string): this; + } + + type InsertQueryBuilder = QueryBuilder + & InsertableQueryBuilder + & TtlableQueryBuilder; + type SelectQueryBuilder = QueryBuilder + & WhereableQueryBuilder + & LimitableQueryBuilder + & FromableQueryBuilder; + type UpdateQueryBuilder = QueryBuilder + & WhereableQueryBuilder + & UpdateableQueryBuilder + & IfableQueryBuilder + & TtlableQueryBuilder; + type DeleteQueryBuilder = QueryBuilder + & WhereableQueryBuilder + & FromableQueryBuilder; + type CreateColumnFamilyQueryBuilder = QueryBuilder + & FieldValueQueryBuilder + & CreateableColumnFamilyBuilder; + type KeyspaceQueryBuilder = QueryBuilder + & KeyspaceableQueryBuilder; + type CreateTypeQueryBuilder = QueryBuilder + & FieldValueQueryBuilder; + type AlterColumnFamilyQueryBuilder = QueryBuilder + & AlterableQueryBuilder + & FieldValueQueryBuilder; +} diff --git a/types/cassanknex/tsconfig.json b/types/cassanknex/tsconfig.json new file mode 100644 index 0000000000..d77cbaca70 --- /dev/null +++ b/types/cassanknex/tsconfig.json @@ -0,0 +1,24 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6", + "dom" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "cassanknex-tests.ts" + ] +} \ No newline at end of file diff --git a/types/cassanknex/tslint.json b/types/cassanknex/tslint.json new file mode 100644 index 0000000000..8bd9293b77 --- /dev/null +++ b/types/cassanknex/tslint.json @@ -0,0 +1,14 @@ +{ + "extends": "dtslint/dt.json", + "rules": { + "space-before-function-paren": [true, "always"], + "no-unnecessary-generics": false, + "strict-export-declare-modifiers": false, + "prefer-readonly": false, + "await-promise": false, + "no-for-in-array": false, + "no-void-expression": false, + "expect": false, + "no-declare-current-package": false + } +} \ No newline at end of file From b2d972b0ae8649d0651d8128f935f3de09452bec Mon Sep 17 00:00:00 2001 From: Dan Chao Date: Fri, 2 Nov 2018 13:57:08 -0700 Subject: [PATCH 2/8] expect: true --- types/cassanknex/tslint.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/cassanknex/tslint.json b/types/cassanknex/tslint.json index 8bd9293b77..978a6cf2fc 100644 --- a/types/cassanknex/tslint.json +++ b/types/cassanknex/tslint.json @@ -8,7 +8,7 @@ "await-promise": false, "no-for-in-array": false, "no-void-expression": false, - "expect": false, + "expect": true, "no-declare-current-package": false } } \ No newline at end of file From 08544665c8862d3637605b9390dca5b2bc583187 Mon Sep 17 00:00:00 2001 From: Dan Chao Date: Fri, 2 Nov 2018 13:58:44 -0700 Subject: [PATCH 3/8] fix linting errors --- types/cassanknex/index.d.ts | 102 ++++++++++++++++++------------------ 1 file changed, 51 insertions(+), 51 deletions(-) diff --git a/types/cassanknex/index.d.ts b/types/cassanknex/index.d.ts index 5f5dc72b8c..0de4ac8ebc 100644 --- a/types/cassanknex/index.d.ts +++ b/types/cassanknex/index.d.ts @@ -20,9 +20,9 @@ export = CassanKnex; */ type TypeMatchedValue = T[K] extends Type ? This : never; -type MappedDict = { +interface MappedDict { [key: string]: B -}; +} type InRestriction = 'in' | 'IN'; @@ -49,18 +49,18 @@ declare namespace CassanKnex { } interface QueryBuilderRoot { - insert (values: Partial | T): InsertQueryBuilder; - select (...columns: Array): SelectQueryBuilder; - select (values: SelectAsClause): SelectQueryBuilder; - update (table: string): UpdateQueryBuilder; - delete (): DeleteQueryBuilder; - alterColumnFamily (columnFamily: string): AlterColumnFamilyQueryBuilder; - createColumnFamily (columnFamily: string): CreateColumnFamilyQueryBuilder; - createColumnFamilyIfNotExists (columnFamily: string): CreateColumnFamilyQueryBuilder; - createIndex (columnFamily: string, indexName: string, column: keyof T): QueryBuilder; - createIndexCustom (columnFamily: string, indexName: string, column: keyof T): QueryBuilder & CreateableIndexBuilder; - createType (typeName: string): CreateTypeQueryBuilder; - createTypeIfNotExists (typeName: string): CreateTypeQueryBuilder; + insert (values: Partial | T): InsertQueryBuilder; + select (...columns: Array): SelectQueryBuilder; + select (values: SelectAsClause): SelectQueryBuilder; + update (table: string): UpdateQueryBuilder; + delete (): DeleteQueryBuilder; + alterColumnFamily (columnFamily: string): AlterColumnFamilyQueryBuilder; + createColumnFamily (columnFamily: string): CreateColumnFamilyQueryBuilder; + createColumnFamilyIfNotExists (columnFamily: string): CreateColumnFamilyQueryBuilder; + createIndex (columnFamily: string, indexName: string, column: keyof T): QueryBuilder; + createIndexCustom (columnFamily: string, indexName: string, column: keyof T): QueryBuilder & CreateableIndexBuilder; + createType (typeName: string): CreateTypeQueryBuilder; + createTypeIfNotExists (typeName: string): CreateTypeQueryBuilder; dropColumnFamily (columnFamily: string): QueryBuilder; dropColumnFamilyIfExists (columnFamily: string): QueryBuilder; dropType (): QueryBuilder; @@ -82,33 +82,33 @@ declare namespace CassanKnex { } interface FieldValueQueryBuilder { - decimal (columnName: K): TypeMatchedValue; - boolean (columnName: K): TypeMatchedValue; - blob (columnName: K): TypeMatchedValue; - timestamp (columnName: K): TypeMatchedValue; - date (columnName: K): TypeMatchedValue; - inet (columnName: K): TypeMatchedValue; - bigint (columnName: K): TypeMatchedValue; - counter (columnName: K): TypeMatchedValue; - double (columnName: K): TypeMatchedValue; - int (columnName: K): TypeMatchedValue; - float (columnName: K): TypeMatchedValue; - map (columnName: K, a: A, b: B): TypeMatchedValue, this>; - ascii (columnName: K): TypeMatchedValue; - text (columnName: K): TypeMatchedValue; - timeuuid (columnName: K): TypeMatchedValue; - uuid (columnName: K): TypeMatchedValue; - varchar (columnName: K): TypeMatchedValue; - list (columnName: K, typeName: string): TypeMatchedValue; + decimal (columnName: K): TypeMatchedValue; + boolean (columnName: K): TypeMatchedValue; + blob (columnName: K): TypeMatchedValue; + timestamp (columnName: K): TypeMatchedValue; + date (columnName: K): TypeMatchedValue; + inet (columnName: K): TypeMatchedValue; + bigint (columnName: K): TypeMatchedValue; + counter (columnName: K): TypeMatchedValue; + double (columnName: K): TypeMatchedValue; + int (columnName: K): TypeMatchedValue; + float (columnName: K): TypeMatchedValue; + map (columnName: K, a: A, b: B): TypeMatchedValue, this>; + ascii (columnName: K): TypeMatchedValue; + text (columnName: K): TypeMatchedValue; + timeuuid (columnName: K): TypeMatchedValue; + uuid (columnName: K): TypeMatchedValue; + varchar (columnName: K): TypeMatchedValue; + list (columnName: K, typeName: string): TypeMatchedValue; primary (primaryKey: string): this; - set (columnName: K, a: A): TypeMatchedValue, this>; + set (columnName: K, a: A): TypeMatchedValue, this>; } interface CreateableColumnFamilyBuilder { withCaching (): this; withCompression (): this; withCompaction (): this; - withClusteringOrderBy (value: K, direction: 'desc' | 'asc'): this; + withClusteringOrderBy (value: K, direction: 'desc' | 'asc'): this; } interface CreateableIndexBuilder { @@ -132,19 +132,19 @@ declare namespace CassanKnex { } interface WhereableQueryBuilder { - where (lhs: K, comparison: InRestriction, rhs: Array): this; - where (lhs: K, comparison: ComparisonRestriction, rhs: T[K]): this; - orWhere (lhs: K, comparison: InRestriction, rhs: Array): this; - orWhere (lhs: K, comparison: ComparisonRestriction, rhs: T[K]): this; - andWhere (lhs: K, comparison: InRestriction, rhs: Array): this; - andWhere (lhs: K, comparison: ComparisonRestriction, rhs: T[K]): this; - tokenWhere (lhs: K, comparison: InRestriction, rhs: Array): this; - tokenWhere (lhs: K, comparison: ComparisonRestriction, rhs: T[K]): this; - ttl (columnName: K): this; + where (lhs: K, comparison: InRestriction, rhs: Array): this; + where (lhs: K, comparison: ComparisonRestriction, rhs: T[K]): this; + orWhere (lhs: K, comparison: InRestriction, rhs: Array): this; + orWhere (lhs: K, comparison: ComparisonRestriction, rhs: T[K]): this; + andWhere (lhs: K, comparison: InRestriction, rhs: Array): this; + andWhere (lhs: K, comparison: ComparisonRestriction, rhs: T[K]): this; + tokenWhere (lhs: K, comparison: InRestriction, rhs: Array): this; + tokenWhere (lhs: K, comparison: ComparisonRestriction, rhs: T[K]): this; + ttl (columnName: K): this; } interface IfableQueryBuilder { - if (lhs: K, comparison: ComparisonRestriction, rhs: T[K] | null): this; + if (lhs: K, comparison: ComparisonRestriction, rhs: T[K] | null): this; } interface LimitableQueryBuilder { @@ -157,12 +157,12 @@ declare namespace CassanKnex { } interface UpdateableQueryBuilder { - set (key: K, value: T[K]): this; + set (key: K, value: T[K]): this; set (object: Partial): this; - add (key: K, value: { [str: string]: T[K] }): TypeMatchedValue, this>; - add (key: K, value: Array): TypeMatchedValue, this>; + add (key: K, value: { [str: string]: T[K] }): TypeMatchedValue, this>; + add (key: K, value: Array): TypeMatchedValue, this>; add (object: Partial): this; - remove (key: K, value: Array): this; + remove (key: K, value: Array): this; remove (object: Partial): this; increment (column: keyof T, amount: number): this; increment (object: Partial): this; @@ -171,9 +171,9 @@ declare namespace CassanKnex { } interface AlterableQueryBuilder { - drop (...columns: K[]): this; - rename (column: K, newColumn: K): this; - alter (column: K, newType: string): this; + drop (...columns: K[]): this; + rename (column: K, newColumn: K): this; + alter (column: K, newType: string): this; } type InsertQueryBuilder = QueryBuilder From f681ca576b3cbbe8c7785858f542f415e9191344 Mon Sep 17 00:00:00 2001 From: Dan Chao Date: Fri, 2 Nov 2018 14:00:02 -0700 Subject: [PATCH 4/8] semicolon --- types/cassanknex/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/cassanknex/index.d.ts b/types/cassanknex/index.d.ts index 0de4ac8ebc..bd85325b4b 100644 --- a/types/cassanknex/index.d.ts +++ b/types/cassanknex/index.d.ts @@ -21,7 +21,7 @@ export = CassanKnex; type TypeMatchedValue = T[K] extends Type ? This : never; interface MappedDict { - [key: string]: B + [key: string]: B; } type InRestriction = 'in' | 'IN'; From 4ee3aa7569fb9a21baaef713529de9328d4658e3 Mon Sep 17 00:00:00 2001 From: Dan Chao Date: Fri, 2 Nov 2018 14:43:57 -0700 Subject: [PATCH 5/8] move all type aliases to within the namespace --- types/cassanknex/index.d.ts | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/types/cassanknex/index.d.ts b/types/cassanknex/index.d.ts index bd85325b4b..b9b75e92e6 100644 --- a/types/cassanknex/index.d.ts +++ b/types/cassanknex/index.d.ts @@ -15,33 +15,33 @@ declare function CassanKnex (options?: CassanKnex.DriverOptions): CassanKnex.Cas export = CassanKnex; -/** - * Will return the `never` type if `T[K]` is not a member of `Type`, for all `T[K]`. - */ -type TypeMatchedValue = T[K] extends Type ? This : never; - -interface MappedDict { - [key: string]: B; -} - -type InRestriction = 'in' | 'IN'; - -type ComparisonRestriction = '=' | '<' | '>' | '<=' | '>='; - declare namespace CassanKnex { interface DriverOptions { debug?: boolean; connection?: Client | ClientOptions; } + /** + * Will return the `never` type if `T[K]` is not a member of `Type`, for all `T[K]`. + */ + type TypeMatchedValue = T[K] extends Type ? This : never; + + interface MappedDict { + [key: string]: B; + } + + type InRestriction = 'in' | 'IN'; + + type ComparisonRestriction = '=' | '<' | '>' | '<=' | '>='; + + type SelectAsClause = { + [P in keyof T]: string; + }; + interface CassanKnex extends EventEmitter { (keyspace?: string): QueryBuilderRoot; } - type SelectAsClause = { - [P in keyof T]: string; - }; - interface StreamParams { readable: (this: Readable) => any; end: (this: Readable) => any; From 51f148ad836c791c8b947f86a2d366a1d714dfc4 Mon Sep 17 00:00:00 2001 From: Dan Chao Date: Mon, 5 Nov 2018 17:37:33 -0800 Subject: [PATCH 6/8] use import = require syntax per PR feedback --- types/cassanknex/cassanknex-tests.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/cassanknex/cassanknex-tests.ts b/types/cassanknex/cassanknex-tests.ts index 45e4ba3261..550fe141aa 100644 --- a/types/cassanknex/cassanknex-tests.ts +++ b/types/cassanknex/cassanknex-tests.ts @@ -1,4 +1,4 @@ -import * as cassanknex from "cassanknex"; +import cassanknex = require('cassanknex'); const knex = cassanknex({ connection: { From 4ec7a6b59bf208fa631398ef5f7cb9924a3740e4 Mon Sep 17 00:00:00 2001 From: Dan Chao Date: Sun, 2 Dec 2018 13:04:25 -0800 Subject: [PATCH 7/8] re-emable most dts-lint errors --- types/cassanknex/index.d.ts | 176 +++++++++++++++++------------------ types/cassanknex/tslint.json | 15 +-- 2 files changed, 92 insertions(+), 99 deletions(-) diff --git a/types/cassanknex/index.d.ts b/types/cassanknex/index.d.ts index b9b75e92e6..fd7f9c53f4 100644 --- a/types/cassanknex/index.d.ts +++ b/types/cassanknex/index.d.ts @@ -11,7 +11,7 @@ import { Client, ClientOptions, types, ResultCallback } from "cassandra-driver"; import * as Long from "long"; import { Readable } from "stream"; -declare function CassanKnex (options?: CassanKnex.DriverOptions): CassanKnex.CassanKnex; +declare function CassanKnex(options?: CassanKnex.DriverOptions): CassanKnex.CassanKnex; export = CassanKnex; @@ -49,134 +49,134 @@ declare namespace CassanKnex { } interface QueryBuilderRoot { - insert (values: Partial | T): InsertQueryBuilder; - select (...columns: Array): SelectQueryBuilder; - select (values: SelectAsClause): SelectQueryBuilder; - update (table: string): UpdateQueryBuilder; - delete (): DeleteQueryBuilder; - alterColumnFamily (columnFamily: string): AlterColumnFamilyQueryBuilder; - createColumnFamily (columnFamily: string): CreateColumnFamilyQueryBuilder; - createColumnFamilyIfNotExists (columnFamily: string): CreateColumnFamilyQueryBuilder; - createIndex (columnFamily: string, indexName: string, column: keyof T): QueryBuilder; - createIndexCustom (columnFamily: string, indexName: string, column: keyof T): QueryBuilder & CreateableIndexBuilder; - createType (typeName: string): CreateTypeQueryBuilder; - createTypeIfNotExists (typeName: string): CreateTypeQueryBuilder; - dropColumnFamily (columnFamily: string): QueryBuilder; - dropColumnFamilyIfExists (columnFamily: string): QueryBuilder; - dropType (): QueryBuilder; - dropTypeIfExists (): QueryBuilder; - truncate (columnFamily: string): QueryBuilder; - alterKeyspace (keyspace: string): KeyspaceQueryBuilder; - createKeyspace (keyspace: string): KeyspaceQueryBuilder; - createKeyspaceIfNotExists (keyspace: string): KeyspaceQueryBuilder; - dropKeyspace (): QueryBuilder; - dropKeyspaceIfExists (): QueryBuilder; + insert (values: Partial | T): InsertQueryBuilder; + select (...columns: Array): SelectQueryBuilder; + select (values: SelectAsClause): SelectQueryBuilder; + update (table: string): UpdateQueryBuilder; + delete (): DeleteQueryBuilder; + alterColumnFamily (columnFamily: string): AlterColumnFamilyQueryBuilder; + createColumnFamily (columnFamily: string): CreateColumnFamilyQueryBuilder; + createColumnFamilyIfNotExists (columnFamily: string): CreateColumnFamilyQueryBuilder; + createIndex (columnFamily: string, indexName: string, column: keyof T): QueryBuilder; + createIndexCustom (columnFamily: string, indexName: string, column: keyof T): QueryBuilder & CreateableIndexBuilder; + createType (typeName: string): CreateTypeQueryBuilder; + createTypeIfNotExists (typeName: string): CreateTypeQueryBuilder; + dropColumnFamily(columnFamily: string): QueryBuilder; + dropColumnFamilyIfExists(columnFamily: string): QueryBuilder; + dropType(): QueryBuilder; + dropTypeIfExists(): QueryBuilder; + truncate(columnFamily: string): QueryBuilder; + alterKeyspace(keyspace: string): KeyspaceQueryBuilder; + createKeyspace(keyspace: string): KeyspaceQueryBuilder; + createKeyspaceIfNotExists(keyspace: string): KeyspaceQueryBuilder; + dropKeyspace(): QueryBuilder; + dropKeyspaceIfExists(): QueryBuilder; } interface QueryBuilder { - cql (): string; - bindings (): any[]; - exec (cb: ResultCallback): undefined; - eachRow (onEachRow: (n: number, row: types.Row) => any, onError: (err: Error) => any): undefined; - stream (params: StreamParams): undefined; + cql(): string; + bindings(): any[]; + exec(cb: ResultCallback): undefined; + eachRow(onEachRow: (n: number, row: types.Row) => any, onError: (err: Error) => any): undefined; + stream(params: StreamParams): undefined; } interface FieldValueQueryBuilder { - decimal (columnName: K): TypeMatchedValue; - boolean (columnName: K): TypeMatchedValue; - blob (columnName: K): TypeMatchedValue; - timestamp (columnName: K): TypeMatchedValue; - date (columnName: K): TypeMatchedValue; - inet (columnName: K): TypeMatchedValue; - bigint (columnName: K): TypeMatchedValue; - counter (columnName: K): TypeMatchedValue; - double (columnName: K): TypeMatchedValue; - int (columnName: K): TypeMatchedValue; - float (columnName: K): TypeMatchedValue; - map (columnName: K, a: A, b: B): TypeMatchedValue, this>; - ascii (columnName: K): TypeMatchedValue; - text (columnName: K): TypeMatchedValue; - timeuuid (columnName: K): TypeMatchedValue; - uuid (columnName: K): TypeMatchedValue; - varchar (columnName: K): TypeMatchedValue; - list (columnName: K, typeName: string): TypeMatchedValue; - primary (primaryKey: string): this; - set (columnName: K, a: A): TypeMatchedValue, this>; + decimal (columnName: K): TypeMatchedValue; + boolean (columnName: K): TypeMatchedValue; + blob (columnName: K): TypeMatchedValue; + timestamp (columnName: K): TypeMatchedValue; + date (columnName: K): TypeMatchedValue; + inet (columnName: K): TypeMatchedValue; + bigint (columnName: K): TypeMatchedValue; + counter (columnName: K): TypeMatchedValue; + double (columnName: K): TypeMatchedValue; + int (columnName: K): TypeMatchedValue; + float (columnName: K): TypeMatchedValue; + map (columnName: K, a: A, b: B): TypeMatchedValue, this>; + ascii (columnName: K): TypeMatchedValue; + text (columnName: K): TypeMatchedValue; + timeuuid (columnName: K): TypeMatchedValue; + uuid (columnName: K): TypeMatchedValue; + varchar (columnName: K): TypeMatchedValue; + list (columnName: K, typeName: string): TypeMatchedValue; + primary(primaryKey: string): this; + set (columnName: K, a: A): TypeMatchedValue, this>; } interface CreateableColumnFamilyBuilder { - withCaching (): this; - withCompression (): this; - withCompaction (): this; - withClusteringOrderBy (value: K, direction: 'desc' | 'asc'): this; + withCaching(): this; + withCompression(): this; + withCompaction(): this; + withClusteringOrderBy (value: K, direction: 'desc' | 'asc'): this; } interface CreateableIndexBuilder { - withOptions (opts: MappedDict): this; + withOptions(opts: MappedDict): this; } interface KeyspaceableQueryBuilder { - withNetworkTopologyStrategy (strategy: MappedDict): this; - withSimpleStrategy (replicas: number): this; - withDurableWrites (durableWrites: boolean): this; + withNetworkTopologyStrategy(strategy: MappedDict): this; + withSimpleStrategy(replicas: number): this; + withDurableWrites(durableWrites: boolean): this; } interface InsertableQueryBuilder { - into (table: string): this; - ifNotExists (): this; + into(table: string): this; + ifNotExists(): this; } interface TtlableQueryBuilder { - usingTimestamp (timestamp: number): this; - usingTTL (ttl: number): this; + usingTimestamp(timestamp: number): this; + usingTTL(ttl: number): this; } interface WhereableQueryBuilder { - where (lhs: K, comparison: InRestriction, rhs: Array): this; - where (lhs: K, comparison: ComparisonRestriction, rhs: T[K]): this; - orWhere (lhs: K, comparison: InRestriction, rhs: Array): this; - orWhere (lhs: K, comparison: ComparisonRestriction, rhs: T[K]): this; - andWhere (lhs: K, comparison: InRestriction, rhs: Array): this; - andWhere (lhs: K, comparison: ComparisonRestriction, rhs: T[K]): this; - tokenWhere (lhs: K, comparison: InRestriction, rhs: Array): this; - tokenWhere (lhs: K, comparison: ComparisonRestriction, rhs: T[K]): this; - ttl (columnName: K): this; + where (lhs: K, comparison: InRestriction, rhs: Array): this; + where (lhs: K, comparison: ComparisonRestriction, rhs: T[K]): this; + orWhere (lhs: K, comparison: InRestriction, rhs: Array): this; + orWhere (lhs: K, comparison: ComparisonRestriction, rhs: T[K]): this; + andWhere (lhs: K, comparison: InRestriction, rhs: Array): this; + andWhere (lhs: K, comparison: ComparisonRestriction, rhs: T[K]): this; + tokenWhere (lhs: K, comparison: InRestriction, rhs: Array): this; + tokenWhere (lhs: K, comparison: ComparisonRestriction, rhs: T[K]): this; + ttl (columnName: K): this; } interface IfableQueryBuilder { - if (lhs: K, comparison: ComparisonRestriction, rhs: T[K] | null): this; + if (lhs: K, comparison: ComparisonRestriction, rhs: T[K] | null): this; } interface LimitableQueryBuilder { - limit (limit: number): this; - limitPerPartition (limit: number): this; + limit(limit: number): this; + limitPerPartition(limit: number): this; } interface FromableQueryBuilder { - from (table: string): this; + from(table: string): this; } interface UpdateableQueryBuilder { - set (key: K, value: T[K]): this; - set (object: Partial): this; - add (key: K, value: { [str: string]: T[K] }): TypeMatchedValue, this>; - add (key: K, value: Array): TypeMatchedValue, this>; - add (object: Partial): this; - remove (key: K, value: Array): this; - remove (object: Partial): this; - increment (column: keyof T, amount: number): this; - increment (object: Partial): this; - decrement (column: keyof T, amount: number): this; - decrement (object: Partial): this; + set (key: K, value: T[K]): this; + set(object: Partial): this; + add (key: K, value: { [str: string]: T[K] }): TypeMatchedValue, this>; + add (key: K, value: Array): TypeMatchedValue, this>; + add(object: Partial): this; + remove (key: K, value: Array): this; + remove(object: Partial): this; + increment(column: keyof T, amount: number): this; + increment(object: Partial): this; + decrement(column: keyof T, amount: number): this; + decrement(object: Partial): this; } interface AlterableQueryBuilder { - drop (...columns: K[]): this; - rename (column: K, newColumn: K): this; - alter (column: K, newType: string): this; + drop (...columns: K[]): this; + rename (column: K, newColumn: K): this; + alter (column: K, newType: string): this; } - type InsertQueryBuilder = QueryBuilder + type InsertQueryBuilder = QueryBuilder & InsertableQueryBuilder & TtlableQueryBuilder; type SelectQueryBuilder = QueryBuilder diff --git a/types/cassanknex/tslint.json b/types/cassanknex/tslint.json index 978a6cf2fc..4074d3cece 100644 --- a/types/cassanknex/tslint.json +++ b/types/cassanknex/tslint.json @@ -1,14 +1,7 @@ { "extends": "dtslint/dt.json", - "rules": { - "space-before-function-paren": [true, "always"], - "no-unnecessary-generics": false, - "strict-export-declare-modifiers": false, - "prefer-readonly": false, - "await-promise": false, - "no-for-in-array": false, - "no-void-expression": false, - "expect": true, - "no-declare-current-package": false - } + "rules": { + "no-unnecessary-generics": false, + "strict-export-declare-modifiers": false + } } \ No newline at end of file From 9a5fd17efc249b0085813aad11c5589e03425ab9 Mon Sep 17 00:00:00 2001 From: Dan Chao Date: Sun, 2 Dec 2018 13:10:33 -0800 Subject: [PATCH 8/8] fix more linting errors --- types/cassanknex/cassanknex-tests.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/types/cassanknex/cassanknex-tests.ts b/types/cassanknex/cassanknex-tests.ts index 550fe141aa..b874d2a784 100644 --- a/types/cassanknex/cassanknex-tests.ts +++ b/types/cassanknex/cassanknex-tests.ts @@ -46,11 +46,11 @@ const query2 = knex("keyspace") .from("table"); query2.stream({ - readable () { + readable() { const row = this.read(); }, - end () {}, - error () {} + end() {}, + error() {} }); const values = {