@bluedot-innovation/models 3.0.0-alpha.3 → 3.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +9 -0
- package/helpers.js +18 -1
- package/models/BoundingBox.js +6 -12
- package/models/Circle.js +1 -4
- package/models/MessageAction.js +6 -11
- package/models/Polygon.js +1 -4
- package/models/Polyline.js +6 -12
- package/models/UrlAction.js +6 -13
- package/models/Zone.js +6 -3
- package/models/ZoneBeacon.js +5 -0
- package/models/filters/DayRange.js +17 -15
- package/models/filters/Speed.js +4 -6
- package/models/filters/TimeActive.js +11 -10
- package/models/filters/TravelDirection.js +1 -1
- package/models/filters/TravelPath.js +5 -2
- package/package.json +1 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
## 3.0.1
|
|
2
|
+
- DayRange must have at least startTime or endTime or both
|
|
3
|
+
|
|
1
4
|
## 3.0.0
|
|
2
5
|
|
|
3
6
|
- Breaking changes:
|
|
@@ -6,6 +9,12 @@
|
|
|
6
9
|
- `percentage.percentage` -> `travelPath.minimumGeofeaturesCrossed`
|
|
7
10
|
- `timeOfDayRange` -> `timeActive`
|
|
8
11
|
- `calendarDateRange` -> `dayRange`
|
|
12
|
+
- Remove `state` from all subdocuments
|
|
13
|
+
- Remove `creationTime` from all subdocuments
|
|
14
|
+
- Remove `lastUpdateTime` from all subdocuments
|
|
15
|
+
- Remove `_id` from all subdocuments EXCEPT geofeatures
|
|
16
|
+
- Remove `description` from all subdocuments
|
|
17
|
+
- Remove `__v` from all subdocuments
|
|
9
18
|
|
|
10
19
|
## 2.0.22
|
|
11
20
|
|
package/helpers.js
CHANGED
|
@@ -20,12 +20,29 @@ helpers.validateCustomData = function (data) {
|
|
|
20
20
|
let hasValidationErrors = false
|
|
21
21
|
|
|
22
22
|
customDataKeys.forEach(key => {
|
|
23
|
-
const alphaNumericValidation = new RegExp(
|
|
23
|
+
const alphaNumericValidation = new RegExp(/^[\w\s]+$/)
|
|
24
24
|
if(!alphaNumericValidation.test(key)){
|
|
25
25
|
hasValidationErrors = true
|
|
26
26
|
}
|
|
27
27
|
})
|
|
28
28
|
|
|
29
|
+
const checkDuplicateKeys = [...new Set(customDataKeys)]
|
|
30
|
+
if(customDataKeys.length > checkDuplicateKeys.length) {
|
|
31
|
+
hasValidationErrors = true
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return !hasValidationErrors
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
helpers.checkDuplicateKeys = function (data) {
|
|
38
|
+
const customDataKeys = Object.keys(data)
|
|
39
|
+
let hasValidationErrors = false
|
|
40
|
+
|
|
41
|
+
const duplicateKeys = [...new Set(customDataKeys)]
|
|
42
|
+
if(customDataKeys.length > duplicateKeys.length) {
|
|
43
|
+
hasValidationErrors = true
|
|
44
|
+
}
|
|
45
|
+
|
|
29
46
|
return !hasValidationErrors
|
|
30
47
|
}
|
|
31
48
|
|
package/models/BoundingBox.js
CHANGED
|
@@ -10,22 +10,16 @@ const schema = {
|
|
|
10
10
|
name: {type: String, required: [true, 'name is required. ']},
|
|
11
11
|
color: String,
|
|
12
12
|
northEast: {type: Point, required: [true, 'northEast is required. ']},
|
|
13
|
-
southWest: {type: Point, required: [true, 'southWest is required. ']}
|
|
14
|
-
creationTime: {type: Date, default: Date.now},
|
|
15
|
-
lastUpdateTime: {type: Date, default: Date.now},
|
|
16
|
-
state: {type: String, default: StateEnum.active, select: false}
|
|
13
|
+
southWest: {type: Point, required: [true, 'southWest is required. ']}
|
|
17
14
|
}
|
|
18
15
|
|
|
19
|
-
const BoundingBoxSchema = new mongoose.Schema(
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
versionKey: false
|
|
24
|
-
})
|
|
16
|
+
const BoundingBoxSchema = new mongoose.Schema(schema, {
|
|
17
|
+
_id: false,
|
|
18
|
+
versionKey: false
|
|
19
|
+
})
|
|
25
20
|
|
|
26
21
|
BoundingBoxSchema.add({
|
|
27
|
-
type:
|
|
28
|
-
{type: String, required: true}
|
|
22
|
+
type: {type: String, required: true}
|
|
29
23
|
})
|
|
30
24
|
|
|
31
25
|
// optional mongoose
|
package/models/Circle.js
CHANGED
|
@@ -10,10 +10,7 @@ let schema = {
|
|
|
10
10
|
name: {type: String, required: [true, 'name is required. ']},
|
|
11
11
|
color: String,
|
|
12
12
|
radius: {type: Number, required: [true, 'radius is required. '], min: 5},
|
|
13
|
-
center: {type: Point, required: [true, 'center is required. ']}
|
|
14
|
-
creationTime: {type: Date, default: Date.now},
|
|
15
|
-
lastUpdateTime: {type: Date, default: Date.now},
|
|
16
|
-
state: {type: String, default: StateEnum.active, select: false}
|
|
13
|
+
center: {type: Point, required: [true, 'center is required. ']}
|
|
17
14
|
}
|
|
18
15
|
|
|
19
16
|
let CircleSchema = new mongoose.Schema(
|
package/models/MessageAction.js
CHANGED
|
@@ -3,22 +3,17 @@ let StateEnum = require('@bluedot-innovation/enums').StateEnum
|
|
|
3
3
|
let uuidv4 = require('uuid/v4')
|
|
4
4
|
|
|
5
5
|
let schema = {
|
|
6
|
-
_id: {type: String, default: uuidv4},
|
|
7
6
|
title: {type: String, required: [true, 'title is required. ']},
|
|
8
|
-
message: {type: String, required: [true, 'message is required. ']}
|
|
9
|
-
creationTime: {type: Date, default: Date.now},
|
|
10
|
-
lastUpdateTime: {type: Date, default: Date.now},
|
|
11
|
-
state: {type: String, default: StateEnum.active, select: false}
|
|
7
|
+
message: {type: String, required: [true, 'message is required. ']}
|
|
12
8
|
}
|
|
13
9
|
|
|
14
|
-
let MessageActionSchema = new mongoose.Schema(schema,
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
10
|
+
let MessageActionSchema = new mongoose.Schema(schema, {
|
|
11
|
+
_id: false,
|
|
12
|
+
versionKey: false
|
|
13
|
+
})
|
|
18
14
|
|
|
19
15
|
MessageActionSchema.add({
|
|
20
|
-
type:
|
|
21
|
-
{type: String, required: true}
|
|
16
|
+
type: {type: String, required: true}
|
|
22
17
|
})
|
|
23
18
|
|
|
24
19
|
// optional mongoose
|
package/models/Polygon.js
CHANGED
|
@@ -15,10 +15,7 @@ const schema = {
|
|
|
15
15
|
validator: helpers.validatePolygonVertices,
|
|
16
16
|
msg: 'A polygon must have 3 or more vertices.'
|
|
17
17
|
}
|
|
18
|
-
}
|
|
19
|
-
creationTime: {type: Date, default: Date.now},
|
|
20
|
-
lastUpdateTime: {type: Date, default: Date.now},
|
|
21
|
-
state: {type: String, default: StateEnum.active, select: false}
|
|
18
|
+
}
|
|
22
19
|
}
|
|
23
20
|
|
|
24
21
|
const PolygonSchema = new mongoose.Schema(schema, {
|
package/models/Polyline.js
CHANGED
|
@@ -8,22 +8,16 @@ const schema = {
|
|
|
8
8
|
_id: {type: String, default: uuidv4},
|
|
9
9
|
geometry: {type: MultiLineStringGeometry},
|
|
10
10
|
name: {type: String, required: [true, 'name is required. ']},
|
|
11
|
-
vertices: {type: [Point], required: [true, 'vertices is required. ']}
|
|
12
|
-
creationTime: {type: Date, default: Date.now},
|
|
13
|
-
lastUpdateTime: {type: Date, default: Date.now},
|
|
14
|
-
state: {type: String, default: StateEnum.active, select: false}
|
|
11
|
+
vertices: {type: [Point], required: [true, 'vertices is required. ']}
|
|
15
12
|
}
|
|
16
13
|
|
|
17
|
-
const PolylineSchema = new mongoose.Schema(
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
versionKey: false
|
|
22
|
-
})
|
|
14
|
+
const PolylineSchema = new mongoose.Schema(schema, {
|
|
15
|
+
_id: false,
|
|
16
|
+
versionKey: false
|
|
17
|
+
})
|
|
23
18
|
|
|
24
19
|
PolylineSchema.add({
|
|
25
|
-
type:
|
|
26
|
-
{type: String, required: true}
|
|
20
|
+
type: {type: String, required: true}
|
|
27
21
|
})
|
|
28
22
|
|
|
29
23
|
// optional mongoose
|
package/models/UrlAction.js
CHANGED
|
@@ -3,7 +3,6 @@ let StateEnum = require('@bluedot-innovation/enums').StateEnum
|
|
|
3
3
|
let uuidv4 = require('uuid/v4')
|
|
4
4
|
|
|
5
5
|
let schema = {
|
|
6
|
-
_id: {type: String, default: uuidv4},
|
|
7
6
|
url: {
|
|
8
7
|
type: String,
|
|
9
8
|
required: [true, 'url is required. '],
|
|
@@ -11,22 +10,16 @@ let schema = {
|
|
|
11
10
|
isAsync: true,
|
|
12
11
|
validator: validateURL
|
|
13
12
|
}
|
|
14
|
-
}
|
|
15
|
-
description: {type: String, default: ''},
|
|
16
|
-
creationTime: {type: Date, default: Date.now},
|
|
17
|
-
lastUpdateTime: {type: Date, default: Date.now},
|
|
18
|
-
state: {type: String, default: StateEnum.active, select: false}
|
|
13
|
+
}
|
|
19
14
|
}
|
|
20
15
|
|
|
21
|
-
let URLActionSchema = new mongoose.Schema(schema,
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
})
|
|
16
|
+
let URLActionSchema = new mongoose.Schema(schema, {
|
|
17
|
+
_id: false,
|
|
18
|
+
__v: false
|
|
19
|
+
})
|
|
26
20
|
|
|
27
21
|
URLActionSchema.add({
|
|
28
|
-
type:
|
|
29
|
-
{type: String, required: true}
|
|
22
|
+
type: {type: String, required: true}
|
|
30
23
|
})
|
|
31
24
|
|
|
32
25
|
function validateURL (url, magicCallback) {
|
package/models/Zone.js
CHANGED
|
@@ -30,6 +30,11 @@ let helpers = require('../helpers')
|
|
|
30
30
|
// Schema //
|
|
31
31
|
// ////// //
|
|
32
32
|
|
|
33
|
+
let customDataValidators = [
|
|
34
|
+
{validator: helpers.validateCustomData, msg: 'CustomData key should have alpha numeric and _ characters only'},
|
|
35
|
+
{validator: helpers.checkDuplicateKeys, msg: 'CustomData key should be unique'},
|
|
36
|
+
];
|
|
37
|
+
|
|
33
38
|
let actionSchema = new Schema({},
|
|
34
39
|
{ discriminatorKey: 'type', _id: false })
|
|
35
40
|
|
|
@@ -64,7 +69,7 @@ let zoneSchema = new Schema({
|
|
|
64
69
|
required: true
|
|
65
70
|
},
|
|
66
71
|
triggerOnExit: {type: Boolean, default: false},
|
|
67
|
-
customData: {type: Schema.Types.Mixed},
|
|
72
|
+
customData: {type: Schema.Types.Mixed, validate: customDataValidators},
|
|
68
73
|
creationTime: {type: Date, default: Date.now},
|
|
69
74
|
lastUpdateTime: {type: Date, default: Date.now},
|
|
70
75
|
projectId: {type: String, required: [true, 'projectId is required']},
|
|
@@ -90,8 +95,6 @@ zoneSchema.path('geofeatures').discriminator('polygon', new Schema(polygonSchema
|
|
|
90
95
|
zoneSchema.path('geofeatures').discriminator('polyline', new Schema(polylineSchema))
|
|
91
96
|
zoneSchema.path('geofeatures').discriminator('boundingBox', new Schema(boundingBoxSchema))
|
|
92
97
|
|
|
93
|
-
zoneSchema.path('customData').validate(helpers.validateCustomData, 'CustomData key should have alpha numeric and _ characters only')
|
|
94
|
-
|
|
95
98
|
// optional mongoose
|
|
96
99
|
const model = (mongooseInstance) => {
|
|
97
100
|
let Zone
|
package/models/ZoneBeacon.js
CHANGED
|
@@ -5,6 +5,11 @@ const BeaconEnum = require('@bluedot-innovation/enums').BeaconEnum
|
|
|
5
5
|
|
|
6
6
|
const schema = cloneDeep(beaconSchema)
|
|
7
7
|
|
|
8
|
+
delete schema.state
|
|
9
|
+
delete schema.creationTime
|
|
10
|
+
delete schema.lastUpdateTime
|
|
11
|
+
delete schema.__v
|
|
12
|
+
|
|
8
13
|
schema.proximity = {
|
|
9
14
|
type: String,
|
|
10
15
|
default: BeaconEnum.FAR,
|
|
@@ -2,24 +2,26 @@ let mongoose = require('mongoose')
|
|
|
2
2
|
let uuidv4 = require('uuid/v4')
|
|
3
3
|
|
|
4
4
|
let schema = {
|
|
5
|
-
_id: {type: String, default: uuidv4},
|
|
6
5
|
startDate: {type: Date},
|
|
7
6
|
endDate: {type: Date, validate: {isAsync: true, validator: validateDateRange}}
|
|
8
7
|
}
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
8
|
+
|
|
9
|
+
let DayRangeFilterSchema = new mongoose.Schema(schema, {
|
|
10
|
+
_id: false,
|
|
11
|
+
versionKey: false
|
|
12
|
+
})
|
|
14
13
|
|
|
15
14
|
DayRangeFilterSchema.add({
|
|
16
|
-
type:
|
|
17
|
-
{type: String, required: true}
|
|
15
|
+
type: {type: String, required: true}
|
|
18
16
|
})
|
|
19
17
|
|
|
20
|
-
function validateDateRange (endDate,
|
|
18
|
+
function validateDateRange (endDate, callback) {
|
|
21
19
|
let startDate = this.startDate
|
|
22
20
|
|
|
21
|
+
if (!startDate && !endDate) {
|
|
22
|
+
return callback(false, `Must have a startDate, endDate, or both.`)
|
|
23
|
+
}
|
|
24
|
+
|
|
23
25
|
if (this.startDate) {
|
|
24
26
|
startDate = new Date(this.startDate)
|
|
25
27
|
}
|
|
@@ -29,21 +31,21 @@ function validateDateRange (endDate, magicCallback) {
|
|
|
29
31
|
}
|
|
30
32
|
|
|
31
33
|
if (startDate && endDate && endDate < startDate) {
|
|
32
|
-
return
|
|
34
|
+
return callback(false, `startDate has to be less than endDate.`)
|
|
33
35
|
}
|
|
34
|
-
|
|
36
|
+
callback(true)
|
|
35
37
|
}
|
|
36
38
|
|
|
37
39
|
// optional mongoose
|
|
38
40
|
let model = (mongooseInstance) => {
|
|
39
|
-
let
|
|
41
|
+
let DayRangeFilter
|
|
40
42
|
if (mongooseInstance) {
|
|
41
|
-
|
|
43
|
+
DayRangeFilter = mongooseInstance.model('DayRangeFilter', DayRangeFilterSchema)
|
|
42
44
|
} else {
|
|
43
|
-
|
|
45
|
+
DayRangeFilter = mongoose.model('DayRangeFilter', DayRangeFilterSchema)
|
|
44
46
|
}
|
|
45
47
|
|
|
46
|
-
return
|
|
48
|
+
return DayRangeFilter
|
|
47
49
|
}
|
|
48
50
|
// Exports Mongoose Model, Mongoose Schema, JSON schema (required locally for discriminators)
|
|
49
51
|
module.exports = { Model: model, Schema: DayRangeFilterSchema, rawSchema: schema }
|
package/models/filters/Speed.js
CHANGED
|
@@ -2,15 +2,13 @@ let mongoose = require('mongoose')
|
|
|
2
2
|
let uuidv4 = require('uuid/v4')
|
|
3
3
|
|
|
4
4
|
let schema = {
|
|
5
|
-
_id: {type: String, default: uuidv4},
|
|
6
5
|
minimumSpeed: {type: Number, required: [true, 'minimumSpeed is required. '], min: 0},
|
|
7
6
|
maximumSpeed: {type: Number, required: true, validate: {isAsync: true, validator: validateMaxSpeed, msg: 'default error message'}}
|
|
8
7
|
}
|
|
9
|
-
let SpeedFilterSchema = new mongoose.Schema(
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
})
|
|
8
|
+
let SpeedFilterSchema = new mongoose.Schema(schema, {
|
|
9
|
+
_id: false,
|
|
10
|
+
versionKey: false
|
|
11
|
+
})
|
|
14
12
|
|
|
15
13
|
SpeedFilterSchema.add({
|
|
16
14
|
type: {type: String, required: true}
|
|
@@ -2,15 +2,16 @@ let mongoose = require('mongoose')
|
|
|
2
2
|
let uuidv4 = require('uuid/v4')
|
|
3
3
|
|
|
4
4
|
let schema = {
|
|
5
|
-
_id: {type: String, default: uuidv4},
|
|
6
5
|
fromTime: {type: Number, required: [true, 'time is required. '], min: 0, max: 86400},
|
|
7
6
|
toTime: {type: Number, required: true, min: 0, max: 86400, validate: {isAsync: true, validator: validateTime}}
|
|
8
7
|
}
|
|
9
|
-
let
|
|
8
|
+
let TimeActiveFilterSchema = new mongoose.Schema(schema, {
|
|
9
|
+
_id: false,
|
|
10
|
+
versionKey: false
|
|
11
|
+
})
|
|
10
12
|
|
|
11
|
-
|
|
12
|
-
type:
|
|
13
|
-
{type: String, required: true}
|
|
13
|
+
TimeActiveFilterSchema.add({
|
|
14
|
+
type: {type: String, required: true}
|
|
14
15
|
})
|
|
15
16
|
|
|
16
17
|
function validateTime (toTime, magicCallback) {
|
|
@@ -24,15 +25,15 @@ function validateTime (toTime, magicCallback) {
|
|
|
24
25
|
|
|
25
26
|
// optional mongoose
|
|
26
27
|
let model = (mongooseInstance) => {
|
|
27
|
-
let
|
|
28
|
+
let TimeActiveFilter
|
|
28
29
|
if (mongooseInstance) {
|
|
29
|
-
|
|
30
|
+
TimeActiveFilter = mongooseInstance.model('TimeActiveFilter', TimeActiveFilterSchema)
|
|
30
31
|
} else {
|
|
31
|
-
|
|
32
|
+
TimeActiveFilter = mongoose.model('TimeActiveFilter', TimeActiveFilterSchema)
|
|
32
33
|
}
|
|
33
34
|
|
|
34
|
-
return
|
|
35
|
+
return TimeActiveFilter
|
|
35
36
|
}
|
|
36
37
|
|
|
37
38
|
// Exports Mongoose Model, Mongoose Schema, JSON schema (required locally for discriminators)
|
|
38
|
-
module.exports = { Model: model, Schema:
|
|
39
|
+
module.exports = { Model: model, Schema: TimeActiveFilterSchema, rawSchema: schema }
|
|
@@ -2,12 +2,12 @@ let mongoose = require('mongoose')
|
|
|
2
2
|
let uuidv4 = require('uuid/v4')
|
|
3
3
|
|
|
4
4
|
const schema = {
|
|
5
|
-
_id: {type: String, default: uuidv4},
|
|
6
5
|
fromAngle: {type: Number, required: [true, 'fromAngle is required. '], min: 0, max: 359},
|
|
7
6
|
toAngle: {type: Number, required: true, min: 0, max: 359, validate: {isAsync: true, validator: validateAngles, msg: 'default error message'}}
|
|
8
7
|
}
|
|
9
8
|
|
|
10
9
|
const TravelDirectionFilterSchema = new mongoose.Schema(schema, {
|
|
10
|
+
_id: false,
|
|
11
11
|
versionKey: false
|
|
12
12
|
})
|
|
13
13
|
|
|
@@ -3,7 +3,6 @@ let mongoose = require('mongoose')
|
|
|
3
3
|
let uuidv4 = require('uuid/v4')
|
|
4
4
|
|
|
5
5
|
let schema = {
|
|
6
|
-
_id: {type: String, default: uuidv4},
|
|
7
6
|
minimumGeofeaturesCrossed: {
|
|
8
7
|
type: Number,
|
|
9
8
|
required: [true, 'minimumGeofeaturesCrossed is required.'],
|
|
@@ -12,7 +11,11 @@ let schema = {
|
|
|
12
11
|
timeOutSeconds: {type: Number, required: [true, 'timeOutSeconds is required. '], min: 60, max: 86400},
|
|
13
12
|
sequential: {type: Boolean, default: false}
|
|
14
13
|
}
|
|
15
|
-
|
|
14
|
+
|
|
15
|
+
let TravelPathFilterSchema = new mongoose.Schema(schema, {
|
|
16
|
+
_id: false,
|
|
17
|
+
versionKey: false
|
|
18
|
+
})
|
|
16
19
|
|
|
17
20
|
TravelPathFilterSchema.add({
|
|
18
21
|
type: {type: String, required: true}
|
package/package.json
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bluedot-innovation/models",
|
|
3
|
-
"version": "3.0.
|
|
4
|
-
"description": "",
|
|
3
|
+
"version": "3.0.1",
|
|
5
4
|
"main": "Models.js",
|
|
6
5
|
"scripts": {
|
|
7
6
|
"lint": "./node_modules/.bin/eslint -c .eslintrc.js ./models/*.js ./__tests__/**/*.js ./__tests__/**/**/*.js ./schemas/*.js",
|