mongoose 7.0.1 → 7.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,115 @@
1
+ 'use strict';
2
+
3
+ let config;
4
+ try {
5
+ config = require('../.config.js');
6
+ } finally {
7
+ if (!config || !config.uri) {
8
+ console.error('No Config or config.URI given, please create a .config.js file with those values in the root of the repository');
9
+ process.exit(-1);
10
+ }
11
+ }
12
+ const axios = require('axios');
13
+ const fs = require('fs');
14
+ const mongoose = require('../');
15
+
16
+ run().catch(err => {
17
+ console.error(err);
18
+ process.exit(-1);
19
+ });
20
+
21
+ // only "." because fs resolves relative to the CWD instead of relative to __dirname
22
+ const docsDir = './docs';
23
+
24
+ async function run() {
25
+ await mongoose.connect(config.uri);
26
+
27
+ const Subscriber = mongoose.model('Subscriber', mongoose.Schema({
28
+ companyName: String,
29
+ description: String,
30
+ url: String,
31
+ logo: String
32
+ }), 'Subscriber');
33
+
34
+ const Job = mongoose.model('Job', mongoose.Schema({
35
+ logo: String,
36
+ company: String,
37
+ title: String,
38
+ location: {
39
+ type: String,
40
+ required: true
41
+ },
42
+ description: {
43
+ type: String,
44
+ required: true
45
+ },
46
+ url: {
47
+ type: String,
48
+ required: true
49
+ }
50
+ }), 'Job');
51
+
52
+ const OpenCollectiveSponsor = mongoose.model('OpenCollectiveSponsor', mongoose.Schema({
53
+ openCollectiveId: {
54
+ type: Number,
55
+ required: true
56
+ },
57
+ website: {
58
+ type: String,
59
+ required: true
60
+ },
61
+ image: {
62
+ type: String,
63
+ required: true
64
+ },
65
+ alt: {
66
+ type: String
67
+ }
68
+ }), 'OpenCollectiveSponsor');
69
+
70
+ try {
71
+ fs.mkdirSync(`${docsDir}/data`);
72
+ } catch (err) {}
73
+
74
+ const subscribers = await Subscriber.
75
+ find({ companyName: { $exists: true }, description: { $exists: true }, logo: { $exists: true } }).
76
+ sort({ createdAt: 1 }).
77
+ select({ companyName: 1, description: 1, url: 1, logo: 1 });
78
+ fs.writeFileSync(`${docsDir}/data/sponsors.json`, JSON.stringify(subscribers, null, ' '));
79
+
80
+ const jobs = await Job.find().select({ logo: 1, company: 1, title: 1, location: 1, description: 1, url: 1 });
81
+ fs.writeFileSync(`${docsDir}/data/jobs.json`, JSON.stringify(jobs, null, ' '));
82
+
83
+ const opencollectiveSponsors = await axios.get('https://opencollective.com/mongoose/members.json').
84
+ then(res => res.data).
85
+ then(sponsors => {
86
+ return sponsors.filter(result => result.tier == 'sponsor' && result.isActive);
87
+ }).
88
+ catch(() => null);
89
+
90
+ for (const sponsor of opencollectiveSponsors) {
91
+ const override = await OpenCollectiveSponsor.findOne({ openCollectiveId: sponsor['MemberId'] });
92
+ if (override == null) {
93
+ continue;
94
+ }
95
+
96
+ sponsor.website = override.website;
97
+ sponsor.image = override.image;
98
+ if (override.alt != null) {
99
+ sponsor.alt = override.alt;
100
+ }
101
+ }
102
+
103
+ const additionalSponsors = await OpenCollectiveSponsor.find({}).
104
+ then(docs => docs.filter(doc => doc.openCollectiveId == null));
105
+ for (const sponsor of additionalSponsors) {
106
+ opencollectiveSponsors.push(sponsor);
107
+ }
108
+
109
+ if (opencollectiveSponsors != null) {
110
+ fs.writeFileSync(`${docsDir}/data/opencollective.json`, JSON.stringify(opencollectiveSponsors, null, ' '));
111
+ }
112
+
113
+ console.log('Done');
114
+ process.exit(0);
115
+ }
package/types/cursor.d.ts CHANGED
@@ -38,8 +38,8 @@ declare module 'mongoose' {
38
38
  * will wait for the promise to resolve before iterating on to the next one.
39
39
  * Returns a promise that resolves when done.
40
40
  */
41
- eachAsync(fn: (doc: DocType[]) => any, options: EachAsyncOptions & { batchSize: number }): Promise<void>;
42
- eachAsync(fn: (doc: DocType) => any, options?: EachAsyncOptions): Promise<void>;
41
+ eachAsync(fn: (doc: DocType[], i: number) => any, options: EachAsyncOptions & { batchSize: number }): Promise<void>;
42
+ eachAsync(fn: (doc: DocType, i: number) => any, options?: EachAsyncOptions): Promise<void>;
43
43
 
44
44
  /**
45
45
  * Registers a transform function which subsequently maps documents retrieved
package/types/models.d.ts CHANGED
@@ -316,6 +316,24 @@ declare module 'mongoose' {
316
316
  docs: Array<DocContents | TRawDocType>,
317
317
  options: InsertManyOptions & { lean: true; }
318
318
  ): Promise<Array<MergeType<MergeType<TRawDocType, DocContents>, Require_id<TRawDocType>>>>;
319
+ insertMany<DocContents = TRawDocType>(
320
+ doc: DocContents,
321
+ options: InsertManyOptions & { ordered: false; rawResult: true; }
322
+ ): Promise<mongodb.InsertManyResult<TRawDocType> & {
323
+ mongoose: {
324
+ validationErrors: Error[];
325
+ results: Array<
326
+ Error |
327
+ Object |
328
+ HydratedDocument<
329
+ MergeType<
330
+ MergeType<TRawDocType, DocContents>,
331
+ Require_id<TRawDocType>
332
+ >
333
+ >
334
+ >
335
+ }
336
+ }>;
319
337
  insertMany<DocContents = TRawDocType>(
320
338
  docs: Array<DocContents | TRawDocType>,
321
339
  options: InsertManyOptions & { rawResult: true; }
package/types/query.d.ts CHANGED
@@ -109,7 +109,7 @@ declare module 'mongoose' {
109
109
  /**
110
110
  * If truthy, mongoose will return the document as a plain JavaScript object rather than a mongoose document.
111
111
  */
112
- lean?: boolean | any;
112
+ lean?: boolean | Record<string, any>;
113
113
  limit?: number;
114
114
  maxTimeMS?: number;
115
115
  multi?: boolean;
@@ -430,7 +430,7 @@ declare module 'mongoose' {
430
430
  j(val: boolean | null): this;
431
431
 
432
432
  /** Sets the lean option. */
433
- lean<LeanResultType = ResultType extends any[] ? Require_id<RawDocType>[] : Require_id<RawDocType>>(val?: boolean | any): QueryWithHelpers<LeanResultType, DocType, THelpers, RawDocType>;
433
+ lean<LeanResultType = ResultType extends any[] ? Require_id<RawDocType>[] : Require_id<RawDocType>>(val?: boolean | any): QueryWithHelpers<ResultType extends null ? LeanResultType | null : LeanResultType, DocType, THelpers, RawDocType>;
434
434
 
435
435
  /** Specifies the maximum number of documents the query will return. */
436
436
  limit(val: number): this;
@@ -532,7 +532,7 @@ declare module 'mongoose' {
532
532
  replaceOne(filter?: FilterQuery<DocType>, replacement?: DocType | AnyObject, options?: QueryOptions<DocType> | null): QueryWithHelpers<any, DocType, THelpers, RawDocType>;
533
533
 
534
534
  /** Specifies which document fields to include or exclude (also known as the query "projection") */
535
- select(arg: string | any): this;
535
+ select(arg: string | string[] | Record<string, number | boolean | object>): this;
536
536
 
537
537
  /** Determines if field selection has been made. */
538
538
  selected(): boolean;
package/types/types.d.ts CHANGED
@@ -61,7 +61,7 @@ declare module 'mongoose' {
61
61
 
62
62
  class DocumentArray<T> extends Types.Array<T extends Types.Subdocument ? T : Types.Subdocument<InferId<T>> & T> {
63
63
  /** DocumentArray constructor */
64
- constructor(values: any[]);
64
+ constructor(values: AnyObject[]);
65
65
 
66
66
  isMongooseDocumentArray: true;
67
67
 
package/.eslintrc.json DELETED
@@ -1,195 +0,0 @@
1
- {
2
- "extends": [
3
- "eslint:recommended"
4
- ],
5
- "ignorePatterns": [
6
- "docs",
7
- "tools",
8
- "dist",
9
- "website.js",
10
- "test/files/*",
11
- "benchmarks"
12
- ],
13
- "overrides": [
14
- {
15
- "files": [
16
- "**/*.{ts,tsx}"
17
- ],
18
- "extends": [
19
- "plugin:@typescript-eslint/eslint-recommended",
20
- "plugin:@typescript-eslint/recommended"
21
- ],
22
- "plugins": [
23
- "@typescript-eslint"
24
- ],
25
- "rules": {
26
- "@typescript-eslint/triple-slash-reference": "off",
27
- "@typescript-eslint/no-non-null-assertion": "off",
28
- "@typescript-eslint/no-empty-function": "off",
29
- "spaced-comment": [
30
- "error",
31
- "always",
32
- {
33
- "block": {
34
- "markers": [
35
- "!"
36
- ],
37
- "balanced": true
38
- },
39
- "markers": [
40
- "/"
41
- ]
42
- }
43
- ],
44
- "@typescript-eslint/no-explicit-any": "off",
45
- "@typescript-eslint/ban-types": "off",
46
- "@typescript-eslint/no-unused-vars": "off",
47
- "@typescript-eslint/explicit-module-boundary-types": "off",
48
- "@typescript-eslint/indent": [
49
- "warn",
50
- 2,
51
- {
52
- "SwitchCase": 1,
53
- "ignoredNodes": ["TSTypeParameterInstantiation"]
54
- }
55
- ],
56
- "@typescript-eslint/prefer-optional-chain": "error",
57
- "@typescript-eslint/brace-style": "error",
58
- "@typescript-eslint/no-dupe-class-members": "error",
59
- "@typescript-eslint/no-redeclare": "error",
60
- "@typescript-eslint/type-annotation-spacing": "error",
61
- "@typescript-eslint/object-curly-spacing": [
62
- "error",
63
- "always"
64
- ],
65
- "@typescript-eslint/semi": "error",
66
- "@typescript-eslint/space-before-function-paren": [
67
- "error",
68
- "never"
69
- ],
70
- "@typescript-eslint/space-infix-ops": "off"
71
- }
72
- }
73
- ],
74
- "plugins": [
75
- "mocha-no-only"
76
- ],
77
- "parserOptions": {
78
- "ecmaVersion": 2020
79
- },
80
- "env": {
81
- "node": true,
82
- "es6": true
83
- },
84
- "rules": {
85
- "comma-style": "error",
86
- "indent": [
87
- "error",
88
- 2,
89
- {
90
- "SwitchCase": 1,
91
- "VariableDeclarator": 2
92
- }
93
- ],
94
- "keyword-spacing": "error",
95
- "no-whitespace-before-property": "error",
96
- "no-buffer-constructor": "warn",
97
- "no-console": "off",
98
- "no-constant-condition": "off",
99
- "no-multi-spaces": "error",
100
- "func-call-spacing": "error",
101
- "no-trailing-spaces": "error",
102
- "no-undef": "error",
103
- "no-unneeded-ternary": "error",
104
- "no-const-assign": "error",
105
- "no-useless-rename": "error",
106
- "no-dupe-keys": "error",
107
- "space-in-parens": [
108
- "error",
109
- "never"
110
- ],
111
- "spaced-comment": [
112
- "error",
113
- "always",
114
- {
115
- "block": {
116
- "markers": [
117
- "!"
118
- ],
119
- "balanced": true
120
- }
121
- }
122
- ],
123
- "key-spacing": [
124
- "error",
125
- {
126
- "beforeColon": false,
127
- "afterColon": true
128
- }
129
- ],
130
- "comma-spacing": [
131
- "error",
132
- {
133
- "before": false,
134
- "after": true
135
- }
136
- ],
137
- "array-bracket-spacing": 1,
138
- "arrow-spacing": [
139
- "error",
140
- {
141
- "before": true,
142
- "after": true
143
- }
144
- ],
145
- "object-curly-spacing": [
146
- "error",
147
- "always"
148
- ],
149
- "comma-dangle": [
150
- "error",
151
- "never"
152
- ],
153
- "no-unreachable": "error",
154
- "quotes": [
155
- "error",
156
- "single"
157
- ],
158
- "quote-props": [
159
- "error",
160
- "as-needed"
161
- ],
162
- "semi": "error",
163
- "no-extra-semi": "error",
164
- "semi-spacing": "error",
165
- "no-spaced-func": "error",
166
- "no-throw-literal": "error",
167
- "space-before-blocks": "error",
168
- "space-before-function-paren": [
169
- "error",
170
- "never"
171
- ],
172
- "space-infix-ops": "error",
173
- "space-unary-ops": "error",
174
- "no-var": "warn",
175
- "prefer-const": "warn",
176
- "strict": [
177
- "error",
178
- "global"
179
- ],
180
- "no-restricted-globals": [
181
- "error",
182
- {
183
- "name": "context",
184
- "message": "Don't use Mocha's global context"
185
- }
186
- ],
187
- "no-prototype-builtins": "off",
188
- "mocha-no-only/mocha-no-only": [
189
- "error"
190
- ],
191
- "no-empty": "off",
192
- "eol-last": "warn",
193
- "no-multiple-empty-lines": ["warn", { "max": 2 }]
194
- }
195
- }