diff --git a/AGENTS.md b/AGENTS.md index 7207ea00..89084b8f 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -2,7 +2,7 @@ ## Project Structure & Module Organization -Core CLI logic lives in `src/`: `cli/` exposes the executable wrapper, `drizzle-to-zero.ts` coordinates schema translation, adapters sit in `node-postgres/` and `postgres-js/`, and helpers such as `tables.ts` or `relations.ts` centralize shared builders. Vitest unit suites reside in `tests/`, while end-to-end fixtures live under `integration/`, `no-config-integration/`, and `db/`. Generated bundles land in `dist/` and coverage reports in `coverage/`; treat them as expendable artifacts unless you are preparing a release. +Core CLI logic lives in `src/`: `cli/` exposes the executable wrapper, `drizzle-to-zero.ts` coordinates schema translation, and helpers such as `tables.ts` or `relations.ts` centralize shared builders. Vitest unit suites reside in `tests/`, while end-to-end fixtures live under `integration/`, `no-config-integration/`, and `db/`. Generated bundles land in `dist/` and coverage reports in `coverage/`; treat them as expendable artifacts unless you are preparing a release. ## Build, Test, and Development Commands diff --git a/README.md b/README.md index 7d74fe6e..e498a0b5 100644 --- a/README.md +++ b/README.md @@ -90,10 +90,11 @@ The CLI automatically detects whether `.js` file extensions are needed in import You can also control optional outputs from the generator: -- **--skip-types**: Skip generating table `Row<>` type exports. +- **--skip-types**: Skip generating table `Row[]` type exports. - **--skip-builder**: Skip generating the query `builder` export. -- **--disable-legacy-mutators**: Disable legacy CRUD mutators (sets `enableLegacyMutators` to `false` in the generated schema). Use this when you want to use only custom mutators instead of the default CRUD operations. -- **--disable-legacy-queries**: Disable legacy CRUD queries (sets `enableLegacyQueries` to `false` in the generated schema). Use this when you want to use only custom queries. +- **--skip-declare**: Skip generating the module augmentation for default types in Zero. +- **--enable-legacy-mutators**: Disable legacy CRUD mutators (sets `enableLegacyMutators` to `true` in the generated schema). +- **--enable-legacy-queries**: Disable legacy CRUD queries (sets `enableLegacyQueries` to `true` in the generated schema). For more information on disabling legacy mutators and queries, see the [Zero documentation](https://zero.rocicorp.dev/docs/custom-mutators#disabling-crud-mutators). diff --git a/build.ts b/build.ts index 9dc649ab..436f355e 100644 --- a/build.ts +++ b/build.ts @@ -19,41 +19,7 @@ const main = async () => { ], }); - await tsup.build({ - outDir: "./dist/postgres-js", - splitting: false, - dts: true, - entry: ["src/postgres-js/index.ts"], - format: ["cjs", "esm"], - external: [ - "esbuild", - "tsx", - "prettier", - "typescript", - "@rocicorp/zero", - "drizzle-orm", - "commander", - "ts-morph", - ], - }); - - await tsup.build({ - outDir: "./dist/node-postgres", - splitting: false, - dts: true, - entry: ["src/node-postgres/index.ts"], - format: ["cjs", "esm"], - external: [ - "esbuild", - "tsx", - "prettier", - "typescript", - "@rocicorp/zero", - "drizzle-orm", - "commander", - "ts-morph", - ], - }); + await tsup.build({ outDir: "./dist/cli", diff --git a/integration/package.json b/integration/package.json index 3a2eba59..11b11f74 100644 --- a/integration/package.json +++ b/integration/package.json @@ -4,7 +4,7 @@ "type": "module", "scripts": { "build": "tsc", - "drizzle-zero:generate": "drizzle-zero generate -f --disable-legacy-mutators --disable-legacy-queries", + "drizzle-zero:generate": "drizzle-zero generate -f", "pretest": "pnpm drizzle-zero:generate", "test": "pnpm build && vitest run" }, diff --git a/integration/synced-queries.ts b/integration/synced-queries.ts index 227206bc..29278cfb 100644 --- a/integration/synced-queries.ts +++ b/integration/synced-queries.ts @@ -1,18 +1,18 @@ import { syncedQueryWithContext } from "@rocicorp/zero"; import { z } from "zod"; -import { builder } from "./zero-schema.gen"; +import { zql } from "./zero-schema.gen"; export const allUsers = syncedQueryWithContext( "integration.allUsers", z.tuple([]), - (_ctx) => builder.user.orderBy("id", "asc"), + (_ctx) => zql.user.orderBy("id", "asc"), ); export const filtersWithChildren = syncedQueryWithContext( "integration.filtersWithChildren", z.tuple([z.string()]), (_ctx, rootId) => - builder.filters + zql.filters .where((q) => q.cmp("id", "=", rootId)) .related("children", (q) => q.related("children").orderBy("id", "asc")), ); @@ -21,7 +21,7 @@ export const messagesBySender = syncedQueryWithContext( "integration.messagesBySender", z.tuple([z.string()]), (_ctx, senderId) => - builder.message + zql.message .where((q) => q.cmp("senderId", "=", senderId)) .orderBy("id", "asc"), ); @@ -30,14 +30,14 @@ export const messagesByBody = syncedQueryWithContext( "integration.messagesByBody", z.tuple([z.string()]), (_ctx, body) => - builder.message.where((q) => q.cmp("body", "=", body)).orderBy("id", "asc"), + zql.message.where((q) => q.cmp("body", "=", body)).orderBy("id", "asc"), ); export const messageWithRelations = syncedQueryWithContext( "integration.messageWithRelations", z.tuple([z.string()]), (_ctx, id) => - builder.message + zql.message .where((q) => q.cmp("id", "=", id)) .related("medium") .related("sender") @@ -48,7 +48,7 @@ export const userWithMediums = syncedQueryWithContext( "integration.userWithMediums", z.tuple([z.string()]), (_ctx, id) => - builder.user + zql.user .where((q) => q.cmp("id", "=", id)) .related("mediums") .one(), @@ -58,7 +58,7 @@ export const userWithFriends = syncedQueryWithContext( "integration.userWithFriends", z.tuple([z.string()]), (_ctx, id) => - builder.user + zql.user .where((q) => q.cmp("id", "=", id)) .related("friends") .one(), @@ -67,33 +67,33 @@ export const userWithFriends = syncedQueryWithContext( export const messageById = syncedQueryWithContext( "integration.messageById", z.tuple([z.string()]), - (_ctx, id) => builder.message.where((q) => q.cmp("id", "=", id)).one(), + (_ctx, id) => zql.message.where((q) => q.cmp("id", "=", id)).one(), ); export const mediumById = syncedQueryWithContext( "integration.mediumById", z.tuple([z.string()]), - (_ctx, id) => builder.medium.where((q) => q.cmp("id", "=", id)).one(), + (_ctx, id) => zql.medium.where((q) => q.cmp("id", "=", id)).one(), ); export const allTypesById = syncedQueryWithContext( "integration.allTypesById", z.tuple([z.string()]), - (_ctx, id) => builder.allTypes.where((q) => q.cmp("id", "=", id)).one(), + (_ctx, id) => zql.allTypes.where((q) => q.cmp("id", "=", id)).one(), ); export const allTypesByStatus = syncedQueryWithContext( "integration.allTypesByStatus", z.tuple([z.enum(["active", "inactive", "pending"])]), (_ctx, status) => - builder.allTypes.where((q) => q.cmp("status", "=", status)).one(), + zql.allTypes.where((q) => q.cmp("status", "=", status)).one(), ); export const complexOrderWithEverything = syncedQueryWithContext( "integration.complexOrderWithEverything", z.tuple([z.string()]), (_ctx, orderId) => - builder.orderTable + zql.orderTable .where((q) => q.cmp("id", "=", orderId)) .related("customer", (q) => q diff --git a/integration/zero-schema.gen.ts b/integration/zero-schema.gen.ts index 8520720a..ec506c91 100644 --- a/integration/zero-schema.gen.ts +++ b/integration/zero-schema.gen.ts @@ -8916,451 +8916,629 @@ export type Schema = typeof schema; /** * Represents a row from the "allTypes" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["allTypes"] instead from "@rocicorp/zero". */ -export type AllType = Row; +export type AllType = Row["allTypes"]; /** * Represents a row from the "analyticsDashboard" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["analyticsDashboard"] instead from "@rocicorp/zero". */ -export type AnalyticsDashboard = Row; +export type AnalyticsDashboard = Row["analyticsDashboard"]; /** * Represents a row from the "analyticsWidget" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["analyticsWidget"] instead from "@rocicorp/zero". */ -export type AnalyticsWidget = Row; +export type AnalyticsWidget = Row["analyticsWidget"]; /** * Represents a row from the "analyticsWidgetQuery" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["analyticsWidgetQuery"] instead from "@rocicorp/zero". */ -export type AnalyticsWidgetQuery = Row; +export type AnalyticsWidgetQuery = Row["analyticsWidgetQuery"]; /** * Represents a row from the "benefitEnrollment" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["benefitEnrollment"] instead from "@rocicorp/zero". */ -export type BenefitEnrollment = Row; +export type BenefitEnrollment = Row["benefitEnrollment"]; /** * Represents a row from the "benefitPlan" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["benefitPlan"] instead from "@rocicorp/zero". */ -export type BenefitPlan = Row; +export type BenefitPlan = Row["benefitPlan"]; /** * Represents a row from the "billingInvoice" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["billingInvoice"] instead from "@rocicorp/zero". */ -export type BillingInvoice = Row; +export type BillingInvoice = Row["billingInvoice"]; /** * Represents a row from the "billingInvoiceLine" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["billingInvoiceLine"] instead from "@rocicorp/zero". */ -export type BillingInvoiceLine = Row; +export type BillingInvoiceLine = Row["billingInvoiceLine"]; /** * Represents a row from the "budget" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["budget"] instead from "@rocicorp/zero". */ -export type Budget = Row; +export type Budget = Row["budget"]; /** * Represents a row from the "budgetLine" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["budgetLine"] instead from "@rocicorp/zero". */ -export type BudgetLine = Row; +export type BudgetLine = Row["budgetLine"]; /** * Represents a row from the "crmAccount" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["crmAccount"] instead from "@rocicorp/zero". */ -export type CrmAccount = Row; +export type CrmAccount = Row["crmAccount"]; /** * Represents a row from the "crmActivity" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["crmActivity"] instead from "@rocicorp/zero". */ -export type CrmActivity = Row; +export type CrmActivity = Row["crmActivity"]; /** * Represents a row from the "crmActivityType" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["crmActivityType"] instead from "@rocicorp/zero". */ -export type CrmActivityType = Row; +export type CrmActivityType = Row["crmActivityType"]; /** * Represents a row from the "crmContact" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["crmContact"] instead from "@rocicorp/zero". */ -export type CrmContact = Row; +export type CrmContact = Row["crmContact"]; /** * Represents a row from the "crmNote" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["crmNote"] instead from "@rocicorp/zero". */ -export type CrmNote = Row; +export type CrmNote = Row["crmNote"]; /** * Represents a row from the "crmOpportunity" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["crmOpportunity"] instead from "@rocicorp/zero". */ -export type CrmOpportunity = Row; +export type CrmOpportunity = Row["crmOpportunity"]; /** * Represents a row from the "crmOpportunityStageHistory" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["crmOpportunityStageHistory"] instead from "@rocicorp/zero". */ -export type CrmOpportunityStageHistory = Row< - typeof crmOpportunityStageHistoryTable ->; +export type CrmOpportunityStageHistory = Row["crmOpportunityStageHistory"]; /** * Represents a row from the "crmPipelineStage" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["crmPipelineStage"] instead from "@rocicorp/zero". */ -export type CrmPipelineStage = Row; +export type CrmPipelineStage = Row["crmPipelineStage"]; /** * Represents a row from the "department" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["department"] instead from "@rocicorp/zero". */ -export type Department = Row; +export type Department = Row["department"]; /** * Represents a row from the "documentFile" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["documentFile"] instead from "@rocicorp/zero". */ -export type DocumentFile = Row; +export type DocumentFile = Row["documentFile"]; /** * Represents a row from the "documentFileVersion" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["documentFileVersion"] instead from "@rocicorp/zero". */ -export type DocumentFileVersion = Row; +export type DocumentFileVersion = Row["documentFileVersion"]; /** * Represents a row from the "documentFolder" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["documentFolder"] instead from "@rocicorp/zero". */ -export type DocumentFolder = Row; +export type DocumentFolder = Row["documentFolder"]; /** * Represents a row from the "documentLibrary" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["documentLibrary"] instead from "@rocicorp/zero". */ -export type DocumentLibrary = Row; +export type DocumentLibrary = Row["documentLibrary"]; /** * Represents a row from the "documentSharing" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["documentSharing"] instead from "@rocicorp/zero". */ -export type DocumentSharing = Row; +export type DocumentSharing = Row["documentSharing"]; /** * Represents a row from the "employeeDocument" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["employeeDocument"] instead from "@rocicorp/zero". */ -export type EmployeeDocument = Row; +export type EmployeeDocument = Row["employeeDocument"]; /** * Represents a row from the "employeeProfile" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["employeeProfile"] instead from "@rocicorp/zero". */ -export type EmployeeProfile = Row; +export type EmployeeProfile = Row["employeeProfile"]; /** * Represents a row from the "employmentHistory" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["employmentHistory"] instead from "@rocicorp/zero". */ -export type EmploymentHistory = Row; +export type EmploymentHistory = Row["employmentHistory"]; /** * Represents a row from the "expenseItem" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["expenseItem"] instead from "@rocicorp/zero". */ -export type ExpenseItem = Row; +export type ExpenseItem = Row["expenseItem"]; /** * Represents a row from the "expenseReport" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["expenseReport"] instead from "@rocicorp/zero". */ -export type ExpenseReport = Row; +export type ExpenseReport = Row["expenseReport"]; /** * Represents a row from the "filters" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["filters"] instead from "@rocicorp/zero". */ -export type Filter = Row; +export type Filter = Row["filters"]; /** * Represents a row from the "friendship" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["friendship"] instead from "@rocicorp/zero". */ -export type Friendship = Row; +export type Friendship = Row["friendship"]; /** * Represents a row from the "integrationCredential" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["integrationCredential"] instead from "@rocicorp/zero". */ -export type IntegrationCredential = Row; +export type IntegrationCredential = Row["integrationCredential"]; /** * Represents a row from the "integrationEvent" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["integrationEvent"] instead from "@rocicorp/zero". */ -export type IntegrationEvent = Row; +export type IntegrationEvent = Row["integrationEvent"]; /** * Represents a row from the "integrationWebhook" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["integrationWebhook"] instead from "@rocicorp/zero". */ -export type IntegrationWebhook = Row; +export type IntegrationWebhook = Row["integrationWebhook"]; /** * Represents a row from the "inventoryItem" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["inventoryItem"] instead from "@rocicorp/zero". */ -export type InventoryItem = Row; +export type InventoryItem = Row["inventoryItem"]; /** * Represents a row from the "inventoryLevel" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["inventoryLevel"] instead from "@rocicorp/zero". */ -export type InventoryLevel = Row; +export type InventoryLevel = Row["inventoryLevel"]; /** * Represents a row from the "inventoryLocation" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["inventoryLocation"] instead from "@rocicorp/zero". */ -export type InventoryLocation = Row; +export type InventoryLocation = Row["inventoryLocation"]; /** * Represents a row from the "ledgerAccount" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["ledgerAccount"] instead from "@rocicorp/zero". */ -export type LedgerAccount = Row; +export type LedgerAccount = Row["ledgerAccount"]; /** * Represents a row from the "ledgerEntry" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["ledgerEntry"] instead from "@rocicorp/zero". */ -export type LedgerEntry = Row; +export type LedgerEntry = Row["ledgerEntry"]; /** * Represents a row from the "ledgerTransaction" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["ledgerTransaction"] instead from "@rocicorp/zero". */ -export type LedgerTransaction = Row; +export type LedgerTransaction = Row["ledgerTransaction"]; /** * Represents a row from the "marketingAudience" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["marketingAudience"] instead from "@rocicorp/zero". */ -export type MarketingAudience = Row; +export type MarketingAudience = Row["marketingAudience"]; /** * Represents a row from the "marketingCampaign" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["marketingCampaign"] instead from "@rocicorp/zero". */ -export type MarketingCampaign = Row; +export type MarketingCampaign = Row["marketingCampaign"]; /** * Represents a row from the "marketingCampaignAudience" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["marketingCampaignAudience"] instead from "@rocicorp/zero". */ -export type MarketingCampaignAudience = Row< - typeof marketingCampaignAudienceTable ->; +export type MarketingCampaignAudience = Row["marketingCampaignAudience"]; /** * Represents a row from the "marketingCampaignChannel" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["marketingCampaignChannel"] instead from "@rocicorp/zero". */ -export type MarketingCampaignChannel = Row< - typeof marketingCampaignChannelTable ->; +export type MarketingCampaignChannel = Row["marketingCampaignChannel"]; /** * Represents a row from the "marketingChannel" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["marketingChannel"] instead from "@rocicorp/zero". */ -export type MarketingChannel = Row; +export type MarketingChannel = Row["marketingChannel"]; /** * Represents a row from the "medium" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["medium"] instead from "@rocicorp/zero". */ -export type Medium = Row; +export type Medium = Row["medium"]; /** * Represents a row from the "message" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["message"] instead from "@rocicorp/zero". */ -export type Message = Row; +export type Message = Row["message"]; /** * Represents a row from the "omittedTable" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["omittedTable"] instead from "@rocicorp/zero". */ -export type OmittedTable = Row; +export type OmittedTable = Row["omittedTable"]; /** * Represents a row from the "orderItem" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["orderItem"] instead from "@rocicorp/zero". */ -export type OrderItem = Row; +export type OrderItem = Row["orderItem"]; /** * Represents a row from the "orderPayment" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["orderPayment"] instead from "@rocicorp/zero". */ -export type OrderPayment = Row; +export type OrderPayment = Row["orderPayment"]; /** * Represents a row from the "orderTable" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["orderTable"] instead from "@rocicorp/zero". */ -export type OrderTable = Row; +export type OrderTable = Row["orderTable"]; /** * Represents a row from the "payment" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["payment"] instead from "@rocicorp/zero". */ -export type Payment = Row; +export type Payment = Row["payment"]; /** * Represents a row from the "product" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["product"] instead from "@rocicorp/zero". */ -export type Product = Row; +export type Product = Row["product"]; /** * Represents a row from the "productCategory" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["productCategory"] instead from "@rocicorp/zero". */ -export type ProductCategory = Row; +export type ProductCategory = Row["productCategory"]; /** * Represents a row from the "productMedia" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["productMedia"] instead from "@rocicorp/zero". */ -export type ProductMedia = Row; +export type ProductMedia = Row["productMedia"]; /** * Represents a row from the "productVariant" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["productVariant"] instead from "@rocicorp/zero". */ -export type ProductVariant = Row; +export type ProductVariant = Row["productVariant"]; /** * Represents a row from the "project" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["project"] instead from "@rocicorp/zero". */ -export type Project = Row; +export type Project = Row["project"]; /** * Represents a row from the "projectAssignment" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["projectAssignment"] instead from "@rocicorp/zero". */ -export type ProjectAssignment = Row; +export type ProjectAssignment = Row["projectAssignment"]; /** * Represents a row from the "projectAttachment" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["projectAttachment"] instead from "@rocicorp/zero". */ -export type ProjectAttachment = Row; +export type ProjectAttachment = Row["projectAttachment"]; /** * Represents a row from the "projectAudit" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["projectAudit"] instead from "@rocicorp/zero". */ -export type ProjectAudit = Row; +export type ProjectAudit = Row["projectAudit"]; /** * Represents a row from the "projectComment" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["projectComment"] instead from "@rocicorp/zero". */ -export type ProjectComment = Row; +export type ProjectComment = Row["projectComment"]; /** * Represents a row from the "projectNote" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["projectNote"] instead from "@rocicorp/zero". */ -export type ProjectNote = Row; +export type ProjectNote = Row["projectNote"]; /** * Represents a row from the "projectPhase" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["projectPhase"] instead from "@rocicorp/zero". */ -export type ProjectPhase = Row; +export type ProjectPhase = Row["projectPhase"]; /** * Represents a row from the "projectTag" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["projectTag"] instead from "@rocicorp/zero". */ -export type ProjectTag = Row; +export type ProjectTag = Row["projectTag"]; /** * Represents a row from the "projectTask" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["projectTask"] instead from "@rocicorp/zero". */ -export type ProjectTask = Row; +export type ProjectTask = Row["projectTask"]; /** * Represents a row from the "projectTaskTag" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["projectTaskTag"] instead from "@rocicorp/zero". */ -export type ProjectTaskTag = Row; +export type ProjectTaskTag = Row["projectTaskTag"]; /** * Represents a row from the "shipment" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["shipment"] instead from "@rocicorp/zero". */ -export type Shipment = Row; +export type Shipment = Row["shipment"]; /** * Represents a row from the "shipmentItem" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["shipmentItem"] instead from "@rocicorp/zero". */ -export type ShipmentItem = Row; +export type ShipmentItem = Row["shipmentItem"]; /** * Represents a row from the "supportTicket" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["supportTicket"] instead from "@rocicorp/zero". */ -export type SupportTicket = Row; +export type SupportTicket = Row["supportTicket"]; /** * Represents a row from the "supportTicketAssignment" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["supportTicketAssignment"] instead from "@rocicorp/zero". */ -export type SupportTicketAssignment = Row; +export type SupportTicketAssignment = Row["supportTicketAssignment"]; /** * Represents a row from the "supportTicketAudit" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["supportTicketAudit"] instead from "@rocicorp/zero". */ -export type SupportTicketAudit = Row; +export type SupportTicketAudit = Row["supportTicketAudit"]; /** * Represents a row from the "supportTicketMessage" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["supportTicketMessage"] instead from "@rocicorp/zero". */ -export type SupportTicketMessage = Row; +export type SupportTicketMessage = Row["supportTicketMessage"]; /** * Represents a row from the "supportTicketTag" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["supportTicketTag"] instead from "@rocicorp/zero". */ -export type SupportTicketTag = Row; +export type SupportTicketTag = Row["supportTicketTag"]; /** * Represents a row from the "supportTicketTagLink" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["supportTicketTagLink"] instead from "@rocicorp/zero". */ -export type SupportTicketTagLink = Row; +export type SupportTicketTagLink = Row["supportTicketTagLink"]; /** * Represents a row from the "team" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["team"] instead from "@rocicorp/zero". */ -export type Team = Row; +export type Team = Row["team"]; /** * Represents a row from the "testBigSerialPk" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["testBigSerialPk"] instead from "@rocicorp/zero". */ -export type TestBigSerialPk = Row; +export type TestBigSerialPk = Row["testBigSerialPk"]; /** * Represents a row from the "testCompositePkBothDefaults" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["testCompositePkBothDefaults"] instead from "@rocicorp/zero". */ -export type TestCompositePkBothDefault = Row< - typeof testCompositePkBothDefaultsTable ->; +export type TestCompositePkBothDefault = Row["testCompositePkBothDefaults"]; /** * Represents a row from the "testCompositePkOneDefault" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["testCompositePkOneDefault"] instead from "@rocicorp/zero". */ -export type TestCompositePkOneDefault = Row< - typeof testCompositePkOneDefaultTable ->; +export type TestCompositePkOneDefault = Row["testCompositePkOneDefault"]; /** * Represents a row from the "testIntegerDefaultPk" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["testIntegerDefaultPk"] instead from "@rocicorp/zero". */ -export type TestIntegerDefaultPk = Row; +export type TestIntegerDefaultPk = Row["testIntegerDefaultPk"]; /** * Represents a row from the "testSerialPk" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["testSerialPk"] instead from "@rocicorp/zero". */ -export type TestSerialPk = Row; +export type TestSerialPk = Row["testSerialPk"]; /** * Represents a row from the "testTextDefaultPk" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["testTextDefaultPk"] instead from "@rocicorp/zero". */ -export type TestTextDefaultPk = Row; +export type TestTextDefaultPk = Row["testTextDefaultPk"]; /** * Represents a row from the "testTimestampDefaultPk" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["testTimestampDefaultPk"] instead from "@rocicorp/zero". */ -export type TestTimestampDefaultPk = Row; +export type TestTimestampDefaultPk = Row["testTimestampDefaultPk"]; /** * Represents a row from the "testUuidPk" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["testUuidPk"] instead from "@rocicorp/zero". */ -export type TestUuidPk = Row; +export type TestUuidPk = Row["testUuidPk"]; /** * Represents a row from the "testUuidSqlDefaultPk" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["testUuidSqlDefaultPk"] instead from "@rocicorp/zero". */ -export type TestUuidSqlDefaultPk = Row; +export type TestUuidSqlDefaultPk = Row["testUuidSqlDefaultPk"]; /** * Represents a row from the "timeEntry" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["timeEntry"] instead from "@rocicorp/zero". */ -export type TimeEntry = Row; +export type TimeEntry = Row["timeEntry"]; /** * Represents a row from the "timesheet" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["timesheet"] instead from "@rocicorp/zero". */ -export type Timesheet = Row; +export type Timesheet = Row["timesheet"]; /** * Represents a row from the "user" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["user"] instead from "@rocicorp/zero". */ -export type User = Row; +export type User = Row["user"]; +/** + * Represents the ZQL query builder. + * This type is auto-generated from your Drizzle schema definition. + */ +export const zql = createBuilder(schema); /** * Represents the Zero schema query builder. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use `zql` instead. */ -export const builder = createBuilder(schema); +export const builder = zql; + +/** Defines the default types for Zero */ +declare module "@rocicorp/zero" { + interface DefaultTypes { + schema: Schema; + } +} diff --git a/no-config-integration/package.json b/no-config-integration/package.json index a6d39776..00bf9ec9 100644 --- a/no-config-integration/package.json +++ b/no-config-integration/package.json @@ -4,7 +4,7 @@ "type": "module", "scripts": { "build": "tsc", - "drizzle-zero:generate": "drizzle-zero generate -f -s ../db/schema.ts --disable-legacy-mutators --disable-legacy-queries", + "drizzle-zero:generate": "drizzle-zero generate -f -s ../db/schema.ts", "pretest": "pnpm drizzle-zero:generate", "test": "pnpm build && vitest run" }, diff --git a/no-config-integration/synced-queries.ts b/no-config-integration/synced-queries.ts index d1e9a024..22e77d6f 100644 --- a/no-config-integration/synced-queries.ts +++ b/no-config-integration/synced-queries.ts @@ -1,18 +1,18 @@ import { syncedQueryWithContext } from "@rocicorp/zero"; import { z } from "zod"; -import { builder } from "./zero-schema.gen"; +import { zql } from "./zero-schema.gen"; export const allUsers = syncedQueryWithContext( "noConfig.allUsers", z.tuple([]), - (_ctx) => builder.user.orderBy("id", "asc"), + (_ctx) => zql.user.orderBy("id", "asc"), ); export const filtersWithChildren = syncedQueryWithContext( "noConfig.filtersWithChildren", z.tuple([z.string()]), (_ctx, rootId) => - builder.filters + zql.filters .where((q) => q.cmp("id", "=", rootId)) .related("children", (q) => q.related("children").orderBy("id", "asc")), ); @@ -21,7 +21,7 @@ export const messagesBySender = syncedQueryWithContext( "noConfig.messagesBySender", z.tuple([z.string()]), (_ctx, senderId) => - builder.message + zql.message .where((q) => q.cmp("senderId", "=", senderId)) .orderBy("id", "asc"), ); @@ -30,14 +30,14 @@ export const messagesByBody = syncedQueryWithContext( "noConfig.messagesByBody", z.tuple([z.string()]), (_ctx, body) => - builder.message.where((q) => q.cmp("body", "=", body)).orderBy("id", "asc"), + zql.message.where((q) => q.cmp("body", "=", body)).orderBy("id", "asc"), ); export const messageWithRelations = syncedQueryWithContext( "noConfig.messageWithRelations", z.tuple([z.string()]), (_ctx, id) => - builder.message + zql.message .where((q) => q.cmp("id", "=", id)) .related("medium") .related("sender") @@ -47,26 +47,26 @@ export const messageWithRelations = syncedQueryWithContext( export const messageById = syncedQueryWithContext( "noConfig.messageById", z.tuple([z.string()]), - (_ctx, id) => builder.message.where((q) => q.cmp("id", "=", id)).one(), + (_ctx, id) => zql.message.where((q) => q.cmp("id", "=", id)).one(), ); export const mediumById = syncedQueryWithContext( "noConfig.mediumById", z.tuple([z.string()]), - (_ctx, id) => builder.medium.where((q) => q.cmp("id", "=", id)).one(), + (_ctx, id) => zql.medium.where((q) => q.cmp("id", "=", id)).one(), ); export const allTypesById = syncedQueryWithContext( "noConfig.allTypesById", z.tuple([z.string()]), - (_ctx, id) => builder.allTypes.where((q) => q.cmp("id", "=", id)).one(), + (_ctx, id) => zql.allTypes.where((q) => q.cmp("id", "=", id)).one(), ); export const complexOrderWithEverything = syncedQueryWithContext( "integration.complexOrderWithEverything", z.tuple([z.string()]), (_ctx, orderId) => - builder.orderTable + zql.orderTable .where((q) => q.cmp("id", "=", orderId)) .related("customer", (q) => q.related("messages", (q2) => diff --git a/no-config-integration/zero-schema.gen.ts b/no-config-integration/zero-schema.gen.ts index 7b572315..691554e3 100644 --- a/no-config-integration/zero-schema.gen.ts +++ b/no-config-integration/zero-schema.gen.ts @@ -9070,466 +9070,650 @@ export type Schema = typeof schema; /** * Represents a row from the "allTypes" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["allTypes"] instead from "@rocicorp/zero". */ -export type AllType = Row; +export type AllType = Row["allTypes"]; /** * Represents a row from the "analyticsDashboard" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["analyticsDashboard"] instead from "@rocicorp/zero". */ -export type AnalyticsDashboard = Row; +export type AnalyticsDashboard = Row["analyticsDashboard"]; /** * Represents a row from the "analyticsWidget" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["analyticsWidget"] instead from "@rocicorp/zero". */ -export type AnalyticsWidget = Row; +export type AnalyticsWidget = Row["analyticsWidget"]; /** * Represents a row from the "analyticsWidgetQuery" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["analyticsWidgetQuery"] instead from "@rocicorp/zero". */ -export type AnalyticsWidgetQuery = Row; +export type AnalyticsWidgetQuery = Row["analyticsWidgetQuery"]; /** * Represents a row from the "benefitEnrollment" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["benefitEnrollment"] instead from "@rocicorp/zero". */ -export type BenefitEnrollment = Row; +export type BenefitEnrollment = Row["benefitEnrollment"]; /** * Represents a row from the "benefitPlan" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["benefitPlan"] instead from "@rocicorp/zero". */ -export type BenefitPlan = Row; +export type BenefitPlan = Row["benefitPlan"]; /** * Represents a row from the "billingInvoice" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["billingInvoice"] instead from "@rocicorp/zero". */ -export type BillingInvoice = Row; +export type BillingInvoice = Row["billingInvoice"]; /** * Represents a row from the "billingInvoiceLine" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["billingInvoiceLine"] instead from "@rocicorp/zero". */ -export type BillingInvoiceLine = Row; +export type BillingInvoiceLine = Row["billingInvoiceLine"]; /** * Represents a row from the "budget" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["budget"] instead from "@rocicorp/zero". */ -export type Budget = Row; +export type Budget = Row["budget"]; /** * Represents a row from the "budgetLine" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["budgetLine"] instead from "@rocicorp/zero". */ -export type BudgetLine = Row; +export type BudgetLine = Row["budgetLine"]; /** * Represents a row from the "crmAccount" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["crmAccount"] instead from "@rocicorp/zero". */ -export type CrmAccount = Row; +export type CrmAccount = Row["crmAccount"]; /** * Represents a row from the "crmActivity" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["crmActivity"] instead from "@rocicorp/zero". */ -export type CrmActivity = Row; +export type CrmActivity = Row["crmActivity"]; /** * Represents a row from the "crmActivityType" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["crmActivityType"] instead from "@rocicorp/zero". */ -export type CrmActivityType = Row; +export type CrmActivityType = Row["crmActivityType"]; /** * Represents a row from the "crmContact" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["crmContact"] instead from "@rocicorp/zero". */ -export type CrmContact = Row; +export type CrmContact = Row["crmContact"]; /** * Represents a row from the "crmNote" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["crmNote"] instead from "@rocicorp/zero". */ -export type CrmNote = Row; +export type CrmNote = Row["crmNote"]; /** * Represents a row from the "crmOpportunity" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["crmOpportunity"] instead from "@rocicorp/zero". */ -export type CrmOpportunity = Row; +export type CrmOpportunity = Row["crmOpportunity"]; /** * Represents a row from the "crmOpportunityStageHistory" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["crmOpportunityStageHistory"] instead from "@rocicorp/zero". */ -export type CrmOpportunityStageHistory = Row< - typeof crmOpportunityStageHistoryTable ->; +export type CrmOpportunityStageHistory = Row["crmOpportunityStageHistory"]; /** * Represents a row from the "crmPipelineStage" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["crmPipelineStage"] instead from "@rocicorp/zero". */ -export type CrmPipelineStage = Row; +export type CrmPipelineStage = Row["crmPipelineStage"]; /** * Represents a row from the "department" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["department"] instead from "@rocicorp/zero". */ -export type Department = Row; +export type Department = Row["department"]; /** * Represents a row from the "documentFile" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["documentFile"] instead from "@rocicorp/zero". */ -export type DocumentFile = Row; +export type DocumentFile = Row["documentFile"]; /** * Represents a row from the "documentFileVersion" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["documentFileVersion"] instead from "@rocicorp/zero". */ -export type DocumentFileVersion = Row; +export type DocumentFileVersion = Row["documentFileVersion"]; /** * Represents a row from the "documentFolder" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["documentFolder"] instead from "@rocicorp/zero". */ -export type DocumentFolder = Row; +export type DocumentFolder = Row["documentFolder"]; /** * Represents a row from the "documentLibrary" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["documentLibrary"] instead from "@rocicorp/zero". */ -export type DocumentLibrary = Row; +export type DocumentLibrary = Row["documentLibrary"]; /** * Represents a row from the "documentSharing" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["documentSharing"] instead from "@rocicorp/zero". */ -export type DocumentSharing = Row; +export type DocumentSharing = Row["documentSharing"]; /** * Represents a row from the "employeeDocument" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["employeeDocument"] instead from "@rocicorp/zero". */ -export type EmployeeDocument = Row; +export type EmployeeDocument = Row["employeeDocument"]; /** * Represents a row from the "employeeProfile" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["employeeProfile"] instead from "@rocicorp/zero". */ -export type EmployeeProfile = Row; +export type EmployeeProfile = Row["employeeProfile"]; /** * Represents a row from the "employmentHistory" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["employmentHistory"] instead from "@rocicorp/zero". */ -export type EmploymentHistory = Row; +export type EmploymentHistory = Row["employmentHistory"]; /** * Represents a row from the "expenseItem" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["expenseItem"] instead from "@rocicorp/zero". */ -export type ExpenseItem = Row; +export type ExpenseItem = Row["expenseItem"]; /** * Represents a row from the "expenseReport" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["expenseReport"] instead from "@rocicorp/zero". */ -export type ExpenseReport = Row; +export type ExpenseReport = Row["expenseReport"]; /** * Represents a row from the "featureFlag" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["featureFlag"] instead from "@rocicorp/zero". */ -export type FeatureFlag = Row; +export type FeatureFlag = Row["featureFlag"]; /** * Represents a row from the "filters" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["filters"] instead from "@rocicorp/zero". */ -export type Filter = Row; +export type Filter = Row["filters"]; /** * Represents a row from the "friendship" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["friendship"] instead from "@rocicorp/zero". */ -export type Friendship = Row; +export type Friendship = Row["friendship"]; /** * Represents a row from the "integrationCredential" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["integrationCredential"] instead from "@rocicorp/zero". */ -export type IntegrationCredential = Row; +export type IntegrationCredential = Row["integrationCredential"]; /** * Represents a row from the "integrationEvent" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["integrationEvent"] instead from "@rocicorp/zero". */ -export type IntegrationEvent = Row; +export type IntegrationEvent = Row["integrationEvent"]; /** * Represents a row from the "integrationWebhook" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["integrationWebhook"] instead from "@rocicorp/zero". */ -export type IntegrationWebhook = Row; +export type IntegrationWebhook = Row["integrationWebhook"]; /** * Represents a row from the "inventoryItem" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["inventoryItem"] instead from "@rocicorp/zero". */ -export type InventoryItem = Row; +export type InventoryItem = Row["inventoryItem"]; /** * Represents a row from the "inventoryLevel" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["inventoryLevel"] instead from "@rocicorp/zero". */ -export type InventoryLevel = Row; +export type InventoryLevel = Row["inventoryLevel"]; /** * Represents a row from the "inventoryLocation" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["inventoryLocation"] instead from "@rocicorp/zero". */ -export type InventoryLocation = Row; +export type InventoryLocation = Row["inventoryLocation"]; /** * Represents a row from the "ledgerAccount" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["ledgerAccount"] instead from "@rocicorp/zero". */ -export type LedgerAccount = Row; +export type LedgerAccount = Row["ledgerAccount"]; /** * Represents a row from the "ledgerEntry" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["ledgerEntry"] instead from "@rocicorp/zero". */ -export type LedgerEntry = Row; +export type LedgerEntry = Row["ledgerEntry"]; /** * Represents a row from the "ledgerTransaction" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["ledgerTransaction"] instead from "@rocicorp/zero". */ -export type LedgerTransaction = Row; +export type LedgerTransaction = Row["ledgerTransaction"]; /** * Represents a row from the "marketingAudience" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["marketingAudience"] instead from "@rocicorp/zero". */ -export type MarketingAudience = Row; +export type MarketingAudience = Row["marketingAudience"]; /** * Represents a row from the "marketingCampaign" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["marketingCampaign"] instead from "@rocicorp/zero". */ -export type MarketingCampaign = Row; +export type MarketingCampaign = Row["marketingCampaign"]; /** * Represents a row from the "marketingCampaignAudience" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["marketingCampaignAudience"] instead from "@rocicorp/zero". */ -export type MarketingCampaignAudience = Row< - typeof marketingCampaignAudienceTable ->; +export type MarketingCampaignAudience = Row["marketingCampaignAudience"]; /** * Represents a row from the "marketingCampaignChannel" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["marketingCampaignChannel"] instead from "@rocicorp/zero". */ -export type MarketingCampaignChannel = Row< - typeof marketingCampaignChannelTable ->; +export type MarketingCampaignChannel = Row["marketingCampaignChannel"]; /** * Represents a row from the "marketingChannel" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["marketingChannel"] instead from "@rocicorp/zero". */ -export type MarketingChannel = Row; +export type MarketingChannel = Row["marketingChannel"]; /** * Represents a row from the "medium" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["medium"] instead from "@rocicorp/zero". */ -export type Medium = Row; +export type Medium = Row["medium"]; /** * Represents a row from the "message" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["message"] instead from "@rocicorp/zero". */ -export type Message = Row; +export type Message = Row["message"]; /** * Represents a row from the "omittedTable" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["omittedTable"] instead from "@rocicorp/zero". */ -export type OmittedTable = Row; +export type OmittedTable = Row["omittedTable"]; /** * Represents a row from the "orderItem" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["orderItem"] instead from "@rocicorp/zero". */ -export type OrderItem = Row; +export type OrderItem = Row["orderItem"]; /** * Represents a row from the "orderPayment" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["orderPayment"] instead from "@rocicorp/zero". */ -export type OrderPayment = Row; +export type OrderPayment = Row["orderPayment"]; /** * Represents a row from the "orderTable" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["orderTable"] instead from "@rocicorp/zero". */ -export type OrderTable = Row; +export type OrderTable = Row["orderTable"]; /** * Represents a row from the "payment" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["payment"] instead from "@rocicorp/zero". */ -export type Payment = Row; +export type Payment = Row["payment"]; /** * Represents a row from the "product" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["product"] instead from "@rocicorp/zero". */ -export type Product = Row; +export type Product = Row["product"]; /** * Represents a row from the "productCategory" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["productCategory"] instead from "@rocicorp/zero". */ -export type ProductCategory = Row; +export type ProductCategory = Row["productCategory"]; /** * Represents a row from the "productMedia" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["productMedia"] instead from "@rocicorp/zero". */ -export type ProductMedia = Row; +export type ProductMedia = Row["productMedia"]; /** * Represents a row from the "productVariant" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["productVariant"] instead from "@rocicorp/zero". */ -export type ProductVariant = Row; +export type ProductVariant = Row["productVariant"]; /** * Represents a row from the "project" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["project"] instead from "@rocicorp/zero". */ -export type Project = Row; +export type Project = Row["project"]; /** * Represents a row from the "projectAssignment" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["projectAssignment"] instead from "@rocicorp/zero". */ -export type ProjectAssignment = Row; +export type ProjectAssignment = Row["projectAssignment"]; /** * Represents a row from the "projectAttachment" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["projectAttachment"] instead from "@rocicorp/zero". */ -export type ProjectAttachment = Row; +export type ProjectAttachment = Row["projectAttachment"]; /** * Represents a row from the "projectAudit" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["projectAudit"] instead from "@rocicorp/zero". */ -export type ProjectAudit = Row; +export type ProjectAudit = Row["projectAudit"]; /** * Represents a row from the "projectComment" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["projectComment"] instead from "@rocicorp/zero". */ -export type ProjectComment = Row; +export type ProjectComment = Row["projectComment"]; /** * Represents a row from the "projectNote" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["projectNote"] instead from "@rocicorp/zero". */ -export type ProjectNote = Row; +export type ProjectNote = Row["projectNote"]; /** * Represents a row from the "projectPhase" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["projectPhase"] instead from "@rocicorp/zero". */ -export type ProjectPhase = Row; +export type ProjectPhase = Row["projectPhase"]; /** * Represents a row from the "projectTag" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["projectTag"] instead from "@rocicorp/zero". */ -export type ProjectTag = Row; +export type ProjectTag = Row["projectTag"]; /** * Represents a row from the "projectTask" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["projectTask"] instead from "@rocicorp/zero". */ -export type ProjectTask = Row; +export type ProjectTask = Row["projectTask"]; /** * Represents a row from the "projectTaskTag" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["projectTaskTag"] instead from "@rocicorp/zero". */ -export type ProjectTaskTag = Row; +export type ProjectTaskTag = Row["projectTaskTag"]; /** * Represents a row from the "shipment" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["shipment"] instead from "@rocicorp/zero". */ -export type Shipment = Row; +export type Shipment = Row["shipment"]; /** * Represents a row from the "shipmentItem" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["shipmentItem"] instead from "@rocicorp/zero". */ -export type ShipmentItem = Row; +export type ShipmentItem = Row["shipmentItem"]; /** * Represents a row from the "supportTicket" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["supportTicket"] instead from "@rocicorp/zero". */ -export type SupportTicket = Row; +export type SupportTicket = Row["supportTicket"]; /** * Represents a row from the "supportTicketAssignment" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["supportTicketAssignment"] instead from "@rocicorp/zero". */ -export type SupportTicketAssignment = Row; +export type SupportTicketAssignment = Row["supportTicketAssignment"]; /** * Represents a row from the "supportTicketAudit" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["supportTicketAudit"] instead from "@rocicorp/zero". */ -export type SupportTicketAudit = Row; +export type SupportTicketAudit = Row["supportTicketAudit"]; /** * Represents a row from the "supportTicketMessage" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["supportTicketMessage"] instead from "@rocicorp/zero". */ -export type SupportTicketMessage = Row; +export type SupportTicketMessage = Row["supportTicketMessage"]; /** * Represents a row from the "supportTicketTag" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["supportTicketTag"] instead from "@rocicorp/zero". */ -export type SupportTicketTag = Row; +export type SupportTicketTag = Row["supportTicketTag"]; /** * Represents a row from the "supportTicketTagLink" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["supportTicketTagLink"] instead from "@rocicorp/zero". */ -export type SupportTicketTagLink = Row; +export type SupportTicketTagLink = Row["supportTicketTagLink"]; /** * Represents a row from the "team" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["team"] instead from "@rocicorp/zero". */ -export type Team = Row; +export type Team = Row["team"]; /** * Represents a row from the "telemetryRollup" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["telemetryRollup"] instead from "@rocicorp/zero". */ -export type TelemetryRollup = Row; +export type TelemetryRollup = Row["telemetryRollup"]; /** * Represents a row from the "testBigSerialPk" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["testBigSerialPk"] instead from "@rocicorp/zero". */ -export type TestBigSerialPk = Row; +export type TestBigSerialPk = Row["testBigSerialPk"]; /** * Represents a row from the "testCompositePkBothDefaults" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["testCompositePkBothDefaults"] instead from "@rocicorp/zero". */ -export type TestCompositePkBothDefault = Row< - typeof testCompositePkBothDefaultsTable ->; +export type TestCompositePkBothDefault = Row["testCompositePkBothDefaults"]; /** * Represents a row from the "testCompositePkOneDefault" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["testCompositePkOneDefault"] instead from "@rocicorp/zero". */ -export type TestCompositePkOneDefault = Row< - typeof testCompositePkOneDefaultTable ->; +export type TestCompositePkOneDefault = Row["testCompositePkOneDefault"]; /** * Represents a row from the "testIntegerDefaultPk" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["testIntegerDefaultPk"] instead from "@rocicorp/zero". */ -export type TestIntegerDefaultPk = Row; +export type TestIntegerDefaultPk = Row["testIntegerDefaultPk"]; /** * Represents a row from the "testSerialPk" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["testSerialPk"] instead from "@rocicorp/zero". */ -export type TestSerialPk = Row; +export type TestSerialPk = Row["testSerialPk"]; /** * Represents a row from the "testTextDefaultPk" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["testTextDefaultPk"] instead from "@rocicorp/zero". */ -export type TestTextDefaultPk = Row; +export type TestTextDefaultPk = Row["testTextDefaultPk"]; /** * Represents a row from the "testTimestampDefaultPk" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["testTimestampDefaultPk"] instead from "@rocicorp/zero". */ -export type TestTimestampDefaultPk = Row; +export type TestTimestampDefaultPk = Row["testTimestampDefaultPk"]; /** * Represents a row from the "testUuidPk" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["testUuidPk"] instead from "@rocicorp/zero". */ -export type TestUuidPk = Row; +export type TestUuidPk = Row["testUuidPk"]; /** * Represents a row from the "testUuidSqlDefaultPk" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["testUuidSqlDefaultPk"] instead from "@rocicorp/zero". */ -export type TestUuidSqlDefaultPk = Row; +export type TestUuidSqlDefaultPk = Row["testUuidSqlDefaultPk"]; /** * Represents a row from the "timeEntry" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["timeEntry"] instead from "@rocicorp/zero". */ -export type TimeEntry = Row; +export type TimeEntry = Row["timeEntry"]; /** * Represents a row from the "timesheet" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["timesheet"] instead from "@rocicorp/zero". */ -export type Timesheet = Row; +export type Timesheet = Row["timesheet"]; /** * Represents a row from the "user" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["user"] instead from "@rocicorp/zero". */ -export type User = Row; +export type User = Row["user"]; /** * Represents a row from the "webhookSubscription" table. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use Row["webhookSubscription"] instead from "@rocicorp/zero". */ -export type WebhookSubscription = Row; +export type WebhookSubscription = Row["webhookSubscription"]; +/** + * Represents the ZQL query builder. + * This type is auto-generated from your Drizzle schema definition. + */ +export const zql = createBuilder(schema); /** * Represents the Zero schema query builder. * This type is auto-generated from your Drizzle schema definition. + * + * @deprecated Use `zql` instead. */ -export const builder = createBuilder(schema); +export const builder = zql; + +/** Defines the default types for Zero */ +declare module "@rocicorp/zero" { + interface DefaultTypes { + schema: Schema; + } +} diff --git a/package.json b/package.json index eab0628c..a6149cbc 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "drizzle-zero", - "version": "0.16.2", + "version": "0.17.0-beta.1", "description": "Generate Zero schemas from Drizzle ORM schemas", "type": "module", "scripts": { @@ -23,16 +23,6 @@ "import": "./dist/index.js", "require": "./dist/index.cjs" }, - "./node-postgres": { - "types": "./dist/node-postgres/index.d.ts", - "import": "./dist/node-postgres/index.js", - "require": "./dist/node-postgres/index.cjs" - }, - "./postgres-js": { - "types": "./dist/postgres-js/index.d.ts", - "import": "./dist/postgres-js/index.js", - "require": "./dist/postgres-js/index.cjs" - }, "./package.json": "./package.json" }, "files": [ @@ -65,7 +55,7 @@ "url": "https://github.com/0xcadams/drizzle-zero/issues" }, "peerDependencies": { - "@rocicorp/zero": ">=0.22.2025081301", + "@rocicorp/zero": "", "@types/pg": "", "drizzle-orm": ">=0.36.0", "pg": "", @@ -94,7 +84,7 @@ "ts-morph": "^27.0.2" }, "devDependencies": { - "@rocicorp/zero": "0.24.3000000000", + "@rocicorp/zero": "0.25.0-canary.12", "@ts-morph/common": "^0.28.1", "@types/node": "^24.10.1", "@types/pg": "^8.15.6", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 8e733f27..67ef7b00 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -31,8 +31,8 @@ importers: version: 27.0.2 devDependencies: '@rocicorp/zero': - specifier: 0.24.3000000000 - version: 0.24.3000000000(@opentelemetry/core@2.2.0(@opentelemetry/api@1.9.0)) + specifier: 0.25.0-canary.12 + version: 0.25.0-canary.12(@opentelemetry/core@2.2.0(@opentelemetry/api@1.9.0)) '@ts-morph/common': specifier: ^0.28.1 version: 0.28.1 @@ -735,10 +735,6 @@ packages: resolution: {integrity: sha512-1TUx3KdaU3cN7nfCdNf+UVqA/PSX29Cjcox3fZZBtINlRrXVTmUkQnCKv2MbBUbCopbK4olAT1IHl76uZyCiVA==} engines: {node: '>=14.0.0'} - '@grpc/grpc-js@1.14.0': - resolution: {integrity: sha512-N8Jx6PaYzcTRNzirReJCtADVoq4z7+1KQ4E70jTg/koQiMoUSN1kbNjPOqpPbhMFhfU1/l7ixspPl8dNY+FoUg==} - engines: {node: '>=12.10.0'} - '@grpc/grpc-js@1.14.1': resolution: {integrity: sha512-sPxgEWtPUR3EnRJCEtbGZG2iX8LQDUls2wUS3o27jg07KqJFMq6YDeWvMo1wfpmy3rqRdS0rivpLwhqQtEyCuQ==} engines: {node: '>=12.10.0'} @@ -1344,8 +1340,8 @@ packages: engines: {bun: '>=1.1.0', node: 20.x || 22.x || 23.x || 24.x} hasBin: true - '@rocicorp/zero@0.24.3000000000': - resolution: {integrity: sha512-rKIoRXnrNj08NLM8I8e5+d0Jl7dNhuolzg2yx8NOVJQERzFBwjApaiTDj1151x+cnt88pnbCf6PsSAEmbcHnBw==} + '@rocicorp/zero@0.25.0-canary.12': + resolution: {integrity: sha512-0UrZd6crZ7YyVSAE5M57uaTCJL2SAdZID4ZQXLMyIkzhFd8s/B6km4ac4SaDvnTVX6CxBfR7PH3csIdkxJx/6w==} engines: {node: '>=22'} hasBin: true peerDependencies: @@ -3921,11 +3917,6 @@ snapshots: '@google-cloud/precise-date@4.0.0': {} - '@grpc/grpc-js@1.14.0': - dependencies: - '@grpc/proto-loader': 0.8.0 - '@js-sdsl/ordered-map': 4.4.2 - '@grpc/grpc-js@1.14.1': dependencies: '@grpc/proto-loader': 0.8.0 @@ -4070,7 +4061,7 @@ snapshots: '@opentelemetry/exporter-logs-otlp-grpc@0.203.0(@opentelemetry/api@1.9.0)': dependencies: - '@grpc/grpc-js': 1.14.0 + '@grpc/grpc-js': 1.14.1 '@opentelemetry/api': 1.9.0 '@opentelemetry/core': 2.0.1(@opentelemetry/api@1.9.0) '@opentelemetry/otlp-exporter-base': 0.203.0(@opentelemetry/api@1.9.0) @@ -4100,7 +4091,7 @@ snapshots: '@opentelemetry/exporter-metrics-otlp-grpc@0.203.0(@opentelemetry/api@1.9.0)': dependencies: - '@grpc/grpc-js': 1.14.0 + '@grpc/grpc-js': 1.14.1 '@opentelemetry/api': 1.9.0 '@opentelemetry/core': 2.0.1(@opentelemetry/api@1.9.0) '@opentelemetry/exporter-metrics-otlp-http': 0.203.0(@opentelemetry/api@1.9.0) @@ -4138,7 +4129,7 @@ snapshots: '@opentelemetry/exporter-trace-otlp-grpc@0.203.0(@opentelemetry/api@1.9.0)': dependencies: - '@grpc/grpc-js': 1.14.0 + '@grpc/grpc-js': 1.14.1 '@opentelemetry/api': 1.9.0 '@opentelemetry/core': 2.0.1(@opentelemetry/api@1.9.0) '@opentelemetry/otlp-exporter-base': 0.203.0(@opentelemetry/api@1.9.0) @@ -4530,7 +4521,7 @@ snapshots: '@opentelemetry/otlp-grpc-exporter-base@0.203.0(@opentelemetry/api@1.9.0)': dependencies: - '@grpc/grpc-js': 1.14.0 + '@grpc/grpc-js': 1.14.1 '@opentelemetry/api': 1.9.0 '@opentelemetry/core': 2.0.1(@opentelemetry/api@1.9.0) '@opentelemetry/otlp-exporter-base': 0.203.0(@opentelemetry/api@1.9.0) @@ -4735,7 +4726,7 @@ snapshots: bindings: 1.5.0 prebuild-install: 7.1.3 - '@rocicorp/zero@0.24.3000000000(@opentelemetry/core@2.2.0(@opentelemetry/api@1.9.0))': + '@rocicorp/zero@0.25.0-canary.12(@opentelemetry/core@2.2.0(@opentelemetry/api@1.9.0))': dependencies: '@badrap/valita': 0.3.11 '@databases/escape-identifier': 1.0.3 @@ -4758,6 +4749,7 @@ snapshots: '@rocicorp/logger': 5.4.0 '@rocicorp/resolver': 1.0.2 '@rocicorp/zero-sqlite3': 1.0.12 + '@standard-schema/spec': 1.0.0 '@types/basic-auth': 1.1.8 basic-auth: 2.0.1 chalk: 5.6.2 diff --git a/src/cli/index.ts b/src/cli/index.ts index 028107a0..c95d7c51 100644 --- a/src/cli/index.ts +++ b/src/cli/index.ts @@ -55,8 +55,9 @@ export interface GeneratorOptions { jsFileExtension?: boolean; skipTypes?: boolean; skipBuilder?: boolean; - disableLegacyMutators?: boolean; - disableLegacyQueries?: boolean; + skipDeclare?: boolean; + enableLegacyMutators?: boolean; + enableLegacyQueries?: boolean; } async function main(opts: GeneratorOptions = {}) { @@ -71,8 +72,9 @@ async function main(opts: GeneratorOptions = {}) { jsFileExtension, skipTypes, skipBuilder, - disableLegacyMutators, - disableLegacyQueries, + skipDeclare, + enableLegacyMutators, + enableLegacyQueries, } = { ...opts }; const resolvedTsConfigPath = tsConfigPath ?? defaultTsConfigFile; @@ -142,8 +144,9 @@ async function main(opts: GeneratorOptions = {}) { jsExtensionOverride: jsFileExtension ? "force" : "auto", skipTypes: Boolean(skipTypes), skipBuilder: Boolean(skipBuilder), - disableLegacyMutators: Boolean(disableLegacyMutators), - disableLegacyQueries: Boolean(disableLegacyQueries), + skipDeclare: Boolean(skipDeclare), + enableLegacyMutators: Boolean(enableLegacyMutators), + enableLegacyQueries: Boolean(enableLegacyQueries), }); if (format) { @@ -187,16 +190,17 @@ async function cli() { "-j, --js-file-extension", `Add a .js file extension to imports in the generated output (auto-detected from tsconfig if not specified)`, ) - .option("--skip-types", "Skip generating table Row<> type exports", false) + .option("--skip-types", "Skip generating table Row[] type exports", false) .option("--skip-builder", "Skip generating the builder export", false) + .option("--skip-declare", "Skip generating the module augmentation for default types in Zero", false) .option( - "--disable-legacy-mutators", - "Disable legacy CRUD mutators (sets enableLegacyMutators to false)", + "--enable-legacy-mutators", + "Enable legacy CRUD mutators (sets enableLegacyMutators to true)", false, ) .option( - "--disable-legacy-queries", - "Disable legacy CRUD queries (sets enableLegacyQueries to false)", + "--enable-legacy-queries", + "Enable legacy CRUD queries (sets enableLegacyQueries to true)", false, ) .action(async (command) => { @@ -213,8 +217,9 @@ async function cli() { jsFileExtension: command.jsFileExtension, skipTypes: command.skipTypes, skipBuilder: command.skipBuilder, - disableLegacyMutators: command.disableLegacyMutators, - disableLegacyQueries: command.disableLegacyQueries, + skipDeclare: command.skipDeclare, + enableLegacyMutators: command.enableLegacyMutators, + enableLegacyQueries: command.enableLegacyQueries, }); if (command.output) { diff --git a/src/cli/shared.ts b/src/cli/shared.ts index 18783efb..56ed2a0f 100755 --- a/src/cli/shared.ts +++ b/src/cli/shared.ts @@ -17,8 +17,9 @@ export async function getGeneratedSchema({ jsExtensionOverride = "auto", skipTypes = false, skipBuilder = false, - disableLegacyMutators = false, - disableLegacyQueries = false, + skipDeclare = false, + enableLegacyMutators = false, + enableLegacyQueries = false, debug, }: { tsProject: Project; @@ -29,8 +30,9 @@ export async function getGeneratedSchema({ jsExtensionOverride?: "auto" | "force" | "none"; skipTypes?: boolean; skipBuilder?: boolean; - disableLegacyMutators?: boolean; - disableLegacyQueries?: boolean; + skipDeclare?: boolean; + enableLegacyMutators?: boolean; + enableLegacyQueries?: boolean; debug?: boolean; }) { // Auto-detect if .js extensions are needed based on tsconfig @@ -360,9 +362,9 @@ export async function getGeneratedSchema({ ); } } else if (key === "enableLegacyMutators") { - writer.write(disableLegacyMutators ? "false" : "true"); + writer.write(enableLegacyMutators ? "true" : "false"); } else if (key === "enableLegacyQueries") { - writer.write(disableLegacyQueries ? "false" : "true"); + writer.write(enableLegacyQueries ? "true" : "false"); } else { writeValue(writer, propValue, { keys: [...keys, key], @@ -511,19 +513,15 @@ export async function getGeneratedSchema({ const typeName = camelCase(pluralize.singular(tableName), { pascalCase: true, }); - const tableConstName = tableConstNames.get(tableName); - const rowTarget = tableConstName - ? `typeof ${tableConstName}` - : `${typename}["tables"]["${tableName}"]`; const tableTypeAlias = zeroSchemaGenerated.addTypeAlias({ name: typeName, isExported: true, - type: `Row<${rowTarget}>`, + type: `Row["${tableName}"]`, }); tableTypeAlias.addJsDoc({ - description: `\nRepresents a row from the "${tableName}" table.\nThis type is auto-generated from your Drizzle schema definition.`, + description: `\nRepresents a row from the "${tableName}" table.\nThis type is auto-generated from your Drizzle schema definition.\n\n@deprecated Use Row["${tableName}"] instead from "@rocicorp/zero".`, }); } } @@ -535,20 +533,48 @@ export async function getGeneratedSchema({ namedImports: [{ name: "createBuilder" }], }); + const zqlVariable = zeroSchemaGenerated.addVariableStatement({ + declarationKind: VariableDeclarationKind.Const, + isExported: true, + declarations: [ + { + name: "zql", + initializer: `createBuilder(${schemaObjectName})`, + }, + ], + }); + + zqlVariable.addJsDoc({ + description: + "\nRepresents the ZQL query builder.\nThis type is auto-generated from your Drizzle schema definition.", + }); + const builderVariable = zeroSchemaGenerated.addVariableStatement({ declarationKind: VariableDeclarationKind.Const, isExported: true, declarations: [ { name: "builder", - initializer: `createBuilder(${schemaObjectName})`, + initializer: "zql", }, ], }); builderVariable.addJsDoc({ description: - "\nRepresents the Zero schema query builder.\nThis type is auto-generated from your Drizzle schema definition.", + "\nRepresents the Zero schema query builder.\nThis type is auto-generated from your Drizzle schema definition.\n\n@deprecated Use `zql` instead.", + }); + } + + // Add module augmentation for default types + if (!skipDeclare) { + zeroSchemaGenerated.addStatements((writer) => { + writer.write(`\n/** Defines the default types for Zero */\n`); + writer.write(`declare module '@rocicorp/zero' {`); + writer.write(` interface DefaultTypes {`); + writer.write(` schema: ${typename};`); + writer.write(` }`); + writer.write(`}`); }); } diff --git a/src/node-postgres/index.ts b/src/node-postgres/index.ts deleted file mode 100644 index 26124c77..00000000 --- a/src/node-postgres/index.ts +++ /dev/null @@ -1,87 +0,0 @@ -import type { - NodePgClient, - NodePgDatabase, - NodePgQueryResultHKT, -} from "drizzle-orm/node-postgres"; -import type { PgTransaction } from "drizzle-orm/pg-core"; -import type { ExtractTablesWithRelations } from "drizzle-orm/relations"; - -/** - * @deprecated use `DrizzleTransaction` from `@rocicorp/zero/server/adapters/drizzle` instead. - * @see https://zero.rocicorp.dev/docs/zql-on-the-server#drizzle - */ -export type NodePgZeroTransaction< - TDbOrSchema extends - | (NodePgDatabase> & { $client: NodePgClient }) - | Record, - TSchema extends Record = TDbOrSchema extends NodePgDatabase< - infer TSchema - > - ? TSchema - : TDbOrSchema, -> = PgTransaction< - NodePgQueryResultHKT, - TSchema, - ExtractTablesWithRelations ->; - -/** - * @deprecated use `zeroDrizzle` from `@rocicorp/zero/server/adapters/drizzle` instead. - * @see https://zero.rocicorp.dev/docs/zql-on-the-server#drizzle - */ -export class NodePgConnection< - TDrizzle extends NodePgDatabase> & { - $client: NodePgClient; - }, - TSchema extends TDrizzle extends NodePgDatabase - ? TSchema - : never, - TTransaction extends NodePgZeroTransaction, -> { - readonly #drizzle: TDrizzle; - - constructor(drizzle: TDrizzle) { - this.#drizzle = drizzle; - } - - query(sql: string, params: unknown[]): Promise[]> { - return this.#drizzle.$client.query(sql, params).then(({ rows }) => rows); - } - - transaction(fn: (tx: any) => Promise): Promise { - return this.#drizzle.transaction((drizzleTx) => - fn( - new ZeroNodePgTransaction( - drizzleTx as TTransaction, - ), - ), - ); - } -} - -class ZeroNodePgTransaction< - TDrizzle extends NodePgDatabase> & { - $client: NodePgClient; - }, - TSchema extends TDrizzle extends NodePgDatabase - ? TSchema - : never, - TTransaction extends PgTransaction< - NodePgQueryResultHKT, - TSchema, - ExtractTablesWithRelations - >, -> { - readonly wrappedTransaction: TTransaction; - - constructor(drizzleTx: TTransaction) { - this.wrappedTransaction = drizzleTx; - } - - query(sql: string, params: unknown[]): Promise[]> { - const session = this.wrappedTransaction._.session as unknown as { - client: TDrizzle["$client"]; - }; - return session.client.query(sql, params).then(({ rows }) => rows); - } -} diff --git a/src/postgres-js/index.ts b/src/postgres-js/index.ts deleted file mode 100644 index a3a5e538..00000000 --- a/src/postgres-js/index.ts +++ /dev/null @@ -1,96 +0,0 @@ -import type { PgTransaction } from "drizzle-orm/pg-core"; -import type { - PostgresJsDatabase, - PostgresJsQueryResultHKT, -} from "drizzle-orm/postgres-js"; -import type { ExtractTablesWithRelations } from "drizzle-orm/relations"; -import type postgres from "postgres"; - -/** - * @deprecated use `DrizzleTransaction` from `@rocicorp/zero/server/adapters/drizzle` instead. - * @see https://zero.rocicorp.dev/docs/zql-on-the-server#drizzle - */ -export type PostgresJsZeroTransaction< - TDbOrSchema extends - | (PostgresJsDatabase> & { - $client: postgres.Sql<{}>; - }) - | Record, - TSchema extends Record< - string, - unknown - > = TDbOrSchema extends PostgresJsDatabase - ? TSchema - : TDbOrSchema, -> = PgTransaction< - PostgresJsQueryResultHKT, - TSchema, - ExtractTablesWithRelations ->; - -/** - * @deprecated use `zeroDrizzle` from `@rocicorp/zero/server/adapters/drizzle` instead. - * @see https://zero.rocicorp.dev/docs/zql-on-the-server#drizzle - */ -export class PostgresJsConnection< - TDrizzle extends PostgresJsDatabase> & { - $client: postgres.Sql<{}>; - }, - TSchema extends TDrizzle extends PostgresJsDatabase - ? TSchema - : never, - TTransaction extends PostgresJsZeroTransaction, -> { - readonly #drizzle: TDrizzle; - - constructor(drizzle: TDrizzle) { - this.#drizzle = drizzle; - } - - query(sql: string, params: unknown[]): Promise[]> { - return this.#drizzle.$client.unsafe( - sql, - params as postgres.ParameterOrJSON[], - ); - } - - transaction(fn: (tx: any) => Promise): Promise { - return this.#drizzle.transaction((drizzleTx) => - fn( - new ZeroPostgresJsTransaction( - drizzleTx as TTransaction, - ), - ), - ); - } -} - -class ZeroPostgresJsTransaction< - TDrizzle extends PostgresJsDatabase> & { - $client: postgres.Sql<{}>; - }, - TSchema extends TDrizzle extends PostgresJsDatabase - ? TSchema - : never, - TTransaction extends PgTransaction< - PostgresJsQueryResultHKT, - TSchema, - ExtractTablesWithRelations - >, -> { - readonly wrappedTransaction: TTransaction; - - constructor(drizzleTx: TTransaction) { - this.wrappedTransaction = drizzleTx; - } - - query(sql: string, params: unknown[]): Promise[]> { - const session = this.wrappedTransaction._.session as unknown as { - client: TDrizzle["$client"]; - }; - return session.client.unsafe( - sql, - params as postgres.ParameterOrJSON[], - ); - } -} diff --git a/tests/cli.test.ts b/tests/cli.test.ts index ab537f75..84a1fd13 100644 --- a/tests/cli.test.ts +++ b/tests/cli.test.ts @@ -179,10 +179,19 @@ describe("getGeneratedSchema", () => { export type User = Row; /** - * Represents the Zero schema query builder. + * Represents the ZQL query builder. * This type is auto-generated from your Drizzle schema definition. */ - export const builder = createBuilder(schema); + export const zql = createBuilder(schema); + + /** + * Defines the default types for Zero. + */ + declare module '@rocicorp/zero' { + interface DefaultTypes { + schema: Schema; + } + } " `); }); @@ -1374,7 +1383,7 @@ describe("getGeneratedSchema", () => { ); }); - it("should set enableLegacyMutators to false when disableLegacyMutators is true", async () => { + it("should set enableLegacyMutators to true", async () => { const zeroSchemaTypeDecl = await getZeroSchemaDefsFromConfig({ tsProject, configPath: schemaPath, @@ -1402,15 +1411,15 @@ describe("getGeneratedSchema", () => { zeroSchemaTypeDeclarations: zeroSchemaTypeDecl, }, outputFilePath, - disableLegacyMutators: true, + enableLegacyMutators: true, }); - // Check that enableLegacyMutators is set to false in the generated schema - expect(generatedSchema).toContain('"enableLegacyMutators": false'); - expect(generatedSchema).not.toContain('"enableLegacyMutators": true'); + // Check that enableLegacyMutators is set to true in the generated schema + expect(generatedSchema).toContain('"enableLegacyMutators": true'); + expect(generatedSchema).not.toContain('"enableLegacyMutators": false'); }); - it("should set enableLegacyQueries to false when disableLegacyQueries is true", async () => { + it("should set enableLegacyQueries to true", async () => { const zeroSchemaTypeDecl = await getZeroSchemaDefsFromConfig({ tsProject, configPath: schemaPath, @@ -1438,15 +1447,15 @@ describe("getGeneratedSchema", () => { zeroSchemaTypeDeclarations: zeroSchemaTypeDecl, }, outputFilePath, - disableLegacyQueries: true, + enableLegacyQueries: true, }); // Check that enableLegacyQueries is set to false in the generated schema - expect(generatedSchema).toContain('"enableLegacyQueries": false'); - expect(generatedSchema).not.toContain('"enableLegacyQueries": true'); + expect(generatedSchema).toContain('"enableLegacyQueries": true'); + expect(generatedSchema).not.toContain('"enableLegacyQueries": false'); }); - it("should set both enableLegacyMutators and enableLegacyQueries to false when both disable flags are true", async () => { + it("should set both enableLegacyMutators and enableLegacyQueries to true when both enable flags are true", async () => { const zeroSchemaTypeDecl = await getZeroSchemaDefsFromConfig({ tsProject, configPath: schemaPath, @@ -1475,86 +1484,14 @@ describe("getGeneratedSchema", () => { zeroSchemaTypeDeclarations: zeroSchemaTypeDecl, }, outputFilePath, - disableLegacyMutators: true, - disableLegacyQueries: true, + enableLegacyMutators: true, + enableLegacyQueries: true, }); // Check that both flags are set to false in the generated schema - expect(generatedSchema).toContain('"enableLegacyMutators": false'); - expect(generatedSchema).toContain('"enableLegacyQueries": false'); - expect(generatedSchema).not.toContain('"enableLegacyMutators": true'); - expect(generatedSchema).not.toContain('"enableLegacyQueries": true'); - }); - - it("should keep enableLegacyMutators as true when disableLegacyMutators is false", async () => { - const zeroSchemaTypeDecl = await getZeroSchemaDefsFromConfig({ - tsProject, - configPath: schemaPath, - exportName: "schema", - }); - - const generatedSchema = await getGeneratedSchema({ - tsProject, - result: { - type: "config", - zeroSchema: { - tables: { - users: { - name: "users", - primaryKey: ["id"], - columns: { - id: { type: "number", optional: false, customType: undefined }, - }, - }, - }, - relationships: {}, - enableLegacyMutators: true, - }, - exportName: "schema", - zeroSchemaTypeDeclarations: zeroSchemaTypeDecl, - }, - outputFilePath, - disableLegacyMutators: false, - }); - - // Check that enableLegacyMutators remains true in the generated schema expect(generatedSchema).toContain('"enableLegacyMutators": true'); - expect(generatedSchema).not.toContain('"enableLegacyMutators": false'); - }); - - it("should keep enableLegacyQueries as true when disableLegacyQueries is false", async () => { - const zeroSchemaTypeDecl = await getZeroSchemaDefsFromConfig({ - tsProject, - configPath: schemaPath, - exportName: "schema", - }); - - const generatedSchema = await getGeneratedSchema({ - tsProject, - result: { - type: "config", - zeroSchema: { - tables: { - users: { - name: "users", - primaryKey: ["id"], - columns: { - id: { type: "number", optional: false, customType: undefined }, - }, - }, - }, - relationships: {}, - enableLegacyQueries: true, - }, - exportName: "schema", - zeroSchemaTypeDeclarations: zeroSchemaTypeDecl, - }, - outputFilePath, - disableLegacyQueries: false, - }); - - // Check that enableLegacyQueries remains true in the generated schema expect(generatedSchema).toContain('"enableLegacyQueries": true'); + expect(generatedSchema).not.toContain('"enableLegacyMutators": false'); expect(generatedSchema).not.toContain('"enableLegacyQueries": false'); }); }); @@ -1573,9 +1510,8 @@ describe("drizzle-kit functions", () => { describe("getDrizzleSchemaSourceFile", () => { it("should return source file when it exists", async () => { // Import the function to test - const { getDrizzleSchemaSourceFile } = await import( - "../src/cli/drizzle-kit" - ); + const { getDrizzleSchemaSourceFile } = + await import("../src/cli/drizzle-kit"); // Call the function with valid path const sourceFile = await getDrizzleSchemaSourceFile({ @@ -1590,9 +1526,8 @@ describe("drizzle-kit functions", () => { it("should throw error when source file does not exist", async () => { // Import the function to test - const { getDrizzleSchemaSourceFile } = await import( - "../src/cli/drizzle-kit" - ); + const { getDrizzleSchemaSourceFile } = + await import("../src/cli/drizzle-kit"); // Call with invalid path and expect error await expect( @@ -1607,9 +1542,8 @@ describe("drizzle-kit functions", () => { describe("getFullDrizzleSchemaFilePath", () => { it("should return the provided schema path when it exists", async () => { // Import the function to test - const { getFullDrizzleSchemaFilePath } = await import( - "../src/cli/drizzle-kit" - ); + const { getFullDrizzleSchemaFilePath } = + await import("../src/cli/drizzle-kit"); // Create a temporary test file const tempFilePath = path.resolve(process.cwd(), "temp-schema.ts"); @@ -1636,9 +1570,8 @@ describe("drizzle-kit functions", () => { vi.resetModules(); // Import the function to test - const { getFullDrizzleSchemaFilePath } = await import( - "../src/cli/drizzle-kit" - ); + const { getFullDrizzleSchemaFilePath } = + await import("../src/cli/drizzle-kit"); // Mock process.exit to throw instead of exiting const mockExit = vi.spyOn(process, "exit").mockImplementation((() => { diff --git a/tests/pg.test.ts b/tests/pg.test.ts deleted file mode 100644 index 3290dbc2..00000000 --- a/tests/pg.test.ts +++ /dev/null @@ -1,225 +0,0 @@ -import { eq, sql } from "drizzle-orm"; -import { drizzle as drizzleNodePg } from "drizzle-orm/node-postgres"; -import { pgTable, text } from "drizzle-orm/pg-core"; -import { drizzle as drizzlePostgresJs } from "drizzle-orm/postgres-js"; -import { afterAll, beforeAll, describe, expectTypeOf, test } from "vitest"; -import { - pool, - postgresJsClient, - shutdown, - startPostgres, -} from "../db/test-utils"; -import { - NodePgConnection, - type NodePgZeroTransaction, -} from "../src/node-postgres"; -import { - PostgresJsConnection, - type PostgresJsZeroTransaction, -} from "../src/postgres-js"; - -const countryTable = pgTable("country", { - id: text("id").primaryKey(), - name: text("name"), -}); - -const drizzleSchema = { - country: countryTable, -}; - -const getRandomCountry = () => { - const id = Math.random().toString(36).substring(2, 15); - - const newCountry = { - id, - name: `Country ${id}`, - }; - - return newCountry; -}; - -describe("node-postgres", () => { - let db = drizzleNodePg(pool, { schema: drizzleSchema }); - - beforeAll(async () => { - await startPostgres(); - - await db.execute(sql` - CREATE TABLE IF NOT EXISTS "country" ( - id TEXT PRIMARY KEY, - name TEXT - ) - `); - }, 60000); - - afterAll(async () => { - await shutdown(); - }); - - test("types - implicit schema generic", async () => { - const s = null as unknown as NodePgZeroTransaction; - - const country = null as unknown as Awaited< - ReturnType - >; - - expectTypeOf(country).toExtend< - { id: string; name: string | null } | undefined - >(); - }); - - test("types - explicit schema generic", async () => { - const s = null as unknown as NodePgZeroTransaction; - - const country = null as unknown as Awaited< - ReturnType - >; - - expectTypeOf(country).toExtend< - { id: string; name: string | null } | undefined - >(); - }); - - test("can query from the database", async ({ expect }) => { - const newCountry = getRandomCountry(); - - await db.insert(drizzleSchema.country).values(newCountry); - - const drizzleConnection = new NodePgConnection(db); - const result = await drizzleConnection.query( - 'SELECT * FROM "country" WHERE id = $1', - [newCountry.id], - ); - expect(result[0]?.name).toBe(newCountry.name); - expect(result[0]?.id).toBe(newCountry.id); - }); - - test("can query from the database in a transaction", async ({ expect }) => { - const newCountry = getRandomCountry(); - - await db.insert(drizzleSchema.country).values(newCountry); - - const drizzleConnection = new NodePgConnection(db); - const result = await drizzleConnection.transaction(async (tx) => { - const result = await tx.query('SELECT * FROM "country" WHERE id = $1', [ - newCountry.id, - ]); - return result; - }); - - for await (const row of result) { - expect(row.name).toBe(newCountry.name); - expect(row.id).toBe(newCountry.id); - } - }); - - test("can use the underlying wrappedTransaction", async ({ expect }) => { - const newCountry = getRandomCountry(); - - await db.insert(drizzleSchema.country).values(newCountry); - - const drizzleConnection = new NodePgConnection(db); - const result = await drizzleConnection.transaction(async (tx) => { - return tx.wrappedTransaction.query.country.findFirst({ - where: eq(drizzleSchema.country.id, newCountry.id), - }); - }); - - expect(result?.name).toBe(newCountry.name); - expect(result?.id).toBe(newCountry.id); - }); -}); - -describe("postgres-js", () => { - let db = drizzlePostgresJs(postgresJsClient, { schema: drizzleSchema }); - - beforeAll(async () => { - await startPostgres(); - - await db.execute(sql` - CREATE TABLE IF NOT EXISTS "country" ( - id TEXT PRIMARY KEY, - name TEXT - ) - `); - }, 60000); - - afterAll(async () => { - await shutdown(); - }); - - test("types - implicit schema generic", async () => { - const s = null as unknown as PostgresJsZeroTransaction; - - const country = null as unknown as Awaited< - ReturnType - >; - - expectTypeOf(country).toExtend< - { id: string; name: string | null } | undefined - >(); - }); - - test("types - explicit schema generic", async () => { - const s = null as unknown as PostgresJsZeroTransaction< - typeof drizzleSchema - >; - - const country = null as unknown as Awaited< - ReturnType - >; - - expectTypeOf(country).toExtend< - { id: string; name: string | null } | undefined - >(); - }); - - test("can query from the database", async ({ expect }) => { - const newCountry = getRandomCountry(); - - await db.insert(drizzleSchema.country).values(newCountry); - - const drizzleConnection = new PostgresJsConnection(db); - const result = await drizzleConnection.query( - 'SELECT * FROM "country" WHERE id = $1', - [newCountry.id], - ); - expect(result[0]?.name).toBe(newCountry.name); - expect(result[0]?.id).toBe(newCountry.id); - }); - - test("can query from the database in a transaction", async ({ expect }) => { - const newCountry = getRandomCountry(); - - await db.insert(drizzleSchema.country).values(newCountry); - - const drizzleConnection = new PostgresJsConnection(db); - const result = await drizzleConnection.transaction(async (tx) => { - const result = await tx.query('SELECT * FROM "country" WHERE id = $1', [ - newCountry.id, - ]); - return result; - }); - - for await (const row of result) { - expect(row.name).toBe(newCountry.name); - expect(row.id).toBe(newCountry.id); - } - }); - - test("can use the underlying wrappedTransaction", async ({ expect }) => { - const newCountry = getRandomCountry(); - - await db.insert(drizzleSchema.country).values(newCountry); - - const drizzleConnection = new PostgresJsConnection(db); - const result = await drizzleConnection.transaction(async (tx) => { - return tx.wrappedTransaction.query.country.findFirst({ - where: eq(drizzleSchema.country.id, newCountry.id), - }); - }); - - expect(result?.name).toBe(newCountry.name); - expect(result?.id).toBe(newCountry.id); - }); -}); diff --git a/tests/ts-project.test.ts b/tests/ts-project.test.ts index d176e920..e2dddf01 100644 --- a/tests/ts-project.test.ts +++ b/tests/ts-project.test.ts @@ -12,6 +12,7 @@ describe("ensureSourceFileInProject", () => { beforeEach(() => { tsProject = new Project({ tsConfigFilePath: path.resolve(__dirname, "../tsconfig.json"), + skipAddingFilesFromTsConfig: true, }); });