import type { TypesaurusUtils as Utils } from "./utils.js"; import type { TypesaurusQuery as Query } from "./query.js"; import type { TypesaurusUpdate as Update } from "./update.js"; import type { TypesaurusFirebase as Firebase } from "./firebase.js"; import type { TypesaurusTransaction as Transaction } from "./transaction.js"; import type { TypesaurusShared as Shared } from "./shared.js"; export declare namespace TypesaurusCore { export interface Function { (getSchema: ($: SchemaHelpers) => Schema, options?: Opts): DB; } /** * Define custom id passing the collection path string as the generic. */ export type Id> = string & { [idBrand]: Path; }; const idBrand: unique symbol; /** * The custom id constrain. Used to define collection id type. */ export type CustomIdConstrain = Id | string | false; export type ModelType = ModelObjectType | ModelVariableType; export type ModelVariableType = [ModelObjectType] | [ModelObjectType, ModelObjectType] | [ModelObjectType, ModelObjectType, ModelObjectType] | [ModelObjectType, ModelObjectType, ModelObjectType, ModelObjectType] | [ ModelObjectType, ModelObjectType, ModelObjectType, ModelObjectType, ModelObjectType ] | [ ModelObjectType, ModelObjectType, ModelObjectType, ModelObjectType, ModelObjectType, ModelObjectType ] | [ ModelObjectType, ModelObjectType, ModelObjectType, ModelObjectType, ModelObjectType, ModelObjectType, ModelObjectType ] | [ ModelObjectType, ModelObjectType, ModelObjectType, ModelObjectType, ModelObjectType, ModelObjectType, ModelObjectType, ModelObjectType ] | [ ModelObjectType, ModelObjectType, ModelObjectType, ModelObjectType, ModelObjectType, ModelObjectType, ModelObjectType, ModelObjectType, ModelObjectType ] | [ ModelObjectType, ModelObjectType, ModelObjectType, ModelObjectType, ModelObjectType, ModelObjectType, ModelObjectType, ModelObjectType, ModelObjectType, ModelObjectType ]; export type ModelObjectType = object & { length?: never; }; /** * Resolves document model from the document definition. */ export type DocModel = Utils.NeverIfEmpty>; /** * Resolves document model from the document definition. Unlike * {@link DocModel} this version resolves unknown if the model has no keys. */ export type DocModelOrUnknown = Utils.UnknownIfEmpty>; /** * Resolves the reduced model or the shared model shape otherwise. */ export type DocModelShape = Def["Flags"]["Reduced"] extends true ? IntersectVariableModelType : SharedVariableModelType; export type IntersectVariableModelType = Model extends ModelObjectType ? Model : Model extends [ infer A extends ModelObjectType, infer B extends ModelObjectType, infer C extends ModelObjectType, infer D extends ModelObjectType, infer E extends ModelObjectType, infer F extends ModelObjectType, infer G extends ModelObjectType, infer H extends ModelObjectType, infer I extends ModelObjectType, infer J extends ModelObjectType ] ? Utils.IntersectShape : Model extends [ infer A extends ModelObjectType, infer B extends ModelObjectType, infer C extends ModelObjectType, infer D extends ModelObjectType, infer E extends ModelObjectType, infer F extends ModelObjectType, infer G extends ModelObjectType, infer H extends ModelObjectType, infer I extends ModelObjectType ] ? Utils.IntersectShape : Model extends [ infer A extends ModelObjectType, infer B extends ModelObjectType, infer C extends ModelObjectType, infer D extends ModelObjectType, infer E extends ModelObjectType, infer F extends ModelObjectType, infer G extends ModelObjectType, infer H extends ModelObjectType ] ? Utils.IntersectShape : Model extends [ infer A extends ModelObjectType, infer B extends ModelObjectType, infer C extends ModelObjectType, infer D extends ModelObjectType, infer E extends ModelObjectType, infer F extends ModelObjectType, infer G extends ModelObjectType ] ? Utils.IntersectShape : Model extends [ infer A extends ModelObjectType, infer B extends ModelObjectType, infer C extends ModelObjectType, infer D extends ModelObjectType, infer E extends ModelObjectType, infer F extends ModelObjectType ] ? Utils.IntersectShape : Model extends [ infer A extends ModelObjectType, infer B extends ModelObjectType, infer C extends ModelObjectType, infer D extends ModelObjectType, infer E extends ModelObjectType ] ? Utils.IntersectShape : Model extends [ infer A extends ModelObjectType, infer B extends ModelObjectType, infer C extends ModelObjectType, infer D extends ModelObjectType ] ? Utils.IntersectShape : Model extends [ infer A extends ModelObjectType, infer B extends ModelObjectType, infer C extends ModelObjectType ] ? Utils.IntersectShape : Model extends [ infer A extends ModelObjectType, infer B extends ModelObjectType ] ? Utils.IntersectShape : Model extends [infer A extends ModelObjectType] ? A : never; export type SharedVariableModelType = Model extends ModelObjectType ? Model : Model extends [ infer A extends ModelObjectType, infer B extends ModelObjectType, infer C extends ModelObjectType, infer D extends ModelObjectType, infer E extends ModelObjectType, infer F extends ModelObjectType, infer G extends ModelObjectType, infer H extends ModelObjectType, infer I extends ModelObjectType, infer J extends ModelObjectType ] ? Utils.SharedShape10 : Model extends [ infer A extends ModelObjectType, infer B extends ModelObjectType, infer C extends ModelObjectType, infer D extends ModelObjectType, infer E extends ModelObjectType, infer F extends ModelObjectType, infer G extends ModelObjectType, infer H extends ModelObjectType, infer I extends ModelObjectType ] ? Utils.SharedShape9 : Model extends [ infer A extends ModelObjectType, infer B extends ModelObjectType, infer C extends ModelObjectType, infer D extends ModelObjectType, infer E extends ModelObjectType, infer F extends ModelObjectType, infer G extends ModelObjectType, infer H extends ModelObjectType ] ? Utils.SharedShape8 : Model extends [ infer A extends ModelObjectType, infer B extends ModelObjectType, infer C extends ModelObjectType, infer D extends ModelObjectType, infer E extends ModelObjectType, infer F extends ModelObjectType, infer G extends ModelObjectType ] ? Utils.SharedShape7 : Model extends [ infer A extends ModelObjectType, infer B extends ModelObjectType, infer C extends ModelObjectType, infer D extends ModelObjectType, infer E extends ModelObjectType, infer F extends ModelObjectType ] ? Utils.SharedShape6 : Model extends [ infer A extends ModelObjectType, infer B extends ModelObjectType, infer C extends ModelObjectType, infer D extends ModelObjectType, infer E extends ModelObjectType ] ? Utils.SharedShape5 : Model extends [ infer A extends ModelObjectType, infer B extends ModelObjectType, infer C extends ModelObjectType, infer D extends ModelObjectType ] ? Utils.SharedShape4 : Model extends [ infer A extends ModelObjectType, infer B extends ModelObjectType, infer C extends ModelObjectType ] ? Utils.SharedShape3 : Model extends [ infer A extends ModelObjectType, infer B extends ModelObjectType ] ? Utils.SharedShape2 : Model extends [infer A extends ModelObjectType] ? A : never; export type UnionVariableModelType = Model extends [ infer A extends ModelObjectType, infer B extends ModelObjectType, infer C extends ModelObjectType, infer D extends ModelObjectType, infer E extends ModelObjectType, infer F extends ModelObjectType, infer G extends ModelObjectType, infer H extends ModelObjectType, infer I extends ModelObjectType, infer J extends ModelObjectType ] ? A | B | C | D | E | F | G | H | I | J : Model extends [ infer A extends ModelObjectType, infer B extends ModelObjectType, infer C extends ModelObjectType, infer D extends ModelObjectType, infer E extends ModelObjectType, infer F extends ModelObjectType, infer G extends ModelObjectType, infer H extends ModelObjectType, infer I extends ModelObjectType ] ? A | B | C | D | E | F | G | H | I : Model extends [ infer A extends ModelObjectType, infer B extends ModelObjectType, infer C extends ModelObjectType, infer D extends ModelObjectType, infer E extends ModelObjectType, infer F extends ModelObjectType, infer G extends ModelObjectType, infer H extends ModelObjectType ] ? A | B | C | D | E | F | G | H : Model extends [ infer A extends ModelObjectType, infer B extends ModelObjectType, infer C extends ModelObjectType, infer D extends ModelObjectType, infer E extends ModelObjectType, infer F extends ModelObjectType, infer G extends ModelObjectType ] ? A | B | C | D | E | F | G : Model extends [ infer A extends ModelObjectType, infer B extends ModelObjectType, infer C extends ModelObjectType, infer D extends ModelObjectType, infer E extends ModelObjectType, infer F extends ModelObjectType ] ? Utils.SharedShape6 : Model extends [ infer A extends ModelObjectType, infer B extends ModelObjectType, infer C extends ModelObjectType, infer D extends ModelObjectType, infer E extends ModelObjectType ] ? A | B | C | D | E : Model extends [ infer A extends ModelObjectType, infer B extends ModelObjectType, infer C extends ModelObjectType, infer D extends ModelObjectType ] ? A | B | C | D : Model extends [ infer A extends ModelObjectType, infer B extends ModelObjectType, infer C extends ModelObjectType ] ? A | B | C : Model extends [ infer A extends ModelObjectType, infer B extends ModelObjectType ] ? A | B : Model extends [infer A extends ModelObjectType] ? A : Model extends ModelObjectType ? Model : never; /** * Concats models into single variable model type. Useful to define and export * variable models ouside of the centraliazed schema definition. */ export type ConcatModel = ModelToConcatTo extends ModelObjectType ? ModelToConcat extends ModelObjectType ? [ModelToConcatTo, ModelToConcat] : ModelToConcat extends ModelVariableType ? [ModelToConcatTo, ...ModelToConcat] : never : ModelToConcatTo extends ModelVariableType ? ModelToConcat extends ModelObjectType ? [...ModelToConcatTo, ModelToConcat] : ModelToConcat extends ModelVariableType ? [...ModelToConcatTo, ...ModelToConcat] : never : never; export interface DocDefFlags { /** Signifies if a variable model document got reduced to a single shape. */ Reduced: boolean; /** Signifies if a document got narrowed to shared shape. */ Shared: boolean; } export interface DocDef { Model: ModelType; /** * The collection name (path segment). */ Name: string; Id: Id | string; /** * If the collection has variable shape, it will contain models tuple, * otherwise it will be equal {@link Model}. */ WideModel: ModelType; Flags: DocDefFlags; } export interface DocProps { readonly environment: RuntimeEnvironment; readonly source: DataSource; readonly dateStrategy: ServerDateStrategy; readonly pendingWrites: boolean; } /** * The type of a `DocumentChange` may be 'added', 'removed', or 'modified'. */ export type DocChangeType = "added" | "removed" | "modified"; /** * Doc change information. It contains the type of change, the doc after * the change, and the position change. */ export interface DocChange { /** The type of change. */ readonly type: DocChangeType; /** The document affected by this change. */ readonly doc: Doc; /** * The index of the changed document in the result set immediately prior to * this `DocumentChange` (i.e. supposing that all prior `DocumentChange` objects * have been applied). Is -1 for 'added' events. */ readonly oldIndex: number; /** * The index of the changed document in the result set immediately after * this `DocumentChange` (i.e. supposing that all prior `DocumentChange` * objects and the current `DocumentChange` object have been applied). * Is -1 for 'removed' events. */ readonly newIndex: number; } /** * An options object that configures the snapshot contents of `all` and * `query`. */ export interface SubscriptionListMeta { /** * Returns an array of the documents changes since the last snapshot. If * this is the first snapshot, all documents will be in the list as added * changes. */ changes: () => DocChange[]; /** The number of documents in the QuerySnapshot. */ readonly size: number; /** True if there are no documents in the QuerySnapshot. */ readonly empty: boolean; } export interface DocOptions { serverTimestamps?: Props["dateStrategy"]; } export interface ReadOptions extends DocOptions, OperationOptions { } export type NarrowDef = { Model: ReduceToModel; Id: Def["Id"]; WideModel: Def["WideModel"]; Flags: Flags; }; /** * The document type. It contains the reference in the DB and the model data. */ export interface Doc extends DocAPI { type: "doc"; /** The doc's ref. */ ref: Ref; data: DocData; readonly props: Props; test>(props: Props): this is Doc; assert>(props: Props): asserts this is Doc; /** * The function narrows the type to shared doc type. Unlike regular doc, * shared doc lacks methods which type-safety depends on knowing the full * type of the model: `set`, `upset`, and `as`. The `ref` is also limited. * * When models don't match, it resolves `unknown`. */ as: Shared.DocAs; } export type ServerData = Data; export type AnyData = Data; /** * Doc data type. Defines the shape of the document data returned from the * database. It resolves server dates. */ export type Data = { [Key in keyof Model]: DataField; }; /** * Doc data field. Processes data field types and resolves server dates. */ export type DataField = Type extends ServerDate ? DateMissing extends "missing" ? Date | null : Date : Type extends Date | Ref | string | number | boolean | null | undefined ? Type : Type extends Array ? Array> : Type extends object ? Data : never; /** * The document reference type. */ export interface Ref extends DocAPI { type: "ref"; collection: Collection; id: Def["Id"]; /** * The function narrows the type to shared ref type. Unlike regular ref, * shared ref lacks methods which type-safety depends on knowing the full * type of the model: `set`, `upset`, and `as`. The `collection` is also * limited. * * When models don't match, it resolves `unknown`. */ as: Shared.RefAs; } export type ServerDateMissing = "missing" | "present"; export type ServerDateStrategy = "estimate" | "previous" | "none"; export type RuntimeEnvironment = "server" | "client"; export type DataSource = "cache" | "database"; export interface ServerDate extends Date { [serverDateBrand]: true; } const serverDateBrand: unique symbol; export type DocData = Props["environment"] extends "server" ? ServerData> : Props["source"] extends "database" ? Data, "present"> : Props["dateStrategy"] extends "estimate" | "previous" ? Data, "present"> : Data, "missing">; /** * Write data helpers, whichs allow to set special values, such as server date, * increment, etc. */ export interface WriteHelpers<_Model> { /** * Returns server date value that sets the field to the server date. */ serverDate(): ValueServerDate; /** * Returns remove value that removes the field. */ remove(): ValueRemove; /** * Returns increment value that increments the field by the given value. * * @param value - The number to increment by. */ increment(value: NumberType): ValueIncrement; /** * Returns array union value that unions the given values with the array. * * @param values - The values to union to the array. */ arrayUnion(values: Type | Type[]): ValueArrayUnion; /** * Returns array remove value that removes the given values from the array. * * @param values - The values to remove from the array. */ arrayRemove(values: Type | Type[]): ValueArrayRemove; } /** * Assign argument. It resolves to assign data or getter function that returns * the assign data. It's used in add, set and upset functions. */ export type AssignArg = WriteData | AssignGetter; /** * Assign data getter, accepts helper functions and returns the assign data. */ export type AssignGetter = ($: WriteHelpers) => WriteData; /** * Type of the data passed to assign functions (add, set and upset). * It extends the model allowing to set special values, such as server date, * increment, etc. */ export type WriteData = { [Key in keyof Model]: WriteField; }; /** * Write data field. Processes write data field types and adds corresponding * write helpers such as server data, increment, etc. Used in assign * functions (add, set and upset) and update functions. */ export type WriteField = Type extends number ? WriteFieldNumber : Type extends ServerDate ? WriteFieldServerDate : Type extends undefined ? WriteFieldUndefined : Type extends Date | Ref | string | boolean | null ? WriteFieldAsIs : Type extends Array ? WriteFieldArray : Type extends object ? WriteFieldObject : never; /** * Write field object. Resolves object union with special value types. */ export type WriteFieldObject = WriteData | MaybeValueRemove; /** * Number write field. Resolves number union with special value types. */ export type WriteFieldNumber = Parent[Key] | ValueIncrement | MaybeValueRemove; /** * Server data write field. Resolves server date union with special value * types. When used in the server environment, it resolves to date as well. */ export type WriteFieldServerDate = Props["environment"] extends "server" ? Date | ValueServerDate | MaybeValueRemove : ValueServerDate | MaybeValueRemove; /** * Undefined write field. Resolves undefined union with special value types. */ export type WriteFieldUndefined = (Utils.ActuallyUndefined extends true ? undefined | null : never) | MaybeValueRemove; /** * As-is write field. Resolves as-is types union with special value types. */ export type WriteFieldAsIs = Exclude | MaybeValueRemove; /** * Array write field. Resolves array union with special value types. */ export type WriteFieldArray = Array> | ValueArrayUnion> | ValueArrayRemove> | MaybeValueRemove; /** * Array write item type. Unlike {@link WriteField} it disallows arrays, * server dates and other special value types. */ export type WriteArrayItem = Type extends ServerDate | Array ? never : Type extends Date | Ref | string | number | boolean | null | undefined ? Type : Type extends object ? WriteArrayItemObject : never; /** * Array write item object type. It's an array-nested object and behaves * differently than {@link WriteData}. */ export type WriteArrayItemObject = { [Key in keyof Data]: WriteArrayObjectField; }; /** * It differs from {@link WriteArrayItem} as it allows arrays. */ export type WriteArrayObjectField = Type extends Array ? Array> : WriteArrayItem; /** * Resolves the remove type value unless the key is required. */ export type MaybeValueRemove = Utils.RequiredKey extends true ? never : ValueRemove; /** * Available value kinds. */ export type ValueKind = "remove" | "increment" | "arrayUnion" | "arrayRemove" | "serverDate"; /** * The remove value type. */ export interface ValueRemove { type: "value"; kind: "remove"; } /** * The increment value type. It holds the increment value. */ export interface ValueIncrement { type: "value"; kind: "increment"; number: NumberType; } /** * The array union value type. It holds the payload to union. */ export interface ValueArrayUnion { type: "value"; kind: "arrayUnion"; values: Type[]; } /** * The array remove value type. It holds the data to remove from the target array. */ export interface ValueArrayRemove { type: "value"; kind: "arrayRemove"; values: Type[]; } /** * The server date value type. */ export interface ValueServerDate { type: "value"; kind: "serverDate"; } export interface SchemaHelpers { collection(): PlainCollection; } export interface OperationOptions { as?: Environment; } export type SubscriptionErrorCallback = (error: unknown) => any; export type OffSubscription = () => void; export interface OffSubscriptionWithCatch { (): void; catch(callback: SubscriptionErrorCallback): OffSubscription; } export interface SubscriptionPromise extends Promise { request: Request; on: SubscriptionPromiseOn; } export interface SubscriptionPromiseOn { (callback: SubscriptionPromiseCallback): OffSubscriptionWithCatch; request: Request; } export type SubscriptionPromiseCallback = SubscriptionMeta extends undefined ? (result: Result) => void : (result: Result, meta: SubscriptionMeta) => void; export interface Request { type: "request"; kind: Kind; path: string; group?: boolean; } export interface GetRequest extends Request<"get"> { id: string; } export interface AllRequest extends Request<"all"> { } export interface ManyRequest extends Request<"many"> { ids: string; } export interface QueryRequest extends Request<"many"> { queries: Query.Query[]; } export interface DocAPI { get(options?: ReadOptions): SubscriptionPromise | null>; set(data: AssignArg, Props>, options?: OperationOptions): Promise>; upset(data: AssignArg, Props>, options?: OperationOptions): Promise>; update: Update.DocFunction; remove(): Promise>; narrow(fn: DocNarrowFunction, NarrowToModel>): Doc<{ Model: NarrowToModel; Name: Def["Name"]; Id: Def["Id"]; WideModel: Def["WideModel"]; Flags: Def["Flags"] & { Reduced: true; }; }, DocProps> | undefined; } export type DocNarrowFunction = (data: InputModel) => false | Nullify; export interface CollectionAPI { all(options?: ReadOptions): SubscriptionPromise[], SubscriptionListMeta>; query: Query.Function; count(): Promise; sum(field: Utils.KeysOfType, number>): Promise; average(field: Utils.KeysOfType, number>): Promise; } /** * */ export interface Collection extends CollectionAPI { /** The collection type */ type: "collection"; /** The collection path */ path: string; /** The collection name */ name: string; get(id: Def["Id"], options?: ReadOptions): SubscriptionPromise | null>; many(ids: Def["Id"][], options?: ReadOptions): SubscriptionPromise | null>>; add(data: AssignArg, Props>, options?: OperationOptions): Promise>; set(id: Def["Id"], data: AssignArg, Props>, options?: OperationOptions): Promise>; upset(id: Def["Id"], data: AssignArg, Props>, options?: OperationOptions): Promise>; update: Update.CollectionFunction; remove(id: Def["Id"]): Promise>; ref(id: Def["Id"]): Ref; doc(snapshot: Firebase.Snapshot): Doc | null; doc(id: Def["Id"], data: DocData, options?: OperationOptions): Doc; /** * Cast a string to typed document id. * * [Learn more on the docs website](https://typesaurus.com/docs/api/id). * * @param id - the string to cast to the typed document id * @returns typed document id * * @example * const commentId = db.comments.id('t2nNOgoQY8a5vcvWl1yAz26Ue7k2') */ id(id: string): Def["Id"]; /** * Generate random document id using Firebase. * * [Learn more on the docs website](https://typesaurus.com/docs/api/id). * * @returns promise to random typed document id * * @example * const newCommentId = await db.comments.id() */ id(): Promise; /** * The function narrows the type to shared collection type. Unlike regular * collection, shared collection lacks methods which type-safety depends on * knowing the full type of the model: `set`, `upset`, and `as`. The `ref` * is also limited. * * When models don't match, it resolves `unknown`. */ as: Shared.CollectionAs; } export interface CollectionConfig { path?: string; } export interface NestedCollection extends Collection { (id: Def["Id"]): Schema; schema: Schema; sub: NestedCollectionShortcuts; } export type NestedCollectionShortcuts = { [Path in keyof Schema]: Path extends string ? Schema[Path] extends NestedCollection ? NestedCollectionShortcut : Schema[Path] extends Collection ? CollectionShortcut : Schema[Path] : never; }; export interface CollectionShortcut { /** * Cast a string to typed document id. * * [Learn more on the docs website](https://typesaurus.com/docs/api/id). * * @param id - the string to cast to the typed document id * @returns typed document id * * @example * const commentId = db.posts.sub.comments.id('t2nNOgoQY8a5vcvWl1yAz26Ue7k2') */ id(id: string): Def["Id"]; /** * Generate random document id using Firebase. * * [Learn more on the docs website](https://typesaurus.com/docs/api/id). * * @returns promise to random typed document id * * @example * const newCommentId = await db.posts.sub.comments.id() */ id(): Promise; } export interface NestedCollectionShortcut extends CollectionShortcut { sub: NestedCollectionShortcuts; } export type AnyCollection = Collection | NestedCollection; export interface PlainCollection { /** The collection type */ type: "collection"; sub(schema: Schema): NestedPlainCollection; name(name: Name): PlainCollection; } export interface NestedPlainCollection<_Model extends ModelType, Schema extends PlainSchema, _CustomId extends CustomIdConstrain = false, _CustomName extends string | false = false> { /** The collection type */ type: "collection"; schema: Schema; } export type AnyPlainCollection = PlainCollection | NestedPlainCollection; export interface PlainSchema { [Path: string | symbol]: PlainCollection | NestedPlainCollection; } export interface AnyDB { [CollectionPath: string]: AnyCollection; } export type DB = { [Name in keyof Schema]: Name extends string ? Schema[Name] extends NestedPlainCollection ? NestedCollection, DB>> : Schema[Name] extends PlainCollection ? Collection> : never : never; }; /** * Resolves collection def. */ export type CollectionDef = { Model: NullifyModel; Name: CustomName extends string ? CustomName : Name; Id: CustomId extends Id | string ? CustomId : Id>; WideModel: NullifyModel; Flags: DocDefFlags; }; /** * Infers schema types. Useful to define function arguments that accept * collection doc, ref, id or data. */ export type InferSchema> = { [Path in keyof DB]: DB[Path] extends Collection | NestedCollection ? { /** * The type allows to access subcollections. * * [Learn more on the docs website](https://typesaurus.com/types/schema/#subcollections) */ sub: DB[Path] extends NestedCollection> ? InferSchema : never; /** * The type represents the document id. * * [Learn more on the docs website](https://typesaurus.com/types/schema/#id) */ Id: Def["Id"]; /** * The type represents the collection Collection instance. * * [Learn more on the docs website](https://typesaurus.com/types/schema/#collection) */ Collection: DB[Path]; /** * The type represents the document Ref instance. * * [Learn more on the docs website](https://typesaurus.com/types/schema/#ref) */ Ref: TypesaurusCore.Ref; /** * The type represents the document Doc instance. * * [Learn more on the docs website](https://typesaurus.com/types/schema/#doc) */ Doc: TypesaurusCore.Doc; /** * The type represents the document data. It’s what you get reading or * creating a document via collection’s doc. * * [Learn more on the docs website](https://typesaurus.com/types/schema/#data) */ Data: Data, ServerDateMissing>; /** * The type represents the result of a reading operation, like the get * method. It can be the Doc instance, null if the document is not * found, or undefined if the operation is still in progress. * * [Learn more on the docs website](https://typesaurus.com/types/schema/#result) */ Result: Doc | null | undefined; /** * The type represents the argument of an assign function. It can be * used for all writing operations and expects the complete document * data. * * It unions AssignData and AssignGetter types. * * [Learn more on the docs website](https://typesaurus.com/types/schema/#assignarg) */ AssignArg: AssignArg, DocProps>; /** * The type represents the data of an assign function. It can be used * for all writing operations and expects the complete document data. * * [Learn more on the docs website](https://typesaurus.com/types/schema/#assigndata) */ AssignData: WriteData, DocProps>; /** * The type represents the getter of an assign function. It can be * used for all writing operations and expects the complete document * data. * * [Learn more on the docs website](https://typesaurus.com/types/schema/#assigngetter) */ AssignGetter: AssignGetter, DocProps>; /** * The type represents the write helpers of an assign function. It can * be used for all writing operations. * * [Learn more on the docs website](https://typesaurus.com/types/schema/#writehelpers) */ WriteHelpers: WriteHelpers; /** * The type represents the update builder object. * * [Learn more on the docs website](https://typesaurus.com/types/schema/#updatebuilder) */ UpdateBuilder: Update.Builder; /** * The type represents the argument of an update function. * * It unions UpdateData and UpdateGetter types. * * [Learn more on the docs website](https://typesaurus.com/types/schema/#updatearg) */ UpdateArg: Update.Arg; /** * The type represents the data of an update function. * * [Learn more on the docs website](https://typesaurus.com/types/schema/#updatedata) */ UpdateData: Update.Data, DocProps>; /** * The type represents the getter of an update function. * * [Learn more on the docs website](https://typesaurus.com/types/schema/#updategetter) */ UpdateGetter: Update.ArgGetter; /** * The type represents the update helpers of an update function. * * [Learn more on the docs website](https://typesaurus.com/types/schema/#updatehelpers) */ UpdateHelpers: Update.Helpers; /** * The type represents the query builder object. * * [Learn more on the docs website](https://typesaurus.com/types/schema/#querybuilder) */ QueryBuilder: Query.Builder; /** * The type represents what the query method expects you to return * from the query function. * * [Learn more on the docs website](https://typesaurus.com/types/schema/#querydata). */ QueryData: Query.Data; /** * The type represents the query function. * * [Learn more on the docs website](https://typesaurus.com/types/schema/#querygetter) */ QueryGetter: Query.Getter; /** * The type represents the query helpers of a query function. * * [Learn more on the docs website](https://typesaurus.com/types/schema/#queryhelpers) */ QueryHelpers: Query.Helpers; /** * The type is a server version of the Doc type where server dates are * always present, unlike the client version where they might be null. * * [Learn more on the docs website](https://typesaurus.com/types/schema/#serverdoc) */ ServerDoc: TypesaurusCore.Doc; /** * The type is a server version of the Data type where server dates * are always present, unlike the client version where they might be * null. * * [Learn more on the docs website](https://typesaurus.com/types/schema/#serverdata) */ ServerData: ServerData>; /** * The type is a server version of the Result type where server dates * are always present, unlike the client version where they might be * null. * * [Learn more on the docs website](https://typesaurus.com/types/schema/#serverresult) */ ServerResult: Doc | null | undefined; /** * The type is a server version of the AssignArg type where server * dates are always present, unlike the client version where they * might be null. * * [Learn more on the docs website](https://typesaurus.com/types/schema/#serverassignarg) */ ServerAssignArg: AssignArg, DocProps>; /** * The type is a server version of the AssignData type where server * dates are always present, unlike the client version where they * might be null. * * [Learn more on the docs website](https://typesaurus.com/types/schema/#serverassigndata) */ ServerAssignData: WriteData, DocProps & { environment: "server"; }>; /** * The type is a server version of the AssignGetter type where server * dates are always present, unlike the client version where they * might be null. * * [Learn more on the docs website](https://typesaurus.com/types/schema/#serverassigngetter) */ ServerAssignGetter: AssignGetter, DocProps & { environment: "server"; }>; /** * The type is a server version of the UpdateBuilder type where server * dates are always present, unlike the client version where they * might be null. * * [Learn more on the docs website](https://typesaurus.com/types/schema/#serverupdatebuilder) */ ServerUpdateBuilder: Update.Builder; /** * The type is a server version of the UpdateArg type where server * dates are always present, unlike the client version where they * might be null. * * [Learn more on the docs website](https://typesaurus.com/types/schema/#serverupdatearg) */ ServerUpdateArg: Update.Arg; /** * The type is a server version of the UpdateData type where server * dates are always present, unlike the client version where they * might be null. * * [Learn more on the docs website](https://typesaurus.com/types/schema/#serverupdatedata) */ ServerUpdateData: Update.Data; /** * The type is a server version of the UpdateGetter type where server * dates are always present, unlike the client version where they * might be null. * * [Learn more on the docs website](https://typesaurus.com/types/schema/#serverupdategetter) */ ServerUpdateGetter: Update.ArgGetter; /** * The type is a server version of the UpdateHelpers type where server * dates are always present, unlike the client version where they * might be null. * * [Learn more on the docs website](https://typesaurus.com/types/schema/#serverupdatehelpers) */ ServerUpdateHelpers: Update.Helpers; /** * The type represents transaction read document. What you return from * the transaction read function. * * [Learn more on the docs website](https://typesaurus.com/types/schema/#transactionreaddoc) */ TransactionReadDoc: Transaction.ReadDoc; /** * The type represents transaction write document. What you get in * the transaction write function. * * [Learn more on the docs website](https://typesaurus.com/types/schema/#transactionwritedoc) */ TransactionWriteDoc: Transaction.WriteDoc; /** * The type represents the document definition. It’s in many methods * as a generic parameter. * * [Learn more on the docs website](https://typesaurus.com/types/schema/#def) */ Def: Def; } : never; }; /** * Narrow doc type. If your doc has multiple shapes, the type will help you * narrow down data type to a specific type. */ export type NarrowDoc, NarrowToModel extends ModelObjectType> = OriginalDoc extends Doc ? NarrowToModel extends IntersectVariableModelType ? Doc<{ Model: NarrowToModel; Name: Def["Name"]; Id: Def["Id"]; WideModel: Def["WideModel"]; Flags: Def["Flags"] & { Reduced: true; }; }, Props> : never : never; /** * Deeply normalizes server dates in a given type. It replaces ServerDate with * regular Date. It's useful when reusing interfaces in a non-Typesaurus * environment or when you need to store it in an array (where server dates * are not allowed). */ export type NormalizeServerDates = Type extends ServerDate ? Date : Type extends Date | Ref | string | number | boolean ? Type : Type extends Array ? Array> : Type extends object ? { [Key in keyof Type]: NormalizeServerDates; } : never; /** * The options. It allows to configure the Firebase settings. */ export interface Options { /** The app name. */ app?: string; /** The server options. */ server?: OptionsServer; } /** * The server options. */ export interface OptionsServer { /** The server app name. It takes priority over the root's app name. */ app?: string; /** The option forces Firestore the use of REST transport until an operation * requires gRPC. It helps to speed up the cold start of the Functions. */ preferRest?: boolean; } /** * The client options. */ export interface OptionsServer { /** The client app name. It takes priority over the root's app name. */ app?: string; } /** * Deeply adds null to all undefined values. */ export type Nullify = Type extends null | undefined ? Type | null : Type extends ServerDate | Date | Ref | string | number | boolean ? Type : Type extends Array ? Array> : Type extends object ? { [Key in keyof Type]: Utils.ActuallyUndefined extends true ? Nullify : Nullify>; } : never; /** * Deeply adds null to shapes of a variable model. */ export type NullifyModel = Model extends ModelObjectType ? Nullify : Model extends [ infer A extends ModelObjectType, infer B extends ModelObjectType, infer C extends ModelObjectType, infer D extends ModelObjectType, infer E extends ModelObjectType, infer F extends ModelObjectType, infer G extends ModelObjectType, infer H extends ModelObjectType, infer I extends ModelObjectType, infer J extends ModelObjectType ] ? [ Nullify, Nullify, Nullify, Nullify, Nullify, Nullify, Nullify, Nullify, Nullify, Nullify ] : Model extends [ infer A extends ModelObjectType, infer B extends ModelObjectType, infer C extends ModelObjectType, infer D extends ModelObjectType, infer E extends ModelObjectType, infer F extends ModelObjectType, infer G extends ModelObjectType, infer H extends ModelObjectType, infer I extends ModelObjectType ] ? [ Nullify, Nullify, Nullify, Nullify, Nullify, Nullify, Nullify, Nullify, Nullify ] : Model extends [ infer A extends ModelObjectType, infer B extends ModelObjectType, infer C extends ModelObjectType, infer D extends ModelObjectType, infer E extends ModelObjectType, infer F extends ModelObjectType, infer G extends ModelObjectType, infer H extends ModelObjectType ] ? [ Nullify, Nullify, Nullify, Nullify, Nullify, Nullify, Nullify, Nullify ] : Model extends [ infer A extends ModelObjectType, infer B extends ModelObjectType, infer C extends ModelObjectType, infer D extends ModelObjectType, infer E extends ModelObjectType, infer F extends ModelObjectType, infer G extends ModelObjectType ] ? [ Nullify, Nullify, Nullify, Nullify, Nullify, Nullify, Nullify ] : Model extends [ infer A extends ModelObjectType, infer B extends ModelObjectType, infer C extends ModelObjectType, infer D extends ModelObjectType, infer E extends ModelObjectType, infer F extends ModelObjectType ] ? [ Nullify, Nullify, Nullify, Nullify, Nullify, Nullify ] : Model extends [ infer A extends ModelObjectType, infer B extends ModelObjectType, infer C extends ModelObjectType, infer D extends ModelObjectType, infer E extends ModelObjectType ] ? [Nullify, Nullify, Nullify, Nullify, Nullify] : Model extends [ infer A extends ModelObjectType, infer B extends ModelObjectType, infer C extends ModelObjectType, infer D extends ModelObjectType ] ? [Nullify, Nullify, Nullify, Nullify] : Model extends [ infer A extends ModelObjectType, infer B extends ModelObjectType, infer C extends ModelObjectType ] ? [Nullify, Nullify, Nullify] : Model extends [ infer A extends ModelObjectType, infer B extends ModelObjectType ] ? [Nullify, Nullify] : Model extends [infer A extends ModelObjectType] ? [Nullify] : never; export {}; }