mongoose 7.6.0 → 7.6.2
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.
- package/dist/browser.umd.js +1 -1
- package/lib/model.js +34 -21
- package/lib/query.js +1 -1
- package/lib/schema/SubdocumentPath.js +6 -0
- package/lib/schema/documentarray.js +6 -0
- package/lib/schema.js +12 -20
- package/package.json +2 -11
- package/types/document.d.ts +5 -0
- package/types/inferschematype.d.ts +1 -1
- package/types/models.d.ts +31 -1
- package/types/query.d.ts +5 -0
- package/.eslintrc.js +0 -236
- package/.markdownlint-cli2.cjs +0 -69
- package/.mocharc.yml +0 -4
- package/lgtm.yml +0 -12
- package/scripts/build-browser.js +0 -18
- package/scripts/create-tarball.js +0 -7
- package/scripts/generateSearch.js +0 -161
- package/scripts/loadSponsorData.js +0 -115
- package/scripts/tsc-diagnostics-check.js +0 -15
- package/tools/auth.js +0 -31
- package/tools/repl.js +0 -35
- package/tools/sharded.js +0 -46
- package/tsconfig.json +0 -9
package/.mocharc.yml
DELETED
package/lgtm.yml
DELETED
package/scripts/build-browser.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const config = require('../webpack.config.js');
|
|
4
|
-
const webpack = require('webpack');
|
|
5
|
-
|
|
6
|
-
const compiler = webpack(config);
|
|
7
|
-
|
|
8
|
-
console.log('Starting browser build...');
|
|
9
|
-
compiler.run((err, stats) => {
|
|
10
|
-
if (err) {
|
|
11
|
-
console.err(stats.toString());
|
|
12
|
-
console.err('Browser build unsuccessful.');
|
|
13
|
-
process.exit(1);
|
|
14
|
-
}
|
|
15
|
-
console.log(stats.toString());
|
|
16
|
-
console.log('Browser build successful.');
|
|
17
|
-
process.exit(0);
|
|
18
|
-
});
|
|
@@ -1,161 +0,0 @@
|
|
|
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 cheerio = require('cheerio');
|
|
13
|
-
const docsFilemap = require('../docs/source');
|
|
14
|
-
const fs = require('fs');
|
|
15
|
-
const pug = require('pug');
|
|
16
|
-
const mongoose = require('../');
|
|
17
|
-
let { version } = require('../package.json');
|
|
18
|
-
|
|
19
|
-
const { marked: markdown } = require('marked');
|
|
20
|
-
const highlight = require('highlight.js');
|
|
21
|
-
markdown.setOptions({
|
|
22
|
-
highlight: function(code) {
|
|
23
|
-
return highlight.highlight(code, { language: 'JavaScript' }).value;
|
|
24
|
-
}
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
// 5.13.5 -> 5.x, 6.8.2 -> 6.x, etc.
|
|
28
|
-
version = version.slice(0, version.indexOf('.')) + '.x';
|
|
29
|
-
|
|
30
|
-
const contentSchema = new mongoose.Schema({
|
|
31
|
-
title: { type: String, required: true },
|
|
32
|
-
body: { type: String, required: true },
|
|
33
|
-
url: { type: String, required: true },
|
|
34
|
-
version: { type: String, required: true, default: version },
|
|
35
|
-
versionNumber: { type: Number, required: true, default: version.replace(/\.x$/, '') }
|
|
36
|
-
});
|
|
37
|
-
contentSchema.index({ title: 'text', body: 'text' });
|
|
38
|
-
const Content = mongoose.model('Content', contentSchema, 'Content');
|
|
39
|
-
|
|
40
|
-
const contents = [];
|
|
41
|
-
|
|
42
|
-
for (const [filename, file] of Object.entries(docsFilemap.fileMap)) {
|
|
43
|
-
if (file.api) {
|
|
44
|
-
for (const prop of file.props) {
|
|
45
|
-
const content = new Content({
|
|
46
|
-
title: `API: ${prop.name}`,
|
|
47
|
-
body: prop.description,
|
|
48
|
-
url: `${filename}#${prop.anchorId}`
|
|
49
|
-
});
|
|
50
|
-
const err = content.validateSync();
|
|
51
|
-
if (err != null) {
|
|
52
|
-
console.error(content);
|
|
53
|
-
throw err;
|
|
54
|
-
}
|
|
55
|
-
contents.push(content);
|
|
56
|
-
}
|
|
57
|
-
} else if (file.markdown) {
|
|
58
|
-
let text = fs.readFileSync(filename, 'utf8');
|
|
59
|
-
text = markdown.parse(text);
|
|
60
|
-
|
|
61
|
-
const content = new Content({
|
|
62
|
-
title: file.title,
|
|
63
|
-
body: text,
|
|
64
|
-
url: filename.replace('.md', '.html').replace(/^docs/, '')
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
content.validateSync();
|
|
68
|
-
|
|
69
|
-
const $ = cheerio.load(text);
|
|
70
|
-
|
|
71
|
-
contents.push(content);
|
|
72
|
-
|
|
73
|
-
// Break up individual h3's into separate content for more fine grained search
|
|
74
|
-
$('h3').each((index, el) => {
|
|
75
|
-
el = $(el);
|
|
76
|
-
const title = el.text();
|
|
77
|
-
const html = el.nextUntil('h3').html();
|
|
78
|
-
const content = new Content({
|
|
79
|
-
title: `${file.title}: ${title}`,
|
|
80
|
-
body: html,
|
|
81
|
-
url: `${filename.replace('.md', '.html').replace(/^docs/, '')}#${el.prop('id')}`
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
content.validateSync();
|
|
85
|
-
contents.push(content);
|
|
86
|
-
});
|
|
87
|
-
} else if (file.guide) {
|
|
88
|
-
let text = fs.readFileSync(filename, 'utf8');
|
|
89
|
-
text = text.substr(text.indexOf('block content') + 'block content\n'.length);
|
|
90
|
-
text = pug.render(`div\n${text}`, { filters: { markdown }, filename });
|
|
91
|
-
|
|
92
|
-
const content = new Content({
|
|
93
|
-
title: file.title,
|
|
94
|
-
body: text,
|
|
95
|
-
url: filename.replace('.pug', '.html').replace(/^docs/, '')
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
content.validateSync();
|
|
99
|
-
|
|
100
|
-
const $ = cheerio.load(text);
|
|
101
|
-
|
|
102
|
-
contents.push(content);
|
|
103
|
-
|
|
104
|
-
// Break up individual h3's into separate content for more fine grained search
|
|
105
|
-
$('h3').each((index, el) => {
|
|
106
|
-
el = $(el);
|
|
107
|
-
const title = el.text();
|
|
108
|
-
const html = el.nextUntil('h3').html();
|
|
109
|
-
const content = new Content({
|
|
110
|
-
title: `${file.title}: ${title}`,
|
|
111
|
-
body: html,
|
|
112
|
-
url: `${filename.replace('.pug', '.html').replace(/^docs/, '')}#${el.prop('id')}`
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
content.validateSync();
|
|
116
|
-
contents.push(content);
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
run().catch(async error => {
|
|
122
|
-
console.error(error.stack);
|
|
123
|
-
|
|
124
|
-
// ensure the script exists in case of error
|
|
125
|
-
await mongoose.disconnect();
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
async function run() {
|
|
129
|
-
await mongoose.connect(config.uri, { dbName: 'mongoose', serverSelectionTimeoutMS: 5000 });
|
|
130
|
-
|
|
131
|
-
// wait for the index to be created
|
|
132
|
-
await Content.init();
|
|
133
|
-
|
|
134
|
-
await Content.deleteMany({ version });
|
|
135
|
-
let count = 0;
|
|
136
|
-
for (const content of contents) {
|
|
137
|
-
if (version === '7.x') {
|
|
138
|
-
let url = content.url.startsWith('/') ? content.url : `/${content.url}`;
|
|
139
|
-
if (!url.startsWith('/docs')) {
|
|
140
|
-
url = '/docs' + url;
|
|
141
|
-
}
|
|
142
|
-
content.url = url;
|
|
143
|
-
} else {
|
|
144
|
-
const url = content.url.startsWith('/') ? content.url : `/${content.url}`;
|
|
145
|
-
content.url = `/docs/${version}/docs${url}`;
|
|
146
|
-
}
|
|
147
|
-
console.log(`${++count} / ${contents.length}`);
|
|
148
|
-
await content.save();
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
const results = await Content.
|
|
152
|
-
find({ $text: { $search: 'validate' }, version }, { score: { $meta: 'textScore' } }).
|
|
153
|
-
sort({ score: { $meta: 'textScore' } }).
|
|
154
|
-
limit(10);
|
|
155
|
-
|
|
156
|
-
console.log(results.map(res => res.url));
|
|
157
|
-
|
|
158
|
-
console.log(`Added ${contents.length} Content`);
|
|
159
|
-
|
|
160
|
-
process.exit(0);
|
|
161
|
-
}
|
|
@@ -1,115 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const fs = require('fs');
|
|
4
|
-
|
|
5
|
-
const stdin = fs.readFileSync(0).toString('utf8');
|
|
6
|
-
const maxInstantiations = isNaN(process.argv[2]) ? 120000 : parseInt(process.argv[2], 10);
|
|
7
|
-
|
|
8
|
-
console.log(stdin);
|
|
9
|
-
|
|
10
|
-
const numInstantiations = parseInt(stdin.match(/Instantiations:\s+(\d+)/)[1], 10);
|
|
11
|
-
if (numInstantiations > maxInstantiations) {
|
|
12
|
-
throw new Error(`Instantiations ${numInstantiations} > max ${maxInstantiations}`);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
process.exit(0);
|
package/tools/auth.js
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const Server = require('mongodb-topology-manager').Server;
|
|
4
|
-
const mongodb = require('mongodb');
|
|
5
|
-
|
|
6
|
-
run().catch(error => {
|
|
7
|
-
console.error(error);
|
|
8
|
-
process.exit(-1);
|
|
9
|
-
});
|
|
10
|
-
|
|
11
|
-
async function run() {
|
|
12
|
-
// Create new instance
|
|
13
|
-
const server = new Server('mongod', {
|
|
14
|
-
auth: null,
|
|
15
|
-
dbpath: '/data/db/27017'
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
// Purge the directory
|
|
19
|
-
await server.purge();
|
|
20
|
-
|
|
21
|
-
// Start process
|
|
22
|
-
await server.start();
|
|
23
|
-
|
|
24
|
-
const db = await mongodb.MongoClient.connect('mongodb://127.0.0.1:27017/admin');
|
|
25
|
-
|
|
26
|
-
await db.addUser('passwordIsTaco', 'taco', {
|
|
27
|
-
roles: ['dbOwner']
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
console.log('done');
|
|
31
|
-
}
|
package/tools/repl.js
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
run().catch(error => {
|
|
4
|
-
console.error(error);
|
|
5
|
-
process.exit(-1);
|
|
6
|
-
});
|
|
7
|
-
|
|
8
|
-
async function run() {
|
|
9
|
-
const ReplSet = require('mongodb-memory-server').MongoMemoryReplSet;
|
|
10
|
-
|
|
11
|
-
// Create new instance
|
|
12
|
-
const replSet = new ReplSet({
|
|
13
|
-
binary: {
|
|
14
|
-
version: process.argv[2]
|
|
15
|
-
},
|
|
16
|
-
instanceOpts: [
|
|
17
|
-
// Set the expiry job in MongoDB to run every second
|
|
18
|
-
{
|
|
19
|
-
port: 27017,
|
|
20
|
-
args: ['--setParameter', 'ttlMonitorSleepSecs=1']
|
|
21
|
-
}
|
|
22
|
-
],
|
|
23
|
-
dbName: 'mongoose_test',
|
|
24
|
-
replSet: {
|
|
25
|
-
name: 'rs0',
|
|
26
|
-
count: 2,
|
|
27
|
-
storageEngine: 'wiredTiger'
|
|
28
|
-
}
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
await replSet.start();
|
|
32
|
-
await replSet.waitUntilRunning();
|
|
33
|
-
console.log('MongoDB-ReplicaSet is now running.');
|
|
34
|
-
console.log(replSet.getUri('mongoose_test'));
|
|
35
|
-
}
|
package/tools/sharded.js
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
run().catch(error => {
|
|
4
|
-
console.error(error);
|
|
5
|
-
process.exit(-1);
|
|
6
|
-
});
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
async function run() {
|
|
10
|
-
const Sharded = require('mongodb-topology-manager').Sharded;
|
|
11
|
-
|
|
12
|
-
// Create new instance
|
|
13
|
-
const topology = new Sharded({
|
|
14
|
-
mongod: 'mongod',
|
|
15
|
-
mongos: 'mongos'
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
await topology.addShard([{
|
|
19
|
-
options: {
|
|
20
|
-
bind_ip: '127.0.0.1', port: 31000, dbpath: '/data/db/31000', shardsvr: null
|
|
21
|
-
}
|
|
22
|
-
}], { replSet: 'rs1' });
|
|
23
|
-
|
|
24
|
-
await topology.addConfigurationServers([{
|
|
25
|
-
options: {
|
|
26
|
-
bind_ip: '127.0.0.1', port: 35000, dbpath: '/data/db/35000'
|
|
27
|
-
}
|
|
28
|
-
}], { replSet: 'rs0' });
|
|
29
|
-
|
|
30
|
-
await topology.addProxies([{
|
|
31
|
-
bind_ip: '127.0.0.1', port: 51000, configdb: '127.0.0.1:35000'
|
|
32
|
-
}], {
|
|
33
|
-
binary: 'mongos'
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
console.log('Start...');
|
|
37
|
-
// Start up topology
|
|
38
|
-
await topology.start();
|
|
39
|
-
|
|
40
|
-
console.log('Started');
|
|
41
|
-
|
|
42
|
-
// Shard db
|
|
43
|
-
await topology.enableSharding('test');
|
|
44
|
-
|
|
45
|
-
console.log('done');
|
|
46
|
-
}
|