Skip to content

Commit

Permalink
fix: prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
0xcadams committed Dec 20, 2024
1 parent f0d76b3 commit 8e0e0fb
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 61 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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", {
Expand All @@ -32,7 +32,7 @@ const userSchema = createTableSchema(
drizzleToZero(userTable, {
id: true,
name: true,
})
}),
);

// Create your Zero schema
Expand Down
83 changes: 42 additions & 41 deletions package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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"
}
}
"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"
}
}
10 changes: 10 additions & 0 deletions pnpm-lock.yaml

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

8 changes: 4 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ function typedEntries<T extends object>(obj: T): [keyof T, T[keyof T]][] {

const drizzleToZero = <
T extends Table,
C extends ColumnsConfig<T, FindPrimaryKeyFromTable<T>>
C extends ColumnsConfig<T, FindPrimaryKeyFromTable<T>>,
>(
table: T,
columns: C
columns: C,
): DrizzleToZeroResult<T, C> => {
const tableColumns = getTableColumns(table);

Expand Down Expand Up @@ -55,7 +55,7 @@ const drizzleToZero = <
[key]: schemaValue,
};
},
{} as ZeroColumns<T, C>
{} as ZeroColumns<T, C>,
);

const tableName = getTableName(table);
Expand All @@ -69,7 +69,7 @@ const drizzleToZero = <

type DrizzleToZeroResult<
T extends Table,
C extends ColumnsConfig<T, FindPrimaryKeyFromTable<T>>
C extends ColumnsConfig<T, FindPrimaryKeyFromTable<T>>,
> = Flatten<{
readonly tableName: T["_"]["name"];
readonly primaryKey: FindPrimaryKeyFromTable<T>;
Expand Down
10 changes: 5 additions & 5 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ type Columns<T extends Table> = T["_"]["columns"];
type ColumnNames<T extends Table> = keyof Columns<T>;
type ColumnDefinition<
T extends Table,
K extends ColumnNames<T>
K extends ColumnNames<T>,
> = Columns<T>[K];

export type FindPrimaryKeyFromTable<TTable extends Table> = {
Expand All @@ -23,7 +23,7 @@ type TypeOverride<TCustomType> = {

export type ColumnsConfig<
T extends Table,
PK extends FindPrimaryKeyFromTable<T>
PK extends FindPrimaryKeyFromTable<T>,
> = {
readonly [K in ColumnNames<T>]?:
| boolean
Expand Down Expand Up @@ -62,14 +62,14 @@ type ZeroColumnDefinition<T extends Table, K extends ColumnNames<T>> = {

export type ZeroColumns<
T extends Table,
C extends ColumnsConfig<T, FindPrimaryKeyFromTable<T>>
C extends ColumnsConfig<T, FindPrimaryKeyFromTable<T>>,
> = {
[K in keyof C]: K extends ColumnNames<T>
? C[K] extends TypeOverride<any>
? C[K]
: C[K] extends true
? ZeroColumnDefinition<T, K>
: never
? ZeroColumnDefinition<T, K>
: never
: never;
};

Expand Down
13 changes: 6 additions & 7 deletions test/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ export type ZeroTableSchema = TableSchema;
export function expectDeepEqual<
S extends ZeroTableSchema,
T extends Table,
C extends ColumnsConfig<T, FindPrimaryKeyFromTable<T>>
C extends ColumnsConfig<T, FindPrimaryKeyFromTable<T>>,
>(actual: DrizzleToZeroResult<T, C>) {
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)) {
Expand All @@ -28,10 +28,9 @@ export function expectDeepEqual<
}
export function Expect<T extends true>() {}

export type Equal<X, Y extends X> = (<T>() => T extends X ? 1 : 2) extends <
T
>() => T extends Y ? 1 : 2
? true
: false;
export type Equal<X, Y extends X> =
(<T>() => T extends X ? 1 : 2) extends <T>() => T extends Y ? 1 : 2
? true
: false;

export type NotEqual<X, Y extends X> = Equal<X, Y> extends true ? false : true;

0 comments on commit 8e0e0fb

Please sign in to comment.