@leofcoin/endpoint-clients 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/exports/http.js +3 -0
- package/package.json +1 -1
- package/test/index.js +13 -0
- package/test/spec.js +43 -0
package/exports/http.js
CHANGED
package/package.json
CHANGED
package/test/index.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { needsImplementations } from './spec.js';
|
|
2
|
+
import WsClient from './../exports/ws.js'
|
|
3
|
+
import HttpClient from './../exports/http.js'
|
|
4
|
+
|
|
5
|
+
try {
|
|
6
|
+
const wsNeeds = needsImplementations(new WsClient())
|
|
7
|
+
if (wsNeeds.length > 0) throw new Error(`ws: missing implementations ${wsNeeds.length > 2 ? wsNeeds.join(', ') : wsNeeds.join(' & ')}`)
|
|
8
|
+
|
|
9
|
+
const httpNeeds = needsImplementations(new HttpClient())
|
|
10
|
+
if (httpNeeds.length > 0) throw new Error(`http: missing implementations ${httpNeeds.length > 2 ? httpNeeds.join(', ') : httpNeeds.join(' & ')}`)
|
|
11
|
+
} catch (error) {
|
|
12
|
+
console.error(error);
|
|
13
|
+
}
|
package/test/spec.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
export const implementations = [
|
|
2
|
+
'accounts',
|
|
3
|
+
'balanceOf',
|
|
4
|
+
'balances',
|
|
5
|
+
'blocks',
|
|
6
|
+
'contracts',
|
|
7
|
+
'createContractAddress',
|
|
8
|
+
'createTransactionFrom',
|
|
9
|
+
'deployContract',
|
|
10
|
+
'getBlock',
|
|
11
|
+
'hasTransactionToHandle',
|
|
12
|
+
'lookup',
|
|
13
|
+
'nativeBurns',
|
|
14
|
+
'nativeCalls',
|
|
15
|
+
'nativeMints',
|
|
16
|
+
'nativeToken',
|
|
17
|
+
'nativeTransfers',
|
|
18
|
+
'participate',
|
|
19
|
+
'participating',
|
|
20
|
+
'peerId',
|
|
21
|
+
'peers',
|
|
22
|
+
'pubsub',
|
|
23
|
+
'selectAccount',
|
|
24
|
+
'selectedAccount',
|
|
25
|
+
'staticCall',
|
|
26
|
+
'totalBlocks',
|
|
27
|
+
'totalSize',
|
|
28
|
+
'totalTransactions',
|
|
29
|
+
'validators'
|
|
30
|
+
]
|
|
31
|
+
|
|
32
|
+
export const needsImplementations = (client) => {
|
|
33
|
+
const needs = []
|
|
34
|
+
for (const key of implementations) {
|
|
35
|
+
try {
|
|
36
|
+
if (!client[key] && key === 'pubsub' && !client.isHttpClient) needs.push(key)
|
|
37
|
+
} catch (error) {
|
|
38
|
+
if (error.message !== "Cannot read properties of undefined (reading 'pubsub')") throw new Error(error)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
}
|
|
42
|
+
return needs
|
|
43
|
+
}
|