From 0842c0f245572a253ef3e520154ad064f4b4eb18 Mon Sep 17 00:00:00 2001 From: Farrel Darian <62016900+farreldarian@users.noreply.github.com> Date: Sat, 9 Mar 2024 21:48:32 +0700 Subject: [PATCH] chore: update and apply biome (#37) * chore: update biome config * chore: enable no unused import * chore: apply biome * chore: format more --------- Co-authored-by: farreldarian --- biome.json | 10 +++- package.json | 10 ++-- packages/generator/src/generator.ts | 37 +++++++------- packages/generator/src/lib/adapter/adapter.ts | 11 +++-- .../declarations/generateEnumDeclaration.ts | 4 +- .../declarations/generateSchemaDeclaration.ts | 2 +- .../declarations/generateTableDeclaration.ts | 4 +- .../generateTableRelationsDeclaration.ts | 8 ++-- .../src/lib/adapter/fields/createField.ts | 10 ++-- .../lib/adapter/modules/createModelModule.ts | 4 +- .../src/lib/adapter/providers/postgres.ts | 2 +- packages/generator/src/lib/adapter/types.ts | 6 +-- packages/generator/src/lib/config.ts | 4 +- packages/generator/src/lib/context.ts | 6 +-- packages/generator/src/lib/logger.ts | 2 +- .../generator/src/lib/prisma-helpers/enums.ts | 2 +- .../generator/src/lib/prisma-helpers/field.ts | 2 +- .../generator/src/lib/prisma-helpers/model.ts | 2 +- packages/generator/src/lib/syntaxes/module.ts | 2 +- packages/generator/src/lib/types/utils.ts | 4 +- .../generator/src/shared/generator-context.ts | 6 +-- packages/generator/tsconfig.json | 48 +++++++++---------- packages/usage/scripts/cloneMysql.ts | 2 +- packages/usage/scripts/cloneSqlite.ts | 2 +- packages/usage/src/lib/mysql.ts | 2 +- packages/usage/src/lib/types.ts | 4 +- packages/usage/tests/mysql.test.ts | 12 ++--- packages/usage/tests/postgres.test.ts | 10 ++-- packages/usage/tests/shared/testDefault.ts | 4 +- .../shared/testDisambiguatingRelationship.ts | 2 +- packages/usage/tests/shared/testFields.ts | 2 +- .../usage/tests/shared/testIgnoreDecorator.ts | 2 +- packages/usage/tests/shared/testManyToMany.ts | 3 +- packages/usage/tests/shared/testOneToMany.ts | 2 +- packages/usage/tests/shared/testOneToOne.ts | 2 +- .../usage/tests/shared/testSelfReferring.ts | 3 +- packages/usage/tests/sqlite.test.ts | 12 ++--- packages/usage/tests/utils/types.ts | 2 +- 38 files changed, 132 insertions(+), 120 deletions(-) diff --git a/biome.json b/biome.json index 30d746c..5d7e9e3 100644 --- a/biome.json +++ b/biome.json @@ -1,12 +1,18 @@ { - "$schema": "https://biomejs.dev/schemas/1.5.2/schema.json", + "$schema": "https://biomejs.dev/schemas/1.6.0/schema.json", + "files": { + "ignore": ["**/dist", "packages/usages/prisma/**"] + }, "organizeImports": { "enabled": true }, "linter": { "enabled": true, "rules": { - "recommended": true + "recommended": true, + "correctness": { + "noUnusedImports": "warn" + } } }, "javascript": { diff --git a/package.json b/package.json index 73f5d06..f24b405 100644 --- a/package.json +++ b/package.json @@ -1,8 +1,6 @@ { - "workspaces": [ - "packages/*" - ], - "devDependencies": { - "@biomejs/biome": "^1.6.0" - } + "workspaces": ["packages/*"], + "devDependencies": { + "@biomejs/biome": "^1.6.0" + } } diff --git a/packages/generator/src/generator.ts b/packages/generator/src/generator.ts index 9c5a1ce..ea0442a 100644 --- a/packages/generator/src/generator.ts +++ b/packages/generator/src/generator.ts @@ -1,29 +1,33 @@ +import { execSync } from 'node:child_process' +import fs from 'node:fs' +import path from 'node:path' import { - DMMF, + type DMMF, + type GeneratorOptions, generatorHandler, - GeneratorOptions, } from '@prisma/generator-helper' -import { execSync } from 'child_process' import { map, reduce } from 'fp-ts/lib/Array' import { pipe } from 'fp-ts/lib/function' -import fs from 'fs' import { isEmpty } from 'lodash' -import path from 'path' import { GENERATOR_NAME } from './constants' import { generateEnumDeclaration } from './lib/adapter/declarations/generateEnumDeclaration' import { generateSchemaDeclaration } from './lib/adapter/declarations/generateSchemaDeclaration' import { generateTableRelationsDeclaration } from './lib/adapter/declarations/generateTableRelationsDeclaration' import { + type ModelModule, createModelModule, - ModelModule, } from './lib/adapter/modules/createModelModule' import { isRelationalQueryEnabled } from './lib/config' -import { Context } from './lib/context' +import type { Context } from './lib/context' import { logger } from './lib/logger' import { getEnumModuleName } from './lib/prisma-helpers/enums' import { isRelationField } from './lib/prisma-helpers/field' -import { ImportValue, namedImport, NamedImport } from './lib/syntaxes/imports' -import { createModule, Module } from './lib/syntaxes/module' +import { + type ImportValue, + type NamedImport, + namedImport, +} from './lib/syntaxes/imports' +import { type Module, createModule } from './lib/syntaxes/module' import { setGeneratorContext } from './shared/generator-context' const { version } = require('../package.json') @@ -60,13 +64,13 @@ generatorHandler({ fs.existsSync(basePath) && fs.rmSync(basePath, { recursive: true }) fs.mkdirSync(basePath, { recursive: true }) - adapter.extraModules?.forEach((module) => { + for (const module of adapter.extraModules ?? []) { const moduleCreation = logger.createTask() writeModule(basePath, module) moduleCreation.end(`◟ ${module.name}.ts`) - }) + } - options.dmmf.datamodel.enums.forEach((prismaEnum) => { + for (const prismaEnum of options.dmmf.datamodel.enums ?? []) { const enumCreation = logger.createTask() const enumModule = createModule({ @@ -76,8 +80,7 @@ generatorHandler({ writeModule(basePath, enumModule) enumCreation.end(`◟ ${enumModule.name}.ts`) - return enumModule - }) + } const modelModules = options.dmmf.datamodel.models.map((model) => { const modelCreation = logger.createTask() @@ -143,7 +146,7 @@ generatorHandler({ writeModule(basePath, schemaModule) } - const formatter = options.generator.config['formatter'] + const formatter = options.generator.config.formatter if (formatter === 'prettier') { execSync(`prettier --write ${basePath}`, { stdio: 'inherit' }) } @@ -173,7 +176,9 @@ export function reduceImports(imports: ImportValue[]) { if (command.type !== 'namedImport') return accum const imports = new Set(accum.get(command.module)) - command.names.forEach((name) => imports.add(name)) + for (const name of command.names) { + imports.add(name) + } return accum.set(command.module, imports) }), diff --git a/packages/generator/src/lib/adapter/adapter.ts b/packages/generator/src/lib/adapter/adapter.ts index db59a78..9534d5b 100644 --- a/packages/generator/src/lib/adapter/adapter.ts +++ b/packages/generator/src/lib/adapter/adapter.ts @@ -1,7 +1,10 @@ -import { PrismaEnumField, PrismaScalarField } from '../prisma-helpers/field' -import { ImportValue } from '../syntaxes/imports' -import { Module } from '../syntaxes/module' -import { FieldFunc } from './fields/createField' +import type { + PrismaEnumField, + PrismaScalarField, +} from '../prisma-helpers/field' +import type { ImportValue } from '../syntaxes/imports' +import type { Module } from '../syntaxes/module' +import type { FieldFunc } from './fields/createField' type ParsableField = PrismaScalarField | PrismaEnumField diff --git a/packages/generator/src/lib/adapter/declarations/generateEnumDeclaration.ts b/packages/generator/src/lib/adapter/declarations/generateEnumDeclaration.ts index e08058e..5b511b1 100644 --- a/packages/generator/src/lib/adapter/declarations/generateEnumDeclaration.ts +++ b/packages/generator/src/lib/adapter/declarations/generateEnumDeclaration.ts @@ -1,7 +1,7 @@ -import { DMMF } from '@prisma/generator-helper' +import type { DMMF } from '@prisma/generator-helper' import { getDbName } from '~/lib/prisma-helpers/getDbName' import { getEnumVarName } from '../../prisma-helpers/enums' -import { Adapter } from '../types' +import type { Adapter } from '../types' export function generateEnumDeclaration( adapter: Adapter, diff --git a/packages/generator/src/lib/adapter/declarations/generateSchemaDeclaration.ts b/packages/generator/src/lib/adapter/declarations/generateSchemaDeclaration.ts index feaf976..a1ce71f 100644 --- a/packages/generator/src/lib/adapter/declarations/generateSchemaDeclaration.ts +++ b/packages/generator/src/lib/adapter/declarations/generateSchemaDeclaration.ts @@ -1,5 +1,5 @@ import { camelCase } from 'lodash' -import { Module } from '~/lib/syntaxes/module' +import type { Module } from '~/lib/syntaxes/module' import { wildcardImport } from '../../syntaxes/imports' export function generateSchemaDeclaration(models: Module[]) { diff --git a/packages/generator/src/lib/adapter/declarations/generateTableDeclaration.ts b/packages/generator/src/lib/adapter/declarations/generateTableDeclaration.ts index 1b7a681..207f8ee 100644 --- a/packages/generator/src/lib/adapter/declarations/generateTableDeclaration.ts +++ b/packages/generator/src/lib/adapter/declarations/generateTableDeclaration.ts @@ -1,10 +1,10 @@ -import { DMMF } from '@prisma/generator-helper' +import type { DMMF } from '@prisma/generator-helper' import { or } from 'fp-ts/lib/Refinement' import { pipe } from 'fp-ts/lib/function' import { isKind } from '~/lib/prisma-helpers/field' import { getDbName } from '~/lib/prisma-helpers/getDbName' import { getModelVarName } from '~/lib/prisma-helpers/model' -import { Adapter } from '../types' +import type { Adapter } from '../types' export function generateTableDeclaration(adapter: Adapter, model: DMMF.Model) { const fields = model.fields diff --git a/packages/generator/src/lib/adapter/declarations/generateTableRelationsDeclaration.ts b/packages/generator/src/lib/adapter/declarations/generateTableRelationsDeclaration.ts index 80529cc..9c97bee 100644 --- a/packages/generator/src/lib/adapter/declarations/generateTableRelationsDeclaration.ts +++ b/packages/generator/src/lib/adapter/declarations/generateTableRelationsDeclaration.ts @@ -1,16 +1,16 @@ -import { DMMF } from '@prisma/generator-helper' +import type { DMMF } from '@prisma/generator-helper' import { map } from 'fp-ts/lib/Array' import { pipe } from 'fp-ts/lib/function' import { camelCase, kebabCase } from 'lodash' import pluralize from 'pluralize' -import { ModelModule } from '~/lib/adapter/model-module' import { - PrismaRelationField, + type PrismaRelationField, isRelationField, } from '~/lib/prisma-helpers/field' import { getDbName } from '~/lib/prisma-helpers/getDbName' import { getModelVarName } from '~/lib/prisma-helpers/model' import { namedImport } from '../../syntaxes/imports' +import type { ModelModule } from '../modules/createModelModule' type GenerateTableRelationsInput = { fields: PrismaRelationField[] @@ -40,7 +40,7 @@ export function generateTableRelationsDeclaration( } function getRelationField(ctx: GenerateTableRelationsInput) { - return function (field: PrismaRelationField) { + return (field: PrismaRelationField) => { const { implicit, opts, referenceModelVarName } = !field.isList ? getOneToOneOrManyRelation(field, ctx) : opposingIsList(field, ctx) diff --git a/packages/generator/src/lib/adapter/fields/createField.ts b/packages/generator/src/lib/adapter/fields/createField.ts index f0fc473..81be337 100644 --- a/packages/generator/src/lib/adapter/fields/createField.ts +++ b/packages/generator/src/lib/adapter/fields/createField.ts @@ -1,6 +1,6 @@ -import { DMMF } from '@prisma/generator-helper' -import { ImportValue, namedImport } from '~/lib/syntaxes/imports' -import { MakeRequired, ModifyType, Prettify } from '~/lib/types/utils' +import type { DMMF } from '@prisma/generator-helper' +import { type ImportValue, namedImport } from '~/lib/syntaxes/imports' +import type { MakeRequired, ModifyType, Prettify } from '~/lib/types/utils' export type DefineImport = { module: string @@ -111,7 +111,9 @@ function getCustomDefault(field: DMMF.Field) { imports: namedImport([type], module), code: `.$defaultFn(() => ${type}())`, } - } else if (splits2.length !== 3) + } + + if (splits2.length !== 3) throw new Error(`Invalid default definition: ${field.documentation}`) const [type, code] = splits2 diff --git a/packages/generator/src/lib/adapter/modules/createModelModule.ts b/packages/generator/src/lib/adapter/modules/createModelModule.ts index 03c97df..25d96a7 100644 --- a/packages/generator/src/lib/adapter/modules/createModelModule.ts +++ b/packages/generator/src/lib/adapter/modules/createModelModule.ts @@ -1,5 +1,5 @@ -import { DMMF } from '@prisma/generator-helper' -import { Context } from '../../context' +import type { DMMF } from '@prisma/generator-helper' +import type { Context } from '../../context' import { getModelModuleName } from '../../prisma-helpers/model' import { createModule } from '../../syntaxes/module' import { generateTableDeclaration } from '../declarations/generateTableDeclaration' diff --git a/packages/generator/src/lib/adapter/providers/postgres.ts b/packages/generator/src/lib/adapter/providers/postgres.ts index 9638cbc..e0a318d 100644 --- a/packages/generator/src/lib/adapter/providers/postgres.ts +++ b/packages/generator/src/lib/adapter/providers/postgres.ts @@ -3,7 +3,7 @@ import { getDbName } from '~/lib/prisma-helpers/getDbName' import { namedImport } from '~/lib/syntaxes/imports' import { createAdapter } from '../adapter' import { - CreateFieldInput, + type CreateFieldInput, createField as baseCreateField, hasDefault, isDefaultFunc, diff --git a/packages/generator/src/lib/adapter/types.ts b/packages/generator/src/lib/adapter/types.ts index e0e6040..3a0c868 100644 --- a/packages/generator/src/lib/adapter/types.ts +++ b/packages/generator/src/lib/adapter/types.ts @@ -1,6 +1,6 @@ -import { mysqlAdapter } from './providers/mysql' -import { postgresAdapter } from './providers/postgres' -import { sqliteAdapter } from './providers/sqlite' +import type { mysqlAdapter } from './providers/mysql' +import type { postgresAdapter } from './providers/postgres' +import type { sqliteAdapter } from './providers/sqlite' export type Adapter = | typeof postgresAdapter diff --git a/packages/generator/src/lib/config.ts b/packages/generator/src/lib/config.ts index 3fb2e60..340f8e8 100644 --- a/packages/generator/src/lib/config.ts +++ b/packages/generator/src/lib/config.ts @@ -1,9 +1,9 @@ -import { Dictionary } from '@prisma/sdk' +import type { Dictionary } from '@prisma/sdk' export type Config = Dictionary export function isRelationalQueryEnabled(config: Config) { - const value = config['relationalQuery'] + const value = config.relationalQuery if (value === 'false') return false return true } diff --git a/packages/generator/src/lib/context.ts b/packages/generator/src/lib/context.ts index e8b012b..4d75f5a 100644 --- a/packages/generator/src/lib/context.ts +++ b/packages/generator/src/lib/context.ts @@ -1,6 +1,6 @@ -import { DMMF } from '@prisma/generator-helper' -import { Adapter } from './adapter/types' -import { Config } from './config' +import type { DMMF } from '@prisma/generator-helper' +import type { Adapter } from './adapter/types' +import type { Config } from './config' export type Context = { adapter: Adapter diff --git a/packages/generator/src/lib/logger.ts b/packages/generator/src/lib/logger.ts index a351a89..79c3e45 100644 --- a/packages/generator/src/lib/logger.ts +++ b/packages/generator/src/lib/logger.ts @@ -1,4 +1,4 @@ -import { GeneratorOptions } from '@prisma/generator-helper' +import type { GeneratorOptions } from '@prisma/generator-helper' import { logger as baseLogger } from '@prisma/sdk' import { GENERATOR_NAME } from 'src/constants' diff --git a/packages/generator/src/lib/prisma-helpers/enums.ts b/packages/generator/src/lib/prisma-helpers/enums.ts index 6722a4f..f382fb4 100644 --- a/packages/generator/src/lib/prisma-helpers/enums.ts +++ b/packages/generator/src/lib/prisma-helpers/enums.ts @@ -1,4 +1,4 @@ -import { DMMF } from '@prisma/generator-helper' +import type { DMMF } from '@prisma/generator-helper' import { camelCase, kebabCase, memoize } from 'lodash' export const getEnumVarName = memoize((prismaEnum: DMMF.DatamodelEnum) => { diff --git a/packages/generator/src/lib/prisma-helpers/field.ts b/packages/generator/src/lib/prisma-helpers/field.ts index dcc4c77..87ddb65 100644 --- a/packages/generator/src/lib/prisma-helpers/field.ts +++ b/packages/generator/src/lib/prisma-helpers/field.ts @@ -1,4 +1,4 @@ -import { DMMF } from '@prisma/generator-helper' +import type { DMMF } from '@prisma/generator-helper' export type PrismaFieldType = | 'BigInt' diff --git a/packages/generator/src/lib/prisma-helpers/model.ts b/packages/generator/src/lib/prisma-helpers/model.ts index 518c440..1184702 100644 --- a/packages/generator/src/lib/prisma-helpers/model.ts +++ b/packages/generator/src/lib/prisma-helpers/model.ts @@ -1,4 +1,4 @@ -import { DMMF } from '@prisma/generator-helper' +import type { DMMF } from '@prisma/generator-helper' import { camelCase, kebabCase, memoize } from 'lodash' import pluralize from 'pluralize' diff --git a/packages/generator/src/lib/syntaxes/module.ts b/packages/generator/src/lib/syntaxes/module.ts index 4d43f0a..a745bb6 100644 --- a/packages/generator/src/lib/syntaxes/module.ts +++ b/packages/generator/src/lib/syntaxes/module.ts @@ -1,7 +1,7 @@ import { flatMap } from 'fp-ts/lib/Array' import { pipe } from 'fp-ts/lib/function' import { reduceImports } from '../../generator' -import { ImportValue } from './imports' +import type { ImportValue } from './imports' export type Module = ReturnType diff --git a/packages/generator/src/lib/types/utils.ts b/packages/generator/src/lib/types/utils.ts index 3ffe78c..6a17de6 100644 --- a/packages/generator/src/lib/types/utils.ts +++ b/packages/generator/src/lib/types/utils.ts @@ -11,12 +11,12 @@ export type Prettify = { } & {} export type MakeRequired< - shake extends Record, + shake extends Record, key extends keyof shake, > = Omit & Required> export type ModifyType< - shape extends Record, + shape extends Record, key extends keyof shape, modified, > = Omit & Record diff --git a/packages/generator/src/shared/generator-context.ts b/packages/generator/src/shared/generator-context.ts index 7e083f8..3a5843f 100644 --- a/packages/generator/src/shared/generator-context.ts +++ b/packages/generator/src/shared/generator-context.ts @@ -1,6 +1,6 @@ -import path from 'path' -import fs from 'fs' -import { GeneratorOptions } from '@prisma/generator-helper' +import fs from 'node:fs' +import path from 'node:path' +import type { GeneratorOptions } from '@prisma/generator-helper' import { getModuleResolution } from '~/lib/config' type GeneratorContext = { diff --git a/packages/generator/tsconfig.json b/packages/generator/tsconfig.json index c3f732f..da0b954 100644 --- a/packages/generator/tsconfig.json +++ b/packages/generator/tsconfig.json @@ -1,26 +1,26 @@ { - "compilerOptions": { - "target": "ES2018", - "module": "commonjs", - "lib": ["esnext"], - "strict": true, - "strictPropertyInitialization": false, - "esModuleInterop": true, - "experimentalDecorators": true, - "emitDecoratorMetadata": true, - "skipLibCheck": true, - "forceConsistentCasingInFileNames": true, - "removeComments": true, - "sourceMap": true, - "baseUrl": ".", - "moduleResolution": "Node", - "outDir": "./dist", - "rootDir": "./src", - "newLine": "lf", - "paths": { - "~/*": ["src/*"] - } - }, - "include": ["src/**/*"], - "exclude": ["**/node_modules"] + "compilerOptions": { + "target": "ES2018", + "module": "commonjs", + "lib": ["esnext"], + "strict": true, + "strictPropertyInitialization": false, + "esModuleInterop": true, + "experimentalDecorators": true, + "emitDecoratorMetadata": true, + "skipLibCheck": true, + "forceConsistentCasingInFileNames": true, + "removeComments": true, + "sourceMap": true, + "baseUrl": ".", + "moduleResolution": "Node", + "outDir": "./dist", + "rootDir": "./src", + "newLine": "lf", + "paths": { + "~/*": ["src/*"] + } + }, + "include": ["src/**/*"], + "exclude": ["**/node_modules"] } diff --git a/packages/usage/scripts/cloneMysql.ts b/packages/usage/scripts/cloneMysql.ts index 38c5cff..d64cfbd 100644 --- a/packages/usage/scripts/cloneMysql.ts +++ b/packages/usage/scripts/cloneMysql.ts @@ -1,4 +1,4 @@ -export {} +export type {} const BASE_PATH = './prisma/schema.prisma' const TARGET_PATH = './prisma/mysql/schema.prisma' diff --git a/packages/usage/scripts/cloneSqlite.ts b/packages/usage/scripts/cloneSqlite.ts index 2ad0327..dad778c 100644 --- a/packages/usage/scripts/cloneSqlite.ts +++ b/packages/usage/scripts/cloneSqlite.ts @@ -1,4 +1,4 @@ -export {} +export type {} const BASE_PATH = './prisma/schema.prisma' const TARGET_PATH = './prisma/sqlite/schema.prisma' diff --git a/packages/usage/src/lib/mysql.ts b/packages/usage/src/lib/mysql.ts index cc9857e..de1fec9 100644 --- a/packages/usage/src/lib/mysql.ts +++ b/packages/usage/src/lib/mysql.ts @@ -1,7 +1,7 @@ import { drizzle } from 'drizzle-orm/mysql2' import mysql from 'mysql2/promise' import { schema } from 'prisma/mysql/drizzle/schema' -import { object, parse, string, url } from 'valibot' +import { url, object, parse, string } from 'valibot' const env = parse( object({ diff --git a/packages/usage/src/lib/types.ts b/packages/usage/src/lib/types.ts index ddf4ae1..1dd6d30 100644 --- a/packages/usage/src/lib/types.ts +++ b/packages/usage/src/lib/types.ts @@ -1,5 +1,5 @@ -import { schema } from 'prisma/drizzle/schema' -import { db } from './postgres' +import type { schema } from 'prisma/drizzle/schema' +import type { db } from './postgres' export type Db = typeof db export type Schema = typeof schema diff --git a/packages/usage/tests/mysql.test.ts b/packages/usage/tests/mysql.test.ts index 3ee057e..9453fe6 100644 --- a/packages/usage/tests/mysql.test.ts +++ b/packages/usage/tests/mysql.test.ts @@ -1,15 +1,15 @@ import { schema } from 'prisma/mysql/drizzle/schema' import { db } from 'src/lib/mysql' -import { Db, Schema } from 'src/lib/types' -import { testIgnoreDecorator } from './shared/testIgnoreDecorator' -import { testManyToMany } from './shared/testManyToMany' +import type { Db, Schema } from 'src/lib/types' import { testDefault } from './shared/testDefault' -import { testSelfReferring } from './shared/testSelfReferring' +import { testDisambiguatingRelationship } from './shared/testDisambiguatingRelationship' import { testFields } from './shared/testFields' -import { TestContext } from './utils/types' +import { testIgnoreDecorator } from './shared/testIgnoreDecorator' +import { testManyToMany } from './shared/testManyToMany' import { testOneToMany } from './shared/testOneToMany' import { testOneToOne } from './shared/testOneToOne' -import { testDisambiguatingRelationship } from './shared/testDisambiguatingRelationship' +import { testSelfReferring } from './shared/testSelfReferring' +import type { TestContext } from './utils/types' const ctx: TestContext = { db: db as unknown as Db, diff --git a/packages/usage/tests/postgres.test.ts b/packages/usage/tests/postgres.test.ts index c5fe638..1617f23 100644 --- a/packages/usage/tests/postgres.test.ts +++ b/packages/usage/tests/postgres.test.ts @@ -1,14 +1,14 @@ import { schema } from 'prisma/drizzle/schema' import { db } from 'src/lib/postgres' -import { testIgnoreDecorator } from './shared/testIgnoreDecorator' -import { testManyToMany } from './shared/testManyToMany' import { testDefault } from './shared/testDefault' -import { testSelfReferring } from './shared/testSelfReferring' -import { TestContext } from './utils/types' +import { testDisambiguatingRelationship } from './shared/testDisambiguatingRelationship' import { testFields } from './shared/testFields' +import { testIgnoreDecorator } from './shared/testIgnoreDecorator' +import { testManyToMany } from './shared/testManyToMany' import { testOneToMany } from './shared/testOneToMany' import { testOneToOne } from './shared/testOneToOne' -import { testDisambiguatingRelationship } from './shared/testDisambiguatingRelationship' +import { testSelfReferring } from './shared/testSelfReferring' +import type { TestContext } from './utils/types' const ctx: TestContext = { db, schema, provider: 'postgres' } diff --git a/packages/usage/tests/shared/testDefault.ts b/packages/usage/tests/shared/testDefault.ts index 14a43f4..0f9214a 100644 --- a/packages/usage/tests/shared/testDefault.ts +++ b/packages/usage/tests/shared/testDefault.ts @@ -2,9 +2,9 @@ import { createId, isCuid } from '@paralleldrive/cuid2' import { isAfter, subSeconds } from 'date-fns' import Decimal from 'decimal.js' import { eq, inArray } from 'drizzle-orm' -import { validate as validateUuid } from 'uuid' import { throwIfnull } from 'tests/utils/query' -import { TestContext } from 'tests/utils/types' +import type { TestContext } from 'tests/utils/types' +import { validate as validateUuid } from 'uuid' import { describe, expect, test } from 'vitest' export function testDefault({ db, schema, provider }: TestContext) { diff --git a/packages/usage/tests/shared/testDisambiguatingRelationship.ts b/packages/usage/tests/shared/testDisambiguatingRelationship.ts index c830ef8..0a87b96 100644 --- a/packages/usage/tests/shared/testDisambiguatingRelationship.ts +++ b/packages/usage/tests/shared/testDisambiguatingRelationship.ts @@ -1,7 +1,7 @@ import { createId } from '@paralleldrive/cuid2' import { inArray } from 'drizzle-orm' import { throwIfnull } from 'tests/utils/query' -import { TestContext } from 'tests/utils/types' +import type { TestContext } from 'tests/utils/types' export function testDisambiguatingRelationship({ db, schema }: TestContext) { const taxReceiver = { id: createId() } diff --git a/packages/usage/tests/shared/testFields.ts b/packages/usage/tests/shared/testFields.ts index b0b0f40..efa610f 100644 --- a/packages/usage/tests/shared/testFields.ts +++ b/packages/usage/tests/shared/testFields.ts @@ -2,7 +2,7 @@ import { createId } from '@paralleldrive/cuid2' import Decimal from 'decimal.js' import { eq } from 'drizzle-orm' import { throwIfnull } from 'tests/utils/query' -import { TestContext } from 'tests/utils/types' +import type { TestContext } from 'tests/utils/types' export function testFields({ db, schema, provider }: TestContext) { type Data = typeof schema.fields.$inferInsert diff --git a/packages/usage/tests/shared/testIgnoreDecorator.ts b/packages/usage/tests/shared/testIgnoreDecorator.ts index 9d22676..e9553cf 100644 --- a/packages/usage/tests/shared/testIgnoreDecorator.ts +++ b/packages/usage/tests/shared/testIgnoreDecorator.ts @@ -1,4 +1,4 @@ -import { TestContext } from 'tests/utils/types' +import type { TestContext } from 'tests/utils/types' import { describe, expect, test } from 'vitest' export function testIgnoreDecorator({ schema }: TestContext) { diff --git a/packages/usage/tests/shared/testManyToMany.ts b/packages/usage/tests/shared/testManyToMany.ts index 7da89ab..da790e9 100644 --- a/packages/usage/tests/shared/testManyToMany.ts +++ b/packages/usage/tests/shared/testManyToMany.ts @@ -1,6 +1,5 @@ import { createId } from '@paralleldrive/cuid2' -import { Db, Schema } from 'src/lib/types' -import { TestContext } from 'tests/utils/types' +import type { TestContext } from 'tests/utils/types' import { describe, expect, test } from 'vitest' export async function testManyToMany({ db, schema }: TestContext) { diff --git a/packages/usage/tests/shared/testOneToMany.ts b/packages/usage/tests/shared/testOneToMany.ts index 5cfa705..fe01349 100644 --- a/packages/usage/tests/shared/testOneToMany.ts +++ b/packages/usage/tests/shared/testOneToMany.ts @@ -1,7 +1,7 @@ import { createId } from '@paralleldrive/cuid2' import { eq, inArray } from 'drizzle-orm' import { throwIfnull } from 'tests/utils/query' -import { TestContext } from 'tests/utils/types' +import type { TestContext } from 'tests/utils/types' export function testOneToMany({ db, schema }: TestContext) { const many: typeof schema.oneToManyManies.$inferInsert = { id: createId() } diff --git a/packages/usage/tests/shared/testOneToOne.ts b/packages/usage/tests/shared/testOneToOne.ts index 1725c06..7c33600 100644 --- a/packages/usage/tests/shared/testOneToOne.ts +++ b/packages/usage/tests/shared/testOneToOne.ts @@ -1,7 +1,7 @@ import { createId } from '@paralleldrive/cuid2' import { eq } from 'drizzle-orm' import { throwIfnull } from 'tests/utils/query' -import { TestContext } from 'tests/utils/types' +import type { TestContext } from 'tests/utils/types' export function testOneToOne({ db, schema }: TestContext) { const b: typeof schema.oneToOneBs.$inferInsert = { id: createId() } diff --git a/packages/usage/tests/shared/testSelfReferring.ts b/packages/usage/tests/shared/testSelfReferring.ts index 66173d7..fe43ff3 100644 --- a/packages/usage/tests/shared/testSelfReferring.ts +++ b/packages/usage/tests/shared/testSelfReferring.ts @@ -1,6 +1,5 @@ import { createId } from '@paralleldrive/cuid2' -import { Db, Schema } from 'src/lib/types' -import { TestContext } from 'tests/utils/types' +import type { TestContext } from 'tests/utils/types' import { describe, test } from 'vitest' export function testSelfReferring({ db, schema }: TestContext) { diff --git a/packages/usage/tests/sqlite.test.ts b/packages/usage/tests/sqlite.test.ts index 29cf229..309a75b 100644 --- a/packages/usage/tests/sqlite.test.ts +++ b/packages/usage/tests/sqlite.test.ts @@ -1,15 +1,15 @@ import { schema } from 'prisma/sqlite/drizzle/schema' import { db } from 'src/lib/sqlite' -import { Db, Schema } from 'src/lib/types' -import { testIgnoreDecorator } from './shared/testIgnoreDecorator' -import { testManyToMany } from './shared/testManyToMany' +import type { Db, Schema } from 'src/lib/types' import { testDefault } from './shared/testDefault' -import { testSelfReferring } from './shared/testSelfReferring' -import { TestContext } from './utils/types' +import { testDisambiguatingRelationship } from './shared/testDisambiguatingRelationship' import { testFields } from './shared/testFields' +import { testIgnoreDecorator } from './shared/testIgnoreDecorator' +import { testManyToMany } from './shared/testManyToMany' import { testOneToMany } from './shared/testOneToMany' import { testOneToOne } from './shared/testOneToOne' -import { testDisambiguatingRelationship } from './shared/testDisambiguatingRelationship' +import { testSelfReferring } from './shared/testSelfReferring' +import type { TestContext } from './utils/types' const ctx: TestContext = { db: db as unknown as Db, diff --git a/packages/usage/tests/utils/types.ts b/packages/usage/tests/utils/types.ts index f003681..bbe7141 100644 --- a/packages/usage/tests/utils/types.ts +++ b/packages/usage/tests/utils/types.ts @@ -1,4 +1,4 @@ -import { Db, Schema } from 'src/lib/types' +import type { Db, Schema } from 'src/lib/types' export type TestContext = { db: Db