Skip to content

Commit

Permalink
more lint
Browse files Browse the repository at this point in the history
  • Loading branch information
mmkal committed Mar 21, 2024
1 parent f1161f6 commit acc7fbc
Show file tree
Hide file tree
Showing 12 changed files with 131 additions and 132 deletions.
12 changes: 0 additions & 12 deletions packages/client/.prettierrc.js

This file was deleted.

6 changes: 6 additions & 0 deletions packages/client/eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,10 @@ module.exports = [
'@typescript-eslint/no-unused-vars': 'off',
},
},
{
files: ['test/**/*.ts'],
rules: {
'@typescript-eslint/no-unsafe-argument': 'off',
},
},
]
102 changes: 52 additions & 50 deletions packages/client/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -759,40 +759,40 @@ expect(log.mock.calls[0][0]).toMatchInlineSnapshot(
took: expect.any(Number),
},
`
{
"start": {
"inverse": false
},
"end": {
"inverse": false
},
"took": {
"inverse": false
},
"query": {
"name": "select-recipes_test_8d7ce25",
"sql": "select * from recipes_test",
"token": "sql",
"values": []
},
"result": {
"rows": [
{
"id": 1,
"name": "one"
},
{
"id": 2,
"name": "two"
},
{
"id": 3,
"name": "three"
}
]
{
"start": {
"inverse": false
},
"end": {
"inverse": false
},
"took": {
"inverse": false
},
"query": {
"name": "select-recipes_test_8d7ce25",
"sql": "select * from recipes_test",
"token": "sql",
"values": []
},
"result": {
"rows": [
{
"id": 1,
"name": "one"
},
{
"id": 2,
"name": "two"
},
{
"id": 3,
"name": "three"
}
]
}
}
}
`,
`,
)
```

