Skip to main content

🔧 API Reference

Firetype generates fully typed APIs that mirror your Firestore database structure. Here’s a comprehensive reference of the generated functions and types.

Generated Functions

createFireTypeAdmin(firestoreInstance)

Creates a type-safe Firestore API for server-side operations using the Firebase Admin SDK. Parameters:
  • firestoreInstance: Firebase Admin Firestore instance
Returns: Type-safe API object matching your schema structure

createFireTypeClient(firestoreInstance)

Creates a type-safe Firestore API for client-side operations using the Firebase Web SDK. Parameters:
  • firestoreInstance: Firebase Client Firestore instance
Returns: Type-safe API object matching your schema structure

API Structure

The generated API mirrors your directory structure. For this schema structure:
You get this typed API:

Collection API Methods

getCollectionRef(validate?: boolean)

Returns a typed Firestore collection reference. Parameters:
  • validate (boolean, optional): Enable runtime validation (default: false)
Returns:
  • Admin: AdminCollectionReference<T>
  • Client: ClientCollectionReference<T>
Example:

getDocumentRef(documentId, validate?: boolean)

Returns a typed Firestore document reference. Parameters:
  • documentId (string): The document ID
  • validate (boolean, optional): Enable runtime validation (default: false)
Returns:
  • Admin: AdminDocumentReference<T>
  • Client: ClientDocumentReference<T>
Example:

getCollectionGroupRef(validate?: boolean)

Returns a typed collection group reference for querying across all subcollections. Parameters:
  • validate (boolean, optional): Enable runtime validation (default: false)
Returns:
  • Admin: AdminCollectionGroup<T>
  • Client: ClientQuery<T>
Example:

Subcollection API Methods

For subcollections, the API methods require parent document IDs:

getCollectionRef(args, validate?: boolean)

Parameters:
  • args: Object containing parent document IDs (e.g., { usersId: "user123" })
  • validate (boolean, optional): Enable runtime validation (default: false)
Example:

getDocumentRef(args, documentId, validate?: boolean)

Parameters:
  • args: Object containing parent document IDs
  • documentId (string): The document ID
  • validate (boolean, optional): Enable runtime validation (default: false)
Example:

Validation

Firetype supports optional runtime validation using your Zod schemas:

Type Safety

All generated APIs are fully type-safe:

Error Handling

Firetype throws descriptive errors for common issues:
  • Validation errors: Zod validation errors when validation is enabled
  • Schema errors: Issues with your schema definitions
  • Firestore errors: Standard Firestore SDK errors are passed through

Generated Types

Schema Types

For each schema file, Firetype generates:
  • Document type: The TypeScript type for your document data
  • Create type: Type for creating new documents (with optional fields)
  • Update type: Type for updating existing documents

Reference Types

  • firestoreRef(path?): Creates document reference schemas. When a path is provided, it will be replaced during generation with a strongly-typed reference schema. When omitted, it behaves as a permissive Zod schema at authoring time and supports composition like z.array(firestoreRef()).
  • collectionPath(path): Generic helper that preserves literal types and brands collection paths.

SDK-Specific Types

Admin SDK:
  • AdminCollectionReference<T>
  • AdminDocumentReference<T>
  • AdminCollectionGroup<T>
Client SDK:
  • ClientCollectionReference<T>
  • ClientDocumentReference<T>
  • ClientQuery<T>

Helper Functions

firestoreRef(collectionPath?)

Creates a strongly-typed Firestore document reference field.

collectionPath(path)

Creates a branded collection path for better type safety.

Best Practices

Validation Strategy

Error Handling Patterns

Type-Safe Queries