Skip to content

Commit

Permalink
Merge branch 'master' into vkarpov15/gh-12593
Browse files Browse the repository at this point in the history
  • Loading branch information
vkarpov15 committed Nov 4, 2022
2 parents 243e4d4 + ae14d0e commit e559695
Show file tree
Hide file tree
Showing 14 changed files with 79 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/benchmark.yml
Expand Up @@ -22,7 +22,7 @@ jobs:
runs-on: ubuntu-20.04
name: Benchmark TypeScript Types
steps:
- uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b # v3.0.2
- uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # v3.1.0
with:
fetch-depth: 0
- name: Setup node
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/codeql.yml
Expand Up @@ -21,7 +21,7 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # v3.1.0

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/documentation.yml
Expand Up @@ -28,7 +28,7 @@ jobs:
runs-on: ubuntu-20.04
name: Test Generating Docs
steps:
- uses: actions/checkout@a12a3943b4bdde767164f792f33f40b04645d846 # v3
- uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # v3.1.0

- name: Setup node
uses: actions/setup-node@8c91899e586c5b171469028077307d293428b516 # v3.5.1
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/test.yml
Expand Up @@ -22,7 +22,7 @@ jobs:
runs-on: ubuntu-latest
name: Lint JS-Files
steps:
- uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b # v3.0.2
- uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # v3.1.0

- name: Setup node
uses: actions/setup-node@8c91899e586c5b171469028077307d293428b516 # v3.5.1
Expand Down Expand Up @@ -59,7 +59,7 @@ jobs:
MONGOMS_VERSION: ${{ matrix.mongodb }}
MONGOMS_PREFER_GLOBAL_PATH: 1
steps:
- uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b # v3.0.2
- uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # v3.1.0

- name: Setup node
uses: actions/setup-node@8c91899e586c5b171469028077307d293428b516 # v3.5.1
Expand Down Expand Up @@ -93,7 +93,7 @@ jobs:
runs-on: ubuntu-latest
name: Replica Set tests
steps:
- uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b # v3.0.2
- uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # v3.1.0
- name: Setup node
uses: actions/setup-node@8c91899e586c5b171469028077307d293428b516 # v3.5.1
with:
Expand All @@ -110,6 +110,6 @@ jobs:
contents: read
steps:
- name: Check out repo
uses: actions/checkout@v3
uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # v3.1.0
- name: Dependency review
uses: actions/dependency-review-action@v2
2 changes: 1 addition & 1 deletion .github/workflows/tidelift-alignment.yml
Expand Up @@ -15,7 +15,7 @@ jobs:
if: github.repository == 'Automattic/mongoose'
steps:
- name: Checkout
uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b # v3.0.2
uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # v3.1.0
- name: Setup node
uses: actions/setup-node@8c91899e586c5b171469028077307d293428b516 # v3.5.1
with:
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/tsd.yml
Expand Up @@ -22,7 +22,7 @@ jobs:
runs-on: ubuntu-latest
name: Lint TS-Files
steps:
- uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b # v3.0.2
- uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # v3.1.0

- name: Setup node
uses: actions/setup-node@8c91899e586c5b171469028077307d293428b516 # v3.5.1
Expand All @@ -40,7 +40,7 @@ jobs:
runs-on: ubuntu-latest
name: Test Typescript Types
steps:
- uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b # v3.0.2
- uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # v3.1.0

- name: Setup node
uses: actions/setup-node@8c91899e586c5b171469028077307d293428b516 # v3.5.1
Expand All @@ -50,4 +50,4 @@ jobs:
- run: npm install

