@@ -9,8 +9,8 @@ const toUrlSearchParams = require('../../lib/to-url-search-params')
9
9
* @typedef {import('interface-ipfs-core/type/basic').AbortOptions } AbortOptions
10
10
* @typedef {import('interface-ipfs-core/type/pin/remote/service').API } API
11
11
* @typedef {import('interface-ipfs-core/type/pin/remote/service').Credentials } Credentials
12
- * @typedef {import('interface-ipfs-core/type/pin/remote/service').ListOptions } ListOptions
13
12
* @typedef {import('interface-ipfs-core/type/pin/remote/service').RemotePinService } RemotePinService
13
+ * @typedef {import('interface-ipfs-core/type/pin/remote/service').RemotePinServiceWithStat } RemotePinServiceWithStat
14
14
* @implements {API}
15
15
*/
16
16
class Service {
@@ -56,8 +56,9 @@ class Service {
56
56
}
57
57
58
58
/**
59
+ * @template {true} Stat
59
60
* @param {Client } client
60
- * @param {ListOptions & AbortOptions & HttpOptions } [options]
61
+ * @param {{ stat?: Stat } & AbortOptions & HttpOptions } [options]
61
62
*/
62
63
static async ls ( client , { stat, timeout, signal, headers } = { } ) {
63
64
const response = await client . post ( 'pin/remote/service/ls' , {
@@ -68,24 +69,26 @@ class Service {
68
69
} )
69
70
/** @type {{RemoteServices: Object[]} } */
70
71
const { RemoteServices } = await response . json ( )
71
- return RemoteServices . map ( Service . decodeRemoteService )
72
+
73
+ /** @type {Stat extends true ? RemotePinServiceWithStat[] : RemotePinService [] } */
74
+ return ( RemoteServices . map ( Service . decodeRemoteService ) )
72
75
}
73
76
74
77
/**
75
78
* @param {Object } json
76
- * @returns {import('interface-ipfs-core/type/pin/remote/service').RemotePinService }
79
+ * @returns {RemotePinServiceWithStat }
77
80
*/
78
81
static decodeRemoteService ( json ) {
79
82
return {
80
83
service : json . Service ,
81
84
endpoint : new URL ( json . ApiEndpoint ) ,
82
- stat : Service . decodeStat ( json . stat )
85
+ stat : json . stat && Service . decodeStat ( json . stat )
83
86
}
84
87
}
85
88
86
89
/**
87
90
* @param {Object } json
88
- * @returns {import('interface-ipfs-core/type/pin/remote/service').Stat|undefined }
91
+ * @returns {import('interface-ipfs-core/type/pin/remote/service').Stat }
89
92
*/
90
93
static decodeStat ( json ) {
91
94
switch ( json . Status ) {
@@ -98,8 +101,9 @@ class Service {
98
101
case 'invalid' : {
99
102
return { status : 'invalid' }
100
103
}
101
- default :
102
- return undefined
104
+ default : {
105
+ return { status : json . Status }
106
+ }
103
107
}
104
108
}
105
109
@@ -128,7 +132,7 @@ class Service {
128
132
/**
129
133
* List registered remote pinning services.
130
134
*
131
- * @param {ListOptions & AbortOptions & HttpOptions } [options]
135
+ * @param {{ stat?: true } & AbortOptions & HttpOptions } [options]
132
136
*/
133
137
ls ( options ) {
134
138
return Service . ls ( this . client , options )
0 commit comments