-
Notifications
You must be signed in to change notification settings - Fork 31
/
index.js
executable file
·36 lines (26 loc) · 1.18 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
const schema_jsonSchema = require('./lib/schema');
const model_jsonSchema = require('./lib/model');
const query_jsonSchema = require('./lib/query');
const types = require('./lib/types');
module.exports = function moduleFactory(mongoose) {
// eslint-disable-next-line global-require
mongoose = mongoose || require('mongoose');
const { Types } = mongoose.Schema;
mongoose.SchemaType.prototype.jsonSchema = types.simpleType_jsonSchema;
Types.Date.prototype.jsonSchema = types.date_jsonSchema;
Types.ObjectId.prototype.jsonSchema = types.objectId_jsonSchema;
Types.Array.prototype.jsonSchema = types.array_jsonSchema;
Types.DocumentArray.prototype.jsonSchema = types.array_jsonSchema;
if (Types.Embedded) {
Types.Embedded.prototype.jsonSchema = types.mixed_jsonSchema;
}
if (Types.Subdocument) {
Types.Subdocument.prototype.jsonSchema = types.mixed_jsonSchema;
}
Types.Mixed.prototype.jsonSchema = types.mixed_jsonSchema;
Types.Map.prototype.jsonSchema = types.map_jsonSchema;
mongoose.Schema.prototype.jsonSchema = schema_jsonSchema;
mongoose.Model.jsonSchema = model_jsonSchema;
mongoose.Query.prototype.jsonSchema = query_jsonSchema;
return mongoose;
};