- name: Typings
run: npm run test-tsd
run: npm run test-tsd
12 changes: 12 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,15 @@
6.7.1 / 2022-11-02
==================
* fix(query): select Map field with select: false when explicitly requested #12616 #12603 [lpizzinidev](https://github.com/lpizzinidev)
* fix: correctly find paths underneath single nested document with an array of mixed #12605 #12530
* fix(populate): better support for populating maps of arrays of refs #12601 #12494
* fix(types): add missing create constructor signature override type #12585 [naorpeled](https://github.com/naorpeled)
* fix(types): make array paths optional in inferred type of array default returns undefined #12649 #12420
* fix(types): improve ValidateOpts type #12606 [Freezystem](https://github.com/Freezystem)
* docs: add Lodash guide highlighting issues with cloneDeep() #12609
* docs: removed v5 link from v6 docs #12641 #12624 [lpizzinidev](https://github.com/lpizzinidev)
* docs: removed outdated connection example #12618 [lpizzinidev](https://github.com/lpizzinidev)

6.7.0 / 2022-10-24
==================
* feat: upgrade to mongodb driver 4.11.0 #12446
Expand Down
9 changes: 6 additions & 3 deletions docs/loadSponsorData.js
Expand Up @@ -5,9 +5,6 @@ const config = require('../.config');
const fs = require('fs');
const mongoose = require('../');

const poralHost = 'https://staging.poral.io';
const opencollectiveUrl = `${poralHost}/invoke/${config.poralId}/generateSponsors`;

