File tree 3 files changed +49
-0
lines changed
3 files changed +49
-0
lines changed Original file line number Diff line number Diff line change
1
+ 'use strict' ;
2
+
3
+ const SchemaTypeOptions = require ( './SchemaTypeOptions' ) ;
4
+
5
+ /**
6
+ * The options defined on a Map schematype.
7
+ *
8
+ * ####Example:
9
+ *
10
+ * const schema = new Schema({ socialMediaHandles: { type: Map, of: String } });
11
+ * schema.path('socialMediaHandles').options; // SchemaMapOptions instance
12
+ *
13
+ * @api public
14
+ * @inherits SchemaTypeOptions
15
+ * @constructor SchemaMapOptions
16
+ */
17
+
18
+ class SchemaMapOptions extends SchemaTypeOptions { }
19
+
20
+ const opts = require ( './propertyOptions' ) ;
21
+
22
+ /**
23
+ * If set, specifies the type of this map's values. Mongoose will cast
24
+ * this map's values to the given type.
25
+ *
26
+ * If not set, Mongoose will not cast the map's values.
27
+ *
28
+ * ####Example:
29
+ *
30
+ * // Mongoose will cast `socialMediaHandles` values to strings
31
+ * const schema = new Schema({ socialMediaHandles: { type: Map, of: String } });
32
+ * schema.path('socialMediaHandles').options.of; // String
33
+ *
34
+ * @api public
35
+ * @property of
36
+ * @memberOf SchemaMapOptions
37
+ * @type Function|string
38
+ * @instance
39
+ */
40
+
41
+ Object . defineProperty ( SchemaMapOptions . prototype , 'of' , opts ) ;
42
+
43
+ module . exports = SchemaMapOptions ;
Original file line number Diff line number Diff line change 5
5
*/
6
6
7
7
const MongooseMap = require ( '../types/map' ) ;
8
+ const SchemaMapOptions = require ( '../options/SchemaMapOptions' ) ;
8
9
const SchemaType = require ( '../schematype' ) ;
9
10
10
11
/*!
@@ -42,4 +43,6 @@ class Map extends SchemaType {
42
43
}
43
44
}
44
45
46
+ Map . prototype . OptionsConstructor = SchemaMapOptions ;
47
+
45
48
module . exports = Map ;
Original file line number Diff line number Diff line change 6
6
7
7
const start = require ( './common' ) ;
8
8
9
+ const SchemaMapOptions = require ( '../lib/options/SchemaMapOptions' ) ;
9
10
const assert = require ( 'assert' ) ;
10
11
const co = require ( 'co' ) ;
11
12
@@ -47,6 +48,8 @@ describe('Map', function() {
47
48
}
48
49
} ) ;
49
50
51
+ assert . ok ( TestSchema . path ( 'v' ) . options instanceof SchemaMapOptions ) ;
52
+
50
53
const Test = db . model ( 'MapTest' , TestSchema ) ;
51
54
52
55
return co ( function * ( ) {
You can’t perform that action at this time.
0 commit comments