browser.js 3.1 KB

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