Expand All @@ -818,22 +818,22 @@ const patient = createClient(client.connectionString() + '?longTimeout', {
const sleepSeconds = (shortTimeoutMs * 2) / 1000
await expect(impatient.one(sql`select pg_sleep(${sleepSeconds})`)).rejects.toThrowErrorMatchingInlineSnapshot(
`
{
"cause": {
"query": {
"name": "select_9dcc021",
"sql": "select pg_sleep($1)",
"token": "sql",
"values": [
0.04
]
},
"error": {
"query": "select pg_sleep(0.04)"
{
"cause": {
"query": {
"name": "select_9dcc021",
"sql": "select pg_sleep($1)",
"token": "sql",
"values": [
0.04
]
},
"error": {
"query": "select pg_sleep(0.04)"
}
}
}
}
`,
`,
)
await expect(patient.one(sql`select pg_sleep(${sleepSeconds})`)).resolves.toMatchObject({
pg_sleep: '',
Expand All @@ -860,7 +860,7 @@ const patientClient = createClient(client.connectionString() + '?longTimeout', {
})

const appClient = createClient(client.connectionString(), {
wrapQueryFn: queryFn => {
wrapQueryFn: _queryFn => {
return async query => {
let clientToUse = patientClient
try {
Expand All @@ -870,7 +870,9 @@ const appClient = createClient(client.connectionString(), {
if (parsed.every(statement => statement.type === 'select')) {
clientToUse = impatientClient
}
} catch {}
} catch {
// ignore
}

return clientToUse.query(query)
}
Expand Down Expand Up @@ -908,7 +910,7 @@ await expect(
insert into recipes_test (id, name)
values (10, 'ten')
returning *
`),
`),
).resolves.toMatchObject({
id: 10,
name: 'ten',
Expand Down
1 change: 1 addition & 0 deletions packages/client/src/sql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ export const allSqlHelpers = {...sqlMethodHelpers, ...sqlTagHelpers}

export const sql: SQLTagFunction & SQLTagHelpers & SQLMethodHelpers = Object.assign(sqlFn, allSqlHelpers)

// eslint-disable-next-line @typescript-eslint/no-explicit-any
export const createSqlTag = <TypeAliases extends Record<string, ZodesqueType<any>>>(params: {
typeAliases: TypeAliases
}) => {
Expand Down
5 changes: 3 additions & 2 deletions packages/client/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ export interface SQLQuery<Result = Record<string, unknown>, Values extends unkno
values: Values
parse: (input: unknown) => Result | Promise<Result>
/** @internal */
templateArgs: () => [strings: readonly string[], ...inputParameters: readonly any[]]
templateArgs: () => [strings: readonly string[], ...inputParameters: readonly unknown[]]
}

export type TimeUnit = 'years' | 'months' | 'weeks' | 'days' | 'hours' | 'minutes' | 'seconds'
export type IntervalInput = Partial<Record<TimeUnit, number>> // todo type-fest oneOf

// eslint-disable-next-line @typescript-eslint/no-explicit-any
export type SQLQueryResult<Query extends SQLQuery<any>> = ReturnType<Query['parse']>

export type SQLQueryParameter = {token: string}
Expand Down Expand Up @@ -65,7 +66,7 @@ export type SqlFragment = {
sql: string
values: unknown[]
/** @internal */
templateArgs: () => [strings: readonly string[], ...inputParameters: readonly any[]]
templateArgs: () => [strings: readonly string[], ...inputParameters: readonly unknown[]]
}
/**
* "string" type covers all type name identifiers – the literal values are added only to assist developer
Expand Down
1 change: 1 addition & 0 deletions packages/client/test/api-usage.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-shadow */
import {beforeAll, beforeEach, expect, expectTypeOf, test, vi} from 'vitest'
import {z} from 'zod'
import {createClient, createSqlTag, sql} from '../src'
Expand Down
2 changes: 1 addition & 1 deletion packages/client/test/errors.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ expect.addSnapshotSerializer({
let pool: Awaited<ReturnType<typeof createPool>>

beforeAll(async () => {
// eslint-disable-next-line mmkal/@typescript-eslint/await-thenable
// eslint-disable-next-line @typescript-eslint/await-thenable
pool = await createPool('postgresql://postgres:postgres@localhost:5432/postgres')
await pool.query(sql`DROP TABLE IF EXISTS test_errors`)
await pool.query(sql`CREATE TABLE test_errors (id int, name text)`)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
type GenerateOptions = {
removeTests?: string[]
}

export const generate: import('eslint-plugin-codegen').Preset<GenerateOptions> = ({options, dependencies, context}) => {
/** @type {import('eslint-plugin-codegen').Preset<{removeTests?: string[]}>} */
exports.generate = ({options, dependencies, context}) => {
const original = dependencies.fs.readFileSync(dependencies.path.join(__dirname, 'api-usage.test.ts'), 'utf8')
let updated = original
.slice(original.indexOf('beforeEach('))
.replaceAll('usage_test', 'test_' + context.physicalFilename.split('/').at(-1)!.split('.')[0])
.replaceAll('usage_test', 'test_' + context.physicalFilename.split('/').at(-1).split('.')[0])
.replaceAll('expect(result).toBeInstanceOf(Date)', 'expect(new Date(result)).toBeInstanceOf(Date)')

let is = ['updated.length ' + updated.length] as (string | number)[]
/** @type {Array<string | number>} */
const is = ['updated.length ' + updated.length]

options.removeTests?.forEach(name => {
const start = updated.indexOf(`test('${name}'`)
Expand All @@ -33,7 +31,7 @@ export const generate: import('eslint-plugin-codegen').Preset<GenerateOptions> =

const newContent = updated
.split('\n')
.flatMap((line, i, arr) => (line || arr[i - 1] ? [line] : []))
.flatMap((line, j, arr) => (line || arr[j - 1] ? [line] : []))
.join('\n')

if (newContent.includes('toMatchInlineSnapshot')) {
Expand Down
107 changes: 55 additions & 52 deletions packages/client/test/recipes.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {beforeAll, beforeEach, expect, expectTypeOf, test, vi} from 'vitest'
import * as pgSqlAstParser from 'pgsql-ast-parser'
/* eslint-disable @typescript-eslint/no-shadow */
import * as pgMem from 'pg-mem'
import * as pgSqlAstParser from 'pgsql-ast-parser'
import {beforeAll, beforeEach, expect, test, vi} from 'vitest'
import {createClient, sql} from '../src'

export let client: Awaited<ReturnType<typeof createClient>>
Expand Down Expand Up @@ -92,40 +93,40 @@ test('Query logging', async () => {
took: expect.any(Number),
},
`
{
"start": {
"inverse": false
},
"end": {
"inverse": false
},
"took": {
"inverse": false
},
"query": {
"name": "select-recipes_test_8d7ce25",
"sql": "select * from recipes_test",
"token": "sql",
"values": []
},
"result": {
"rows": [
{
"id": 1,
"name": "one"
},
{
"id": 2,
"name": "two"
},
{
"id": 3,
"name": "three"
}
]
{
"start": {
"inverse": false
},
"end": {
"inverse": false
},
"took": {
"inverse": false
},
"query": {
"name": "select-recipes_test_8d7ce25",
"sql": "select * from recipes_test",
"token": "sql",
"values": []
},
"result": {
"rows": [
{
"id": 1,
"name": "one"
},
{
"id": 2,
"name": "two"
},
{
"id": 3,
"name": "three"
}
]
}
}
}
`,
`,
)
})

Expand All @@ -149,22 +150,22 @@ test('query timeouts', async () => {
const sleepSeconds = (shortTimeoutMs * 2) / 1000
await expect(impatient.one(sql`select pg_sleep(${sleepSeconds})`)).rejects.toThrowErrorMatchingInlineSnapshot(
`
{
"cause": {
"query": {
"name": "select_9dcc021",
"sql": "select pg_sleep($1)",
"token": "sql",
"values": [
0.04
]
},
"error": {
"query": "select pg_sleep(0.04)"
{
"cause": {
"query": {
"name": "select_9dcc021",
"sql": "select pg_sleep($1)",
"token": "sql",
"values": [
0.04
]
},
"error": {
"query": "select pg_sleep(0.04)"
}
}
}
}
`,
`,
)
await expect(patient.one(sql`select pg_sleep(${sleepSeconds})`)).resolves.toMatchObject({
pg_sleep: '',
Expand All @@ -189,7 +190,7 @@ test('switchable clients', async () => {
})

const appClient = createClient(client.connectionString(), {
wrapQueryFn: queryFn => {
wrapQueryFn: _queryFn => {
return async query => {
let clientToUse = patientClient
try {
Expand All @@ -199,7 +200,9 @@ test('switchable clients', async () => {
if (parsed.every(statement => statement.type === 'select')) {
clientToUse = impatientClient
}
} catch {}
} catch {
// ignore
}

return clientToUse.query(query)
}
Expand Down Expand Up @@ -237,7 +240,7 @@ test('switchable clients', async () => {
insert into recipes_test (id, name)
values (10, 'ten')
returning *
`),
`),
).resolves.toMatchObject({
id: 10,
name: 'ten',
Expand Down

0 comments on commit acc7fbc

Please sign in to comment.