run().catch(err => {
console.error(err);
process.exit(-1);
Expand Down Expand Up @@ -91,6 +88,12 @@ async function run() {
sponsor.alt = override.alt;
}
}

const additionalSponsors = await OpenCollectiveSponsor.find({}).
then(docs => docs.filter(doc => doc.openCollectiveId == null));
for (const sponsor of additionalSponsors) {
opencollectiveSponsors.push(sponsor);
}

if (opencollectiveSponsors != null) {
fs.writeFileSync(`${__dirname}/data/opencollective.json`, JSON.stringify(opencollectiveSponsors, null, ' '));
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,7 +1,7 @@
{
"name": "mongoose",
"description": "Mongoose MongoDB ODM",
"version": "6.7.0",
"version": "6.7.1",
"author": "Guillermo Rauch <guillermo@learnboost.com>",
"keywords": [
"mongodb",
Expand Down
8 changes: 8 additions & 0 deletions test/types/models.test.ts
Expand Up @@ -192,6 +192,14 @@ projectSchema.post('save', function() {
// this => IProject
});

projectSchema.pre('deleteOne', function() {
this.model;
});

projectSchema.post('deleteOne', function() {
this.model;
});

projectSchema.methods.myMethod = () => 10;

projectSchema.statics.myStatic = () => 42;
Expand Down
27 changes: 27 additions & 0 deletions test/types/schema.test.ts
Expand Up @@ -412,6 +412,7 @@ export function autoTypedSchema() {
array5: any[];
array6: string[];
array7?: string[];
array8?: string[];
decimal1?: Types.Decimal128;
decimal2?: Types.Decimal128;
decimal3?: Types.Decimal128;
Expand Down Expand Up @@ -458,6 +459,7 @@ export function autoTypedSchema() {
array5: [],
array6: { type: [String] },
array7: { type: [String], default: undefined },
array8: { type: [String], default: () => undefined },
decimal1: Schema.Types.Decimal128,
decimal2: 'Decimal128',
decimal3: 'decimal128'
Expand Down Expand Up @@ -893,3 +895,28 @@ async function gh12593() {
type ExampleArr = InferSchemaType<typeof arrSchema>;
expectType<{ arr: Buffer[] }>({} as ExampleArr);
}

function gh12562() {
const emailRegExp = /@/;
const userSchema = new Schema(
{
email: {
type: String,
trim: true,
validate: {
validator: (value: string) => emailRegExp.test(value),
message: 'Email is not valid'
},
index: { // uncomment the index object and for me trim was throwing an error
partialFilterExpression: {
email: {
$exists: true,
$ne: null
}
}
},
select: false
}
}
);
}
12 changes: 6 additions & 6 deletions types/index.d.ts
Expand Up @@ -274,19 +274,19 @@ declare module 'mongoose' {
plugin<PFunc extends PluginFunction<DocType, M, any, any, any, any>, POptions extends Parameters<PFunc>[1] = Parameters<PFunc>[1]>(fn: PFunc, opts?: POptions): this;

/** Defines a post hook for the model. */
post<T = HydratedDocument<DocType, TInstanceMethods>>(method: MongooseDocumentMiddleware | MongooseDocumentMiddleware[] | RegExp, fn: PostMiddlewareFunction<T, T>): this;
post<T = HydratedDocument<DocType, TInstanceMethods>>(method: MongooseDocumentMiddleware | MongooseDocumentMiddleware[] | RegExp, options: SchemaPostOptions, fn: PostMiddlewareFunction<T, T>): this;
post<T = Query<any, any>>(method: MongooseQueryMiddleware | MongooseQueryMiddleware[] | RegExp, fn: PostMiddlewareFunction<T, QueryResultType<T>>): this;
post<T = Query<any, any>>(method: MongooseQueryMiddleware | MongooseQueryMiddleware[] | RegExp, options: SchemaPostOptions, fn: PostMiddlewareFunction<T, QueryResultType<T>>): this;
post<T = HydratedDocument<DocType, TInstanceMethods>>(method: MongooseDocumentMiddleware | MongooseDocumentMiddleware[] | RegExp, fn: PostMiddlewareFunction<T, T>): this;
post<T = HydratedDocument<DocType, TInstanceMethods>>(method: MongooseDocumentMiddleware | MongooseDocumentMiddleware[] | RegExp, options: SchemaPostOptions, fn: PostMiddlewareFunction<T, T>): this;
post<T extends Aggregate<any>>(method: 'aggregate' | RegExp, fn: PostMiddlewareFunction<T, Array<AggregateExtract<T>>>): this;
post<T extends Aggregate<any>>(method: 'aggregate' | RegExp, options: SchemaPostOptions, fn: PostMiddlewareFunction<T, Array<AggregateExtract<T>>>): this;
post<T = M>(method: 'insertMany' | RegExp, fn: PostMiddlewareFunction<T, T>): this;
post<T = M>(method: 'insertMany' | RegExp, options: SchemaPostOptions, fn: PostMiddlewareFunction<T, T>): this;

post<T = HydratedDocument<DocType, TInstanceMethods>>(method: MongooseDocumentMiddleware | MongooseDocumentMiddleware[] | RegExp, fn: ErrorHandlingMiddlewareFunction<T>): this;
post<T = HydratedDocument<DocType, TInstanceMethods>>(method: MongooseDocumentMiddleware | MongooseDocumentMiddleware[] | RegExp, options: SchemaPostOptions, fn: ErrorHandlingMiddlewareFunction<T>): this;
post<T = Query<any, any>>(method: MongooseQueryMiddleware | MongooseQueryMiddleware[] | RegExp, fn: ErrorHandlingMiddlewareFunction<T>): this;
post<T = Query<any, any>>(method: MongooseQueryMiddleware | MongooseQueryMiddleware[] | RegExp, options: SchemaPostOptions, fn: ErrorHandlingMiddlewareFunction<T>): this;
post<T = HydratedDocument<DocType, TInstanceMethods>>(method: MongooseDocumentMiddleware | MongooseDocumentMiddleware[] | RegExp, fn: ErrorHandlingMiddlewareFunction<T>): this;
post<T = HydratedDocument<DocType, TInstanceMethods>>(method: MongooseDocumentMiddleware | MongooseDocumentMiddleware[] | RegExp, options: SchemaPostOptions, fn: ErrorHandlingMiddlewareFunction<T>): this;
post<T extends Aggregate<any>>(method: 'aggregate' | RegExp, fn: ErrorHandlingMiddlewareFunction<T, Array<any>>): this;
post<T extends Aggregate<any>>(method: 'aggregate' | RegExp, options: SchemaPostOptions, fn: ErrorHandlingMiddlewareFunction<T, Array<any>>): this;
post<T = M>(method: 'insertMany' | RegExp, fn: ErrorHandlingMiddlewareFunction<T>): this;
Expand All @@ -295,10 +295,10 @@ declare module 'mongoose' {
/** Defines a pre hook for the model. */
pre<T = HydratedDocument<DocType, TInstanceMethods>>(method: 'save', fn: PreSaveMiddlewareFunction<T>): this;
pre<T = HydratedDocument<DocType, TInstanceMethods>>(method: 'save', options: SchemaPreOptions, fn: PreSaveMiddlewareFunction<T>): this;
pre<T = HydratedDocument<DocType, TInstanceMethods>>(method: MongooseDocumentMiddleware | MongooseDocumentMiddleware[] | RegExp, fn: PreMiddlewareFunction<T>): this;
pre<T = HydratedDocument<DocType, TInstanceMethods>>(method: MongooseDocumentMiddleware | MongooseDocumentMiddleware[] | RegExp, options: SchemaPreOptions, fn: PreMiddlewareFunction<T>): this;
pre<T = Query<any, any>>(method: MongooseQueryMiddleware | MongooseQueryMiddleware[] | RegExp, fn: PreMiddlewareFunction<T>): this;
pre<T = Query<any, any>>(method: MongooseQueryMiddleware | MongooseQueryMiddleware[] | RegExp, options: SchemaPreOptions, fn: PreMiddlewareFunction<T>): this;
pre<T = HydratedDocument<DocType, TInstanceMethods>>(method: MongooseDocumentMiddleware | MongooseDocumentMiddleware[] | RegExp, fn: PreMiddlewareFunction<T>): this;
pre<T = HydratedDocument<DocType, TInstanceMethods>>(method: MongooseDocumentMiddleware | MongooseDocumentMiddleware[] | RegExp, options: SchemaPreOptions, fn: PreMiddlewareFunction<T>): this;
pre<T extends Aggregate<any>>(method: 'aggregate' | RegExp, fn: PreMiddlewareFunction<T>): this;
pre<T extends Aggregate<any>>(method: 'aggregate' | RegExp, options: SchemaPreOptions, fn: PreMiddlewareFunction<T>): this;
pre<T = M>(method: 'insertMany' | RegExp, fn: (this: T, next: (err?: CallbackError) => void, docs: any | Array<any>) => void | Promise<void>): this;
Expand Down
8 changes: 7 additions & 1 deletion types/inferschematype.d.ts
Expand Up @@ -60,6 +60,12 @@ declare module 'mongoose' {
: unknown;
}

type IsPathDefaultUndefined<PathType> = PathType extends { default: undefined } ?
true :
PathType extends { default: (...args: any[]) => undefined } ?
true :
false;

/**
* @summary Checks if a document path is required or optional.
* @param {P} P Document path.
Expand All @@ -69,7 +75,7 @@ type IsPathRequired<P, TypeKey extends TypeKeyBaseType = DefaultTypeKey> =
P extends { required: true | [true, string | undefined] } | ArrayConstructor | any[]
? true
: P extends (Record<TypeKey, ArrayConstructor | any[]>)
? P extends { default: undefined }
? IsPathDefaultUndefined<P> extends true
? false
: true
: P extends (Record<TypeKey, any>)
Expand Down
2 changes: 1 addition & 1 deletion types/schematypes.d.ts
Expand Up @@ -100,7 +100,7 @@ declare module 'mongoose' {
* If [truthy](https://masteringjs.io/tutorials/fundamentals/truthy), Mongoose will
* build an index on this path when the model is compiled.
*/
index?: boolean | IndexDirection;
index?: boolean | IndexDirection | IndexOptions;

/**
* If [truthy](https://masteringjs.io/tutorials/fundamentals/truthy), Mongoose
Expand Down

0 comments on commit e559695

Please sign in to comment.