fireodm
Version:
A basic and extensible ODM for the Firestore Admin SDK in Node.js with decorators, relationships, and validation.
99 lines • 4.15 kB
TypeScript
import "reflect-metadata";
import { ZodTypeAny } from "zod";
import { BaseModel } from "./base-model";
import { BaseModelConstructor } from "./types";
export declare const SUBCOL_DOC_KEY: unique symbol;
export declare const COLLECTION_KEY: unique symbol;
export declare const RELATION_KEY: unique symbol;
export declare const TIMESTAMP_KEY: unique symbol;
export declare const BOOLEAN_KEY: unique symbol;
export declare const SUBCOL_KEY: unique symbol;
export declare const SUBMODEL_KEY: unique symbol;
/**
* Class decorator to define the Firestore collection name for a model.
* @param name The name of the Firestore collection.
* @example
* ```typescript
* @Collection('users')
* class User extends BaseModel {
* // ...
* }
* ```
*/
export declare function Collection(name: string): <T extends {
new (...args: any[]): {};
}>(constructor: T) => void;
/**
* Decorator to link a property to a specific document within a subcollection.
* @param modelGetter A function returning the constructor of the model for the document.
* @param docId The fixed ID of the document within the subcollection.
* @param options Options object, must include the subcollection name.
*/
export declare function SubCollectionDoc<T extends typeof BaseModel>(modelGetter: () => BaseModelConstructor<T>, docId: string, options: {
subcollection: string;
}): (target: any, propertyName: string) => void;
export declare function SubCollectionModel(parentGetter: () => BaseModelConstructor<any>, subPath: string): ClassDecorator;
export declare function SubCollection<T extends typeof BaseModel>(modelGetter: () => BaseModelConstructor<T>, name?: string): (target: any, propertyName: string) => void;
/**
* Property decorator to define a relationship stored as a DocumentReference.
* @param relatedModelGetter A function returning the constructor of the related model (e.g., `() => User`). Essential for handling circular dependencies.
* @example
* ```typescript
* import { Department } from './Department'; // Assuming Department model exists
*
* @Collection('employees')
* class Employee extends BaseModel {
* name: string;
*
* @Relation(() => Department)
* department?: DocumentReference | Department | null; // Can hold Ref, populated instance, or be null
* }
* ```
*/
export declare function Relation<T extends typeof BaseModel>(relatedModelGetter: () => BaseModelConstructor<T>, options?: {
lazy?: boolean;
}): (target: any, propertyName: string) => void;
export declare function StringField(opts?: {
min?: number;
max?: number;
message?: string;
required?: boolean;
}): (target: any, propertyKey: string) => void;
export declare function EmailField(message?: string, opts?: {
required?: boolean;
}): (target: any, propertyKey: string) => void;
export declare function NumberField(opts?: {
min?: number;
max?: number;
message?: string;
required?: boolean;
}): (target: any, propertyKey: string) => void;
export declare function BooleanField(opts?: {
required?: boolean;
defaultValue?: boolean;
}): (target: any, propertyName: string) => void;
export declare function TimestampField(opts?: {
required?: boolean;
autoFill?: boolean;
}): (target: any, propertyName: string) => void;
export declare function GeoPointField(opts?: {
required?: boolean;
}): (target: any, propertyKey: string) => void;
export declare function ArrayField(schemaDef: ZodTypeAny, opts?: {
required?: boolean;
}): (target: any, propertyKey: string) => void;
export declare function MapField(schemaDef: ZodTypeAny, opts?: {
required?: boolean;
}): (target: any, propertyKey: string) => void;
/**
* Decorator for Firestore DocumentReference fields.
* Combines validation with loading logic: apply alongside @Relation for relations.
*/
export declare function DocumentReferenceField(opts?: {
required?: boolean;
}): (target: any, propertyKey: string) => void;
export declare function EnumField<T extends Record<string, any>>(enumObj: T, opts?: {
required?: boolean;
defaultValue?: T[keyof T];
}): (target: any, propertyKey: string) => void;
//# sourceMappingURL=decorators.d.ts.map