ffffng/shared/validation/constraints.js

140 lines
3.7 KiB
JavaScript
Raw Normal View History

2014-05-12 20:08:19 +02:00
'use strict';
2018-12-17 22:49:54 +01:00
(function () {
var constraints = {
id:{
2016-06-07 00:21:26 +02:00
type: 'string',
regex: /^[1-9][0-9]*$/,
optional: false
},
2018-12-17 22:49:54 +01:00
token:{
2016-06-07 00:21:26 +02:00
type: 'string',
2018-12-17 22:49:54 +01:00
regex: /^[0-9a-f]{16}$/i,
2016-06-07 00:21:26 +02:00
optional: false
},
2018-12-17 22:49:54 +01:00
node: {
hostname: {
type: 'string',
regex: /^[-a-z0-9_]{1,32}$/i,
optional: false
},
key: {
type: 'string',
regex: /^([a-f0-9]{64})$/i,
optional: true
},
email: {
type: 'string',
regex: /^[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/i,
optional: false
},
nickname: {
type: 'string',
regex: /^[-a-z0-9_ äöüß]{1,64}$/i,
optional: false
},
mac: {
type: 'string',
regex: /^([a-f0-9]{12}|([a-f0-9]{2}:){5}[a-f0-9]{2})$/i,
optional: false
},
coords: {
type: 'string',
regex: /^(-?[0-9]{1,3}(\.[0-9]{1,15})? -?[0-9]{1,3}(\.[0-9]{1,15})?)$/,
optional: true
},
monitoring: {
type: 'boolean',
optional: false
}
},
2018-12-17 22:49:54 +01:00
nodeFilters: {
hasKey: {
type: 'boolean',
optional: true
},
2018-12-17 22:49:54 +01:00
hasCoords: {
type: 'boolean',
optional: true
},
2018-12-17 22:49:54 +01:00
onlineState: {
type: 'string',
regex: /^(ONLINE|OFFLINE)$/,
optional: true
},
2018-12-17 22:49:54 +01:00
monitoringState: {
type: 'string',
2018-12-17 22:49:54 +01:00
regex: /^(disabled|active|pending)$/,
optional: true
2016-06-07 12:39:52 +02:00
},
2018-12-17 22:49:54 +01:00
site: {
2016-06-07 12:39:52 +02:00
type: 'string',
2018-12-17 22:49:54 +01:00
regex: /^[a-z0-9_-]{1,32}$/,
2016-06-07 12:39:52 +02:00
optional: true
2018-12-17 22:49:54 +01:00
},
domain: {
type: 'string',
regex: /^[a-z0-9_-]{1,32}$/,
optional: true
}
},
rest: {
list: {
_page: {
type: 'number',
min: 1,
optional: true,
default: 1
},
_perPage: {
type: 'number',
min: 1,
max: 50,
optional: true,
default: 20
},
_sortDir: {
type: 'enum',
allowed: ['ASC', 'DESC'],
optional: true,
default: 'ASC'
},
_sortField: {
type: 'string',
regex: /^[a-zA-Z0-9_]{1,32}$/,
optional: true
},
q: {
type: 'string',
regex: /^[äöüß a-z0-9!#$%&@:.'*+/=?^_`{|}~-]{1,64}$/i,
optional: true
}
}
}
2016-06-07 00:21:26 +02:00
}
2018-12-17 22:49:54 +01:00
2019-03-29 20:54:57 +01:00
var _angular = null
2018-12-17 22:49:54 +01:00
try {
_angular = angular
}
catch (error) {
// ReferenceError, as angular is not defined.
}
2019-03-29 20:54:57 +01:00
var _module = null
2018-12-17 22:49:54 +01:00
try {
_module = module
}
catch (error) {
// ReferenceError, as module is not defined.
}
if (_angular) {
angular.module('ffffng').constant('Constraints', constraints)
}
if (_module) {
module.exports = constraints
}
})()