import { Model } from './Model'; import { CollectionCounter } from './CollectionCounter'; import { Query } from './Query'; /** * A path string, a {@link Model}, or a {@link Query}. */ export type Subscribable = string | Model | Query; declare module './Model' { interface Model { /** * Retrieve data from the server, loading it into the model. * * @param items - Items to fetch * @param cb - Callback called when operation completed * * @see https://derbyjs.github.io/derby/models/backends#loading-data-into-a-model */ fetch(items: Subscribable[], cb?: ErrorCallback): Model; /** * Retrieve data from the server, loading it into the model. * * @param item - Item to fetch * @param cb - Callback called when operation completed * * @see https://derbyjs.github.io/derby/models/backends#loading-data-into-a-model */ fetch(item: Subscribable, cb?: ErrorCallback): Model; /** * Retrieve data from the server, loading it into the model. * * @param cb - Callback called when operation completed * * @see https://derbyjs.github.io/derby/models/backends#loading-data-into-a-model */ fetch(cb?: ErrorCallback): Model; /** * Promised version of {@link Model.fetch}. Instead of a callback, returns a promise * that is resolved when operation completed * * @param items */ fetchPromised(items: Subscribable[]): Promise; /** * Promised version of {@link Model.fetch}. Instead of a callback, returns a promise * that is resolved when operation completed * * @param item */ fetchPromised(item: Subscribable): Promise; /** * Promised version of {@link Model.fetch}. Instead of a callback, returns a promise * that is resolved when operation completed */ fetchPromised(): Promise; /** * Retrieve data from the server, loading it into the model. * * @param collecitonName - Name of colleciton to load item to * @param id - Id of doc to load * @param callback - Callback called when operation completed * * @see https://derbyjs.github.io/derby/models/backends#loading-data-into-a-model */ fetchDoc(collecitonName: string, id: string, callback?: ErrorCallback): void; /** * Promised version of {@link Model.fetchDoc}. Instead of a callback, returns a promise * that is resolved when operation completed * * @param collecitonName - Name of colleciton to load item to * @param id - Id of doc to load */ fetchDocPromised(collecitonName: string, id: string): Promise; fetchOnly: boolean; /** * Retrieve data from the server, loading it into the model. In addition, * subscribe to the items, such that updates from any other client will * automatically get reflected in this client's model. * * Any item that's already subscribed will not result in a network call. * * @param items - Item to subscribe to * @param cb - Callback called when operation completed * * @see https://derbyjs.github.io/derby/models/backends#loading-data-into-a-model */ subscribe(items: Subscribable[], cb?: ErrorCallback): Model; /** * Retrieve data from the server, loading it into the model. In addition, * subscribe to the items, such that updates from any other client will * automatically get reflected in this client's model. * * Any item that's already subscribed will not result in a network call. * * @param item - Item to subscribe to * @param cb - Callback called when operation completed * * @see https://derbyjs.github.io/derby/models/backends#loading-data-into-a-model */ subscribe(item: Subscribable, cb?: ErrorCallback): Model; /** * Retrieve data from the server, loading it into the model. In addition, * subscribe to the items, such that updates from any other client will * automatically get reflected in this client's model. * * Any item that's already subscribed will not result in a network call. * * @param cb - Callback called when operation completed * * @see https://derbyjs.github.io/derby/models/backends#loading-data-into-a-model */ subscribe(cb?: ErrorCallback): Model; /** * Promised version of {@link Model.subscribe}. Instead of a callback, returns a promise * that is resolved when operation completed * * @param items - Items to subscribe to */ subscribePromised(items: Subscribable[]): Promise; /** * Promised version of {@link Model.subscribe}. Instead of a callback, returns a promise * that is resolved when operation completed * * @param item - Item to subscribe to */ subscribePromised(item: Subscribable): Promise; /** * Promised version of {@link Model.subscribe}. Instead of a callback, returns a promise * that is resolved when operation completed */ subscribePromised(): Promise; subscribeDoc(collecitonName: string, id: string, callback?: ErrorCallback): void; subscribeDocPromised(collecitonName: string, id: string): Promise; /** * The reverse of {@link Model.fetch}, marking the items as no longer needed in the * model. * * @param items - Items to unfetch * @param cb - Optional Called after operation completed * * @see https://derbyjs.github.io/derby/models/backends#loading-data-into-a-model */ unfetch(items: Subscribable[], cb?: ErrorCallback): Model; /** * The reverse of {@link Model.fetch}, marking the items as no longer needed in the * model. * * @param item - Item to unfetch * @param cb - Optional Called after operation completed * * @see https://derbyjs.github.io/derby/models/backends#loading-data-into-a-model */ unfetch(item: Subscribable, cb?: ErrorCallback): Model; /** * The reverse of {@link Model.fetch}, marking the items as no longer needed in the * model. * * @param cb - Optional Called after operation completed * * @see https://derbyjs.github.io/derby/models/backends#loading-data-into-a-model */ unfetch(cb?: ErrorCallback): Model; /** * Promised unfetch. See {@link Model.unfetch}. Instead of a callback, returns a promise * that is resolved when operation completed * * @param items - Items to unfetch * @returns Promise */ unfetchPromised(items: Subscribable[]): Promise; /** * Promised unfetch. See {@link Model.unfetch}. Instead of a callback, returns a promise * that is resolved when operation completed * * @param item - Item to unfetch * @returns Promise */ unfetchPromised(item: Subscribable): Promise; /** * Promised {@link Model.unfetch}. Instead of taking a callback, returns a promise * that is resolved when operation completed * * @returns Promise */ unfetchPromised(): Promise; /** * Unfetch a document give collection name and document id * * @param collectionName - Collection name * @param id - Document id to be unfeched */ unfetchDoc(collectionName: string, id: string, callback?: (err?: Error, count?: number) => void): void; /** * Promised {@link Model.unfetchDoc}. Instead of taking a callback, returns a promise * that is resolved when operation completed * * @param collectionName - Collection name * @param id - Document id to be unfeched * @returns Promise */ unfetchDocPromised(collectionName: string, id: string): Promise; /** * Delay in milliseconds before model data actually unloaded after call to {@link Model.unload} */ unloadDelay: number; /** * The reverse of {@link Model.subscribe}, marking the items as no longer needed in the * model. * * @param items - The items to unsubscribe * @param cb - Optional Called after operation completed * * @see https://derbyjs.github.io/derby/models/backends#loading-data-into-a-model */ unsubscribe(items: Subscribable[], cb?: ErrorCallback): Model; /** * The reverse of {@link Model.subscribe}, marking the items as no longer needed in the * model. * * @param item - The item to unsubscribe * @param cb - Optional Called after operation completed * * @see https://derbyjs.github.io/derby/models/backends#loading-data-into-a-model */ unsubscribe(item: Subscribable, cb?: ErrorCallback): Model; /** * The reverse of {@link Model.subscribe}, marking the items as no longer needed in the * model. * * @param cb - Optional Called after operation completed * * @see https://derbyjs.github.io/derby/models/backends#loading-data-into-a-model */ unsubscribe(cb?: ErrorCallback): Model; /** * Promised version of {@link Model.unsubscribe}. Instead of taking a callback, returns a promise * that is resolved when operation completed */ unsubscribePromised(): Promise; /** * Unsubscribe document by collection name and id * * @param collectionName - Name of collection containting document * @param id - Document id to unsubscribe * @param callback - Optional Called after operation completed */ unsubscribeDoc(collectionName: string, id: string, callback?: (err?: Error, count?: number) => void): void; /** * Promised version of {@link Model.unsubscribeDoc} * * @param collectionName - Name of collection containting document * @param id - Document id to unsbscribe */ unsubscribeDocPromised(collectionName: string, id: string): Promise; _fetchedDocs: CollectionCounter; _forSubscribable(argumentsObject: any, method: any): void; _hasDocReferences(collecitonName: string, id: string): boolean; _maybeUnloadDoc(collecitonName: string, id: string): void; _subscribedDocs: CollectionCounter; } }