UNPKG

2.97 kBJavaScriptView Raw
1/* eslint-env browser */
2
3'use strict';
4
5require('./driver').set(require('./drivers/browser'));
6
7const DocumentProvider = require('./document_provider.js');
8const PromiseProvider = require('./promise_provider');
9
10DocumentProvider.setBrowser(true);
11
12/**
13 * The Mongoose [Promise](#promise_Promise) constructor.
14 *
15 * @method Promise
16 * @api public
17 */
18
19Object.defineProperty(exports, 'Promise', {
20 get: function() {
21 return PromiseProvider.get();
22 },
23 set: function(lib) {
24 PromiseProvider.set(lib);
25 }
26});
27
28/**
29 * Storage layer for mongoose promises
30 *
31 * @method PromiseProvider
32 * @api public
33 */
34
35exports.PromiseProvider = PromiseProvider;
36
37/**
38 * The [MongooseError](#error_MongooseError) constructor.
39 *
40 * @method Error
41 * @api public
42 */
43
44exports.Error = require('./error/index');
45
46/**
47 * The Mongoose [Schema](#schema_Schema) constructor
48 *
49 * ####Example:
50 *
51 * var mongoose = require('mongoose');
52 * var Schema = mongoose.Schema;
53 * var CatSchema = new Schema(..);
54 *
55 * @method Schema
56 * @api public
57 */
58
59exports.Schema = require('./schema');
60
61/**
62 * The various Mongoose Types.
63 *
64 * ####Example:
65 *
66 * var mongoose = require('mongoose');
67 * var array = mongoose.Types.Array;
68 *
69 * ####Types:
70 *
71 * - [ObjectId](#types-objectid-js)
72 * - [Buffer](#types-buffer-js)
73 * - [SubDocument](#types-embedded-js)
74 * - [Array](#types-array-js)
75 * - [DocumentArray](#types-documentarray-js)
76 *
77 * Using this exposed access to the `ObjectId` type, we can construct ids on demand.
78 *
79 * var ObjectId = mongoose.Types.ObjectId;
80 * var id1 = new ObjectId;
81 *
82 * @property Types
83 * @api public
84 */
85exports.Types = require('./types');
86
87/**
88 * The Mongoose [VirtualType](#virtualtype_VirtualType) constructor
89 *
90 * @method VirtualType
91 * @api public
92 */
93exports.VirtualType = require('./virtualtype');
94
95/**
96 * The various Mongoose SchemaTypes.
97 *
98 * ####Note:
99 *
100 * _Alias of mongoose.Schema.Types for backwards compatibility._
101 *
102 * @property SchemaTypes
103 * @see Schema.SchemaTypes #schema_Schema.Types
104 * @api public
105 */
106
107exports.SchemaType = require('./schematype.js');
108
109/**
110 * Internal utils
111 *
112 * @property utils
113 * @api private
114 */
115
116exports.utils = require('./utils.js');
117
118/**
119 * The Mongoose browser [Document](/api/document.html) constructor.
120 *
121 * @method Document
122 * @api public
123 */
124exports.Document = DocumentProvider();
125
126/**
127 * Return a new browser model. In the browser, a model is just
128 * a simplified document with a schema - it does **not** have
129 * functions like `findOne()`, etc.
130 *
131 * @method model
132 * @api public
133 * @param {String} name
134 * @param {Schema} schema
135 * @return Class
136 */
137exports.model = function(name, schema) {
138 class Model extends exports.Document {
139 constructor(obj, fields) {
140 super(obj, schema, fields);
141 }
142 }
143 Model.modelName = name;
144
145 return Model;
146};
147
148/*!
149 * Module exports.
150 */
151
152if (typeof window !== 'undefined') {
153 window.mongoose = module.exports;
154 window.Buffer = Buffer;
155}