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