yeow-api 0.2.54 → 0.2.56
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/package.json +1 -1
- package/src/service.ts +6 -7
package/package.json
CHANGED
package/src/service.ts
CHANGED
|
@@ -23,28 +23,27 @@ export async function registerService(refName: string, onRequest: (path: string,
|
|
|
23
23
|
return r;
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
export async function registerNativeService(refName: string, platforms: Record<string, string>, isPublic = true): Promise<
|
|
27
|
-
const r = $send('service', { t: 'registerNative', refName, platforms, public: isPublic }) as
|
|
26
|
+
export async function registerNativeService(refName: string, platforms: Record<string, string>, isPublic = true): Promise<{ serviceId: string }> {
|
|
27
|
+
const r = $send('service', { t: 'registerNative', refName, platforms, public: isPublic }) as { serviceId: string };
|
|
28
28
|
return r;
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
// ── Request ──
|
|
32
32
|
|
|
33
33
|
export function request(serviceId: string, path: string, body?: any): Promise<any> {
|
|
34
|
-
const reqId = 'svcreq_' + (++_reqSeq);
|
|
35
34
|
return new Promise((resolve, reject) => {
|
|
36
|
-
_registerCallback((result: any) => {
|
|
35
|
+
const cbId = _registerCallback((result: any) => {
|
|
37
36
|
if (result?.err) { reject(new Error(result.err)); } else resolve(result);
|
|
38
37
|
});
|
|
39
|
-
$send('service', { t: 'request', serviceId, path, body: body || {}, requestId:
|
|
38
|
+
$send('service', { t: 'request', serviceId, path, body: body || {}, requestId: cbId });
|
|
40
39
|
});
|
|
41
40
|
}
|
|
42
41
|
|
|
43
42
|
// ── Subscribe ──
|
|
44
43
|
|
|
45
|
-
export function subscribe(serviceId: string, eventPath: string, handler: (
|
|
44
|
+
export function subscribe(serviceId: string, eventPath: string, handler: (body: any, eventPath: string) => void): () => void {
|
|
46
45
|
const cbId = _registerCallback((payload: any) => {
|
|
47
|
-
handler(payload.
|
|
46
|
+
handler(payload.body, payload.eventPath);
|
|
48
47
|
}, { persistent: true });
|
|
49
48
|
$send('service', { t: 'subscribe', serviceId, eventPath, cb: cbId });
|
|
50
49
|
return () => {
|