1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | 'use strict';
|
7 |
|
8 | const Types = {};
|
9 |
|
10 |
|
11 |
|
12 | Types.Text = function Text(value) {
|
13 | if (!(this instanceof Text)) {
|
14 | return value;
|
15 | }
|
16 | this.value = value;
|
17 | };
|
18 |
|
19 | Types.Text.prototype.toObject = Types.Text.prototype.toJSON = function() {
|
20 | return this.value;
|
21 | };
|
22 |
|
23 | Types.JSON = function JSON(value) {
|
24 | if (!(this instanceof JSON)) {
|
25 | return value;
|
26 | }
|
27 | this.value = value;
|
28 | };
|
29 | Types.JSON.prototype.toObject = Types.JSON.prototype.toJSON = function() {
|
30 | return this.value;
|
31 | };
|
32 |
|
33 | Types.Any = function Any(value) {
|
34 | if (!(this instanceof Any)) {
|
35 | return value;
|
36 | }
|
37 | this.value = value;
|
38 | };
|
39 | Types.Any.prototype.toObject = Types.Any.prototype.toJSON = function() {
|
40 | return this.value;
|
41 | };
|
42 |
|
43 | module.exports = function(modelTypes) {
|
44 | const DateString = require('./date-string');
|
45 | const GeoPoint = require('./geo').GeoPoint;
|
46 |
|
47 | for (const t in Types) {
|
48 | modelTypes[t] = Types[t];
|
49 | }
|
50 |
|
51 | modelTypes.schemaTypes = {};
|
52 | modelTypes.registerType = function(type, names) {
|
53 | names = names || [];
|
54 | names = names.concat([type.name]);
|
55 | for (let n = 0; n < names.length; n++) {
|
56 | this.schemaTypes[names[n].toLowerCase()] = type;
|
57 | }
|
58 | };
|
59 |
|
60 | modelTypes.registerType(Types.Text);
|
61 | modelTypes.registerType(Types.JSON);
|
62 | modelTypes.registerType(Types.Any);
|
63 |
|
64 | modelTypes.registerType(String);
|
65 | modelTypes.registerType(Number);
|
66 | modelTypes.registerType(Boolean);
|
67 | modelTypes.registerType(Date);
|
68 | modelTypes.registerType(DateString);
|
69 | modelTypes.registerType(Buffer, ['Binary']);
|
70 | modelTypes.registerType(Array);
|
71 | modelTypes.registerType(GeoPoint);
|
72 | modelTypes.registerType(Object);
|
73 | };
|
74 |
|
75 | module.exports.Types = Types;
|