UNPKG

2.24 kBJavaScriptView Raw
1'use strict';
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.info = info;
7exports.version = version;
8exports.devices = devices;
9exports.acquire = acquire;
10exports.call = call;
11function info(res) {
12 if (typeof res !== 'object' || res == null) {
13 throw new Error('Wrong result type.');
14 }
15 var version = res.version;
16 if (typeof version !== 'string') {
17 throw new Error('Wrong result type.');
18 }
19 var configured = !!res.configured;
20 return { version: version, configured: configured };
21}
22
23// input checks for high-level transports
24
25function version(version) {
26 if (typeof version !== 'string') {
27 throw new Error('Wrong result type.');
28 }
29 return version.trim();
30}
31
32function devices(res) {
33 if (typeof res !== 'object') {
34 throw new Error('Wrong result type.');
35 }
36 if (!(res instanceof Array)) {
37 throw new Error('Wrong result type.');
38 }
39 return res.map(function (o) {
40 if (typeof o !== 'object' || o == null) {
41 throw new Error('Wrong result type.');
42 }
43 var path = o.path;
44 if (typeof path !== 'number' && typeof path !== 'string') {
45 throw new Error('Wrong result type.');
46 }
47 var pathS = path.toString();
48 var session = o.session;
49 if (session == null) {
50 return {
51 path: pathS,
52 session: null
53 };
54 } else {
55 if (typeof session !== 'number' && typeof session !== 'string') {
56 throw new Error('Wrong result type.');
57 }
58 return {
59 path: pathS,
60 session: session.toString()
61 };
62 }
63 });
64}
65
66function acquire(res) {
67 if (typeof res !== 'object' || res == null) {
68 throw new Error('Wrong result type.');
69 }
70 var session = res.session;
71 if (typeof session !== 'string' && typeof session !== 'number') {
72 throw new Error('Wrong result type.');
73 }
74 return session.toString();
75}
76
77function call(res) {
78 if (typeof res !== 'object' || res == null) {
79 throw new Error('Wrong result type.');
80 }
81 var type = res.type;
82 if (typeof type !== 'string') {
83 throw new Error('Wrong result type.');
84 }
85 var message = res.message;
86 if (typeof message !== 'object' || message == null) {
87 throw new Error('Wrong result type.');
88 }
89 return { type: type, message: message };
90}
\No newline at end of file