Skip to content

Commit

Permalink
fix: changed naming
Browse files Browse the repository at this point in the history
  • Loading branch information
0xcadams committed Dec 21, 2024
1 parent 47c6c12 commit 1e7467d
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 27 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ 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 { tableToZero } from "drizzle-zero";
import { createZeroSchema } from "drizzle-zero";

// Define your Drizzle table
const userTable = pgTable("user", {
Expand All @@ -29,7 +29,7 @@ const userTable = pgTable("user", {

// Convert to Zero table schema and select columns
const userSchema = createTableSchema(
tableToZero(userTable, {
createZeroSchema(userTable, {
id: true,
name: true,
}),
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "drizzle-zero",
"version": "0.0.2-beta.2",
"version": "0.0.2-beta.3",
"description": "Generate Zero schemas from Drizzle ORM schemas",
"type": "module",
"scripts": {
Expand Down
10 changes: 5 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ function typedEntries<T extends object>(obj: T): [keyof T, T[keyof T]][] {
return Object.entries(obj) as [keyof T, T[keyof T]][];
}

const tableToZero = <T extends Table, C extends ColumnsConfig<T>>(
const createZeroSchema = <T extends Table, C extends ColumnsConfig<T>>(
table: T,
columns: C,
): TableToZeroResult<T, C> => {
): CreateZeroSchema<T, C> => {
const tableColumns = getTableColumns(table);

let primaryKey: FindPrimaryKeyFromTable<T> | undefined;
Expand Down Expand Up @@ -86,15 +86,15 @@ const tableToZero = <T extends Table, C extends ColumnsConfig<T>>(
} as const;
};

type TableToZeroResult<T extends Table, C extends ColumnsConfig<T>> = Flatten<{
type CreateZeroSchema<T extends Table, C extends ColumnsConfig<T>> = Flatten<{
readonly tableName: T["_"]["name"];
readonly primaryKey: FindPrimaryKeyFromTable<T>;
readonly columns: ZeroColumns<T, C>;
}>;

export {
tableToZero,
createZeroSchema,
type CreateZeroSchema,
type ColumnsConfig,
type TableToZeroResult,
type ZeroColumns,
};
30 changes: 15 additions & 15 deletions tests/pg.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
} from "drizzle-orm/pg-core";
import { expect, test } from "vitest";

import { tableToZero } from "../src";
import { createZeroSchema } from "../src";

import { column, type JSONValue } from "@rocicorp/zero";
import {
Expand All @@ -40,7 +40,7 @@ test("pg - basic", () => {
json: jsonb().notNull(),
});

const result = tableToZero(table, {
const result = createZeroSchema(table, {
id: true,
name: true,
json: true,
Expand All @@ -66,7 +66,7 @@ test("pg - custom types", () => {
json: jsonb().$type<{ foo: string }>().notNull(),
});

const result = tableToZero(table, {
const result = createZeroSchema(table, {
id: column.string(),
json: true,
});
Expand All @@ -92,7 +92,7 @@ test("pg - optional fields", () => {
metadata: jsonb(), // optional
});

const result = tableToZero(table, {
const result = createZeroSchema(table, {
id: true,
name: true,
description: true,
Expand Down Expand Up @@ -122,7 +122,7 @@ test("pg - array types", () => {
});

expect(() =>
tableToZero(table, {
createZeroSchema(table, {
id: true,
tags: true,
scores: true,
Expand All @@ -145,7 +145,7 @@ test("pg - complex custom types", () => {
settings: jsonb().$type<Record<string, boolean>>(),
});

const result = tableToZero(table, {
const result = createZeroSchema(table, {
id: true,
metadata: true,
settings: true,
Expand Down Expand Up @@ -173,7 +173,7 @@ test("pg - partial column selection", () => {
metadata: jsonb().notNull(),
});

const result = tableToZero(table, {
const result = createZeroSchema(table, {
id: true,
metadata: true,
name: false,
Expand Down Expand Up @@ -201,7 +201,7 @@ test("pg - partial column selection", () => {
metadata: jsonb().notNull(),
});

const result = tableToZero(table, {
const result = createZeroSchema(table, {
id: true,
metadata: true,
name: false,
Expand Down Expand Up @@ -232,7 +232,7 @@ test("pg - composite primary key", () => {
(t) => [primaryKey({ columns: [t.userId, t.orgId] })],
);

const result = tableToZero(table, {
const result = createZeroSchema(table, {
userId: true,
orgId: true,
role: true,
Expand Down Expand Up @@ -261,7 +261,7 @@ test("pg - timestamp fields", () => {
scheduledFor: timestamp().notNull(),
});

const result = tableToZero(table, {
const result = createZeroSchema(table, {
id: true,
createdAt: true,
updatedAt: true,
Expand Down Expand Up @@ -294,7 +294,7 @@ test("pg - custom column mapping", () => {
}>(),
});

const result = tableToZero(table, {
const result = createZeroSchema(table, {
id: true,
firstName: true,
lastName: true,
Expand Down Expand Up @@ -328,7 +328,7 @@ test("pg - enum field", () => {
backupRole: roleEnum(),
});

const result = tableToZero(table, {
const result = createZeroSchema(table, {
id: true,
role: true,
backupRole: true,
Expand Down Expand Up @@ -357,7 +357,7 @@ test("pg - simple enum field", () => {
mood: moodEnum().notNull(),
});

const result = tableToZero(table, {
const result = createZeroSchema(table, {
id: true,
name: true,
mood: true,
Expand Down Expand Up @@ -427,7 +427,7 @@ test("pg - all supported data types", () => {
optionalEnum: statusEnum(),
});

const result = tableToZero(table, {
const result = createZeroSchema(table, {
id: true,
smallint: true,
integer: true,
Expand Down Expand Up @@ -524,7 +524,7 @@ test("pg - override column json type", () => {
metadata: jsonb().notNull(),
});

const result = tableToZero(table, {
const result = createZeroSchema(table, {
id: true,
metadata: column.json<{ amount: number; currency: string }>(),
});
Expand Down
4 changes: 2 additions & 2 deletions tests/relationships.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ test.skip("pg - basic", () => {
// }),
// }));
// const postResult = relationsToZero(postsRelations);
// const postResult = tableToZero(postTable, {
// const postResult = createZeroSchema(postTable, {
// id: true,
// text: true,
// userId: true,
// });
// const userResult = tableToZero(userTable, {
// const userResult = createZeroSchema(userTable, {
// id: true,
// name: true,
// });
Expand Down
4 changes: 2 additions & 2 deletions tests/utils.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import type { TableSchema } from "@rocicorp/zero";
import { Table } from "drizzle-orm";
import { expect } from "vitest";
import type { ColumnsConfig, TableToZeroResult } from "../src";
import type { ColumnsConfig, CreateZeroSchema } from "../src";

export type ZeroTableSchema = TableSchema;

export function expectDeepEqual<
S extends ZeroTableSchema,
T extends Table,
C extends ColumnsConfig<T>,
>(actual: TableToZeroResult<T, C>) {
>(actual: CreateZeroSchema<T, C>) {
return {
toEqual(expected: S) {
expect(Object.keys(actual.columns)).toStrictEqual(
Expand Down

0 comments on commit 1e7467d

Please sign in to comment.