Skip to content

Commit 863d7f5

Browse files
authored
chore: rename to drizzle-zero (#213)
* chore: rename to drizzle-zero * chore: rename file
1 parent 878cbe8 commit 863d7f5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+296
-252
lines changed

AGENTS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,4 @@ Follow the conventional-commit style found in `git log` (`feat:`, `fix:`, `chore
2727

2828
## Configuration & Security Tips
2929

30-
Ensure both `drizzle.config.ts` and any `zero-drizzle.config.ts` files stay inside the `tsconfig` `include` glob so type extraction works. Never commit credentials inside fixture configs—use environment variables or `.env.local` ignored by git. When adding new CLI flags, document them in `README.md` and consider wiring sanity tests in `integration/` to prevent regressions around schema casing or output paths.
30+
Ensure both `drizzle.config.ts` and any `drizzle-zero.config.ts` files stay inside the `tsconfig` `include` glob so type extraction works. Never commit credentials inside fixture configs—use environment variables or `.env.local` ignored by git. When adding new CLI flags, document them in `README.md` and consider wiring sanity tests in `integration/` to prevent regressions around schema casing or output paths.

README.md

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
# zero-drizzle
1+
# drizzle-zero
22

33
Generate [Zero](https://zero.rocicorp.dev/) schemas from [Drizzle ORM](https://orm.drizzle.team) schemas.
44

55
## Installation
66

77
```bash
8-
npm install zero-drizzle
8+
npm install drizzle-zero
99
# or
10-
bun add zero-drizzle
10+
bun add drizzle-zero
1111
# or
12-
yarn add zero-drizzle
12+
yarn add drizzle-zero
1313
# or
14-
pnpm add zero-drizzle
14+
pnpm add drizzle-zero
1515
```
1616

1717
## Usage
@@ -62,7 +62,7 @@ You can then add the schema generation script to your `package.json`:
6262
```json
6363
{
6464
"scripts": {
65-
"generate": "zero-drizzle generate --format",
65+
"generate": "drizzle-zero generate --format",
6666
"postinstall": "npm generate"
6767
}
6868
}
@@ -136,22 +136,22 @@ function PostList() {
136136
}
137137
```
138138

139-
### Customize with `zero-drizzle.config.ts`
139+
### Customize with `drizzle-zero.config.ts`
140140

141141
If you want to customize the tables/columns that are synced by Zero, you can optionally
142-
create a new config file at `zero-drizzle.config.ts` specifying the tables and/or columns you want to
142+
create a new config file at `drizzle-zero.config.ts` specifying the tables and/or columns you want to
143143
include in the CLI output:
144144

145145
> **Important:** The config file currently struggles with types for large schemas. In those cases,
146146
> stick with the default CLI behavior.
147147
148148
```ts
149-
import {zeroDrizzleConfig} from 'zero-drizzle';
149+
import {drizzleZeroConfig} from 'drizzle-zero';
150150
// directly glob import your original Drizzle schema w/ tables/relations
151151
import * as drizzleSchema from './drizzle-schema';
152152

153153
// Define your configuration file for the CLI
154-
export default zeroDrizzleConfig(drizzleSchema, {
154+
export default drizzleZeroConfig(drizzleSchema, {
155155
// Specify which tables and columns to include in the Zero schema.
156156
// This allows for the "expand/migrate/contract" pattern recommended in the Zero docs.
157157

@@ -187,18 +187,18 @@ export default zeroDrizzleConfig(drizzleSchema, {
187187

188188
You can customize this config file path with `-c, --config <input-file>`.
189189

190-
**Important:** the `zero-drizzle.config.ts` file **must be included in the tsconfig**
190+
**Important:** the `drizzle-zero.config.ts` file **must be included in the tsconfig**
191191
for the type resolution to work. If they are not included, there will be an error similar to
192192
`Failed to find type definitions`.
193193

194194
## Many-to-Many Relationships
195195

196-
zero-drizzle supports many-to-many relationships with a junction table. You can configure them in two ways:
196+
drizzle-zero supports many-to-many relationships with a junction table. You can configure them in two ways:
197197

198198
### Simple Configuration
199199

200200
```ts
201-
export default zeroDrizzleConfig(drizzleSchema, {
201+
export default drizzleZeroConfig(drizzleSchema, {
202202
tables: {
203203
user: {
204204
id: true,
@@ -216,7 +216,6 @@ export default zeroDrizzleConfig(drizzleSchema, {
216216
manyToMany: {
217217
user: {
218218
// Simple format: [junction table, target table]
219-
// Do not use the same name as any existing relationships
220219
groups: ['usersToGroup', 'group'],
221220
},
222221
},
@@ -248,7 +247,7 @@ console.log(user);
248247
For more complex scenarios like self-referential relationships:
249248

250249
```ts
251-
export default zeroDrizzleConfig(drizzleSchema, {
250+
export default drizzleZeroConfig(drizzleSchema, {
252251
tables: {
253252
user: {
254253
id: true,

custom-types/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "@zero-drizzle/custom-types",
2+
"name": "@drizzle-zero/custom-types",
33
"private": true,
44
"type": "module",
55
"exports": {

db/drizzle/schema.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type {
22
CustomJsonInterface,
33
CustomJsonType,
4-
} from '@zero-drizzle/custom-types';
4+
} from '@drizzle-zero/custom-types';
55
import {relations, sql} from 'drizzle-orm';
66
import {
77
bigint,

db/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "@zero-drizzle/db",
2+
"name": "@drizzle-zero/db",
33
"private": true,
44
"type": "module",
55
"exports": {
@@ -11,9 +11,9 @@
1111
"db:generate": "drizzle-kit generate"
1212
},
1313
"dependencies": {
14-
"@zero-drizzle/custom-types": "workspace:*",
14+
"@drizzle-zero/custom-types": "workspace:*",
1515
"drizzle-orm": "^0.45.0",
16-
"zero-drizzle": "workspace:*"
16+
"drizzle-zero": "workspace:*"
1717
},
1818
"devDependencies": {
1919
"@testcontainers/postgresql": "^11.9.0",

db/test-utils.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
import type {StartedPostgreSqlContainer} from '@testcontainers/postgresql';
22
import {PostgreSqlContainer} from '@testcontainers/postgresql';
3-
import type {NodePgDatabase} from 'drizzle-orm/node-postgres';
43
import {drizzle} from 'drizzle-orm/node-postgres';
54
import path from 'path';
65
import {Pool} from 'pg';
6+
import postgres from 'postgres';
77
import type {StartedNetwork} from 'testcontainers';
88
import {
99
GenericContainer,
1010
Network,
1111
PullPolicy,
1212
type StartedTestContainer,
1313
} from 'testcontainers';
14+
import {getShortCode} from './drizzle/types';
1415
import * as drizzleSchema from './schema';
1516
import {
1617
allTypes,
@@ -91,8 +92,6 @@ import {
9192
timesheet,
9293
user,
9394
} from './schema';
94-
import postgres from 'postgres';
95-
import {getShortCode} from './drizzle/types';
9695

9796
const versionInt = parseInt(process.env.PG_VERSION ?? '16');
9897
const PG_PORT = 5732 + (versionInt - 16);
@@ -114,7 +113,7 @@ let startedNetwork: StartedNetwork | null = null;
114113
let postgresContainer: StartedPostgreSqlContainer | null = null;
115114
let zeroContainer: StartedTestContainer | null = null;
116115

117-
export const db: NodePgDatabase<typeof drizzleSchema> = drizzle(pool, {
116+
export const db = drizzle(pool, {
118117
schema: drizzleSchema,
119118
});
120119

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import {zeroDrizzleConfig} from 'zero-drizzle';
1+
import {drizzleZeroConfig} from 'drizzle-zero';
22
import * as drizzleSchema from '../db/drizzle/schema';
33

4-
export * from '@zero-drizzle/db/types';
4+
export * from '@drizzle-zero/db/types';
55

6-
export const schema = zeroDrizzleConfig(drizzleSchema, {
6+
export const schema = drizzleZeroConfig(drizzleSchema, {
77
tables: {
88
allTypes: true,
99
analyticsDashboard: true,

integration/package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
{
2-
"name": "@zero-drizzle/integration",
2+
"name": "@drizzle-zero/integration",
33
"private": true,
44
"type": "module",
55
"scripts": {
66
"build": "tsc",
7-
"zero-drizzle:generate": "zero-drizzle generate -f",
8-
"pretest": "pnpm zero-drizzle:generate",
7+
"drizzle-zero:generate": "drizzle-zero generate -f",
8+
"pretest": "pnpm drizzle-zero:generate",
99
"test": "pnpm build && vitest run"
1010
},
1111
"dependencies": {
12-
"@zero-drizzle/custom-types": "workspace:*",
13-
"@zero-drizzle/db": "workspace:*",
12+
"@drizzle-zero/custom-types": "workspace:*",
13+
"@drizzle-zero/db": "workspace:*",
1414
"@hono/node-server": "^1.19.6",
15-
"zero-drizzle": "workspace:*",
15+
"drizzle-zero": "workspace:*",
1616
"hono": "^4.10.7",
1717
"zod": "^4.1.13"
1818
}

integration/tests/integration.test.ts

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,30 @@ import {
33
db,
44
shutdown,
55
startPostgresAndZero,
6-
} from '@zero-drizzle/db/test-utils';
6+
} from '@drizzle-zero/db/test-utils';
7+
import {getShortCode} from '@drizzle-zero/db/types';
78
import {Zero} from '@rocicorp/zero';
89
import {zeroDrizzle} from '@rocicorp/zero/server/adapters/drizzle';
10+
import type {Server} from 'http';
911
import {
1012
afterAll,
13+
assert,
1114
beforeAll,
1215
describe,
1316
expect,
1417
expectTypeOf,
1518
test,
1619
} from 'vitest';
1720
import {WebSocket} from 'ws';
21+
import {
22+
startGetQueriesServer,
23+
stopGetQueriesServer,
24+
} from '../get-queries-server';
1825
import {
1926
allTypesById,
2027
allTypesByStatus,
2128
allUsers,
29+
complexOrderWithEverything,
2230
filtersWithChildren,
2331
mediumById,
2432
messageById,
@@ -27,20 +35,13 @@ import {
2735
messagesBySender,
2836
userWithFriends,
2937
userWithMediums,
30-
complexOrderWithEverything,
3138
} from '../synced-queries';
3239
import {schema, type Filter, type Schema} from '../zero-schema.gen';
33-
import {
34-
startGetQueriesServer,
35-
stopGetQueriesServer,
36-
} from '../get-queries-server';
37-
import type {Server} from 'http';
38-
import {getShortCode} from '@zero-drizzle/db/types';
3940

40-
const zeroDb = zeroDrizzle(schema, db as any);
41+
const zeroDb = zeroDrizzle(schema, db);
4142

4243
// Provide WebSocket on the global scope
43-
globalThis.WebSocket = WebSocket as any;
44+
globalThis.WebSocket = WebSocket as unknown as typeof globalThis.WebSocket;
4445

4546
let queriesServer: Server;
4647

@@ -820,7 +821,9 @@ describe('complex order', () => {
820821
});
821822

822823
const query = complexOrderWithEverything(undefined, 'order-test-1');
823-
const result = (await zero.run(query, {type: 'complete'})) as any;
824+
const result = await zero.run(query, {type: 'complete'});
825+
826+
assert(result);
824827

825828
// Order basic fields
826829
expect(result.id).toBe('order-test-1');
@@ -830,6 +833,8 @@ describe('complex order', () => {
830833
expect(result.customerId).toBe('cust-1');
831834
expect(result.opportunityId).toBe('opp-1');
832835

836+
assert(result.customer);
837+
833838
// Customer relationship
834839
expect(result.customer).toBeDefined();
835840
expect(result.customer.id).toBe('cust-1');
@@ -838,36 +843,48 @@ describe('complex order', () => {
838843
expect(result.customer.partner).toBe(false);
839844
expect(result.customer.status).toBe('COMPLETED');
840845

846+
assert(result.customer.friends?.[0]);
847+
841848
// Customer friends relationship
842849
expect(result.customer.friends).toHaveLength(1);
843850
expect(result.customer.friends[0].id).toBe('friend-1');
844851
expect(result.customer.friends[0].name).toBe('Customer Friend');
845852

853+
assert(result.customer.messages?.[0]);
854+
846855
// Customer messages relationship
847856
expect(result.customer.messages).toHaveLength(1);
848857
expect(result.customer.messages[0].id).toBe('msg-cust-1');
849858
expect(result.customer.messages[0].body).toBe('Hello from customer');
850859
expect(result.customer.messages[0].metadata.key).toBe('cust-meta');
851860

861+
assert(result.opportunity);
862+
852863
// Opportunity relationship
853864
expect(result.opportunity).toBeDefined();
854865
expect(result.opportunity.id).toBe('opp-1');
855866
expect(result.opportunity.name).toBe('Big Deal');
856867
expect(result.opportunity.amount).toBe(125000);
857868
expect(result.opportunity.accountId).toBe('acct-1');
858869

870+
assert(result.opportunity.account);
871+
859872
// Opportunity account relationship
860873
expect(result.opportunity.account).toBeDefined();
861874
expect(result.opportunity.account.id).toBe('acct-1');
862875
expect(result.opportunity.account.name).toBe('Acme Corp');
863876
expect(result.opportunity.account.industry).toBe('Manufacturing');
864877
expect(result.opportunity.account.ownerId).toBe('owner-1');
865878

879+
assert(result.opportunity.historyEntries?.[0]);
880+
866881
// Opportunity history entries
867882
expect(result.opportunity.historyEntries).toHaveLength(1);
868883
expect(result.opportunity.historyEntries[0].id).toBe('opp-hist-1');
869884
expect(result.opportunity.historyEntries[0].opportunityId).toBe('opp-1');
870885

886+
assert(result.items?.[0]);
887+
871888
// Order items
872889
expect(result.items).toHaveLength(1);
873890
expect(result.items[0].id).toBe('order-item-test-1');
@@ -876,6 +893,8 @@ describe('complex order', () => {
876893
expect(result.items[0].unitPrice).toBe(4999);
877894
expect(result.items[0].variantId).toBe('variant-1');
878895

896+
assert(result.items?.[0].variant);
897+
879898
// Item variant relationship
880899
expect(result.items[0].variant).toBeDefined();
881900
expect(result.items[0].variant.id).toBe('variant-1');
@@ -884,6 +903,8 @@ describe('complex order', () => {
884903
expect(result.items[0].variant.currency).toBe('USD');
885904
expect(result.items[0].variant.isActive).toBe(true);
886905

906+
assert(result.payments?.[0]);
907+
887908
// Payments
888909
expect(result.payments).toHaveLength(1);
889910
expect(result.payments[0].id).toBe('order-payment-test-1');
@@ -892,6 +913,8 @@ describe('complex order', () => {
892913
expect(result.payments[0].status).toBe('PENDING');
893914
expect(result.payments[0].paymentId).toBe('payment-test-1');
894915

916+
assert(result.payments?.[0].payment);
917+
895918
// Payment relationship
896919
expect(result.payments[0].payment).toBeDefined();
897920
expect(result.payments[0].payment.id).toBe('payment-test-1');
@@ -900,13 +923,17 @@ describe('complex order', () => {
900923
expect(result.payments[0].payment.status).toBe('PENDING');
901924
expect(result.payments[0].payment.receivedById).toBe('sales-1');
902925

926+
assert(result.shipments?.[0]);
927+
903928
// Shipments
904929
expect(result.shipments).toHaveLength(1);
905930
expect(result.shipments[0].id).toBe('shipment-test-1');
906931
expect(result.shipments[0].orderId).toBe('order-test-1');
907932
expect(result.shipments[0].carrier).toBe('UPS');
908933
expect(result.shipments[0].trackingNumber).toBe('1Z999');
909934

935+
assert(result.shipments?.[0].items?.[0]);
936+
910937
// Shipment items
911938
expect(result.shipments[0].items).toHaveLength(1);
912939
expect(result.shipments[0].items[0].id).toBe('shipment-item-test-1');

0 commit comments

Comments
 (0)