UNPKG

2.67 kBTypeScriptView Raw
1/// <reference types="node" />
2import * as mongoose from 'mongoose';
3import type { DocumentType, Ref, RefType } from './types';
4/**
5 * Check if the given document is populated
6 * @param doc The Ref with uncertain type
7 */
8export declare function isDocument<T, S extends RefType>(doc: Ref<T, S>): doc is T extends DocumentType<infer T1, infer T2> ? DocumentType<T1, T2> : T extends object ? DocumentType<T> : never;
9/**
10 * Check if the given array is fully populated
11 * Only returns "true" if all members in the array are populated
12 * @param docs The Array of Refs with uncertain type
13 */
14export declare function isDocumentArray<T, S extends RefType>(docs: mongoose.Types.Array<Ref<T, S>> | undefined): docs is mongoose.Types.Array<DocumentType<NonNullable<T>>>;
15/**
16 * Check if the given array is fully populated
17 * Only returns "true" if all members in the array are populated
18 * @param docs The Array of Refs with uncertain type
19 */
20export declare function isDocumentArray<T, S extends RefType>(docs: Ref<T, S>[] | undefined): docs is DocumentType<NonNullable<T>>[];
21declare type AllowedRefTypes = typeof String | typeof Number | typeof Buffer | typeof mongoose.Types.ObjectId | typeof mongoose.Types.Buffer;
22/**
23 * Check if the document is of type "refType"
24 * @param doc The Ref with uncretain type
25 * @param refType The Expected Reference Type (this is required because this type is only known at compile time, not at runtime)
26 */
27export declare function isRefType<T, S extends RefType>(doc: Ref<T, S> | undefined, refType: AllowedRefTypes): doc is NonNullable<S>;
28/**
29 * Check if the array is fully of type "refType"
30 * Only returns "true" if all members in the array are of type "refType"
31 * @param docs The Ref with uncretain type
32 * @param refType The Expected Reference Type (this is required because this type is only known at compile time, not at runtime)
33 */
34export declare function isRefTypeArray<T, S extends RefType>(docs: mongoose.Types.Array<Ref<T, S>> | undefined, refType: AllowedRefTypes): docs is mongoose.Types.Array<NonNullable<S>>;
35/**
36 * Check if the array is fully of type "refType"
37 * Only returns "true" if all members in the array are of type "refType"
38 * @param docs The Ref with uncretain type
39 * @param refType The Expected Reference Type (this is required because this type is only known at compile time, not at runtime)
40 */
41export declare function isRefTypeArray<T, S extends RefType>(docs: Ref<T, S>[] | undefined, refType: AllowedRefTypes): docs is NonNullable<S>[];
42/**
43 * Check if the input is a mongoose.Model
44 * @param model The Value to check
45 */
46export declare function isModel(model: any): model is mongoose.Model<any>;
47export {};