@ekhein/sekiro-node-client 2.0.0 → 2.0.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/dist/decorators/action.decorator.d.ts +1 -3
- package/dist/decorators/action.decorator.js +7 -6
- package/dist/decorators/fork.decorator.d.ts +1 -3
- package/dist/decorators/fork.decorator.js +7 -6
- package/dist/decorators/index.d.ts +2 -2
- package/dist/decorators/index.js +2 -10
- package/dist/main.d.ts +1 -4
- package/dist/main.js +58 -61
- package/dist/utils/logger.util.d.ts +1 -3
- package/dist/utils/logger.util.js +28 -6
- package/dist/utils/result.util.d.ts +1 -3
- package/dist/utils/result.util.js +8 -6
- package/package.json +16 -11
- package/types/sekiro.d.ts +8 -0
- package/dist/chunk-JB43IB4T.js +0 -13
- package/dist/chunk-T4Y3R2E6.js +0 -12
- package/dist/chunk-VAHS2LQ5.js +0 -12
- package/dist/chunk-WBEASVQZ.js +0 -32
- package/dist/decorators/action.decorator.cjs +0 -36
- package/dist/decorators/action.decorator.d.cts +0 -3
- package/dist/decorators/fork.decorator.cjs +0 -36
- package/dist/decorators/fork.decorator.d.cts +0 -3
- package/dist/decorators/index.cjs +0 -49
- package/dist/decorators/index.d.cts +0 -2
- package/dist/main.cjs +0 -122
- package/dist/main.d.cts +0 -18
- package/dist/utils/logger.util.cjs +0 -56
- package/dist/utils/logger.util.d.cts +0 -13
- package/dist/utils/result.util.cjs +0 -37
- package/dist/utils/result.util.d.cts +0 -6
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
};
|
|
1
|
+
export function Action() {
|
|
2
|
+
return function (target, method, descriptor) {
|
|
3
|
+
if (!target.handlers)
|
|
4
|
+
target.handlers = new Map();
|
|
5
|
+
target.handlers.set(method, descriptor.value);
|
|
6
|
+
};
|
|
7
|
+
}
|
|
@@ -1,3 +1 @@
|
|
|
1
|
-
declare function Fork(count?: number, host?: string, prot?: number, clientId?: string): <T extends new (...args: any[]) => any>(Client: T) => void;
|
|
2
|
-
|
|
3
|
-
export { Fork };
|
|
1
|
+
export declare function Fork(count?: number, host?: string, prot?: number, clientId?: string): <T extends new (...args: any[]) => any>(Client: T) => void;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
};
|
|
1
|
+
export function Fork(count = 1, host, prot, clientId) {
|
|
2
|
+
return function (Client) {
|
|
3
|
+
for (let pid = 1; pid <= count; pid++) {
|
|
4
|
+
new Client(Client.name, pid, host, prot, clientId);
|
|
5
|
+
}
|
|
6
|
+
};
|
|
7
|
+
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { Fork } from
|
|
2
|
-
export { Action } from
|
|
1
|
+
export { Fork } from "./fork.decorator";
|
|
2
|
+
export { Action } from "./action.decorator";
|
package/dist/decorators/index.js
CHANGED
package/dist/main.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { WebSocket } from 'partysocket';
|
|
2
|
-
|
|
3
|
-
declare class SekiroClient extends WebSocket {
|
|
2
|
+
export declare class SekiroClient extends WebSocket {
|
|
4
3
|
readonly scope: string;
|
|
5
4
|
readonly pid: number;
|
|
6
5
|
readonly host: string;
|
|
@@ -14,5 +13,3 @@ declare class SekiroClient extends WebSocket {
|
|
|
14
13
|
private onError;
|
|
15
14
|
private onData;
|
|
16
15
|
}
|
|
17
|
-
|
|
18
|
-
export { SekiroClient };
|
package/dist/main.js
CHANGED
|
@@ -1,63 +1,60 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
} from
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
} from
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
1
|
+
import { format } from 'util';
|
|
2
|
+
import { randomUUID } from 'crypto';
|
|
3
|
+
import { WebSocket } from 'partysocket';
|
|
4
|
+
import { WebSocket as Client } from 'ws';
|
|
5
|
+
import { Result } from './utils/result.util';
|
|
6
|
+
import { Logger } from './utils/logger.util';
|
|
7
|
+
export class SekiroClient extends WebSocket {
|
|
8
|
+
scope;
|
|
9
|
+
pid;
|
|
10
|
+
host;
|
|
11
|
+
prot;
|
|
12
|
+
clientId;
|
|
13
|
+
logger = new Logger(this);
|
|
14
|
+
constructor(scope, pid, host = "192.168.2.102", prot = 5612, clientId = randomUUID().replace(/-/g, "")) {
|
|
15
|
+
super("wss://", [], {
|
|
16
|
+
debug: false,
|
|
17
|
+
maxEnqueuedMessages: -1,
|
|
18
|
+
WebSocket: class extends Client {
|
|
19
|
+
constructor() {
|
|
20
|
+
const site = format("ws://%s:%s", host, prot);
|
|
21
|
+
const wsURL = new URL("/business-demo/register", site);
|
|
22
|
+
wsURL.searchParams.append("group", scope);
|
|
23
|
+
wsURL.searchParams.append("clientId", clientId);
|
|
24
|
+
super(wsURL);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
this.scope = scope;
|
|
29
|
+
this.pid = pid;
|
|
30
|
+
this.host = host;
|
|
31
|
+
this.prot = prot;
|
|
32
|
+
this.clientId = clientId;
|
|
33
|
+
super.addEventListener("open", this.onOpen.bind(this));
|
|
34
|
+
super.addEventListener("message", this.onData.bind(this));
|
|
35
|
+
super.addEventListener("close", this.onClose.bind(this));
|
|
36
|
+
super.addEventListener("error", this.onError.bind(this));
|
|
37
|
+
}
|
|
38
|
+
async onOpen(event) {
|
|
39
|
+
this.logger.info("Connection established");
|
|
40
|
+
}
|
|
41
|
+
async onClose(event) {
|
|
42
|
+
this.logger.warn("Connection closed");
|
|
43
|
+
}
|
|
44
|
+
async onError(event) {
|
|
45
|
+
this.logger.warn("WebSocket error:", event.message);
|
|
46
|
+
}
|
|
47
|
+
async onData(event) {
|
|
48
|
+
this.logger.info("Received request", event.data);
|
|
49
|
+
const request = JSON.parse(event.data);
|
|
50
|
+
try {
|
|
51
|
+
const data = await this.handlers.get(request.action)?.apply(this, [request]);
|
|
52
|
+
const pack = Result.success(request, data);
|
|
53
|
+
this.send(pack);
|
|
54
|
+
}
|
|
55
|
+
catch (error) {
|
|
56
|
+
const pack = Result.unknown(request, error.message);
|
|
57
|
+
this.send(pack);
|
|
25
58
|
}
|
|
26
|
-
}
|
|
27
|
-
});
|
|
28
|
-
this.scope = scope;
|
|
29
|
-
this.pid = pid;
|
|
30
|
-
this.host = host;
|
|
31
|
-
this.prot = prot;
|
|
32
|
-
this.clientId = clientId;
|
|
33
|
-
super.addEventListener("open", this.onOpen.bind(this));
|
|
34
|
-
super.addEventListener("message", this.onData.bind(this));
|
|
35
|
-
super.addEventListener("close", this.onClose.bind(this));
|
|
36
|
-
super.addEventListener("error", this.onError.bind(this));
|
|
37
|
-
}
|
|
38
|
-
logger = new Logger(this);
|
|
39
|
-
async onOpen(event) {
|
|
40
|
-
this.logger.info("Connection established");
|
|
41
|
-
}
|
|
42
|
-
async onClose(event) {
|
|
43
|
-
this.logger.warn("Connection closed");
|
|
44
|
-
}
|
|
45
|
-
async onError(event) {
|
|
46
|
-
this.logger.warn("WebSocket error:", event.message);
|
|
47
|
-
}
|
|
48
|
-
async onData(event) {
|
|
49
|
-
this.logger.info("Received request", event.data);
|
|
50
|
-
const request = JSON.parse(event.data);
|
|
51
|
-
try {
|
|
52
|
-
const data = await this.handlers.get(request.action)?.apply(this, [request]);
|
|
53
|
-
const pack = Result.success(request, data);
|
|
54
|
-
this.send(pack);
|
|
55
|
-
} catch (error) {
|
|
56
|
-
const pack = Result.unknown(request, error.message);
|
|
57
|
-
this.send(pack);
|
|
58
59
|
}
|
|
59
|
-
|
|
60
|
-
};
|
|
61
|
-
export {
|
|
62
|
-
SekiroClient
|
|
63
|
-
};
|
|
60
|
+
}
|
|
@@ -1,6 +1,28 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
}
|
|
1
|
+
import { format } from "util";
|
|
2
|
+
export class Logger {
|
|
3
|
+
context;
|
|
4
|
+
constructor(context) {
|
|
5
|
+
this.context = context;
|
|
6
|
+
}
|
|
7
|
+
log(level, message) {
|
|
8
|
+
const time = new Date().toLocaleString();
|
|
9
|
+
const pid = String(this.context.pid).padStart(2, "0");
|
|
10
|
+
const scope = String(this.context.scope);
|
|
11
|
+
const clientId = String(this.context.clientId);
|
|
12
|
+
const base = format("[%s] [%s] [%s] [%s] [%s]", level, time, scope, pid, clientId);
|
|
13
|
+
switch (level) {
|
|
14
|
+
case "INFO":
|
|
15
|
+
console.info(base, ...message);
|
|
16
|
+
break;
|
|
17
|
+
case "WARN":
|
|
18
|
+
console.warn(base, ...message);
|
|
19
|
+
break;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
info(...message) {
|
|
23
|
+
this.log("INFO", message);
|
|
24
|
+
}
|
|
25
|
+
warn(...message) {
|
|
26
|
+
this.log("WARN", message);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
};
|
|
1
|
+
export class Result {
|
|
2
|
+
static success({ __sekiro_seq__ }, data) {
|
|
3
|
+
return (JSON.stringify({ __sekiro_seq__, data, status: 0 }));
|
|
4
|
+
}
|
|
5
|
+
static unknown({ __sekiro_seq__ }, message) {
|
|
6
|
+
return (JSON.stringify({ __sekiro_seq__, message, status: -1 }));
|
|
7
|
+
}
|
|
8
|
+
}
|
package/package.json
CHANGED
|
@@ -1,21 +1,27 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ekhein/sekiro-node-client",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
|
-
"
|
|
7
|
-
"
|
|
8
|
-
"types": "./dist/main.d.ts",
|
|
6
|
+
"author": "ekhein",
|
|
7
|
+
"main": "./dist/main.js",
|
|
9
8
|
"files": [
|
|
10
|
-
"dist
|
|
9
|
+
"dist",
|
|
10
|
+
"types"
|
|
11
11
|
],
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"import": "./dist/index.js",
|
|
15
|
+
"types": "./dist/index.d.ts"
|
|
16
|
+
},
|
|
17
|
+
"./decorators": {
|
|
18
|
+
"import": "./dist/decorators/index.js",
|
|
19
|
+
"types": "./dist/decorators/index.d.ts"
|
|
20
|
+
}
|
|
21
|
+
},
|
|
12
22
|
"scripts": {
|
|
13
|
-
"build": "
|
|
14
|
-
"watch": "pnpm build --watch src",
|
|
15
|
-
"dev": "tsx example/index.ts"
|
|
23
|
+
"build": "tsc"
|
|
16
24
|
},
|
|
17
|
-
"author": "ekhein",
|
|
18
|
-
"description": "",
|
|
19
25
|
"engines": {
|
|
20
26
|
"node": ">=18.0.0"
|
|
21
27
|
},
|
|
@@ -25,7 +31,6 @@
|
|
|
25
31
|
},
|
|
26
32
|
"devDependencies": {
|
|
27
33
|
"@types/node": "^22.15.18",
|
|
28
|
-
"tsup": "^8.5.0",
|
|
29
34
|
"tsx": "^4.19.4",
|
|
30
35
|
"typescript": "^5.8.3"
|
|
31
36
|
}
|
package/dist/chunk-JB43IB4T.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
// src/utils/result.util.ts
|
|
2
|
-
var Result = class {
|
|
3
|
-
static success({ __sekiro_seq__ }, data) {
|
|
4
|
-
return JSON.stringify({ __sekiro_seq__, data, status: 0 });
|
|
5
|
-
}
|
|
6
|
-
static unknown({ __sekiro_seq__ }, message) {
|
|
7
|
-
return JSON.stringify({ __sekiro_seq__, message, status: -1 });
|
|
8
|
-
}
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
export {
|
|
12
|
-
Result
|
|
13
|
-
};
|
package/dist/chunk-T4Y3R2E6.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
// src/decorators/action.decorator.ts
|
|
2
|
-
function Action() {
|
|
3
|
-
return function(target, method, descriptor) {
|
|
4
|
-
if (!target.handlers)
|
|
5
|
-
target.handlers = /* @__PURE__ */ new Map();
|
|
6
|
-
target.handlers.set(method, descriptor.value);
|
|
7
|
-
};
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export {
|
|
11
|
-
Action
|
|
12
|
-
};
|
package/dist/chunk-VAHS2LQ5.js
DELETED
package/dist/chunk-WBEASVQZ.js
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
// src/utils/logger.util.ts
|
|
2
|
-
import { format } from "util";
|
|
3
|
-
var Logger = class {
|
|
4
|
-
constructor(context) {
|
|
5
|
-
this.context = context;
|
|
6
|
-
}
|
|
7
|
-
log(level, message) {
|
|
8
|
-
const time = (/* @__PURE__ */ new Date()).toLocaleString();
|
|
9
|
-
const pid = String(this.context.pid).padStart(2, "0");
|
|
10
|
-
const scope = String(this.context.scope);
|
|
11
|
-
const clientId = String(this.context.clientId);
|
|
12
|
-
const base = format("[%s] [%s] [%s] [%s] [%s]", level, time, scope, pid, clientId);
|
|
13
|
-
switch (level) {
|
|
14
|
-
case "INFO":
|
|
15
|
-
console.info(base, ...message);
|
|
16
|
-
break;
|
|
17
|
-
case "WARN":
|
|
18
|
-
console.warn(base, ...message);
|
|
19
|
-
break;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
info(...message) {
|
|
23
|
-
this.log("INFO", message);
|
|
24
|
-
}
|
|
25
|
-
warn(...message) {
|
|
26
|
-
this.log("WARN", message);
|
|
27
|
-
}
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
export {
|
|
31
|
-
Logger
|
|
32
|
-
};
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/decorators/action.decorator.ts
|
|
21
|
-
var action_decorator_exports = {};
|
|
22
|
-
__export(action_decorator_exports, {
|
|
23
|
-
Action: () => Action
|
|
24
|
-
});
|
|
25
|
-
module.exports = __toCommonJS(action_decorator_exports);
|
|
26
|
-
function Action() {
|
|
27
|
-
return function(target, method, descriptor) {
|
|
28
|
-
if (!target.handlers)
|
|
29
|
-
target.handlers = /* @__PURE__ */ new Map();
|
|
30
|
-
target.handlers.set(method, descriptor.value);
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
34
|
-
0 && (module.exports = {
|
|
35
|
-
Action
|
|
36
|
-
});
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/decorators/fork.decorator.ts
|
|
21
|
-
var fork_decorator_exports = {};
|
|
22
|
-
__export(fork_decorator_exports, {
|
|
23
|
-
Fork: () => Fork
|
|
24
|
-
});
|
|
25
|
-
module.exports = __toCommonJS(fork_decorator_exports);
|
|
26
|
-
function Fork(count = 1, host, prot, clientId) {
|
|
27
|
-
return function(Client) {
|
|
28
|
-
for (let pid = 1; pid <= count; pid++) {
|
|
29
|
-
new Client(Client.name, pid, host, prot, clientId);
|
|
30
|
-
}
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
34
|
-
0 && (module.exports = {
|
|
35
|
-
Fork
|
|
36
|
-
});
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/decorators/index.ts
|
|
21
|
-
var decorators_exports = {};
|
|
22
|
-
__export(decorators_exports, {
|
|
23
|
-
Action: () => Action,
|
|
24
|
-
Fork: () => Fork
|
|
25
|
-
});
|
|
26
|
-
module.exports = __toCommonJS(decorators_exports);
|
|
27
|
-
|
|
28
|
-
// src/decorators/fork.decorator.ts
|
|
29
|
-
function Fork(count = 1, host, prot, clientId) {
|
|
30
|
-
return function(Client) {
|
|
31
|
-
for (let pid = 1; pid <= count; pid++) {
|
|
32
|
-
new Client(Client.name, pid, host, prot, clientId);
|
|
33
|
-
}
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
// src/decorators/action.decorator.ts
|
|
38
|
-
function Action() {
|
|
39
|
-
return function(target, method, descriptor) {
|
|
40
|
-
if (!target.handlers)
|
|
41
|
-
target.handlers = /* @__PURE__ */ new Map();
|
|
42
|
-
target.handlers.set(method, descriptor.value);
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
46
|
-
0 && (module.exports = {
|
|
47
|
-
Action,
|
|
48
|
-
Fork
|
|
49
|
-
});
|
package/dist/main.cjs
DELETED
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/main.ts
|
|
21
|
-
var main_exports = {};
|
|
22
|
-
__export(main_exports, {
|
|
23
|
-
SekiroClient: () => SekiroClient
|
|
24
|
-
});
|
|
25
|
-
module.exports = __toCommonJS(main_exports);
|
|
26
|
-
var import_util2 = require("util");
|
|
27
|
-
var import_crypto = require("crypto");
|
|
28
|
-
var import_partysocket = require("partysocket");
|
|
29
|
-
var import_ws = require("ws");
|
|
30
|
-
|
|
31
|
-
// src/utils/result.util.ts
|
|
32
|
-
var Result = class {
|
|
33
|
-
static success({ __sekiro_seq__ }, data) {
|
|
34
|
-
return JSON.stringify({ __sekiro_seq__, data, status: 0 });
|
|
35
|
-
}
|
|
36
|
-
static unknown({ __sekiro_seq__ }, message) {
|
|
37
|
-
return JSON.stringify({ __sekiro_seq__, message, status: -1 });
|
|
38
|
-
}
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
// src/utils/logger.util.ts
|
|
42
|
-
var import_util = require("util");
|
|
43
|
-
var Logger = class {
|
|
44
|
-
constructor(context) {
|
|
45
|
-
this.context = context;
|
|
46
|
-
}
|
|
47
|
-
log(level, message) {
|
|
48
|
-
const time = (/* @__PURE__ */ new Date()).toLocaleString();
|
|
49
|
-
const pid = String(this.context.pid).padStart(2, "0");
|
|
50
|
-
const scope = String(this.context.scope);
|
|
51
|
-
const clientId = String(this.context.clientId);
|
|
52
|
-
const base = (0, import_util.format)("[%s] [%s] [%s] [%s] [%s]", level, time, scope, pid, clientId);
|
|
53
|
-
switch (level) {
|
|
54
|
-
case "INFO":
|
|
55
|
-
console.info(base, ...message);
|
|
56
|
-
break;
|
|
57
|
-
case "WARN":
|
|
58
|
-
console.warn(base, ...message);
|
|
59
|
-
break;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
info(...message) {
|
|
63
|
-
this.log("INFO", message);
|
|
64
|
-
}
|
|
65
|
-
warn(...message) {
|
|
66
|
-
this.log("WARN", message);
|
|
67
|
-
}
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
// src/main.ts
|
|
71
|
-
var SekiroClient = class extends import_partysocket.WebSocket {
|
|
72
|
-
constructor(scope, pid, host = "192.168.2.102", prot = 5612, clientId = (0, import_crypto.randomUUID)().replace(/-/g, "")) {
|
|
73
|
-
super("wss://", [], {
|
|
74
|
-
debug: false,
|
|
75
|
-
maxEnqueuedMessages: -1,
|
|
76
|
-
WebSocket: class extends import_ws.WebSocket {
|
|
77
|
-
constructor() {
|
|
78
|
-
const site = (0, import_util2.format)("ws://%s:%s", host, prot);
|
|
79
|
-
const wsURL = new URL("/business-demo/register", site);
|
|
80
|
-
wsURL.searchParams.append("group", scope);
|
|
81
|
-
wsURL.searchParams.append("clientId", clientId);
|
|
82
|
-
super(wsURL);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
});
|
|
86
|
-
this.scope = scope;
|
|
87
|
-
this.pid = pid;
|
|
88
|
-
this.host = host;
|
|
89
|
-
this.prot = prot;
|
|
90
|
-
this.clientId = clientId;
|
|
91
|
-
super.addEventListener("open", this.onOpen.bind(this));
|
|
92
|
-
super.addEventListener("message", this.onData.bind(this));
|
|
93
|
-
super.addEventListener("close", this.onClose.bind(this));
|
|
94
|
-
super.addEventListener("error", this.onError.bind(this));
|
|
95
|
-
}
|
|
96
|
-
logger = new Logger(this);
|
|
97
|
-
async onOpen(event) {
|
|
98
|
-
this.logger.info("Connection established");
|
|
99
|
-
}
|
|
100
|
-
async onClose(event) {
|
|
101
|
-
this.logger.warn("Connection closed");
|
|
102
|
-
}
|
|
103
|
-
async onError(event) {
|
|
104
|
-
this.logger.warn("WebSocket error:", event.message);
|
|
105
|
-
}
|
|
106
|
-
async onData(event) {
|
|
107
|
-
this.logger.info("Received request", event.data);
|
|
108
|
-
const request = JSON.parse(event.data);
|
|
109
|
-
try {
|
|
110
|
-
const data = await this.handlers.get(request.action)?.apply(this, [request]);
|
|
111
|
-
const pack = Result.success(request, data);
|
|
112
|
-
this.send(pack);
|
|
113
|
-
} catch (error) {
|
|
114
|
-
const pack = Result.unknown(request, error.message);
|
|
115
|
-
this.send(pack);
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
};
|
|
119
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
120
|
-
0 && (module.exports = {
|
|
121
|
-
SekiroClient
|
|
122
|
-
});
|
package/dist/main.d.cts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { WebSocket } from 'partysocket';
|
|
2
|
-
|
|
3
|
-
declare class SekiroClient extends WebSocket {
|
|
4
|
-
readonly scope: string;
|
|
5
|
-
readonly pid: number;
|
|
6
|
-
readonly host: string;
|
|
7
|
-
readonly prot: number;
|
|
8
|
-
readonly clientId: string;
|
|
9
|
-
readonly handlers: Map<string, Function>;
|
|
10
|
-
private readonly logger;
|
|
11
|
-
constructor(scope: string, pid: number, host?: string, prot?: number, clientId?: string);
|
|
12
|
-
private onOpen;
|
|
13
|
-
private onClose;
|
|
14
|
-
private onError;
|
|
15
|
-
private onData;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export { SekiroClient };
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/utils/logger.util.ts
|
|
21
|
-
var logger_util_exports = {};
|
|
22
|
-
__export(logger_util_exports, {
|
|
23
|
-
Logger: () => Logger
|
|
24
|
-
});
|
|
25
|
-
module.exports = __toCommonJS(logger_util_exports);
|
|
26
|
-
var import_util = require("util");
|
|
27
|
-
var Logger = class {
|
|
28
|
-
constructor(context) {
|
|
29
|
-
this.context = context;
|
|
30
|
-
}
|
|
31
|
-
log(level, message) {
|
|
32
|
-
const time = (/* @__PURE__ */ new Date()).toLocaleString();
|
|
33
|
-
const pid = String(this.context.pid).padStart(2, "0");
|
|
34
|
-
const scope = String(this.context.scope);
|
|
35
|
-
const clientId = String(this.context.clientId);
|
|
36
|
-
const base = (0, import_util.format)("[%s] [%s] [%s] [%s] [%s]", level, time, scope, pid, clientId);
|
|
37
|
-
switch (level) {
|
|
38
|
-
case "INFO":
|
|
39
|
-
console.info(base, ...message);
|
|
40
|
-
break;
|
|
41
|
-
case "WARN":
|
|
42
|
-
console.warn(base, ...message);
|
|
43
|
-
break;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
info(...message) {
|
|
47
|
-
this.log("INFO", message);
|
|
48
|
-
}
|
|
49
|
-
warn(...message) {
|
|
50
|
-
this.log("WARN", message);
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
54
|
-
0 && (module.exports = {
|
|
55
|
-
Logger
|
|
56
|
-
});
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/utils/result.util.ts
|
|
21
|
-
var result_util_exports = {};
|
|
22
|
-
__export(result_util_exports, {
|
|
23
|
-
Result: () => Result
|
|
24
|
-
});
|
|
25
|
-
module.exports = __toCommonJS(result_util_exports);
|
|
26
|
-
var Result = class {
|
|
27
|
-
static success({ __sekiro_seq__ }, data) {
|
|
28
|
-
return JSON.stringify({ __sekiro_seq__, data, status: 0 });
|
|
29
|
-
}
|
|
30
|
-
static unknown({ __sekiro_seq__ }, message) {
|
|
31
|
-
return JSON.stringify({ __sekiro_seq__, message, status: -1 });
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
35
|
-
0 && (module.exports = {
|
|
36
|
-
Result
|
|
37
|
-
});
|