Chris1203

Untitled

Jun 6th, 2021
987
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. declare module "mongoose" {
  2.     type PartialRecord<K extends keyof any, T> = {
  3.         [P in K]?: T;
  4.     }
  5.  
  6.     export type PresentableFieldKey<T = any> = (keyof { [P in keyof Omit<T, keyof Document>] } | (string & {}));
  7.     export type PresentableFieldValue = boolean | {
  8.         populate: boolean;
  9.     };
  10.  
  11.     export type PresentableField<T = null> = PartialRecord<PresentableFieldKey<T>, PresentableFieldValue>;
  12.  
  13.     interface Document {
  14.         "$raw": Record<string, unknown>;
  15.         "$populated": Record<string, unknown>;
  16.         "$presentables": PresentableField;
  17.  
  18.         wasNew: boolean;
  19.  
  20.         /**
  21.          * Returns the presentable object, populated and cleaned up, ready to be sent to the client
  22.          */
  23.         getPresentableObject(): Record<string, unknown>;
  24.         /**
  25.          * Configure a single presentable field.
  26.          * <note>This applies only to the single document it's run on</note>
  27.          */
  28.         setPresentableField(key: PresentableFieldKey<this> | string, value: PresentableFieldValue): Document;
  29.         /**
  30.          * Configure the presentable fields for the document.
  31.          * <note>This only overwrites the fields that were provided, the others remain intact.</note>
  32.          * <note>This applies only to the single document it's run on</note>
  33.          */
  34.         setPresentableFields(fields: PresentableField<this>): Document;
  35.         /**
  36.          * Get all fields that should be included
  37.          */
  38.         getIncludibleFields(): string[];
  39.     }
  40.  
  41.     interface Model<T extends Document<any, any>, TQueryHelpers = {}, TMethods = {}, QueryHelpers = {}> {
  42.         /**
  43.          * Configure the presentable fields for this model
  44.          */
  45.         setPresentableFields(fields: PresentableField<T>): void;
  46.     }
  47.  
  48.     class Query<ResultType, DocType extends Document, THelpers = {}> {
  49.         raw<T extends Document>(): this;
  50.     }
  51.  
  52.     interface QueryOptions {
  53.         explicitlyPopulated?: boolean;
  54.         rawDocument?: boolean;
  55.     }
  56. }
RAW Paste Data