documentation: add JS api docs
[oweals/luci.git] / documentation / jsapi / LuCI.rpc.html
1 <!DOCTYPE html>
2 <html lang="en">
3 <head>
4     <meta charset="utf-8">
5     <title>JSDoc: Class: rpc</title>
6
7     <script src="scripts/prettify/prettify.js"> </script>
8     <script src="scripts/prettify/lang-css.js"> </script>
9     <!--[if lt IE 9]>
10       <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
11     <![endif]-->
12     <link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
13     <link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
14 </head>
15
16 <body>
17
18 <div id="main">
19
20     <h1 class="page-title">Class: rpc</h1>
21
22     
23
24
25
26
27 <section>
28
29 <header>
30     
31         <h2><span class="attribs"><span class="type-signature"></span></span>
32             <span class="ancestors"><a href="LuCI.html">LuCI</a>.</span>rpc</h2>
33         
34             <div class="class-description"><p>The <code>LuCI.rpc</code> class provides high level ubus JSON-RPC abstractions
35 and means for listing and invoking remove RPC methods.</p></div>
36         
37     
38 </header>
39
40 <article>
41     <div class="container-overview">
42     
43         
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59 <dl class="details">
60
61     
62
63     
64
65     
66
67     
68
69     
70
71     
72
73     
74
75     
76
77     
78
79     
80
81     
82
83     
84
85     
86     <dt class="tag-source">Source:</dt>
87     <dd class="tag-source"><ul class="dummy"><li>
88         <a href="rpc.js.html">rpc.js</a>, <a href="rpc.js.html#line8">line 8</a>
89     </li></ul></dd>
90     
91
92     
93
94     
95
96     
97 </dl>
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118     
119     </div>
120
121     
122
123     
124
125     
126
127     
128
129     
130
131     
132
133     
134
135     
136         <h3 class="subsection-title">Methods</h3>
137
138         
139             
140
141     
142
143     
144     <h4 class="name" id="addInterceptor"><span class="type-signature"></span>addInterceptor<span class="signature">(interceptorFn)</span><span class="type-signature"> &rarr; {<a href="LuCI.rpc.html#~interceptorFn">LuCI.rpc~interceptorFn</a>}</span></h4>
145     
146
147     
148
149
150
151 <div class="description">
152     <p>Registers a new interceptor function.</p>
153 </div>
154
155
156
157
158
159
160
161
162
163     <h5>Parameters:</h5>
164     
165
166 <table class="params">
167     <thead>
168     <tr>
169         
170         <th>Name</th>
171         
172
173         <th>Type</th>
174
175         
176
177         
178
179         <th class="last">Description</th>
180     </tr>
181     </thead>
182
183     <tbody>
184     
185
186         <tr>
187             
188                 <td class="name"><code>interceptorFn</code></td>
189             
190
191             <td class="type">
192             
193                 
194 <span class="param-type"><a href="LuCI.rpc.html#~interceptorFn">LuCI.rpc~interceptorFn</a></span>
195
196
197             
198             </td>
199
200             
201
202             
203
204             <td class="description last"><p>The inteceptor function to register.</p></td>
205         </tr>
206
207     
208     </tbody>
209 </table>
210
211
212
213
214
215
216 <dl class="details">
217
218     
219
220     
221
222     
223
224     
225
226     
227
228     
229
230     
231
232     
233
234     
235
236     
237
238     
239
240     
241
242     
243     <dt class="tag-source">Source:</dt>
244     <dd class="tag-source"><ul class="dummy"><li>
245         <a href="rpc.js.html">rpc.js</a>, <a href="rpc.js.html#line454">line 454</a>
246     </li></ul></dd>
247     
248
249     
250
251     
252
253     
254 </dl>
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270 <h5>Returns:</h5>
271
272         
273 <div class="param-desc">
274     <p>Returns the given function value.</p>
275 </div>
276
277
278
279 <dl>
280     <dt>
281         Type
282     </dt>
283     <dd>
284         
285 <span class="param-type"><a href="LuCI.rpc.html#~interceptorFn">LuCI.rpc~interceptorFn</a></span>
286
287
288     </dd>
289 </dl>
290
291     
292
293
294
295
296
297         
298             
299
300     
301
302     
303     <h4 class="name" id="declare"><span class="type-signature"></span>declare<span class="signature">(options)</span><span class="type-signature"> &rarr; {<a href="LuCI.rpc.html#~invokeFn">LuCI.rpc~invokeFn</a>}</span></h4>
304     
305
306     
307
308
309
310 <div class="description">
311     <p>Describes a remote RPC call procedure and returns a function
312 implementing it.</p>
313 </div>
314
315
316
317
318
319
320
321
322
323     <h5>Parameters:</h5>
324     
325
326 <table class="params">
327     <thead>
328     <tr>
329         
330         <th>Name</th>
331         
332
333         <th>Type</th>
334
335         
336
337         
338
339         <th class="last">Description</th>
340     </tr>
341     </thead>
342
343     <tbody>
344     
345
346         <tr>
347             
348                 <td class="name"><code>options</code></td>
349             
350
351             <td class="type">
352             
353                 
354 <span class="param-type"><a href="LuCI.rpc.html#.DeclareOptions">LuCI.rpc.DeclareOptions</a></span>
355
356
357             
358             </td>
359
360             
361
362             
363
364             <td class="description last"><p>If any object names are given, this function will return the method
365 signatures of each given object.</p></td>
366         </tr>
367
368     
369     </tbody>
370 </table>
371
372
373
374
375
376
377 <dl class="details">
378
379     
380
381     
382
383     
384
385     
386
387     
388
389     
390
391     
392
393     
394
395     
396
397     
398
399     
400
401     
402
403     
404     <dt class="tag-source">Source:</dt>
405     <dd class="tag-source"><ul class="dummy"><li>
406         <a href="rpc.js.html">rpc.js</a>, <a href="rpc.js.html#line292">line 292</a>
407     </li></ul></dd>
408     
409
410     
411
412     
413
414     
415 </dl>
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431 <h5>Returns:</h5>
432
433         
434 <div class="param-desc">
435     <p>Returns a new function implementing the method call described in
436 <code>options</code>.</p>
437 </div>
438
439
440
441 <dl>
442     <dt>
443         Type
444     </dt>
445     <dd>
446         
447 <span class="param-type"><a href="LuCI.rpc.html#~invokeFn">LuCI.rpc~invokeFn</a></span>
448
449
450     </dd>
451 </dl>
452
453     
454
455
456
457
458
459         
460             
461
462     
463
464     
465     <h4 class="name" id="getBaseURL"><span class="type-signature"></span>getBaseURL<span class="signature">()</span><span class="type-signature"> &rarr; {string}</span></h4>
466     
467
468     
469
470
471
472 <div class="description">
473     <p>Returns the current RPC base URL.</p>
474 </div>
475
476
477
478
479
480
481
482
483
484
485
486
487
488 <dl class="details">
489
490     
491
492     
493
494     
495
496     
497
498     
499
500     
501
502     
503
504     
505
506     
507
508     
509
510     
511
512     
513
514     
515     <dt class="tag-source">Source:</dt>
516     <dd class="tag-source"><ul class="dummy"><li>
517         <a href="rpc.js.html">rpc.js</a>, <a href="rpc.js.html#line367">line 367</a>
518     </li></ul></dd>
519     
520
521     
522
523     
524
525     
526 </dl>
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542 <h5>Returns:</h5>
543
544         
545 <div class="param-desc">
546     <p>Returns the RPC URL endpoint to issue requests against.</p>
547 </div>
548
549
550
551 <dl>
552     <dt>
553         Type
554     </dt>
555     <dd>
556         
557 <span class="param-type">string</span>
558
559
560     </dd>
561 </dl>
562
563     
564
565
566
567
568
569         
570             
571
572     
573
574     
575     <h4 class="name" id="getSessionID"><span class="type-signature"></span>getSessionID<span class="signature">()</span><span class="type-signature"> &rarr; {string}</span></h4>
576     
577
578     
579
580
581
582 <div class="description">
583     <p>Returns the current RPC session id.</p>
584 </div>
585
586
587
588
589
590
591
592
593
594
595
596
597
598 <dl class="details">
599
600     
601
602     
603
604     
605
606     
607
608     
609
610     
611
612     
613
614     
615
616     
617
618     
619
620     
621
622     
623
624     
625     <dt class="tag-source">Source:</dt>
626     <dd class="tag-source"><ul class="dummy"><li>
627         <a href="rpc.js.html">rpc.js</a>, <a href="rpc.js.html#line346">line 346</a>
628     </li></ul></dd>
629     
630
631     
632
633     
634
635     
636 </dl>
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652 <h5>Returns:</h5>
653
654         
655 <div class="param-desc">
656     <p>Returns the 32 byte session ID string used for authenticating remote
657 requests.</p>
658 </div>
659
660
661
662 <dl>
663     <dt>
664         Type
665     </dt>
666     <dd>
667         
668 <span class="param-type">string</span>
669
670
671     </dd>
672 </dl>
673
674     
675
676
677
678
679
680         
681             
682
683     
684
685     
686     <h4 class="name" id="getStatusText"><span class="type-signature"></span>getStatusText<span class="signature">(statusCode)</span><span class="type-signature"> &rarr; {string}</span></h4>
687     
688
689     
690
691
692
693 <div class="description">
694     <p>Translates a numeric <code>ubus</code> error code into a human readable
695 description.</p>
696 </div>
697
698
699
700
701
702
703
704
705
706     <h5>Parameters:</h5>
707     
708
709 <table class="params">
710     <thead>
711     <tr>
712         
713         <th>Name</th>
714         
715
716         <th>Type</th>
717
718         
719
720         
721
722         <th class="last">Description</th>
723     </tr>
724     </thead>
725
726     <tbody>
727     
728
729         <tr>
730             
731                 <td class="name"><code>statusCode</code></td>
732             
733
734             <td class="type">
735             
736                 
737 <span class="param-type">number</span>
738
739
740             
741             </td>
742
743             
744
745             
746
747             <td class="description last"><p>The numeric status code.</p></td>
748         </tr>
749
750     
751     </tbody>
752 </table>
753
754
755
756
757
758
759 <dl class="details">
760
761     
762
763     
764
765     
766
767     
768
769     
770
771     
772
773     
774
775     
776
777     
778
779     
780
781     
782
783     
784
785     
786     <dt class="tag-source">Source:</dt>
787     <dd class="tag-source"><ul class="dummy"><li>
788         <a href="rpc.js.html">rpc.js</a>, <a href="rpc.js.html#line391">line 391</a>
789     </li></ul></dd>
790     
791
792     
793
794     
795
796     
797 </dl>
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813 <h5>Returns:</h5>
814
815         
816 <div class="param-desc">
817     <p>Returns the textual description of the code.</p>
818 </div>
819
820
821
822 <dl>
823     <dt>
824         Type
825     </dt>
826     <dd>
827         
828 <span class="param-type">string</span>
829
830
831     </dd>
832 </dl>
833
834     
835
836
837
838
839
840         
841             
842
843     
844
845     
846     <h4 class="name" id="list"><span class="type-signature"></span>list<span class="signature">(&hellip;objectNames<span class="signature-attributes">opt</span>)</span><span class="type-signature"> &rarr; {Promise.&lt;(Array.&lt;string>|Object.&lt;string, Object.&lt;string, Object.&lt;string, string>>>)>}</span></h4>
847     
848
849     
850
851
852
853 <div class="description">
854     <p>Lists available remote ubus objects or the method signatures of
855 specific objects.</p>
856 <p>This function has two signatures and is sensitive to the number of
857 arguments passed to it:</p>
858 <ul>
859 <li><code>list()</code> -
860 Returns an array containing the names of all remote <code>ubus</code> objects</li>
861 <li><code>list(&quot;objname&quot;, ...)</code>
862 Returns method signatures for each given <code>ubus</code> object name.</li>
863 </ul>
864 </div>
865
866
867
868
869
870
871
872
873
874     <h5>Parameters:</h5>
875     
876
877 <table class="params">
878     <thead>
879     <tr>
880         
881         <th>Name</th>
882         
883
884         <th>Type</th>
885
886         
887         <th>Attributes</th>
888         
889
890         
891
892         <th class="last">Description</th>
893     </tr>
894     </thead>
895
896     <tbody>
897     
898
899         <tr>
900             
901                 <td class="name"><code>objectNames</code></td>
902             
903
904             <td class="type">
905             
906                 
907 <span class="param-type">string</span>
908
909
910             
911             </td>
912
913             
914                 <td class="attributes">
915                 
916                     &lt;optional><br>
917                 
918
919                 
920
921                 
922                     &lt;repeatable><br>
923                 
924                 </td>
925             
926
927             
928
929             <td class="description last"><p>If any object names are given, this function will return the method
930 signatures of each given object.</p></td>
931         </tr>
932
933     
934     </tbody>
935 </table>
936
937
938
939
940
941
942 <dl class="details">
943
944     
945
946     
947
948     
949
950     
951
952     
953
954     
955
956     
957
958     
959
960     
961
962     
963
964     
965
966     
967
968     
969     <dt class="tag-source">Source:</dt>
970     <dd class="tag-source"><ul class="dummy"><li>
971         <a href="rpc.js.html">rpc.js</a>, <a href="rpc.js.html#line140">line 140</a>
972     </li></ul></dd>
973     
974
975     
976
977     
978
979     
980 </dl>
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996 <h5>Returns:</h5>
997
998         
999 <div class="param-desc">
1000     <p>When invoked without arguments, this function will return a promise
1001 resolving to an array of <code>ubus</code> object names. When invoked with one or
1002 more arguments, a promise resolving to an object describing the method
1003 signatures of each requested <code>ubus</code> object name will be returned.</p>
1004 </div>
1005
1006
1007
1008 <dl>
1009     <dt>
1010         Type
1011     </dt>
1012     <dd>
1013         
1014 <span class="param-type">Promise.&lt;(Array.&lt;string>|Object.&lt;string, Object.&lt;string, Object.&lt;string, string>>>)></span>
1015
1016
1017     </dd>
1018 </dl>
1019
1020     
1021
1022
1023
1024
1025
1026         
1027             
1028
1029     
1030
1031     
1032     <h4 class="name" id="removeInterceptor"><span class="type-signature"></span>removeInterceptor<span class="signature">(interceptorFn)</span><span class="type-signature"> &rarr; {boolean}</span></h4>
1033     
1034
1035     
1036
1037
1038
1039 <div class="description">
1040     <p>Removes a registered interceptor function.</p>
1041 </div>
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051     <h5>Parameters:</h5>
1052     
1053
1054 <table class="params">
1055     <thead>
1056     <tr>
1057         
1058         <th>Name</th>
1059         
1060
1061         <th>Type</th>
1062
1063         
1064
1065         
1066
1067         <th class="last">Description</th>
1068     </tr>
1069     </thead>
1070
1071     <tbody>
1072     
1073
1074         <tr>
1075             
1076                 <td class="name"><code>interceptorFn</code></td>
1077             
1078
1079             <td class="type">
1080             
1081                 
1082 <span class="param-type"><a href="LuCI.rpc.html#~interceptorFn">LuCI.rpc~interceptorFn</a></span>
1083
1084
1085             
1086             </td>
1087
1088             
1089
1090             
1091
1092             <td class="description last"><p>The inteceptor function to remove.</p></td>
1093         </tr>
1094
1095     
1096     </tbody>
1097 </table>
1098
1099
1100
1101
1102
1103
1104 <dl class="details">
1105
1106     
1107
1108     
1109
1110     
1111
1112     
1113
1114     
1115
1116     
1117
1118     
1119
1120     
1121
1122     
1123
1124     
1125
1126     
1127
1128     
1129
1130     
1131     <dt class="tag-source">Source:</dt>
1132     <dd class="tag-source"><ul class="dummy"><li>
1133         <a href="rpc.js.html">rpc.js</a>, <a href="rpc.js.html#line470">line 470</a>
1134     </li></ul></dd>
1135     
1136
1137     
1138
1139     
1140
1141     
1142 </dl>
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158 <h5>Returns:</h5>
1159
1160         
1161 <div class="param-desc">
1162     <p>Returns <code>true</code> if the given function has been removed or <code>false</code>
1163 if it has not been found.</p>
1164 </div>
1165
1166
1167
1168 <dl>
1169     <dt>
1170         Type
1171     </dt>
1172     <dd>
1173         
1174 <span class="param-type">boolean</span>
1175
1176
1177     </dd>
1178 </dl>
1179
1180     
1181
1182
1183
1184
1185
1186         
1187             
1188
1189     
1190
1191     
1192     <h4 class="name" id="setBaseURL"><span class="type-signature"></span>setBaseURL<span class="signature">(sid)</span><span class="type-signature"></span></h4>
1193     
1194
1195     
1196
1197
1198
1199 <div class="description">
1200     <p>Set the RPC base URL to use.</p>
1201 </div>
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211     <h5>Parameters:</h5>
1212     
1213
1214 <table class="params">
1215     <thead>
1216     <tr>
1217         
1218         <th>Name</th>
1219         
1220
1221         <th>Type</th>
1222
1223         
1224
1225         
1226
1227         <th class="last">Description</th>
1228     </tr>
1229     </thead>
1230
1231     <tbody>
1232     
1233
1234         <tr>
1235             
1236                 <td class="name"><code>sid</code></td>
1237             
1238
1239             <td class="type">
1240             
1241                 
1242 <span class="param-type">string</span>
1243
1244
1245             
1246             </td>
1247
1248             
1249
1250             
1251
1252             <td class="description last"><p>Sets the RPC URL endpoint to issue requests against.</p></td>
1253         </tr>
1254
1255     
1256     </tbody>
1257 </table>
1258
1259
1260
1261
1262
1263
1264 <dl class="details">
1265
1266     
1267
1268     
1269
1270     
1271
1272     
1273
1274     
1275
1276     
1277
1278     
1279
1280     
1281
1282     
1283
1284     
1285
1286     
1287
1288     
1289
1290     
1291     <dt class="tag-source">Source:</dt>
1292     <dd class="tag-source"><ul class="dummy"><li>
1293         <a href="rpc.js.html">rpc.js</a>, <a href="rpc.js.html#line377">line 377</a>
1294     </li></ul></dd>
1295     
1296
1297     
1298
1299     
1300
1301     
1302 </dl>
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323         
1324             
1325
1326     
1327
1328     
1329     <h4 class="name" id="setSessionID"><span class="type-signature"></span>setSessionID<span class="signature">(sid)</span><span class="type-signature"></span></h4>
1330     
1331
1332     
1333
1334
1335
1336 <div class="description">
1337     <p>Set the RPC session id to use.</p>
1338 </div>
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348     <h5>Parameters:</h5>
1349     
1350
1351 <table class="params">
1352     <thead>
1353     <tr>
1354         
1355         <th>Name</th>
1356         
1357
1358         <th>Type</th>
1359
1360         
1361
1362         
1363
1364         <th class="last">Description</th>
1365     </tr>
1366     </thead>
1367
1368     <tbody>
1369     
1370
1371         <tr>
1372             
1373                 <td class="name"><code>sid</code></td>
1374             
1375
1376             <td class="type">
1377             
1378                 
1379 <span class="param-type">string</span>
1380
1381
1382             
1383             </td>
1384
1385             
1386
1387             
1388
1389             <td class="description last"><p>Sets the 32 byte session ID string used for authenticating remote
1390 requests.</p></td>
1391         </tr>
1392
1393     
1394     </tbody>
1395 </table>
1396
1397
1398
1399
1400
1401
1402 <dl class="details">
1403
1404     
1405
1406     
1407
1408     
1409
1410     
1411
1412     
1413
1414     
1415
1416     
1417
1418     
1419
1420     
1421
1422     
1423
1424     
1425
1426     
1427
1428     
1429     <dt class="tag-source">Source:</dt>
1430     <dd class="tag-source"><ul class="dummy"><li>
1431         <a href="rpc.js.html">rpc.js</a>, <a href="rpc.js.html#line357">line 357</a>
1432     </li></ul></dd>
1433     
1434
1435     
1436
1437     
1438
1439     
1440 </dl>
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461         
1462     
1463
1464     
1465         <h3 class="subsection-title">Type Definitions</h3>
1466
1467         
1468                 
1469 <h4 class="name" id=".DeclareOptions">DeclareOptions</h4>
1470
1471
1472
1473
1474
1475
1476     <h5>Type:</h5>
1477     <ul>
1478         <li>
1479             
1480 <span class="param-type">Object</span>
1481
1482
1483         </li>
1484     </ul>
1485
1486
1487
1488
1489
1490     <h5 class="subsection-title">Properties:</h5>
1491
1492     
1493
1494 <table class="props">
1495     <thead>
1496     <tr>
1497         
1498         <th>Name</th>
1499         
1500
1501         <th>Type</th>
1502
1503         
1504         <th>Attributes</th>
1505         
1506
1507         
1508
1509         <th class="last">Description</th>
1510     </tr>
1511     </thead>
1512
1513     <tbody>
1514     
1515
1516         <tr>
1517             
1518                 <td class="name"><code>object</code></td>
1519             
1520
1521             <td class="type">
1522             
1523                 
1524 <span class="param-type">string</span>
1525
1526
1527             
1528             </td>
1529
1530             
1531                 <td class="attributes">
1532                 
1533
1534                 
1535                 </td>
1536             
1537
1538             
1539
1540             <td class="description last"><p>The name of the remote <code>ubus</code> object to invoke.</p></td>
1541         </tr>
1542
1543     
1544
1545         <tr>
1546             
1547                 <td class="name"><code>method</code></td>
1548             
1549
1550             <td class="type">
1551             
1552                 
1553 <span class="param-type">string</span>
1554
1555
1556             
1557             </td>
1558
1559             
1560                 <td class="attributes">
1561                 
1562
1563                 
1564                 </td>
1565             
1566
1567             
1568
1569             <td class="description last"><p>The name of the remote <code>ubus</code> method to invoke.</p></td>
1570         </tr>
1571
1572     
1573
1574         <tr>
1575             
1576                 <td class="name"><code>params</code></td>
1577             
1578
1579             <td class="type">
1580             
1581                 
1582 <span class="param-type">Array.&lt;string></span>
1583
1584
1585             
1586             </td>
1587
1588             
1589                 <td class="attributes">
1590                 
1591                     &lt;optional><br>
1592                 
1593
1594                 
1595                 </td>
1596             
1597
1598             
1599
1600             <td class="description last"><p>Lists the named parameters expected by the remote <code>ubus</code> RPC method.
1601 The arguments passed to the resulting generated method call function
1602 will be mapped to named parameters in the order they appear in this
1603 array.</p>
1604 <p>Extraneous parameters passed to the generated function will not be
1605 sent to the remote procedure but are passed to the
1606 <a href="LuCI.rpc.html#~filterFn"><code>filter function</code></a> if one is specified.</p>
1607 <p>Examples:</p>
1608 <ul>
1609 <li><code>params: [ &quot;foo&quot;, &quot;bar&quot; ]</code> -
1610 When the resulting call function is invoked with <code>fn(true, false)</code>,
1611 the corresponding args object sent to the remote procedure will be
1612 <code>{ foo: true, bar: false }</code>.</li>
1613 <li><code>params: [ &quot;test&quot; ], filter: function(reply, args, extra) { ... }</code> -
1614 When the resultung generated function is invoked with
1615 <code>fn(&quot;foo&quot;, &quot;bar&quot;, &quot;baz&quot;)</code> then <code>{ &quot;test&quot;: &quot;foo&quot; }</code> will be sent as
1616 argument to the remote procedure and the filter function will be
1617 invoked with <code>filterFn(reply, [ &quot;foo&quot; ], &quot;bar&quot;, &quot;baz&quot;)</code></li>
1618 </ul></td>
1619         </tr>
1620
1621     
1622
1623         <tr>
1624             
1625                 <td class="name"><code>expect</code></td>
1626             
1627
1628             <td class="type">
1629             
1630                 
1631 <span class="param-type">Object.&lt;string, *></span>
1632
1633
1634             
1635             </td>
1636
1637             
1638                 <td class="attributes">
1639                 
1640                     &lt;optional><br>
1641                 
1642
1643                 
1644                 </td>
1645             
1646
1647             
1648
1649             <td class="description last"><p>Describes the expected return data structure. The given object is
1650 supposed to contain a single key selecting the value to use from
1651 the returned <code>ubus</code> reply object. The value of the sole key within
1652 the <code>expect</code> object is used to infer the expected type of the received
1653 <code>ubus</code> reply data.</p>
1654 <p>If the received data does not contain <code>expect</code>'s key, or if the
1655 type of the data differs from the type of the value in the expect
1656 object, the expect object's value is returned as default instead.</p>
1657 <p>The key in the <code>expect</code> object may be an empty string (<code>''</code>) in which
1658 case the entire reply object is selected instead of one of its subkeys.</p>
1659 <p>If the <code>expect</code> option is omitted, the received reply will be returned
1660 as-is, regardless of its format or type.</p>
1661 <p>Examples:</p>
1662 <ul>
1663 <li><code>expect: { '': { error: 'Invalid response' } }</code> -
1664 This requires the entire <code>ubus</code> reply to be a plain JavaScript
1665 object. If the reply isn't an object but e.g. an array or a numeric
1666 error code instead, it will get replaced with
1667 <code>{ error: 'Invalid response' }</code> instead.</li>
1668 <li><code>expect: { results: [] }</code> -
1669 This requires the received <code>ubus</code> reply to be an object containing
1670 a key <code>results</code> with an array as value. If the received reply does
1671 not contain such a key, or if <code>reply.results</code> points to a non-array
1672 value, the empty array (<code>[]</code>) will be used instead.</li>
1673 <li><code>expect: { success: false }</code> -
1674 This requires the received <code>ubus</code> reply to be an object containing
1675 a key <code>success</code> with a boolean value. If the reply does not contain
1676 <code>success</code> or if <code>reply.success</code> is not a boolean value, <code>false</code> will
1677 be returned as default instead.</li>
1678 </ul></td>
1679         </tr>
1680
1681     
1682
1683         <tr>
1684             
1685                 <td class="name"><code>filter</code></td>
1686             
1687
1688             <td class="type">
1689             
1690                 
1691 <span class="param-type"><a href="LuCI.rpc.html#~filterFn">LuCI.rpc~filterFn</a></span>
1692
1693
1694             
1695             </td>
1696
1697             
1698                 <td class="attributes">
1699                 
1700                     &lt;optional><br>
1701                 
1702
1703                 
1704                 </td>
1705             
1706
1707             
1708
1709             <td class="description last"><p>Specfies an optional filter function which is invoked to transform the
1710 received reply data before it is returned to the caller.</p></td>
1711         </tr>
1712
1713     
1714     </tbody>
1715 </table>
1716
1717
1718
1719
1720 <dl class="details">
1721
1722     
1723
1724     
1725
1726     
1727
1728     
1729
1730     
1731
1732     
1733
1734     
1735
1736     
1737
1738     
1739
1740     
1741
1742     
1743
1744     
1745
1746     
1747     <dt class="tag-source">Source:</dt>
1748     <dd class="tag-source"><ul class="dummy"><li>
1749         <a href="rpc.js.html">rpc.js</a>, <a href="rpc.js.html#line160">line 160</a>
1750     </li></ul></dd>
1751     
1752
1753     
1754
1755     
1756
1757     
1758 </dl>
1759
1760
1761
1762
1763
1764
1765             
1766                 
1767
1768     
1769
1770     
1771     <h4 class="name" id="~filterFn"><span class="type-signature"></span>filterFn<span class="signature">(data, args, &hellip;extraArgs)</span><span class="type-signature"> &rarr; {*}</span></h4>
1772     
1773
1774     
1775
1776
1777
1778 <div class="description">
1779     <p>The filter function is invoked to transform a received <code>ubus</code> RPC call
1780 reply before returning it to the caller.</p>
1781 </div>
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791     <h5>Parameters:</h5>
1792     
1793
1794 <table class="params">
1795     <thead>
1796     <tr>
1797         
1798         <th>Name</th>
1799         
1800
1801         <th>Type</th>
1802
1803         
1804         <th>Attributes</th>
1805         
1806
1807         
1808
1809         <th class="last">Description</th>
1810     </tr>
1811     </thead>
1812
1813     <tbody>
1814     
1815
1816         <tr>
1817             
1818                 <td class="name"><code>data</code></td>
1819             
1820
1821             <td class="type">
1822             
1823                 
1824 <span class="param-type">*</span>
1825
1826
1827             
1828             </td>
1829
1830             
1831                 <td class="attributes">
1832                 
1833
1834                 
1835
1836                 
1837                 </td>
1838             
1839
1840             
1841
1842             <td class="description last"><p>The received <code>ubus</code> reply data or a subset of it as described in the
1843 <code>expect</code> option of the RPC call declaration. In case of remote call
1844 errors, <code>data</code> is numeric <code>ubus</code> error code instead.</p></td>
1845         </tr>
1846
1847     
1848
1849         <tr>
1850             
1851                 <td class="name"><code>args</code></td>
1852             
1853
1854             <td class="type">
1855             
1856                 
1857 <span class="param-type">Array.&lt;*></span>
1858
1859
1860             
1861             </td>
1862
1863             
1864                 <td class="attributes">
1865                 
1866
1867                 
1868
1869                 
1870                 </td>
1871             
1872
1873             
1874
1875             <td class="description last"><p>The arguments the RPC method has been invoked with.</p></td>
1876         </tr>
1877
1878     
1879
1880         <tr>
1881             
1882                 <td class="name"><code>extraArgs</code></td>
1883             
1884
1885             <td class="type">
1886             
1887                 
1888 <span class="param-type">*</span>
1889
1890
1891             
1892             </td>
1893
1894             
1895                 <td class="attributes">
1896                 
1897
1898                 
1899
1900                 
1901                     &lt;repeatable><br>
1902                 
1903                 </td>
1904             
1905
1906             
1907
1908             <td class="description last"><p>All extraneous arguments passed to the RPC method exceeding the number
1909 of arguments describes in the RPC call declaration.</p></td>
1910         </tr>
1911
1912     
1913     </tbody>
1914 </table>
1915
1916
1917
1918
1919
1920
1921 <dl class="details">
1922
1923     
1924
1925     
1926
1927     
1928
1929     
1930
1931     
1932
1933     
1934
1935     
1936
1937     
1938
1939     
1940
1941     
1942
1943     
1944
1945     
1946
1947     
1948     <dt class="tag-source">Source:</dt>
1949     <dd class="tag-source"><ul class="dummy"><li>
1950         <a href="rpc.js.html">rpc.js</a>, <a href="rpc.js.html#line231">line 231</a>
1951     </li></ul></dd>
1952     
1953
1954     
1955
1956     
1957
1958     
1959 </dl>
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975 <h5>Returns:</h5>
1976
1977         
1978 <div class="param-desc">
1979     <p>The return value of the filter function will be returned to the caller
1980 of the RPC method as-is.</p>
1981 </div>
1982
1983
1984
1985 <dl>
1986     <dt>
1987         Type
1988     </dt>
1989     <dd>
1990         
1991 <span class="param-type">*</span>
1992
1993
1994     </dd>
1995 </dl>
1996
1997     
1998
1999
2000
2001
2002
2003             
2004                 
2005
2006     
2007
2008     
2009     <h4 class="name" id="~interceptorFn"><span class="type-signature"></span>interceptorFn<span class="signature">(msg, req)</span><span class="type-signature"> &rarr; {Promise.&lt;*>|*}</span></h4>
2010     
2011
2012     
2013
2014
2015
2016 <div class="description">
2017     <p>Registered interceptor functions are invoked before the standard reply
2018 parsing and handling logic.</p>
2019 <p>By returning rejected promises, interceptor functions can cause the
2020 invocation function to fail, regardless of the received reply.</p>
2021 <p>Interceptors may also modify their message argument in-place to
2022 rewrite received replies before they're processed by the standard
2023 response handling code.</p>
2024 <p>A common use case for such functions is to detect failing RPC replies
2025 due to expired authentication in order to trigger a new login.</p>
2026 </div>
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036     <h5>Parameters:</h5>
2037     
2038
2039 <table class="params">
2040     <thead>
2041     <tr>
2042         
2043         <th>Name</th>
2044         
2045
2046         <th>Type</th>
2047
2048         
2049
2050         
2051
2052         <th class="last">Description</th>
2053     </tr>
2054     </thead>
2055
2056     <tbody>
2057     
2058
2059         <tr>
2060             
2061                 <td class="name"><code>msg</code></td>
2062             
2063
2064             <td class="type">
2065             
2066                 
2067 <span class="param-type">*</span>
2068
2069
2070             
2071             </td>
2072
2073             
2074
2075             
2076
2077             <td class="description last"><p>The unprocessed, JSON decoded remote RPC method call reply.</p>
2078 <p>Since interceptors run before the standard parsing logic, the reply
2079 data is not verified for correctness or filtered according to
2080 <code>expect</code> and <code>filter</code> specifications in the declarations.</p></td>
2081         </tr>
2082
2083     
2084
2085         <tr>
2086             
2087                 <td class="name"><code>req</code></td>
2088             
2089
2090             <td class="type">
2091             
2092                 
2093 <span class="param-type">Object</span>
2094
2095
2096             
2097             </td>
2098
2099             
2100
2101             
2102
2103             <td class="description last"><p>The related request object which is an extended variant of the
2104 declaration object, allowing access to internals of the invocation
2105 function such as <code>filter</code>, <code>expect</code> or <code>params</code> values.</p></td>
2106         </tr>
2107
2108     
2109     </tbody>
2110 </table>
2111
2112
2113
2114
2115
2116
2117 <dl class="details">
2118
2119     
2120
2121     
2122
2123     
2124
2125     
2126
2127     
2128
2129     
2130
2131     
2132
2133     
2134
2135     
2136
2137     
2138
2139     
2140
2141     
2142
2143     
2144     <dt class="tag-source">Source:</dt>
2145     <dd class="tag-source"><ul class="dummy"><li>
2146         <a href="rpc.js.html">rpc.js</a>, <a href="rpc.js.html#line408">line 408</a>
2147     </li></ul></dd>
2148     
2149
2150     
2151
2152     
2153
2154     
2155 </dl>
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171 <h5>Returns:</h5>
2172
2173         
2174 <div class="param-desc">
2175     <p>Interceptor functions may return a promise to defer response
2176 processing until some delayed work completed. Any values the returned
2177 promise resolves to are ignored.</p>
2178 <p>When the returned promise rejects with an error, the invocation
2179 function will fail too, forwarding the error to the caller.</p>
2180 </div>
2181
2182
2183
2184 <dl>
2185     <dt>
2186         Type
2187     </dt>
2188     <dd>
2189         
2190 <span class="param-type">Promise.&lt;*></span>
2191 |
2192
2193 <span class="param-type">*</span>
2194
2195
2196     </dd>
2197 </dl>
2198
2199     
2200
2201
2202
2203
2204
2205             
2206                 
2207
2208     
2209
2210     
2211     <h4 class="name" id="~invokeFn"><span class="type-signature"></span>invokeFn<span class="signature">(&hellip;params)</span><span class="type-signature"> &rarr; {Promise.&lt;*>}</span></h4>
2212     
2213
2214     
2215
2216
2217
2218 <div class="description">
2219     <p>The generated invocation function is returned by
2220 <a href="LuCI.rpc.html#declare"><code>rpc.declare()</code></a> and encapsulates a single
2221 RPC method call.</p>
2222 <p>Calling this function will execute a remote <code>ubus</code> HTTP call request
2223 using the arguments passed to it as arguments and return a promise
2224 resolving to the received reply values.</p>
2225 </div>
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235     <h5>Parameters:</h5>
2236     
2237
2238 <table class="params">
2239     <thead>
2240     <tr>
2241         
2242         <th>Name</th>
2243         
2244
2245         <th>Type</th>
2246
2247         
2248         <th>Attributes</th>
2249         
2250
2251         
2252
2253         <th class="last">Description</th>
2254     </tr>
2255     </thead>
2256
2257     <tbody>
2258     
2259
2260         <tr>
2261             
2262                 <td class="name"><code>params</code></td>
2263             
2264
2265             <td class="type">
2266             
2267                 
2268 <span class="param-type">*</span>
2269
2270
2271             
2272             </td>
2273
2274             
2275                 <td class="attributes">
2276                 
2277
2278                 
2279
2280                 
2281                     &lt;repeatable><br>
2282                 
2283                 </td>
2284             
2285
2286             
2287
2288             <td class="description last"><p>The parameters to pass to the remote procedure call. The given
2289 positional arguments will be named to named RPC parameters according
2290 to the names specified in the <code>params</code> array of the method declaration.</p>
2291 <p>Any additional parameters exceeding the amount of arguments in the
2292 <code>params</code> declaration are passed as private extra arguments to the
2293 declared filter function.</p></td>
2294         </tr>
2295
2296     
2297     </tbody>
2298 </table>
2299
2300
2301
2302
2303
2304
2305 <dl class="details">
2306
2307     
2308
2309     
2310
2311     
2312
2313     
2314
2315     
2316
2317     
2318
2319     
2320
2321     
2322
2323     
2324
2325     
2326
2327     
2328
2329     
2330
2331     
2332     <dt class="tag-source">Source:</dt>
2333     <dd class="tag-source"><ul class="dummy"><li>
2334         <a href="rpc.js.html">rpc.js</a>, <a href="rpc.js.html#line254">line 254</a>
2335     </li></ul></dd>
2336     
2337
2338     
2339
2340     
2341
2342     
2343 </dl>
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359 <h5>Returns:</h5>
2360
2361         
2362 <div class="param-desc">
2363     <p>Returns a promise resolving to the result data of the remote <code>ubus</code>
2364 RPC method invocation, optionally substituted and filtered according
2365 to the <code>expect</code> and <code>filter</code> declarations.</p>
2366 </div>
2367
2368
2369
2370 <dl>
2371     <dt>
2372         Type
2373     </dt>
2374     <dd>
2375         
2376 <span class="param-type">Promise.&lt;*></span>
2377
2378
2379     </dd>
2380 </dl>
2381
2382     
2383
2384
2385
2386
2387
2388             
2389     
2390
2391     
2392 </article>
2393
2394 </section>
2395
2396
2397
2398
2399 </div>
2400
2401 <nav>
2402     <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="LuCI.html">LuCI</a></li><li><a href="LuCI.Class.html">Class</a></li><li><a href="LuCI.dom.html">dom</a></li><li><a href="LuCI.fs.html">fs</a></li><li><a href="LuCI.Headers.html">Headers</a></li><li><a href="LuCI.Network.html">Network</a></li><li><a href="LuCI.Network.Device.html">Device</a></li><li><a href="LuCI.Network.Hosts.html">Hosts</a></li><li><a href="LuCI.Network.Protocol.html">Protocol</a></li><li><a href="LuCI.Network.WifiDevice.html">WifiDevice</a></li><li><a href="LuCI.Network.WifiNetwork.html">WifiNetwork</a></li><li><a href="LuCI.Poll.html">Poll</a></li><li><a href="LuCI.Request.html">Request</a></li><li><a href="LuCI.Request.poll.html">poll</a></li><li><a href="LuCI.Response.html">Response</a></li><li><a href="LuCI.rpc.html">rpc</a></li><li><a href="LuCI.uci.html">uci</a></li><li><a href="LuCI.view.html">view</a></li><li><a href="LuCI.XHR.html">XHR</a></li></ul>
2403 </nav>
2404
2405 <br class="clear">
2406
2407 <footer>
2408     Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.3</a> on Tue Nov 05 2019 09:33:05 GMT+0100 (Central European Standard Time)
2409 </footer>
2410
2411 <script> prettyPrint(); </script>
2412 <script src="scripts/linenumber.js"> </script>
2413 </body>
2414 </html>