mongoose-management
Version:
Mongoose schemas management tool
91 lines (90 loc) • 2.97 kB
TypeScript
/**
* ######################################################################
* # #
* # Do not change the file! #
* # #
* # All changes are deleted the next time the collection data is read. #
* # #
* ######################################################################
*/
import { IndexOptions } from 'mongodb';
import { SchemaTypeOpts } from 'mongoose';
/**
* Helpers
*/
declare type Keys<T> = {
[K in keyof T]: T[K] extends never ? never : K;
}[keyof T];
declare type Diff<T, U> = T extends U ? never : T;
/**
* Extracts the type from the function
*/
declare type virtualFunctionTypeGet<T extends {
[k: string]: any;
}> = T['get'] extends () => void ? ReturnType<T['get']> : never;
declare type virtualFunctionTypeSet<T extends {
[k: string]: any;
}> = T['set'] extends (value: infer A) => void ? A : never;
/**
* List of all types (with the type "never")
*/
declare type virtualFunctionTypeGetList<T> = {
[K in keyof T]: virtualFunctionTypeGet<T[K]>;
};
declare type virtualFunctionTypeSetList<T> = {
[K in keyof T]: virtualFunctionTypeSet<T[K]>;
};
/**
* List of all types (without the type "never")
*/
declare type virtualTypeGetList<T> = Pick<virtualFunctionTypeGetList<T>, Keys<virtualFunctionTypeGetList<T>>>;
declare type virtualTypeSetList<T> = Pick<virtualFunctionTypeSetList<T>, Keys<virtualFunctionTypeSetList<T>>>;
/**
* List of Keys where the object have only "get"
*/
declare type virtualKeysGetOnly<T> = Diff<keyof virtualTypeGetList<T>, keyof virtualTypeSetList<T>>;
/**
* List of Keys where without "get only" objects
*/
declare type virtualKeysBoth<T> = Diff<keyof T, virtualKeysGetOnly<T>>;
export declare type virtualType<T> = {
readonly [K in keyof virtualTypeGetList<T> & virtualKeysGetOnly<T>]: virtualTypeGetList<T>[K];
} & {
[K in keyof virtualTypeGetList<T> & virtualKeysBoth<T>]: virtualTypeGetList<T>[K];
} & {
[K in keyof virtualTypeSetList<T>]: virtualTypeSetList<T>[K];
};
/**
*
*/
export declare type extendTimestampType = {
readonly createdAt: Date;
readonly updatedAt: Date;
};
/**
*
*/
export declare type extendIdType = {
readonly _id: any;
readonly id: any;
};
/**
*
*/
declare type indexOptionsExclude = 'dropDups' | 'min' | 'max' | 'v' | 'session' | 'w' | 'j' | 'wtimeout';
/**
*
*/
export declare type indexType = {
fields: {
[k: string]: 1 | -1 | 'text' | '2dsphere' | 'hashed';
};
options: Pick<IndexOptions, Exclude<keyof IndexOptions, indexOptionsExclude>>;
};
/**
*
*/
export declare type schemaExtensionType<T extends Record<string, any>> = {
[K in keyof T]?: T[K] extends Array<schemaExtensionType<T>> ? [schemaExtensionType<T[K][0]>] : SchemaTypeOpts<any>;
};
export {};