Skip to content

Commit

Permalink
Merge pull request #13670 from Automattic/IslandRhythms/backport-pull…
Browse files Browse the repository at this point in the history
…-12954

Island rhythms/backport pull 12954
  • Loading branch information
vkarpov15 authored Aug 1, 2023
2 parents 11bb2c4 + 443092a commit 78257e2
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 10 deletions.
31 changes: 26 additions & 5 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1213,6 +1213,27 @@ declare module 'mongoose' {
lean?: boolean;
}

interface GeoNear {
/** [`$geoNear` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/geoNear/) */
$geoNear: {
near: { type: 'Point'; coordinates: [number, number] } | [number, number];
distanceField: string;
distanceMultiplier?: number;
includeLocs?: string;
key?: string;
maxDistance?: number;
minDistance?: number;
query?: AnyObject;
spherical?: boolean;
uniqueDocs?: boolean;
/**
* Deprecated. Use only with MondoDB below 4.2 (removed in 4.2)
* @deprecated
*/
num?: number;
}
}

interface PopulateOptions {
/** space delimited path(s) to populate */
path: string;
Expand Down Expand Up @@ -1336,7 +1357,7 @@ declare module 'mongoose' {
/** Lists all paths and their type in the schema. */
paths: {
[key: string]: SchemaType;
}
};

/** Returns the pathType of `path` for this schema. */
pathType(path: string): string;
Expand Down Expand Up @@ -1692,7 +1713,7 @@ declare module 'mongoose' {
enum?: Array<string | number | null> | ReadonlyArray<string | number | null> | { values: Array<string | number | null> | ReadonlyArray<string | number | null>, message?: string } | { [path: string]: string | number | null };

/** The default [subtype](http://bsonspec.org/spec.html) associated with this buffer when it is stored in MongoDB. Only allowed for buffer paths */
subtype?: number
subtype?: number;

/** The minimum value allowed for this path. Only allowed for numbers and dates. */
min?: number | NativeDate | [number, string] | [NativeDate, string] | readonly [number, string] | readonly [NativeDate, string];
Expand Down Expand Up @@ -2754,10 +2775,10 @@ declare module 'mongoose' {
model(model: any): this;

/**
* Append a new $near operator to this aggregation pipeline
* @param arg $near operator contents
* Append a new $geoNear operator to this aggregation pipeline
* @param arg $geoNear operator contents
*/
near(arg: { near?: number[]; distanceField: string; maxDistance?: number; query?: Record<string, any>; includeLocs?: string; num?: number; uniqueDocs?: boolean }): this;
near(arg: GeoNear['$geoNear']): this;

/** Returns the current pipeline */
pipeline(): any[];
Expand Down
6 changes: 3 additions & 3 deletions lib/aggregate.js
Original file line number Diff line number Diff line change
Expand Up @@ -314,13 +314,13 @@ Aggregate.prototype.project = function(arg) {
* ####Examples:
*
* aggregate.near({
* near: [40.724, -73.997],
* near: { type: 'Point', coordinates: [40.724, -73.997] },
* distanceField: "dist.calculated", // required
* maxDistance: 0.008,
* query: { type: "public" },
* includeLocs: "dist.location",
* uniqueDocs: true,
* num: 5
* spherical: true,
* uniqueDocs: true
* });
*
* @see $geoNear http://docs.mongodb.org/manual/reference/aggregation/geoNear/
Expand Down
4 changes: 2 additions & 2 deletions test/typescript/generics.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { Model, Document } from 'mongoose';

class Repository<T> {
private readonly Model: Model<T & Document>
private readonly Model: Model<T & Document>;

findById(id:string): Promise<T & Document> {
return Model.findById(id).exec();
}
}

class Foo {
name: string
name: string;
}

type Test = Repository<Foo>;

0 comments on commit 78257e2

Please sign in to comment.