diff --git a/README.md b/README.md index 241eed8..7d4fc65 100644 --- a/README.md +++ b/README.md @@ -17,9 +17,9 @@ pnpm add drizzle-zero Here's a simple example of how to convert a Drizzle schema to a Zero schema: ```ts -import { pgTable, text } from 'drizzle-orm/pg-core'; -import { createSchema, createTableSchema } from '@rocicorp/zero'; -import { drizzleToZero } from 'drizzle-zero'; +import { pgTable, text } from "drizzle-orm/pg-core"; +import { createSchema, createTableSchema } from "@rocicorp/zero"; +import { drizzleToZero } from "drizzle-zero"; // Define your Drizzle table const userTable = pgTable("user", { @@ -32,7 +32,7 @@ const userSchema = createTableSchema( drizzleToZero(userTable, { id: true, name: true, - }) + }), ); // Create your Zero schema diff --git a/package.json b/package.json index a18d8fc..be221b5 100644 --- a/package.json +++ b/package.json @@ -1,13 +1,13 @@ { - "name": "drizzle-zero", - "version": "0.0.1-alpha.4", - "description": "Generate Zero schemas from Drizzle ORM schemas", - "type": "module", - "scripts": { - "build": "tsup src/index.ts --format cjs,esm --dts", - "test:types": "cd test && tsc", - "test": "vitest run" - }, + "name": "drizzle-zero", + "version": "0.0.1-alpha.4", + "description": "Generate Zero schemas from Drizzle ORM schemas", + "type": "module", + "scripts": { + "build": "tsup src/index.ts --format cjs,esm --dts", + "test:types": "cd test && tsc", + "test": "vitest run" + }, "main": "dist/index.cjs", "module": "dist/index.js", "types": "dist/index.d.ts", @@ -17,35 +17,36 @@ "require": "./dist/index.cjs" } }, - "repository": { - "type": "git", - "url": "git+https://github.com/BriefHQ/drizzle-zero.git" - }, - "keywords": [ - "zero", - "sync", - "schema", - "drizzle", - "orm", - "pg", - "postgresql", - "postgres", - "database", - "typescript", - "ts" - ], - "author": "Brief", - "license": "Apache-2.0", - "peerDependencies": { - "@rocicorp/zero": ">=0.8.2024121204", - "drizzle-orm": ">=0.36.0" - }, - "devDependencies": { - "@types/node": "^22.10.2", - "tsup": "^8.0.2", - "typescript": "^5.7.2", - "vite-tsconfig-paths": "^5.1.4", - "vitest": "^2.1.8", - "zod": "^3.20.2" - } -} \ No newline at end of file + "repository": { + "type": "git", + "url": "git+https://github.com/BriefHQ/drizzle-zero.git" + }, + "keywords": [ + "zero", + "sync", + "schema", + "drizzle", + "orm", + "pg", + "postgresql", + "postgres", + "database", + "typescript", + "ts" + ], + "author": "Brief", + "license": "Apache-2.0", + "peerDependencies": { + "@rocicorp/zero": ">=0.8.2024121204", + "drizzle-orm": ">=0.36.0" + }, + "devDependencies": { + "@types/node": "^22.10.2", + "prettier": "^3.4.2", + "tsup": "^8.0.2", + "typescript": "^5.7.2", + "vite-tsconfig-paths": "^5.1.4", + "vitest": "^2.1.8", + "zod": "^3.20.2" + } +} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index ab71ecd..1d68018 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -18,6 +18,9 @@ importers: '@types/node': specifier: ^22.10.2 version: 22.10.2 + prettier: + specifier: ^3.4.2 + version: 3.4.2 tsup: specifier: ^8.0.2 version: 8.3.5(postcss@8.4.49)(tsx@4.19.2)(typescript@5.7.2) @@ -1634,6 +1637,11 @@ packages: engines: {node: '>=10'} hasBin: true + prettier@3.4.2: + resolution: {integrity: sha512-e9MewbtFo+Fevyuxn/4rrcDAaq0IYxPGLvObpQjiZBMAzB9IGmzlnG9RZy3FFas+eBMu2vA0CszMeduow5dIuQ==} + engines: {node: '>=14'} + hasBin: true + process-warning@4.0.0: resolution: {integrity: sha512-/MyYDxttz7DfGMMHiysAsFE4qF+pQYAA8ziO/3NcRVrQ5fSk+Mns4QZA/oRPFzvcqNoVJXQNWNAsdwBXLUkQKw==} @@ -3427,6 +3435,8 @@ snapshots: tar-fs: 2.1.1 tunnel-agent: 0.6.0 + prettier@3.4.2: {} + process-warning@4.0.0: {} protobufjs@7.4.0: diff --git a/src/index.ts b/src/index.ts index 204ce46..81678da 100644 --- a/src/index.ts +++ b/src/index.ts @@ -17,10 +17,10 @@ function typedEntries(obj: T): [keyof T, T[keyof T]][] { const drizzleToZero = < T extends Table, - C extends ColumnsConfig> + C extends ColumnsConfig>, >( table: T, - columns: C + columns: C, ): DrizzleToZeroResult => { const tableColumns = getTableColumns(table); @@ -55,7 +55,7 @@ const drizzleToZero = < [key]: schemaValue, }; }, - {} as ZeroColumns + {} as ZeroColumns, ); const tableName = getTableName(table); @@ -69,7 +69,7 @@ const drizzleToZero = < type DrizzleToZeroResult< T extends Table, - C extends ColumnsConfig> + C extends ColumnsConfig>, > = Flatten<{ readonly tableName: T["_"]["name"]; readonly primaryKey: FindPrimaryKeyFromTable; diff --git a/src/types.ts b/src/types.ts index a062e1d..42dd843 100644 --- a/src/types.ts +++ b/src/types.ts @@ -6,7 +6,7 @@ type Columns = T["_"]["columns"]; type ColumnNames = keyof Columns; type ColumnDefinition< T extends Table, - K extends ColumnNames + K extends ColumnNames, > = Columns[K]; export type FindPrimaryKeyFromTable = { @@ -23,7 +23,7 @@ type TypeOverride = { export type ColumnsConfig< T extends Table, - PK extends FindPrimaryKeyFromTable + PK extends FindPrimaryKeyFromTable, > = { readonly [K in ColumnNames]?: | boolean @@ -62,14 +62,14 @@ type ZeroColumnDefinition> = { export type ZeroColumns< T extends Table, - C extends ColumnsConfig> + C extends ColumnsConfig>, > = { [K in keyof C]: K extends ColumnNames ? C[K] extends TypeOverride ? C[K] : C[K] extends true - ? ZeroColumnDefinition - : never + ? ZeroColumnDefinition + : never : never; }; diff --git a/test/utils.ts b/test/utils.ts index 39ec057..375249b 100644 --- a/test/utils.ts +++ b/test/utils.ts @@ -9,12 +9,12 @@ export type ZeroTableSchema = TableSchema; export function expectDeepEqual< S extends ZeroTableSchema, T extends Table, - C extends ColumnsConfig> + C extends ColumnsConfig>, >(actual: DrizzleToZeroResult) { return { toEqual(expected: S) { expect(Object.keys(actual.columns)).toStrictEqual( - Object.keys(expected.columns) + Object.keys(expected.columns), ); for (const key of Object.keys(actual.columns)) { @@ -28,10 +28,9 @@ export function expectDeepEqual< } export function Expect() {} -export type Equal = (() => T extends X ? 1 : 2) extends < - T ->() => T extends Y ? 1 : 2 - ? true - : false; +export type Equal = + (() => T extends X ? 1 : 2) extends () => T extends Y ? 1 : 2 + ? true + : false; export type NotEqual = Equal extends true ? false : true;