Skip to content

Commit

Permalink
Removed type declaration for now
Browse files Browse the repository at this point in the history
  • Loading branch information
SanderPeeters committed May 2, 2024
1 parent f588e99 commit b3804d1
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 49 deletions.
3 changes: 0 additions & 3 deletions fixup
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,3 @@ cat >dist/esm/package.json <<!EOF
"type": "module"
}
!EOF

find src -name '*.d.ts' -exec cp {} dist/mjs \;
find src -name '*.d.ts' -exec cp {} dist/cjs \;
61 changes: 30 additions & 31 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"esm": "^3.2.25",
"jest": "^29.7.0",
"knex": "^1.0.2",
"pg": "^8.7.3",
"pg": "^8.11.5",
"thenby": "^1.3.4",
"ts-jest": "^29.1.2",
"typescript": "^4.5.5"
Expand Down
17 changes: 10 additions & 7 deletions src/__tests__/postgres.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import by from 'thenby'
import { Knex } from 'knex'
import { firstBy } from 'thenby'
import {
ASC, DESC, createCursor, cursorToSqlQuery
} from '../index'
Expand All @@ -10,11 +10,14 @@ import {
} from '../testing'
import UserFactory from '../factories/UserFactory'
import { TABLE_TASKS, TASK_STATUS_COMPLETED, TASK_STATUS_PENDING, tasks } from '../factories/TaskFactory'
import faker from '@faker-js/faker'

const TABLE_USERS = 'users'
const TOTAL_USERS = 2
const TASKS_PER_USER = 2
const DATABASE_NAME = 'testing-postgres'

// We use a random word so when the tests run in parallel they don't collide.
const DATABASE_NAME = faker.random.word()

const users = () => {
const knex = getKnexConnection(DATABASE_NAME)
Expand Down Expand Up @@ -61,7 +64,7 @@ afterAll(async () => {

test('if simple ascending order by finds the correct users.', async () => {
const allUsers = await users().where({})
const sortedUsers = allUsers.sort(firstBy('id', 'asc'))
const sortedUsers = allUsers.sort(by.firstBy('id', 'asc'))
const orderBy = {
id: ASC,
}
Expand All @@ -83,7 +86,7 @@ test('if simple ascending order by finds the correct users.', async () => {

test('if simple descending order by finds the correct users.', async () => {
const allUsers = await users().where({})
const sortedUsers = allUsers.sort(firstBy('id', 'desc'))
const sortedUsers = allUsers.sort(by.firstBy('id', 'desc'))
const orderBy = {
id: DESC,
}
Expand All @@ -106,7 +109,7 @@ test('if simple descending order by finds the correct users.', async () => {
test('if advanced order by finds the correct users.', async () => {
const allUsers = await users().where({})
const sortedUsers = allUsers.sort(
firstBy('lastName', 'desc').thenBy('firstName', 'asc').thenBy('id', 'desc')
by.firstBy('lastName', 'desc').thenBy('firstName', 'asc').thenBy('id', 'desc')
)
const orderBy = {
lastName: DESC,
Expand All @@ -131,7 +134,7 @@ test('if advanced order by finds the correct users.', async () => {

test('if no cursor sorts users correctly.', async () => {
const allUsers = await users().where({})
const sortedUsers = allUsers.sort(firstBy('id', 'desc'))
const sortedUsers = allUsers.sort(by.firstBy('id', 'desc'))
const orderBy = {
id: DESC,
}
Expand Down Expand Up @@ -161,7 +164,7 @@ test('If joined table is sorted correctly', async () => {
`${TABLE_USERS}.id as userId`,
)
.leftJoin(TABLE_USERS, `${TABLE_TASKS}.userId`, `${TABLE_USERS}.id`)
const sortedTasks = allTasks.sort(firstBy('createdAt', 'asc').thenBy('userId', 'asc'))
const sortedTasks = allTasks.sort(by.firstBy('createdAt', 'asc').thenBy('userId', 'asc'))

const TOTAL_USER_TASKS = TOTAL_USERS * TASKS_PER_USER
expect(sortedTasks.length).toEqual(TOTAL_USER_TASKS)
Expand Down
5 changes: 3 additions & 2 deletions src/benchmarking.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Knex } from 'knex'
import {
createTestDatabase,
destroyTestDatabase,
Expand All @@ -6,7 +7,7 @@ import UserFactory, { TABLE_USERS } from 'factories/UserFactory'

const TOTAL_USERS = 2000

export const createBenchmarkDatabase = async (databaseName) => {
export const createBenchmarkDatabase = async (databaseName: string) => {
const knex = await createTestDatabase(databaseName)
if (knex) {
const now = knex.fn.now()
Expand All @@ -23,6 +24,6 @@ export const createBenchmarkDatabase = async (databaseName) => {
}
}

export const destroyBenchmarkDatabase = async (knex) => {
export const destroyBenchmarkDatabase = async (knex: Knex) => {
await destroyTestDatabase(knex)
}
9 changes: 5 additions & 4 deletions src/testing.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ClientConfig, Client as PostgresClient } from 'pg'
import pg from 'pg'
import createKnexConnection, { Knex } from 'knex'
import Factory from '@dashdot/factory'

Expand All @@ -12,7 +12,7 @@ export abstract class KnexFactory extends Factory {
}
}

export async function runRawQuery(query, useRoot = true) {
export async function runRawQuery(query: string, useRoot = true) {
const {
POSTGRES_HOST,
POSTGRES_PORT,
Expand All @@ -27,11 +27,11 @@ export async function runRawQuery(query, useRoot = true) {
password: POSTGRES_PASSWORD,
database: 'postgres',
ssl: false
} as ClientConfig
} as pg.ClientConfig
if (!useRoot) {
config.database = POSTGRES_DATABASE
}
const client = new PostgresClient(config)
const client = new pg.Client(config)
await client.connect()
const result = await client.query(query)
await client.end()
Expand Down Expand Up @@ -96,6 +96,7 @@ export async function destroyTestDatabase(knex: Knex | null = null) {
await knex.destroy()
const destroyDatabaseQuery = `DROP DATABASE IF EXISTS "${databaseName}";`
await runRawQuery(destroyDatabaseQuery)
console.log(`Database "${databaseName}" destroyed.`)
} catch (error) {
console.error(error)
}
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"allowJs": true,
"allowSyntheticDefaultImports": true,
"baseUrl": "src",
"declaration": true,
"declaration": false,
"esModuleInterop": true,
"inlineSourceMap": false,
"lib": ["esnext"],
Expand Down

0 comments on commit b3804d1

Please sign in to comment.