From e672267f233f9e1e5395acd49c3ad76c5d1fe2d9 Mon Sep 17 00:00:00 2001 From: Cyrus Eftos Date: Wed, 2 Jan 2019 11:50:39 +0800 Subject: [PATCH 1/3] build: fixed lint command --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 869c3cd..f6b2847 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "scripts": { "prepack": "yarn verify && yarn build", "build": "tsc -p tsconfig.build.json", - "lint": "yarn tslint --project tsconfig.build.json", + "lint": "yarn tslint --project .", "test": "jest", "verify": "yarn tsc -p tsconfig.json && yarn test && yarn lint", "cz": "git-cz" From fa2ad60d85a72ae2013f30e3bfe8a7f65260be7e Mon Sep 17 00:00:00 2001 From: Cyrus Eftos Date: Wed, 2 Jan 2019 11:51:05 +0800 Subject: [PATCH 2/3] chore: tweaked lint config --- tslint.json | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/tslint.json b/tslint.json index 5e9d47d..a0c3e7b 100644 --- a/tslint.json +++ b/tslint.json @@ -1,10 +1,14 @@ { - "extends": ["tslint:latest", "tslint-eslint-rules", "tslint-config-prettier"], + "extends": [ + "tslint:latest", + "tslint-eslint-rules", + "tslint-config-prettier" + ], "rules": { - "ordered-imports": false, "member-ordering": false, "object-literal-sort-keys": false, "member-access": false, - "interface-name": false + "interface-name": false, + "no-implicit-dependencies": false } } From 8ad44daae6bed25f6ac5d01d356535d4c97d0ad5 Mon Sep 17 00:00:00 2001 From: Cyrus Eftos Date: Wed, 2 Jan 2019 11:52:27 +0800 Subject: [PATCH 3/3] fix: included mockQueryExecutor in package. also updated snapshots and fixed linting errors --- src/__snapshots__/type-safety.test.ts.snap | 6 +++--- src/index.ts | 9 ++++++++- src/mock-query-executor.test.ts | 2 +- src/mock-query-executor.ts | 11 +++-------- src/query-executor.ts | 3 +-- src/read-query-executor.ts | 3 ++- src/test-helpers/knex.ts | 2 +- src/type-safety-fixtures/create-query-helper.ts | 15 +++++++++------ src/type-safety.test.ts | 2 +- src/unit-of-work-query-executor.ts | 3 ++- 10 files changed, 31 insertions(+), 25 deletions(-) diff --git a/src/__snapshots__/type-safety.test.ts.snap b/src/__snapshots__/type-safety.test.ts.snap index 31a84af..d00a77a 100644 --- a/src/__snapshots__/type-safety.test.ts.snap +++ b/src/__snapshots__/type-safety.test.ts.snap @@ -1,9 +1,9 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`Typescript: Typescript expected failures 1`] = ` -"src/type-safety-fixtures/create-query-helper.ts(14,20): error TS2339: Property 'wrongTable' does not exist on type 'TableNames<\\"testTable\\">'. -src/type-safety-fixtures/create-query-helper.ts(15,16): error TS2339: Property 'wrongTable' does not exist on type 'Tables<\\"testTable\\">'. -src/type-safety-fixtures/create-query-helper.ts(17,21): error TS2339: Property 'foo' does not exist on type '{ testArg: string; }'. +"src/type-safety-fixtures/create-query-helper.ts(17,20): error TS2339: Property 'wrongTable' does not exist on type 'TableNames<\\"testTable\\">'. +src/type-safety-fixtures/create-query-helper.ts(18,16): error TS2339: Property 'wrongTable' does not exist on type 'Tables<\\"testTable\\">'. +src/type-safety-fixtures/create-query-helper.ts(20,21): error TS2339: Property 'foo' does not exist on type '{ testArg: string; }'. src/type-safety-fixtures/query-arguments.ts(22,46): error TS2345: Argument of type '{}' is not assignable to parameter of type '{ testArg: string; }'. Property 'testArg' is missing in type '{}' but required in type '{ testArg: string; }'. " diff --git a/src/index.ts b/src/index.ts index a3b7f66..b22cde2 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,9 +1,16 @@ import * as Knex from 'knex' +import { MockQueryExecutor, NoMatch } from './mock-query-executor' import { QueryExecutor } from './query-executor' import { ReadQueryExecutor } from './read-query-executor' import { UnitOfWorkQueryExecutor } from './unit-of-work-query-executor' -export { QueryExecutor, ReadQueryExecutor, UnitOfWorkQueryExecutor } +export { + MockQueryExecutor, + NoMatch, + QueryExecutor, + ReadQueryExecutor, + UnitOfWorkQueryExecutor +} export type Tables = { [table in TTableNames]: () => Knex.QueryBuilder diff --git a/src/mock-query-executor.test.ts b/src/mock-query-executor.test.ts index f8eedc5..3fd8f37 100644 --- a/src/mock-query-executor.test.ts +++ b/src/mock-query-executor.test.ts @@ -1,4 +1,4 @@ -import { MockQueryExecutor } from './mock-query-executor' +import { MockQueryExecutor } from '.' const tables = { tableOne: 'table-one' diff --git a/src/mock-query-executor.ts b/src/mock-query-executor.ts index ee451ca..c4d5735 100644 --- a/src/mock-query-executor.ts +++ b/src/mock-query-executor.ts @@ -1,11 +1,6 @@ -import { - ReadQueryExecutor, - Query, - ExecuteResult, - UnitOfWorkQueryExecutor, - TableNames -} from '.' - +import { ExecuteResult, Query, TableNames } from '.' +import { ReadQueryExecutor } from './read-query-executor' +import { UnitOfWorkQueryExecutor } from './unit-of-work-query-executor' export const NoMatch = Symbol('no match') export type Matcher = (args: Args) => typeof NoMatch | Result diff --git a/src/query-executor.ts b/src/query-executor.ts index 2c8ac7d..e1b97f9 100644 --- a/src/query-executor.ts +++ b/src/query-executor.ts @@ -1,6 +1,5 @@ import * as Knex from 'knex' - -import { Tables, QueryWrapper, TableNames, Query, ExecuteResult } from '.' +import { ExecuteResult, Query, QueryWrapper, TableNames, Tables } from '.' export class QueryExecutor< TTableNames extends string, diff --git a/src/read-query-executor.ts b/src/read-query-executor.ts index 5adce33..a714258 100644 --- a/src/read-query-executor.ts +++ b/src/read-query-executor.ts @@ -1,5 +1,6 @@ import * as Knex from 'knex' -import { QueryExecutor, TableNames } from '.' +import { TableNames } from '.' +import { QueryExecutor } from './query-executor' import { UnitOfWorkQueryExecutor } from './unit-of-work-query-executor' export class ReadQueryExecutor< diff --git a/src/test-helpers/knex.ts b/src/test-helpers/knex.ts index e304430..84e1d09 100644 --- a/src/test-helpers/knex.ts +++ b/src/test-helpers/knex.ts @@ -4,7 +4,7 @@ import mockDb from 'mock-knex' export function createMockedKnex( mockResults: (query: mockDb.QueryDetails, step: number) => void ) { - var db = knex({ + const db = knex({ client: 'sqlite', useNullAsDefault: true }) diff --git a/src/type-safety-fixtures/create-query-helper.ts b/src/type-safety-fixtures/create-query-helper.ts index fcc1bef..99d11a6 100644 --- a/src/type-safety-fixtures/create-query-helper.ts +++ b/src/type-safety-fixtures/create-query-helper.ts @@ -1,15 +1,18 @@ import * as Knex from 'knex' -import { QueryExecutor, ReadQueryExecutor, Query } from '../' +import { ReadQueryExecutor } from '../' declare const knex: Knex -const tableNames = { - testTable: 'testTable' -} - -const queryExecutor = new ReadQueryExecutor(knex, {}, tableNames) +const queryExecutor = new ReadQueryExecutor( + knex, + {}, + { + testTable: 'testTable' + } +) const exampleQuery = queryExecutor.createQuery<{ testArg: string }, string>( + // tslint:disable-next-line:no-shadowed-variable async function exampleQuery({ args, tableNames, tables }) { tableNames.wrongTable tables.wrongTable() diff --git a/src/type-safety.test.ts b/src/type-safety.test.ts index f618c51..7898176 100644 --- a/src/type-safety.test.ts +++ b/src/type-safety.test.ts @@ -1,5 +1,5 @@ -import path from 'path' import spawn from 'cross-spawn' +import path from 'path' test('Typescript', () => { const typescriptCompilation = spawn.sync('./node_modules/.bin/tsc', [ diff --git a/src/unit-of-work-query-executor.ts b/src/unit-of-work-query-executor.ts index e149f7d..d372b6b 100644 --- a/src/unit-of-work-query-executor.ts +++ b/src/unit-of-work-query-executor.ts @@ -1,5 +1,6 @@ import * as Knex from 'knex' -import { TableNames, QueryExecutor } from '.' +import { TableNames } from '.' +import { QueryExecutor } from './query-executor' export class UnitOfWorkQueryExecutor< TTableNames extends string,