@ekhein/sekiro-node-client 1.0.3 → 1.0.4
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/chunk-JB43IB4T.js +13 -0
- package/dist/chunk-ZPXAVFEY.js +13 -0
- package/dist/decorators/action.decorator.cjs +36 -0
- package/dist/decorators/action.decorator.d.cts +3 -0
- package/dist/decorators/action.decorator.d.ts +3 -0
- package/dist/decorators/action.decorator.js +11 -0
- package/dist/decorators/bootstrap.decorator.cjs +37 -0
- package/dist/decorators/bootstrap.decorator.d.cts +3 -0
- package/dist/decorators/bootstrap.decorator.d.ts +3 -0
- package/dist/decorators/bootstrap.decorator.js +12 -0
- package/dist/{SekiroClient.cjs → main.cjs} +15 -19
- package/dist/{SekiroClient.d.cts → main.d.cts} +1 -2
- package/dist/{SekiroClient.d.ts → main.d.ts} +1 -2
- package/dist/{SekiroClient.js → main.js} +14 -33
- package/dist/utils/logger.util.cjs +37 -0
- package/dist/utils/logger.util.d.cts +6 -0
- package/dist/utils/logger.util.d.ts +6 -0
- package/dist/utils/logger.util.js +6 -0
- package/dist/utils/result.util.cjs +37 -0
- package/dist/utils/result.util.d.cts +6 -0
- package/dist/utils/result.util.d.ts +6 -0
- package/dist/utils/result.util.js +6 -0
- package/package.json +5 -5
|
@@ -0,0 +1,13 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// src/utils/logger.util.ts
|
|
2
|
+
var Logger = class {
|
|
3
|
+
static info(...args) {
|
|
4
|
+
console.info("[I] [" + (/* @__PURE__ */ new Date()).toLocaleString() + "]", ...args);
|
|
5
|
+
}
|
|
6
|
+
static warn(...args) {
|
|
7
|
+
console.warn("[W] [" + (/* @__PURE__ */ new Date()).toLocaleString() + "]", ...args);
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export {
|
|
12
|
+
Logger
|
|
13
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
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
|
+
export {
|
|
10
|
+
Action
|
|
11
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
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/bootstrap.decorator.ts
|
|
21
|
+
var bootstrap_decorator_exports = {};
|
|
22
|
+
__export(bootstrap_decorator_exports, {
|
|
23
|
+
Fork: () => Fork
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(bootstrap_decorator_exports);
|
|
26
|
+
function Fork(count = 1, host, prot, clientId) {
|
|
27
|
+
return function(Client) {
|
|
28
|
+
for (let i = 1; i <= count; i++) {
|
|
29
|
+
const group = Array(Client.name, i).join("::");
|
|
30
|
+
new Client(group, host, prot, clientId);
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
35
|
+
0 && (module.exports = {
|
|
36
|
+
Fork
|
|
37
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// src/decorators/bootstrap.decorator.ts
|
|
2
|
+
function Fork(count = 1, host, prot, clientId) {
|
|
3
|
+
return function(Client) {
|
|
4
|
+
for (let i = 1; i <= count; i++) {
|
|
5
|
+
const group = Array(Client.name, i).join("::");
|
|
6
|
+
new Client(group, host, prot, clientId);
|
|
7
|
+
}
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
export {
|
|
11
|
+
Fork
|
|
12
|
+
};
|
|
@@ -17,19 +17,19 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
17
|
};
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
|
|
20
|
-
// src/
|
|
21
|
-
var
|
|
22
|
-
__export(
|
|
20
|
+
// src/main.ts
|
|
21
|
+
var main_exports = {};
|
|
22
|
+
__export(main_exports, {
|
|
23
23
|
SekiroClient: () => SekiroClient
|
|
24
24
|
});
|
|
25
|
-
module.exports = __toCommonJS(
|
|
25
|
+
module.exports = __toCommonJS(main_exports);
|
|
26
26
|
var import_util = require("util");
|
|
27
27
|
var import_crypto = require("crypto");
|
|
28
28
|
var import_partysocket = require("partysocket");
|
|
29
29
|
var import_ws = require("ws");
|
|
30
30
|
|
|
31
|
-
// src/
|
|
32
|
-
var
|
|
31
|
+
// src/utils/result.util.ts
|
|
32
|
+
var Result = class {
|
|
33
33
|
static success({ __sekiro_seq__ }, data) {
|
|
34
34
|
return JSON.stringify({ __sekiro_seq__, data, status: 0 });
|
|
35
35
|
}
|
|
@@ -38,8 +38,8 @@ var SekiroResult = class {
|
|
|
38
38
|
}
|
|
39
39
|
};
|
|
40
40
|
|
|
41
|
-
// src/
|
|
42
|
-
var
|
|
41
|
+
// src/utils/logger.util.ts
|
|
42
|
+
var Logger = class {
|
|
43
43
|
static info(...args) {
|
|
44
44
|
console.info("[I] [" + (/* @__PURE__ */ new Date()).toLocaleString() + "]", ...args);
|
|
45
45
|
}
|
|
@@ -48,9 +48,8 @@ var SekiroLogger = class {
|
|
|
48
48
|
}
|
|
49
49
|
};
|
|
50
50
|
|
|
51
|
-
// src/
|
|
51
|
+
// src/main.ts
|
|
52
52
|
var SekiroClient = class extends import_partysocket.WebSocket {
|
|
53
|
-
handlers = /* @__PURE__ */ new Map([]);
|
|
54
53
|
constructor(scope, host = "192.168.2.102", prot = 5612, clientId = (0, import_crypto.randomUUID)().replace(/-/g, "")) {
|
|
55
54
|
super("wss://", [], {
|
|
56
55
|
debug: false,
|
|
@@ -71,29 +70,26 @@ var SekiroClient = class extends import_partysocket.WebSocket {
|
|
|
71
70
|
super.addEventListener("error", this.onError.bind(this));
|
|
72
71
|
}
|
|
73
72
|
async onOpen(event) {
|
|
74
|
-
|
|
73
|
+
Logger.info("Connection established");
|
|
75
74
|
}
|
|
76
75
|
async onClose(event) {
|
|
77
|
-
|
|
76
|
+
Logger.warn("Connection closed");
|
|
78
77
|
}
|
|
79
78
|
async onError(event) {
|
|
80
|
-
|
|
79
|
+
Logger.warn("WebSocket error:", event.message);
|
|
81
80
|
}
|
|
82
81
|
async onData(event) {
|
|
83
|
-
|
|
82
|
+
Logger.info("Received request", event.data);
|
|
84
83
|
const request = JSON.parse(event.data);
|
|
85
84
|
try {
|
|
86
85
|
const data = await this.handlers.get(request.action)?.apply(this, [request]);
|
|
87
|
-
const pack =
|
|
86
|
+
const pack = Result.success(request, data);
|
|
88
87
|
this.send(pack);
|
|
89
88
|
} catch (error) {
|
|
90
|
-
const pack =
|
|
89
|
+
const pack = Result.unknown(request, error.message);
|
|
91
90
|
this.send(pack);
|
|
92
91
|
}
|
|
93
92
|
}
|
|
94
|
-
async registerAction(action, handler) {
|
|
95
|
-
this.handlers.set(action, handler);
|
|
96
|
-
}
|
|
97
93
|
};
|
|
98
94
|
// Annotate the CommonJS export names for ESM import in node:
|
|
99
95
|
0 && (module.exports = {
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import { WebSocket } from 'partysocket';
|
|
2
2
|
|
|
3
3
|
declare class SekiroClient extends WebSocket {
|
|
4
|
-
|
|
4
|
+
readonly handlers: Map<string, Function>;
|
|
5
5
|
constructor(scope: string, host?: string, prot?: number, clientId?: string);
|
|
6
6
|
private onOpen;
|
|
7
7
|
private onClose;
|
|
8
8
|
private onError;
|
|
9
9
|
private onData;
|
|
10
|
-
registerAction(action: string, handler: ISekiroHandler): Promise<void>;
|
|
11
10
|
}
|
|
12
11
|
|
|
13
12
|
export { SekiroClient };
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import { WebSocket } from 'partysocket';
|
|
2
2
|
|
|
3
3
|
declare class SekiroClient extends WebSocket {
|
|
4
|
-
|
|
4
|
+
readonly handlers: Map<string, Function>;
|
|
5
5
|
constructor(scope: string, host?: string, prot?: number, clientId?: string);
|
|
6
6
|
private onOpen;
|
|
7
7
|
private onClose;
|
|
8
8
|
private onError;
|
|
9
9
|
private onData;
|
|
10
|
-
registerAction(action: string, handler: ISekiroHandler): Promise<void>;
|
|
11
10
|
}
|
|
12
11
|
|
|
13
12
|
export { SekiroClient };
|
|
@@ -1,32 +1,16 @@
|
|
|
1
|
-
|
|
1
|
+
import {
|
|
2
|
+
Logger
|
|
3
|
+
} from "./chunk-ZPXAVFEY.js";
|
|
4
|
+
import {
|
|
5
|
+
Result
|
|
6
|
+
} from "./chunk-JB43IB4T.js";
|
|
7
|
+
|
|
8
|
+
// src/main.ts
|
|
2
9
|
import { format } from "util";
|
|
3
10
|
import { randomUUID } from "crypto";
|
|
4
11
|
import { WebSocket } from "partysocket";
|
|
5
12
|
import { WebSocket as Client } from "ws";
|
|
6
|
-
|
|
7
|
-
// src/SekiroResult.ts
|
|
8
|
-
var SekiroResult = class {
|
|
9
|
-
static success({ __sekiro_seq__ }, data) {
|
|
10
|
-
return JSON.stringify({ __sekiro_seq__, data, status: 0 });
|
|
11
|
-
}
|
|
12
|
-
static unknown({ __sekiro_seq__ }, message) {
|
|
13
|
-
return JSON.stringify({ __sekiro_seq__, message, status: -1 });
|
|
14
|
-
}
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
// src/SekiroLogger.ts
|
|
18
|
-
var SekiroLogger = class {
|
|
19
|
-
static info(...args) {
|
|
20
|
-
console.info("[I] [" + (/* @__PURE__ */ new Date()).toLocaleString() + "]", ...args);
|
|
21
|
-
}
|
|
22
|
-
static warn(...args) {
|
|
23
|
-
console.warn("[W] [" + (/* @__PURE__ */ new Date()).toLocaleString() + "]", ...args);
|
|
24
|
-
}
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
// src/SekiroClient.ts
|
|
28
13
|
var SekiroClient = class extends WebSocket {
|
|
29
|
-
handlers = /* @__PURE__ */ new Map([]);
|
|
30
14
|
constructor(scope, host = "192.168.2.102", prot = 5612, clientId = randomUUID().replace(/-/g, "")) {
|
|
31
15
|
super("wss://", [], {
|
|
32
16
|
debug: false,
|
|
@@ -47,29 +31,26 @@ var SekiroClient = class extends WebSocket {
|
|
|
47
31
|
super.addEventListener("error", this.onError.bind(this));
|
|
48
32
|
}
|
|
49
33
|
async onOpen(event) {
|
|
50
|
-
|
|
34
|
+
Logger.info("Connection established");
|
|
51
35
|
}
|
|
52
36
|
async onClose(event) {
|
|
53
|
-
|
|
37
|
+
Logger.warn("Connection closed");
|
|
54
38
|
}
|
|
55
39
|
async onError(event) {
|
|
56
|
-
|
|
40
|
+
Logger.warn("WebSocket error:", event.message);
|
|
57
41
|
}
|
|
58
42
|
async onData(event) {
|
|
59
|
-
|
|
43
|
+
Logger.info("Received request", event.data);
|
|
60
44
|
const request = JSON.parse(event.data);
|
|
61
45
|
try {
|
|
62
46
|
const data = await this.handlers.get(request.action)?.apply(this, [request]);
|
|
63
|
-
const pack =
|
|
47
|
+
const pack = Result.success(request, data);
|
|
64
48
|
this.send(pack);
|
|
65
49
|
} catch (error) {
|
|
66
|
-
const pack =
|
|
50
|
+
const pack = Result.unknown(request, error.message);
|
|
67
51
|
this.send(pack);
|
|
68
52
|
}
|
|
69
53
|
}
|
|
70
|
-
async registerAction(action, handler) {
|
|
71
|
-
this.handlers.set(action, handler);
|
|
72
|
-
}
|
|
73
54
|
};
|
|
74
55
|
export {
|
|
75
56
|
SekiroClient
|
|
@@ -0,0 +1,37 @@
|
|
|
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 Logger = class {
|
|
27
|
+
static info(...args) {
|
|
28
|
+
console.info("[I] [" + (/* @__PURE__ */ new Date()).toLocaleString() + "]", ...args);
|
|
29
|
+
}
|
|
30
|
+
static warn(...args) {
|
|
31
|
+
console.warn("[W] [" + (/* @__PURE__ */ new Date()).toLocaleString() + "]", ...args);
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
35
|
+
0 && (module.exports = {
|
|
36
|
+
Logger
|
|
37
|
+
});
|
|
@@ -0,0 +1,37 @@
|
|
|
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
|
+
});
|
package/package.json
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ekhein/sekiro-node-client",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
|
-
"main": "./dist/
|
|
7
|
-
"module": "./dist/
|
|
8
|
-
"types": "./dist/
|
|
6
|
+
"main": "./dist/main.cjs",
|
|
7
|
+
"module": "./dist/main.js",
|
|
8
|
+
"types": "./dist/main.d.ts",
|
|
9
9
|
"files": [
|
|
10
10
|
"dist/**/*"
|
|
11
11
|
],
|
|
12
12
|
"scripts": {
|
|
13
|
-
"build": "tsup src
|
|
13
|
+
"build": "tsup 'src/**/*.ts' --format cjs,esm --dts --clean",
|
|
14
14
|
"watch": "pnpm build --watch src",
|
|
15
15
|
"dev": "tsx example/index.ts"
|
|
16
16
|
},
|