UNPKG

@arisan/data-api

Version:

The Universal Database API Gateway for CLIO's Modules

106 lines (93 loc) 2.72 kB
'use strict'; //region 1. Platform Libraries const ipaddr = require('ipaddr.js'); //endregion const isValidStreamIndex = index => Number.isInteger(Number(index)) && Number(index) >= 0; const isWithinValidPublicIpRange = publicIp => { const range = ipaddr.parse(publicIp).range(); return !(range === 'broadcast' || range === 'linkLocal' || range === 'loopback' || range === 'multicast' || range === 'private' || range === 'reserved' || range === 'unspecified'); }; const isValidPublicIP = ip => { if (!ip) { return new Error('No Public IP'); } if (!ipaddr.isValid(ip)) { return new Error(`Malformed Public IP ${ip}`); } if (!isWithinValidPublicIpRange(ip)) { return new Error(`Public IP in Invalid Range ${ip}`); } return true; }; const stripUndefined = obj => { const result = obj; Object.keys(result).forEach(key => { if (result[key] && typeof result[key] === 'object') { stripUndefined(result[key]); } else if (result[key] === undefined) { delete result[key]; } }); return result; }; const valueOf = (obj, ...args) => { let ctx = obj; return args.some((arg, index) => { const hasProperty = {}.hasOwnProperty.call(ctx, args[index]); ctx = ctx[args[index]]; return !hasProperty; }) ? undefined : ctx; }; module.exports = { isValidStreamIndex, isValidPublicIP, isWithinValidPublicIpRange, stripUndefined, valueOf }; /** * @typedef {object} Router * @property {*} use * @property {*} post * @property {*} get * @property {*} put * @property {*} delete */ /** * @typedef {object} RateControl * @property {number} bitrate_limit * @property {number} frame_rate_limit */ /** * @typedef {object} H264 * @property {string} h264_profile * @property {number} gov_length */ /** * @typedef {object} VideoInfo * @property {number} index * @property {*} start_time * @property {*} end_time * @property {string} bucket_name * @property {string} object_name */ /** * @typedef {object} Stream * @property {string} mjpg_url * @property {string} rtsp_url * @property {number} trigger_idle_duration * @property {number} trigger_prealarm_duration * @property {number} trigger_video_duration * @property {RateControl} rate_control * @property {H264} h264 * @property {VideoInfo} video_info * @property {string[]} triggered_streams */ /** * @typedef {object} Camera * @property {string} username * @property {string} password * @property {string} public_address * @property {number} web_port */ //# sourceMappingURL=Utils.js.map