Skip to content

Commit

Permalink
Merge pull request #1 from cyruseftos/fix/export-missing-modules
Browse files Browse the repository at this point in the history
Export MockQueryExecutor
  • Loading branch information
JakeGinnivan authored Jan 2, 2019
2 parents f5fc85a + 8ad44da commit ace86b0
Show file tree
Hide file tree
Showing 12 changed files with 39 additions and 29 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 3 additions & 3 deletions src/__snapshots__/type-safety.test.ts.snap
Original file line number Diff line number Diff line change
@@ -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; }'.
"
Expand Down
9 changes: 8 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -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<TTableNames extends string> = {
[table in TTableNames]: () => Knex.QueryBuilder
Expand Down
2 changes: 1 addition & 1 deletion src/mock-query-executor.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MockQueryExecutor } from './mock-query-executor'
import { MockQueryExecutor } from '.'

const tables = {
tableOne: 'table-one'
Expand Down
11 changes: 3 additions & 8 deletions src/mock-query-executor.ts
Original file line number Diff line number Diff line change
@@ -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, Result> = (args: Args) => typeof NoMatch | Result
Expand Down
3 changes: 1 addition & 2 deletions src/query-executor.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
3 changes: 2 additions & 1 deletion src/read-query-executor.ts
Original file line number Diff line number Diff line change
@@ -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<
Expand Down
2 changes: 1 addition & 1 deletion src/test-helpers/knex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
Expand Down
15 changes: 9 additions & 6 deletions src/type-safety-fixtures/create-query-helper.ts
Original file line number Diff line number Diff line change
@@ -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()
Expand Down
2 changes: 1 addition & 1 deletion src/type-safety.test.ts
Original file line number Diff line number Diff line change
@@ -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', [
Expand Down
3 changes: 2 additions & 1 deletion src/unit-of-work-query-executor.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
10 changes: 7 additions & 3 deletions tslint.json
Original file line number Diff line number Diff line change
@@ -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
}
}

0 comments on commit ace86b0

Please sign in to comment.