UNPKG

3.05 kBJavaScriptView Raw
1/* eslint-env browser */
2
3'use strict';
4
5require('./driver').set(require('./drivers/browser'));
6
7const DocumentProvider = require('./documentProvider.js');
8
9DocumentProvider.setBrowser(true);
10
11/**
12 * The [MongooseError](https://mongoosejs.com/docs/api/error.html#Error()) constructor.
13 *
14 * @method Error
15 * @api public
16 */
17
18exports.Error = require('./error/index');
19
20/**
21 * The Mongoose [Schema](https://mongoosejs.com/docs/api/schema.html#Schema()) constructor
22 *
23 * #### Example:
24 *
25 * const mongoose = require('mongoose');
26 * const Schema = mongoose.Schema;
27 * const CatSchema = new Schema(..);
28 *
29 * @method Schema
30 * @api public
31 */
32
33exports.Schema = require('./schema');
34
35/**
36 * The various Mongoose Types.
37 *
38 * #### Example:
39 *
40 * const mongoose = require('mongoose');
41 * const array = mongoose.Types.Array;
42 *
43 * #### Types:
44 *
45 * - [Array](https://mongoosejs.com/docs/schematypes.html#arrays)
46 * - [Buffer](https://mongoosejs.com/docs/schematypes.html#buffers)
47 * - [Embedded](https://mongoosejs.com/docs/schematypes.html#schemas)
48 * - [DocumentArray](https://mongoosejs.com/docs/api/documentarraypath.html)
49 * - [Decimal128](https://mongoosejs.com/docs/api/decimal128.html#Decimal128())
50 * - [ObjectId](https://mongoosejs.com/docs/schematypes.html#objectids)
51 * - [Map](https://mongoosejs.com/docs/schematypes.html#maps)
52 * - [Subdocument](https://mongoosejs.com/docs/schematypes.html#schemas)
53 *
54 * Using this exposed access to the `ObjectId` type, we can construct ids on demand.
55 *
56 * const ObjectId = mongoose.Types.ObjectId;
57 * const id1 = new ObjectId;
58 *
59 * @property Types
60 * @api public
61 */
62exports.Types = require('./types');
63
64/**
65 * The Mongoose [VirtualType](https://mongoosejs.com/docs/api/virtualtype.html#VirtualType()) constructor
66 *
67 * @method VirtualType
68 * @api public
69 */
70exports.VirtualType = require('./virtualType');
71
72/**
73 * The various Mongoose SchemaTypes.
74 *
75 * #### Note:
76 *
77 * _Alias of mongoose.Schema.Types for backwards compatibility._
78 *
79 * @property SchemaTypes
80 * @see Schema.SchemaTypes https://mongoosejs.com/docs/api/schema.html#Schema.Types
81 * @api public
82 */
83
84exports.SchemaType = require('./schemaType.js');
85
86/**
87 * Internal utils
88 *
89 * @property utils
90 * @api private
91 */
92
93exports.utils = require('./utils.js');
94
95/**
96 * The Mongoose browser [Document](/api/document.html) constructor.
97 *
98 * @method Document
99 * @api public
100 */
101exports.Document = DocumentProvider();
102
103/**
104 * Return a new browser model. In the browser, a model is just
105 * a simplified document with a schema - it does **not** have
106 * functions like `findOne()`, etc.
107 *
108 * @method model
109 * @api public
110 * @param {String} name
111 * @param {Schema} schema
112 * @return Class
113 */
114exports.model = function(name, schema) {
115 class Model extends exports.Document {
116 constructor(obj, fields) {
117 super(obj, schema, fields);
118 }
119 }
120 Model.modelName = name;
121
122 return Model;
123};
124
125/*!
126 * Module exports.
127 */
128
129if (typeof window !== 'undefined') {
130 window.mongoose = module.exports;
131 window.Buffer = Buffer;
132}