Types Package

Shared TypeScript types across the monorepo

Overview

@zooly/types is a shared TypeScript types package used across the entire monorepo. It provides common type definitions, schemas, and interfaces that are used by multiple packages and apps.

Package Details

  • Package Name: @zooly/types
  • Location: packages/types
  • Type: Shared types library

Key Features

  • Shared type definitions across the monorepo
  • Type-safe schemas using Zod
  • Common interfaces for entities like Account, User, StripePayment

Type Definitions

The package includes type definitions for:

  • Account: Account/tenant type definitions
  • User: User type definitions
  • Payment System Types:
    • StripePayment: Payment transaction records
    • PayOut: Payout records
    • PaymentShareTracking: Revenue distribution tracking
    • AccountAgent: Agent relationships
    • AccountPayoutRoute: Payout route configuration
    • PpuCode: PPU (Purchase Proof URL) code records

Dependencies

  • Zod for schema validation
  • Next Auth types

Usage

This package is imported by other packages and apps to ensure type consistency across the monorepo. It helps maintain type safety and reduces duplication of type definitions.

Type Compatibility Checking

To ensure database schemas remain compatible with their corresponding type definitions, each schema in the db package includes a _typeCheck declaration. This pattern verifies at compile time that the inferred schema type matches the expected type from @zooly/types.

If a schema doesn't match its type definition, the build will fail with a compile-time error, preventing type mismatches from reaching production.

Example

import { pgTable, text, timestamp } from "drizzle-orm/pg-core";
import type { Account } from "@zooly/types";

/**
 * Account table schema
 */
export const accountTable = pgTable("account", {
  id: text("id").primaryKey(),
  ownerUserId: text("owner_user_id").notNull().unique(),
  displayName: text("display_name").notNull(),
  // ... other fields
});

// Type compatibility check (will error at build time if incompatible)
const _typeCheck: Account = {} as typeof accountTable.$inferSelect;

This pattern ensures that any changes to the database schema are immediately caught if they don't align with the corresponding type definition, maintaining type safety across the entire codebase.