Skip to content

Commit

Permalink
Fix linting
Browse files Browse the repository at this point in the history
  • Loading branch information
mohammad0-0ahmad committed Jun 3, 2022
1 parent 6810555 commit 98d75d4
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 50 deletions.
12 changes: 6 additions & 6 deletions test/types/create.test.ts
Expand Up @@ -73,14 +73,14 @@ Test.insertMany([{ name: 'test' }], { rawResult: true }, (err, result) => {
expectType<CallbackError>(err);
expectType<boolean>(result.acknowledged);
expectType<number>(result.insertedCount);
expectType<{[key: number]: Types.ObjectId;}>(result.insertedIds)
expectType<{ [key: number]: Types.ObjectId; }>(result.insertedIds);
});

Test.insertMany([{ name: 'test' }], { rawResult: true }, (err, result) => {
expectType<CallbackError>(err);
expectType<boolean>(result.acknowledged);
expectType<number>(result.insertedCount);
expectType<{[key: number]: Types.ObjectId;}>(result.insertedIds)
expectType<{ [key: number]: Types.ObjectId; }>(result.insertedIds);
});

Test.insertMany([{ name: 'test' }], { lean: true }, (err, docs) => {
Expand All @@ -103,7 +103,7 @@ Test.insertMany({ _id: '000000000000000000000000', name: 'test' }, (err, docs) =
expectType<boolean>(docs[0].isNew);
});

Test.insertMany({ _id: new Types.ObjectId('000000000000000000000000')}, (err, docs) => {
Test.insertMany({ _id: new Types.ObjectId('000000000000000000000000') }, (err, docs) => {
expectType<Types.ObjectId>(docs[0]._id);
expectType<string | undefined>(docs[0].name);
expectType<boolean>(docs[0].isNew);
Expand Down Expand Up @@ -136,13 +136,13 @@ Test.insertMany({ name: 'test' }, {}).then(docs => {
Test.insertMany([{ name: 'test' }], { rawResult: true }).then(result => {
expectType<boolean>(result.acknowledged);
expectType<number>(result.insertedCount);
expectType<{[key: number]: Types.ObjectId;}>(result.insertedIds)
expectType<{ [key: number]: Types.ObjectId; }>(result.insertedIds);
});

Test.insertMany([{ name: 'test' }], { rawResult: true }).then(result => {
expectType<boolean>(result.acknowledged);
expectType<number>(result.insertedCount);
expectType<{[key: number]: Types.ObjectId;}>(result.insertedIds)
expectType<{ [key: number]: Types.ObjectId; }>(result.insertedIds);
});

Test.insertMany([{ name: 'test' }], { lean: true }).then(docs => {
Expand Down Expand Up @@ -181,7 +181,7 @@ Test.insertMany({ _id: new Types.ObjectId('000000000000000000000000'), name: 'te
expectType<boolean>(docs[0].isNew);
});

(async () => {
(async() => {
const [t1] = await Test.create([{ name: 'test' }]);
const [t2, t3, t4] = await Test.create({ name: 'test' }, { name: 'test' }, { name: 'test' });
(await Test.create([{ name: 'test' }]))[0];
Expand Down
14 changes: 7 additions & 7 deletions test/types/utility.test.ts
@@ -1,13 +1,13 @@
import { MergeType } from 'mongoose';
import { expectType } from 'tsd';

type A = { a: string, c: number};
type A = { a: string, c: number };
type B = { a: number, b: string };

expectType<string>({} as MergeType<B, A>["a"]);
expectType<string>({} as MergeType<B, A>["b"]);
expectType<number>({} as MergeType<B, A>["c"]);
expectType<string>({} as MergeType<B, A>['a']);
expectType<string>({} as MergeType<B, A>['b']);
expectType<number>({} as MergeType<B, A>['c']);

expectType<number>({} as MergeType<A, B>["a"]);
expectType<string>({} as MergeType<A, B>["b"]);
expectType<number>({} as MergeType<A, B>["c"]);
expectType<number>({} as MergeType<A, B>['a']);
expectType<string>({} as MergeType<A, B>['b']);
expectType<number>({} as MergeType<A, B>['c']);
12 changes: 6 additions & 6 deletions types/index.d.ts
Expand Up @@ -101,15 +101,15 @@ declare module 'mongoose' {
[k: string]: any
}

export type Require_id<T> = T extends { _id?: infer U }
export type Require_id<T> = T extends { _id?: infer U }
? U extends any
? (T & { _id: Types.ObjectId })
: T & Required<{ _id: U }>
: T & Required<{ _id: U }>
: T & { _id: Types.ObjectId };
export type RequireOnlyTypedId<T> = T extends { _id?: infer U; }
? Required<{ _id: U }>
: { _id: Types.ObjectId };

export type RequireOnlyTypedId<T> = T extends { _id?: infer U; }
? Required<{ _id: U }>
: { _id: Types.ObjectId };

export type HydratedDocument<DocType, TMethodsAndOverrides = {}, TVirtuals = {}> = DocType extends Document ? Require_id<DocType> : (Document<unknown, any, DocType> & Require_id<DocType> & TVirtuals & TMethodsAndOverrides);

Expand Down
58 changes: 29 additions & 29 deletions types/models.d.ts
Expand Up @@ -121,11 +121,11 @@ declare module 'mongoose' {
SessionStarter {
new <DocType = T>(doc?: DocType, fields?: any | null, options?: boolean | AnyObject): HydratedDocument<MergeType<T, DocType>, TMethodsAndOverrides, TVirtuals> & ObtainSchemaGeneric<TSchema, 'TStaticMethods'>;

aggregate<R = any>(pipeline?: PipelineStage[], options?: mongodb.AggregateOptions, callback?: Callback<R[]>): Aggregate<Array<R>>;
aggregate<R = any>(pipeline: PipelineStage[], callback?: Callback<R[]>): Aggregate<Array<R>>;
aggregate<R = any>(pipeline?: PipelineStage[], options?: mongodb.AggregateOptions, callback?: Callback<R[]>): Aggregate<Array<R>>;
aggregate<R = any>(pipeline: PipelineStage[], callback?: Callback<R[]>): Aggregate<Array<R>>;

/** Base Mongoose instance the model uses. */
base: Mongoose;
/** Base Mongoose instance the model uses. */
base: Mongoose;

/**
* If this is a discriminator model, `baseModelName` is the name of
Expand Down Expand Up @@ -178,8 +178,8 @@ declare module 'mongoose' {
createCollection<T extends mongodb.Document>(callback: Callback<mongodb.Collection<T>>): void;
createCollection<T extends mongodb.Document>(options?: mongodb.CreateCollectionOptions & Pick<SchemaOptions, 'expires'>): Promise<mongodb.Collection<T>>;

/** Connection the model uses. */
db: Connection;
/** Connection the model uses. */
db: Connection;

/**
* Deletes all of the documents that match `conditions` from the collection.
Expand Down Expand Up @@ -272,38 +272,38 @@ declare module 'mongoose' {
insertMany<DocContents = T>(doc: DocContents, options: InsertManyOptions): Promise<Array<HydratedDocument<MergeType<MergeType<T, DocContents>, RequireOnlyTypedId<T>>, TMethodsAndOverrides, TVirtuals>>>;
insertMany<DocContents = T>(doc: DocContents): Promise<Array<HydratedDocument<MergeType<MergeType<T, DocContents>, RequireOnlyTypedId<T>>, TMethodsAndOverrides, TVirtuals>>>;

/** The name of the model */
modelName: string;
/** The name of the model */
modelName: string;

/** Populates document references. */
populate(docs: Array<any>, options: PopulateOptions | Array<PopulateOptions> | string,
callback?: Callback<(HydratedDocument<T, TMethodsAndOverrides, TVirtuals>)[]>): Promise<Array<HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>>;
populate(doc: any, options: PopulateOptions | Array<PopulateOptions> | string,
callback?: Callback<HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>): Promise<HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>;
/** Populates document references. */
populate(docs: Array<any>, options: PopulateOptions | Array<PopulateOptions> | string,
callback?: Callback<(HydratedDocument<T, TMethodsAndOverrides, TVirtuals>)[]>): Promise<Array<HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>>;
populate(doc: any, options: PopulateOptions | Array<PopulateOptions> | string,
callback?: Callback<HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>): Promise<HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>;


/** Casts and validates the given object against this model's schema, passing the given `context` to custom validators. */
validate(callback?: CallbackWithoutResult): Promise<void>;
validate(optional: any, callback?: CallbackWithoutResult): Promise<void>;
validate(optional: any, pathsToValidate: PathsToValidate, callback?: CallbackWithoutResult): Promise<void>;
/** Casts and validates the given object against this model's schema, passing the given `context` to custom validators. */
validate(callback?: CallbackWithoutResult): Promise<void>;
validate(optional: any, callback?: CallbackWithoutResult): Promise<void>;
validate(optional: any, pathsToValidate: PathsToValidate, callback?: CallbackWithoutResult): Promise<void>;

/** Watches the underlying collection for changes using [MongoDB change streams](https://docs.mongodb.com/manual/changeStreams/). */
watch<ResultType extends mongodb.Document = any>(pipeline?: Array<Record<string, unknown>>, options?: mongodb.ChangeStreamOptions): mongodb.ChangeStream<ResultType>;
/** Watches the underlying collection for changes using [MongoDB change streams](https://docs.mongodb.com/manual/changeStreams/). */
watch<ResultType extends mongodb.Document = any>(pipeline?: Array<Record<string, unknown>>, options?: mongodb.ChangeStreamOptions): mongodb.ChangeStream<ResultType>;

/** Adds a `$where` clause to this query */
$where(argument: string | Function): QueryWithHelpers<Array<HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>, HydratedDocument<T, TMethodsAndOverrides, TVirtuals>, TQueryHelpers, T>;
/** Adds a `$where` clause to this query */
$where(argument: string | Function): QueryWithHelpers<Array<HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>, HydratedDocument<T, TMethodsAndOverrides, TVirtuals>, TQueryHelpers, T>;

/** Registered discriminators for this model. */
discriminators: { [name: string]: Model<any> } | undefined;
/** Registered discriminators for this model. */
discriminators: { [name: string]: Model<any> } | undefined;

/** Translate any aliases fields/conditions so the final query or document object is pure */
translateAliases(raw: any): any;
/** Translate any aliases fields/conditions so the final query or document object is pure */
translateAliases(raw: any): any;

/** Creates a `distinct` query: returns the distinct values of the given `field` that match `filter`. */
distinct<ReturnType = any>(field: string, filter?: FilterQuery<T>, callback?: Callback<number>): QueryWithHelpers<Array<ReturnType>, HydratedDocument<T, TMethodsAndOverrides, TVirtuals>, TQueryHelpers, T>;
/** Creates a `distinct` query: returns the distinct values of the given `field` that match `filter`. */
distinct<ReturnType = any>(field: string, filter?: FilterQuery<T>, callback?: Callback<number>): QueryWithHelpers<Array<ReturnType>, HydratedDocument<T, TMethodsAndOverrides, TVirtuals>, TQueryHelpers, T>;

/** Creates a `estimatedDocumentCount` query: counts the number of documents in the collection. */
estimatedDocumentCount(options?: QueryOptions<T>, callback?: Callback<number>): QueryWithHelpers<number, HydratedDocument<T, TMethodsAndOverrides, TVirtuals>, TQueryHelpers, T>;
/** Creates a `estimatedDocumentCount` query: counts the number of documents in the collection. */
estimatedDocumentCount(options?: QueryOptions<T>, callback?: Callback<number>): QueryWithHelpers<number, HydratedDocument<T, TMethodsAndOverrides, TVirtuals>, TQueryHelpers, T>;

/**
* Returns a document with its `_id` if at least one document exists in the database that matches
Expand Down
4 changes: 2 additions & 2 deletions types/utility.d.ts
Expand Up @@ -7,8 +7,8 @@ declare module 'mongoose' {
type UnpackedIntersection<T, U> = T extends null ? null : T extends (infer A)[]
? (Omit<A, keyof U> & U)[]
: keyof U extends never
? T
: Omit<T, keyof U> & U;
? T
: Omit<T, keyof U> & U;

type MergeType<A extends Record<number | string, any>, B extends Record<number | string, any>> = Omit<A, keyof B> & B;

Expand Down

0 comments on commit 98d75d4

Please sign in to comment.