typed-bridge 2.0.10 → 2.0.12
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/dist/helpers/index.js
CHANGED
|
@@ -26,7 +26,6 @@ const getLocalIPList = () => {
|
|
|
26
26
|
const seperator = '\n-x-x-x-x-x-\n';
|
|
27
27
|
const printStartLogs = (port) => {
|
|
28
28
|
const ipList = getLocalIPList();
|
|
29
|
-
console.log(ipList);
|
|
30
29
|
console.log(seperator);
|
|
31
30
|
console.log(chalk_1.default.bgWhite.black(' Typed Bridge '));
|
|
32
31
|
console.log(seperator);
|
|
@@ -10,45 +10,49 @@ const typescript_1 = __importDefault(require("typescript"));
|
|
|
10
10
|
// Snippet to inject at the end
|
|
11
11
|
const proxySnippet = () => `
|
|
12
12
|
type typedBridgeConfig = {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
host: string
|
|
14
|
+
headers: { [key: string]: string }
|
|
15
|
+
onResponse: (res: Response) => void
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
export const typedBridgeConfig: typedBridgeConfig = {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
host: '',
|
|
20
|
+
headers: { 'Content-Type': 'application/json' },
|
|
21
|
+
onResponse: (res: Response) => {}
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
export const typedBridge = new Proxy(
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
25
|
+
{},
|
|
26
|
+
{
|
|
27
|
+
get(_, methodName: string) {
|
|
28
|
+
return async (args: any) => {
|
|
29
|
+
const response = await fetch(
|
|
30
|
+
typedBridgeConfig.host + (typedBridgeConfig.host.endsWith('/') ? '' : '/') + methodName,
|
|
31
|
+
{
|
|
32
|
+
method: 'POST',
|
|
33
|
+
headers: {
|
|
34
|
+
'Content-Type': 'application/json',
|
|
35
|
+
...typedBridgeConfig.headers
|
|
36
|
+
},
|
|
37
|
+
body: JSON.stringify(args)
|
|
38
|
+
}
|
|
39
|
+
)
|
|
40
40
|
|
|
41
|
-
|
|
41
|
+
typedBridgeConfig.onResponse(response)
|
|
42
42
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
43
|
+
if (!response.ok) {
|
|
44
|
+
const errorText = await response.text()
|
|
45
|
+
console.error('REQ_FAILED', response.url, errorText)
|
|
46
|
+
throw new Error(errorText)
|
|
47
|
+
}
|
|
47
48
|
|
|
48
|
-
|
|
49
|
-
|
|
49
|
+
return response.json().catch(error => {
|
|
50
|
+
console.error('RES_NOT_JSON', response.url, error)
|
|
51
|
+
throw new Error(error.message)
|
|
52
|
+
})
|
|
53
|
+
}
|
|
54
|
+
}
|
|
50
55
|
}
|
|
51
|
-
}
|
|
52
56
|
) as typeof _default
|
|
53
57
|
|
|
54
58
|
export default typedBridge
|