dev-classes 1.3.10 → 1.3.11

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/README.md CHANGED
@@ -132,6 +132,7 @@ interface OneOfPromiseReject{
132
132
  msg: string;
133
133
  }
134
134
 
135
+
135
136
  interface DelaysPromiseProps{
136
137
  startActionEvery: (cb: () => boolean, config: StartActionEveryConfigI) => Promise<{status: boolean, msg: string}>
137
138
  oneOf: (watchPromise: () => Promise<any>, potentialCaseCB: () => void, config: {second: number}) => void
@@ -150,18 +151,7 @@ interface NumbersProps {
150
151
  }
151
152
 
152
153
  ```
153
- <h3 align="center">Number</h3>
154
-
155
- ```ts
156
-
157
- interface NumbersProps {
158
- randomNumber: () => number;
159
- getOnlyTheStringNumbers(dirtyString: string): string;
160
- isNumber(charStr: string | number): boolean;
161
- }
162
-
163
- ```
164
- <h3 align="center">Number</h3>
154
+ <h3 align="center">File</h3>
165
155
 
166
156
  ```ts
167
157
 
@@ -1,55 +1,55 @@
1
1
  var i = Object.defineProperty;
2
- var o = (v, e, t) => e in v ? i(v, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : v[e] = t;
3
- var I = (v, e, t) => (o(v, typeof e != "symbol" ? e + "" : e, t), t);
2
+ var o = (u, e, t) => e in u ? i(u, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : u[e] = t;
3
+ var I = (u, e, t) => (o(u, typeof e != "symbol" ? e + "" : e, t), t);
4
4
  class h {
5
5
  constructor() {
6
6
  I(this, "defaultProps", {
7
7
  interval: 5e3
8
8
  });
9
9
  I(this, "startActionEvery", (e, t = this.defaultProps) => {
10
- const r = (s) => {
10
+ const a = (s) => {
11
11
  t != null && t.watchIdInterval && (t == null || t.watchIdInterval(s));
12
- }, u = (s) => {
12
+ }, v = (s) => {
13
13
  t != null && t.controlAction && (t == null || t.controlAction(s));
14
14
  };
15
15
  return new Promise((s, l) => {
16
16
  let n = 0, m = 0;
17
- const a = {
17
+ const r = {
18
18
  isActive: !0
19
19
  }, A = setInterval(
20
20
  () => {
21
21
  if (n += t.interval, m += 1, t != null && t.cutoffTime && n > t.cutoffTime || t != null && t.countAction && (t == null ? void 0 : t.countAction) < m) {
22
- a.isActive = !1, clearInterval(A), r(null), l({ status: !1, msg: Error("Время загрузки истекло") });
22
+ r.isActive = !1, clearInterval(A), a(null), l({ status: !1, msg: Error("Время загрузки истекло") });
23
23
  return;
24
24
  }
25
- e() && (a.isActive = !1, clearInterval(A), r(null), s({ status: !0, msg: "cb вернул true" }));
25
+ e() && (r.isActive = !1, clearInterval(A), a(null), s({ status: !0, msg: "cb вернул true" }));
26
26
  },
27
27
  t.interval < 200 ? 200 : t.interval
28
28
  );
29
- r(A), u({
30
- getIsActiveEvent: () => a.isActive,
29
+ a(A), v({
30
+ getIsActiveEvent: () => r.isActive,
31
31
  stop: (p) => {
32
32
  const d = "Ручное завершение startActionEvery";
33
- a.isActive = !1, clearInterval(A), r(null), p === !1 ? l({ status: !1, msg: d + ": (false)" }) : s({ status: !0, msg: d + ": (true)" });
33
+ r.isActive = !1, clearInterval(A), a(null), p ? s({ status: p, msg: d + ": (true)" }) : l({ status: p, msg: d + ": (false)" });
34
34
  }
35
35
  });
36
36
  });
37
37
  });
38
- I(this, "oneOf", (e, t, { second: r }) => {
39
- let u = 1;
38
+ I(this, "oneOf", (e, t, { second: a }) => {
39
+ let v = 1;
40
40
  e().then(() => {
41
- u === 1 && (u = 0);
41
+ v === 1 && (v = 0);
42
42
  });
43
43
  let s = setInterval(() => {
44
- u === 1 && t(), clearInterval(s);
45
- }, r * 1e3);
44
+ v === 1 && t(), clearInterval(s);
45
+ }, a * 1e3);
46
46
  });
47
- I(this, "oneOfPromise", (e, t, { second: r }) => new Promise((u, s) => {
47
+ I(this, "oneOfPromise", (e, t, { second: a }) => new Promise((v, s) => {
48
48
  let l = 1, n = { status: !1, msg: "" };
49
- e().then((a) => {
50
- l === 1 && (l = 0, u(a));
51
- }).catch((a) => {
52
- l === 1 && (l = 0, n.msg = a, s(a));
49
+ e().then((r) => {
50
+ l === 1 && (l = 0, v(r));
51
+ }).catch((r) => {
52
+ l === 1 && (l = 0, n.msg = r, s(r));
53
53
  });
54
54
  let m = setInterval(() => {
55
55
  if (l === 1) {
@@ -60,7 +60,7 @@ class h {
60
60
  s({ status: !1, msg: "oneOfPromise reject" });
61
61
  }
62
62
  clearInterval(m);
63
- }, r * 1e3);
63
+ }, a * 1e3);
64
64
  }));
65
65
  }
66
66
  }
@@ -17,10 +17,9 @@ const t = class t {
17
17
  return t.state.isNetworkStatus;
18
18
  }
19
19
  static request({ keyAction: e, request: r }) {
20
- const { url: f, ...w } = r;
21
- return new Promise((I, u) => {
22
- if (!t.getIsInit())
23
- throw new Error("Не вызван HTTPSApi.init()");
20
+ const { url: f, ...I } = r;
21
+ return new Promise((w, u) => {
22
+ t.getIsInit() || t.init();
24
23
  const o = t.getIsNetwork(), a = {
25
24
  url: f,
26
25
  keyAction: e,
@@ -31,7 +30,7 @@ const t = class t {
31
30
  isReload: !1
32
31
  };
33
32
  if (t.events.publish("fetch", a), o) {
34
- l.requestInServer(f, w).then((c) => {
33
+ l.requestInServer(f, I).then((c) => {
35
34
  const n = {
36
35
  isReq: !1,
37
36
  isReload: !0,
@@ -40,7 +39,7 @@ const t = class t {
40
39
  msg: "",
41
40
  ...c
42
41
  };
43
- t.events.publish("fetch", n), I(n);
42
+ t.events.publish("fetch", n), w(n);
44
43
  }).catch((c) => {
45
44
  const n = {
46
45
  isReq: !1,
@@ -110,10 +110,10 @@ n(t, "socketReConnect", () => {
110
110
  if (console.log("reconnect"), t.saveID.idReConnect)
111
111
  console.groupCollapsed("Процесс socketReConnect уже запущен"), console.log("SocketApi.saveID: ", t.saveID), console.groupEnd();
112
112
  else {
113
- t.setStatusReConnect(!0);
113
+ t.setStatusReConnect(!0), t.connect();
114
114
  const { timeReConnect: e, numberOfRepit: s } = t.wsApi.getOptions();
115
115
  t.delay.startActionEvery(
116
- () => (console.log("reconnect:>>delay"), t.wsApi.getStatusSocket() === "ready" ? (console.dir("Подключение установлено"), !0) : !1),
116
+ () => (console.log("reconnect:>>delay"), t.wsApi.getStatusSocket() === "ready" ? (console.dir("Подключение установлено"), !0) : (t.connect(), !1)),
117
117
  {
118
118
  interval: e,
119
119
  countAction: s,
@@ -121,9 +121,7 @@ n(t, "socketReConnect", () => {
121
121
  t.saveID.idReConnect = o;
122
122
  },
123
123
  controlAction: ({ stop: o, getIsActiveEvent: c }) => {
124
- t.stopReConnect = (a) => {
125
- o(a);
126
- };
124
+ t.stopReConnect = o;
127
125
  }
128
126
  }
129
127
  ).then(t.setInfoConnect).catch(t.setInfoConnect);
@@ -14,20 +14,11 @@ export declare class WsApi {
14
14
  private msgHandler;
15
15
  private errHandler;
16
16
  private copyState;
17
- private setResponceInReqSave;
18
- private removeRequestItemSave;
17
+ private filterSaveItemsByResponse;
19
18
  private errorInitSocket;
20
- getRegisteredEvents: () => string[];
21
- send(data: any): void;
22
- getIsInitWS: () => boolean;
19
+ private setStatus;
23
20
  getSocket: () => WebSocket | null;
24
- getOptions: () => WsApi_Options_P;
25
- init: (options: typeof this.options) => void;
26
21
  getStatusSocket: () => WsApiE_StatusConnect_OR;
27
- private setStatus;
28
- on: <K extends keyof WsApi_Events>(name: K, cb: WsApi_Events[K]) => void;
29
- off: <K extends keyof WsApi_Events>(name: K, cb: WsApi_Events[K]) => void;
30
- setRequestSave(reqInfo: (typeof this.state.arrSaveReq)[number]): void;
31
22
  getRequestSave: () => {
32
23
  payload: {
33
24
  [key: string]: any;
@@ -36,7 +27,15 @@ export declare class WsApi {
36
27
  reqId: string;
37
28
  cb: any;
38
29
  }[];
30
+ getOptions: () => WsApi_Options_P;
31
+ getRegisteredEvents: () => string[];
32
+ on: <K extends keyof WsApi_Events>(name: K, cb: WsApi_Events[K]) => void;
33
+ off: <K extends keyof WsApi_Events>(name: K, cb: WsApi_Events[K]) => void;
34
+ init: (options: typeof this.options) => void;
35
+ getIsInitWS: () => boolean;
39
36
  connect(): void;
40
37
  close(): void;
41
38
  disconnect(): void;
39
+ send(data: any): void;
40
+ setRequestSave(reqInfo: (typeof this.state.arrSaveReq)[number]): void;
42
41
  }
@@ -1,74 +1,74 @@
1
1
  var c = Object.defineProperty;
2
- var S = (r, t, e) => t in r ? c(r, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : r[t] = e;
3
- var s = (r, t, e) => (S(r, typeof t != "symbol" ? t + "" : t, e), e);
4
- import { EventSubscribers as l } from "../../../Utils/EventSubscribers/EventSubscribers.js";
5
- class u {
2
+ var l = (a, t, s) => t in a ? c(a, t, { enumerable: !0, configurable: !0, writable: !0, value: s }) : a[t] = s;
3
+ var e = (a, t, s) => (l(a, typeof t != "symbol" ? t + "" : t, s), s);
4
+ import { EventSubscribers as S } from "../../../Utils/EventSubscribers/EventSubscribers.js";
5
+ class v {
6
6
  constructor() {
7
- s(this, "options", {
7
+ e(this, "options", {
8
8
  timeReConnect: 5e3,
9
9
  numberOfRepit: 5,
10
10
  url: ""
11
11
  });
12
- s(this, "state", {
12
+ e(this, "state", {
13
13
  statusConnect: "disconnect",
14
14
  ws: null,
15
15
  arrSaveReq: []
16
16
  });
17
- s(this, "initOptions", !1);
18
- s(this, "events", new l(["status", "msg"]));
19
- s(this, "stateDefault", this.copyState(this.state));
20
- s(this, "eventListener", (t) => {
21
- var i, a;
22
- const e = [
17
+ e(this, "initOptions", !1);
18
+ e(this, "events", new S(["status", "msg"]));
19
+ e(this, "stateDefault", this.copyState(this.state));
20
+ e(this, "eventListener", (t) => {
21
+ var i, r;
22
+ const s = [
23
23
  ["open", this.openHandler],
24
24
  ["close", this.closeHandler],
25
25
  ["message", this.msgHandler],
26
26
  ["error", this.errHandler]
27
27
  ];
28
- for (let n = 0; n < e.length; n++) {
29
- const [o, h] = e[n];
30
- t === "add" ? (i = this.state.ws) == null || i.addEventListener(o, h) : (a = this.state.ws) == null || a.removeEventListener(o, h);
28
+ for (let n = 0; n < s.length; n++) {
29
+ const [o, h] = s[n];
30
+ t === "add" ? (i = this.state.ws) == null || i.addEventListener(o, h) : (r = this.state.ws) == null || r.removeEventListener(o, h);
31
31
  }
32
32
  });
33
- s(this, "openHandler", () => {
33
+ e(this, "openHandler", () => {
34
34
  this.setStatus("ready");
35
35
  });
36
- s(this, "closeHandler", () => {
36
+ e(this, "closeHandler", () => {
37
37
  this.setStatus("close");
38
38
  });
39
- s(this, "msgHandler", (t) => {
40
- const e = JSON.parse(t.data ? t.data : "{}");
39
+ e(this, "msgHandler", (t) => {
40
+ const s = JSON.parse(t.data ? t.data : "{}");
41
41
  try {
42
- const { action: i } = e;
43
- i && this.setResponceInReqSave(e), this.events.publish("msg", e);
42
+ const { action: i } = s;
43
+ i && this.filterSaveItemsByResponse(s), this.events.publish("msg", s);
44
44
  } catch {
45
45
  this.events.publish("msg", JSON.parse("{}"));
46
46
  }
47
47
  });
48
- s(this, "errHandler", (t) => {
48
+ e(this, "errHandler", (t) => {
49
49
  this.setStatus("error");
50
50
  });
51
- s(this, "errorInitSocket", () => {
51
+ e(this, "errorInitSocket", () => {
52
52
  console.error("Вы не установили опции");
53
53
  });
54
- /*----------------------------------------------------------------------------------------------------------*/
55
- s(this, "getRegisteredEvents", () => this.events.getListNameEvents());
56
- s(this, "getIsInitWS", () => {
57
- const t = this.initOptions;
58
- return t || this.errorInitSocket(), t;
54
+ e(this, "setStatus", (t) => {
55
+ this.events.publish("status", t), this.setState({ statusConnect: t });
59
56
  });
60
- s(this, "getSocket", () => this.state.ws);
61
- s(this, "getOptions", () => this.options);
62
- s(this, "init", (t) => {
57
+ /*----------------------------------------------------------------------------------------------------------*/
58
+ e(this, "getSocket", () => this.state.ws);
59
+ e(this, "getStatusSocket", () => this.state.statusConnect);
60
+ e(this, "getRequestSave", () => this.state.arrSaveReq);
61
+ e(this, "getOptions", () => this.options);
62
+ e(this, "getRegisteredEvents", this.events.getListNameEvents);
63
+ e(this, "on", this.events.subscribe);
64
+ e(this, "off", this.events.unsubscribe);
65
+ e(this, "init", (t) => {
63
66
  this.initOptions = !0, this.options = { ...this.options, ...t };
64
67
  });
65
- s(this, "getStatusSocket", () => this.state.statusConnect);
66
- s(this, "setStatus", (t) => {
67
- this.events.publish("status", t), this.setState({ statusConnect: t });
68
+ e(this, "getIsInitWS", () => {
69
+ const t = this.initOptions;
70
+ return t || this.errorInitSocket(), t;
68
71
  });
69
- s(this, "on", this.events.subscribe);
70
- s(this, "off", this.events.unsubscribe);
71
- s(this, "getRequestSave", () => this.state.arrSaveReq);
72
72
  }
73
73
  resetState() {
74
74
  this.state = this.copyState(this.stateDefault);
@@ -79,32 +79,14 @@ class u {
79
79
  copyState(t) {
80
80
  return JSON.parse(JSON.stringify(t));
81
81
  }
82
- setResponceInReqSave(t) {
83
- const e = this.getRequestSave(), i = [];
84
- for (let a = 0; a < e.length; a++) {
85
- const n = e[a];
82
+ filterSaveItemsByResponse(t) {
83
+ const s = this.getRequestSave(), i = [];
84
+ for (let r = 0; r < s.length; r++) {
85
+ const n = s[r];
86
86
  n.payload.action !== t.action ? i.push(n) : n.cb && n.cb(t);
87
87
  }
88
88
  this.state.arrSaveReq = i;
89
89
  }
90
- removeRequestItemSave(t) {
91
- const e = this.state.arrSaveReq.filter((i) => {
92
- var a;
93
- return ((a = i.payload) == null ? void 0 : a.action) !== t;
94
- });
95
- this.state.arrSaveReq = e;
96
- }
97
- send(t) {
98
- var i;
99
- const e = JSON.stringify(t);
100
- (i = this.state.ws) == null || i.send(e);
101
- }
102
- setRequestSave(t) {
103
- if ("action" in t.payload) {
104
- const e = this.state.arrSaveReq.findIndex((i) => i.payload.action === t.payload.action);
105
- ~e ? this.state.arrSaveReq[e] = t : this.state.arrSaveReq.push(t);
106
- }
107
- }
108
90
  connect() {
109
91
  this.initOptions && (this.close(), this.setState({
110
92
  ws: new WebSocket(this.options.url)
@@ -117,7 +99,18 @@ class u {
117
99
  disconnect() {
118
100
  this.close(), this.resetState();
119
101
  }
102
+ send(t) {
103
+ var i;
104
+ const s = JSON.stringify(t);
105
+ (i = this.state.ws) == null || i.send(s);
106
+ }
107
+ setRequestSave(t) {
108
+ if ("action" in t.payload) {
109
+ const s = this.state.arrSaveReq.findIndex((i) => i.payload.action === t.payload.action);
110
+ ~s ? this.state.arrSaveReq[s] = t : this.state.arrSaveReq.push(t);
111
+ }
112
+ }
120
113
  }
121
114
  export {
122
- u as WsApi
115
+ v as WsApi
123
116
  };
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  },
12
12
  "homepage": "https://github.com/SinGlEBW/dev-classes#readme",
13
13
  "license": "MIT",
14
- "version": "1.3.10",
14
+ "version": "1.3.11",
15
15
  "type": "module",
16
16
  "module": "./dist/index.js",
17
17
  "main": "./dist/index.js",