@kitsuned/webos-service 1.0.7 → 1.2.0
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/index.d.ts +2 -15
- package/dist/index.js +13 -28
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,20 +1,9 @@
|
|
|
1
|
+
import { LunaClient, type LunaResponse } from '@kitsuned/webos-luna-isomorphic-client';
|
|
1
2
|
import { Message } from './message';
|
|
2
3
|
type AnyRecord = Record<string, any>;
|
|
3
|
-
export type LunaErrorResponse = {
|
|
4
|
-
returnValue: false;
|
|
5
|
-
errorCode?: number;
|
|
6
|
-
errorText: string;
|
|
7
|
-
};
|
|
8
|
-
export type LunaSuccessResponse<T> = {
|
|
9
|
-
returnValue?: true;
|
|
10
|
-
} & T;
|
|
11
|
-
export type LunaResponse<T extends AnyRecord> = LunaSuccessResponse<T> | LunaErrorResponse;
|
|
12
4
|
export type Executor<TReq extends AnyRecord, TResp extends AnyRecord | void, TNext extends AnyRecord> = (payload: TReq, message: Message<TReq>) => AsyncGenerator<TNext, TResp> | Promise<TResp> | TResp;
|
|
13
|
-
export type Client = Pick<Service, 'oneshot' | 'subscribe' | 'stream'> & {
|
|
14
|
-
id: string | null;
|
|
15
|
-
};
|
|
16
5
|
export declare const isLegacyBus: boolean;
|
|
17
|
-
export declare class Service {
|
|
6
|
+
export declare class Service extends LunaClient {
|
|
18
7
|
readonly id: string;
|
|
19
8
|
private readonly handleOutbound;
|
|
20
9
|
private readonly handlePublic;
|
|
@@ -27,8 +16,6 @@ export declare class Service {
|
|
|
27
16
|
bus?: 'public' | 'private' | 'both';
|
|
28
17
|
}): void;
|
|
29
18
|
subscribe<T extends AnyRecord>(uri: string, params: AnyRecord, callback: (response: LunaResponse<T>) => void): () => void;
|
|
30
|
-
stream<T extends AnyRecord>(uri: string, params?: AnyRecord): AsyncGenerator<LunaResponse<T>, void>;
|
|
31
|
-
oneshot<T extends AnyRecord>(uri: string, params?: AnyRecord): Promise<LunaResponse<T>>;
|
|
32
19
|
unregister(): void;
|
|
33
20
|
private drainExecutor;
|
|
34
21
|
private handleRequest;
|
package/dist/index.js
CHANGED
|
@@ -7,7 +7,7 @@ exports.Service = exports.isLegacyBus = void 0;
|
|
|
7
7
|
const palmbus_1 = __importDefault(require("palmbus"));
|
|
8
8
|
const fs_1 = require("fs");
|
|
9
9
|
const path_1 = require("path");
|
|
10
|
-
const
|
|
10
|
+
const webos_luna_isomorphic_client_1 = require("@kitsuned/webos-luna-isomorphic-client");
|
|
11
11
|
const message_1 = require("./message");
|
|
12
12
|
const idle_timer_1 = require("./idle-timer");
|
|
13
13
|
function extractMethodPath(path) {
|
|
@@ -32,7 +32,7 @@ function readServiceIdFromConfig() {
|
|
|
32
32
|
return config.id;
|
|
33
33
|
}
|
|
34
34
|
exports.isLegacyBus = (0, fs_1.existsSync)('/var/run/ls2/ls-hubd.private.pid');
|
|
35
|
-
class Service {
|
|
35
|
+
class Service extends webos_luna_isomorphic_client_1.LunaClient {
|
|
36
36
|
id;
|
|
37
37
|
handleOutbound;
|
|
38
38
|
handlePublic;
|
|
@@ -41,20 +41,21 @@ class Service {
|
|
|
41
41
|
methods = new Map();
|
|
42
42
|
pending = new Map();
|
|
43
43
|
constructor(serviceId, idleTimeout = null, publicBus = true) {
|
|
44
|
+
super();
|
|
44
45
|
this.idleTimer = new idle_timer_1.IdleTimer(idleTimeout, this.handleQuit.bind(this));
|
|
45
46
|
this.id = serviceId ?? readServiceIdFromConfig();
|
|
47
|
+
const register = (...params) => {
|
|
48
|
+
const handle = new palmbus_1.default.Handle(...params);
|
|
49
|
+
handle.addListener('request', this.handleRequest.bind(this));
|
|
50
|
+
handle.addListener('cancel', this.handleCancel.bind(this));
|
|
51
|
+
return handle;
|
|
52
|
+
};
|
|
46
53
|
if (exports.isLegacyBus) {
|
|
47
|
-
this.handlePublic =
|
|
48
|
-
this.
|
|
49
|
-
this.handlePublic.addListener('cancel', this.handleCancel.bind(this));
|
|
50
|
-
this.handlePrivate = new palmbus_1.default.Handle(this.id, false);
|
|
51
|
-
this.handlePrivate.addListener('request', this.handleRequest.bind(this));
|
|
52
|
-
this.handlePrivate.addListener('cancel', this.handleCancel.bind(this));
|
|
54
|
+
this.handlePublic = register(this.id, true);
|
|
55
|
+
this.handlePrivate = register(this.id, false);
|
|
53
56
|
}
|
|
54
57
|
else {
|
|
55
|
-
const handle =
|
|
56
|
-
handle.addListener('request', this.handleRequest.bind(this));
|
|
57
|
-
handle.addListener('cancel', this.handleCancel.bind(this));
|
|
58
|
+
const handle = register(this.id);
|
|
58
59
|
this.handlePublic = handle;
|
|
59
60
|
this.handlePrivate = handle;
|
|
60
61
|
}
|
|
@@ -83,22 +84,6 @@ class Service {
|
|
|
83
84
|
});
|
|
84
85
|
return () => subscription.cancel();
|
|
85
86
|
}
|
|
86
|
-
async *stream(uri, params = { subscribe: true }) {
|
|
87
|
-
const sink = new async_utils_1.AsyncSink();
|
|
88
|
-
const cancel = this.subscribe(uri, params, payload => sink.push(payload));
|
|
89
|
-
try {
|
|
90
|
-
yield* sink;
|
|
91
|
-
}
|
|
92
|
-
finally {
|
|
93
|
-
cancel();
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
async oneshot(uri, params = {}) {
|
|
97
|
-
const generator = this.stream(uri, params);
|
|
98
|
-
const { value } = await generator.next();
|
|
99
|
-
await generator.return();
|
|
100
|
-
return value;
|
|
101
|
-
}
|
|
102
87
|
unregister() {
|
|
103
88
|
this.pending.clear();
|
|
104
89
|
this.handleOutbound.unregister();
|
|
@@ -149,7 +134,7 @@ class Service {
|
|
|
149
134
|
console.error('webos-service: handleRequest:', e);
|
|
150
135
|
message.respond({
|
|
151
136
|
returnValue: false,
|
|
152
|
-
errorCode: -
|
|
137
|
+
errorCode: -100,
|
|
153
138
|
errorText: e instanceof Error ? e.message : String(e),
|
|
154
139
|
errorStack: 'stack' in e.stack ? String(e.stack) : null,
|
|
155
140
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kitsuned/webos-service",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build": "tsc"
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"types": "./dist/index.d.ts"
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@kitsuned/
|
|
16
|
+
"@kitsuned/webos-luna-isomorphic-client": "^1.0.0"
|
|
17
17
|
},
|
|
18
18
|
"devDependencies": {
|
|
19
19
|
"@types/node": "25.4.0",
|