yeow-api 0.2.57 → 0.2.58
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/assets-path.d.ts +3 -0
- package/src/assets-path.ts +7 -0
- package/src/index.ts +2 -1
- package/src/log.ts +8 -3
- package/src/service.ts +30 -4
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -41,6 +41,7 @@ export {
|
|
|
41
41
|
export { assets, read as assetsRead, readSync as assetsReadSync,
|
|
42
42
|
readBase64 as assetsReadBase64, readBase64Sync as assetsReadBase64Sync,
|
|
43
43
|
extract as assetsExtract, extractSync as assetsExtractSync } from './assets.js';
|
|
44
|
+
export { getAssetsPath } from './assets-path.js';
|
|
44
45
|
export { path } from './path.js';
|
|
45
46
|
export { listen, respond, close, request } from './http.js';
|
|
46
47
|
export { logError } from './log-error.js';
|
|
@@ -80,5 +81,5 @@ export { createBoard as createScoreboard, deleteBoard as deleteScoreboard,
|
|
|
80
81
|
export { getMaterials, getBlocks, getItems } from './material.js';
|
|
81
82
|
export type { MaterialInfo } from './material.js';
|
|
82
83
|
export { registerService, registerNativeService, request as serviceRequest, subscribe as serviceSubscribe, publish as servicePublish } from './service.js';
|
|
83
|
-
export type { ServiceResult } from './service.js';
|
|
84
|
+
export type { ServiceResult, NativeServiceResult } from './service.js';
|
|
84
85
|
export { log, Logger } from './log.js';
|
package/src/log.ts
CHANGED
|
@@ -3,15 +3,20 @@ function _sendLog(level: string, prefix: string, ...args: unknown[]): void {
|
|
|
3
3
|
$send('log', { level, message: msg });
|
|
4
4
|
}
|
|
5
5
|
|
|
6
|
+
function _pluginPrefix(): string {
|
|
7
|
+
return (typeof __plugin !== 'undefined' && __plugin?.name)
|
|
8
|
+
? '[' + __plugin.name + '] ' : '';
|
|
9
|
+
}
|
|
10
|
+
|
|
6
11
|
export const log = {
|
|
7
12
|
info(...args: unknown[]): void {
|
|
8
|
-
_sendLog('INFO',
|
|
13
|
+
_sendLog('INFO', _pluginPrefix(), ...args);
|
|
9
14
|
},
|
|
10
15
|
warn(...args: unknown[]): void {
|
|
11
|
-
_sendLog('WARN',
|
|
16
|
+
_sendLog('WARN', _pluginPrefix(), ...args);
|
|
12
17
|
},
|
|
13
18
|
error(...args: unknown[]): void {
|
|
14
|
-
_sendLog('ERROR',
|
|
19
|
+
_sendLog('ERROR', _pluginPrefix(), ...args);
|
|
15
20
|
},
|
|
16
21
|
};
|
|
17
22
|
|
package/src/service.ts
CHANGED
|
@@ -5,7 +5,10 @@ export interface ServiceResult {
|
|
|
5
5
|
token: string;
|
|
6
6
|
}
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
export interface NativeServiceResult {
|
|
9
|
+
serviceId: string;
|
|
10
|
+
ready: () => Promise<void>;
|
|
11
|
+
}
|
|
9
12
|
|
|
10
13
|
// ── Register Plugin Service ──
|
|
11
14
|
|
|
@@ -28,9 +31,32 @@ export async function registerService(refName: string, onRequest: (path: string,
|
|
|
28
31
|
type NativePlatform = string | { file: string } | { dir: string; entry: string };
|
|
29
32
|
type NativePlatforms = Record<string, NativePlatform>;
|
|
30
33
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
+
function _serviceReady(serviceId: string): Promise<void> {
|
|
35
|
+
return new Promise((resolve, reject) => {
|
|
36
|
+
const cbId = _registerCallback((result: any) => {
|
|
37
|
+
if (result?.err) {
|
|
38
|
+
const info = result.err;
|
|
39
|
+
if (typeof info === 'string') {
|
|
40
|
+
reject(new Error(info));
|
|
41
|
+
} else {
|
|
42
|
+
const e = new Error(info.message || 'Unknown error');
|
|
43
|
+
(e as any).exitCode = info.exitCode;
|
|
44
|
+
(e as any).output = info.output || '';
|
|
45
|
+
reject(e);
|
|
46
|
+
}
|
|
47
|
+
} else resolve();
|
|
48
|
+
});
|
|
49
|
+
$send('service', { t: 'awaitReady', serviceId, cb: cbId });
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export async function registerNativeService(refName: string, platforms: NativePlatforms, isPublic = true): Promise<NativeServiceResult> {
|
|
54
|
+
const r = $send('service', { t: 'registerNative', refName, platforms, public: isPublic }) as { serviceId: string; err?: string };
|
|
55
|
+
if (r.err) throw new Error(r.err);
|
|
56
|
+
return {
|
|
57
|
+
serviceId: r.serviceId,
|
|
58
|
+
ready: () => _serviceReady(r.serviceId),
|
|
59
|
+
};
|
|
34
60
|
}
|
|
35
61
|
|
|
36
62
|
// ── Request ──
|