dev-classes 1.3.27 → 1.3.29
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 +4 -1
- package/dist/classes/DelaysPromise/DelaysPromise.js +53 -50
- package/dist/classes/DelaysPromise/DelaysPromise.types.d.ts +7 -4
- package/dist/classes/SocketApi/SocketApi.d.ts +10 -2
- package/dist/classes/SocketApi/SocketApi.js +24 -30
- package/dist/classes/SocketApi/SocketApi.types.d.ts +5 -2
- package/dist/classes/SocketApi/index.d.ts +1 -1
- package/package.json +7 -6
package/README.md
CHANGED
|
@@ -146,7 +146,10 @@ interface OneOfPromiseReject{
|
|
|
146
146
|
|
|
147
147
|
|
|
148
148
|
interface DelaysPromiseProps{
|
|
149
|
-
|
|
149
|
+
startActionEvery: (cb: () => boolean, config: StartActionEveryConfigI) => {
|
|
150
|
+
stop: ControlAction['stop'],
|
|
151
|
+
promise: Promise<{status: boolean, msg: string}>
|
|
152
|
+
}
|
|
150
153
|
oneOf: (watchPromise: () => Promise<any>, potentialCaseCB: () => void, config: {second: number}) => void
|
|
151
154
|
oneOfPromise:(watchPromise: () => Promise<any>, cbPotentialReject: (p:OneOfPromiseReject) => OneOfPromiseReject, config: {second: number}) => Promise<any>
|
|
152
155
|
}
|
|
@@ -1,69 +1,72 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
class
|
|
1
|
+
var P = Object.defineProperty;
|
|
2
|
+
var h = (m, e, t) => e in m ? P(m, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : m[e] = t;
|
|
3
|
+
var A = (m, e, t) => (h(m, typeof e != "symbol" ? e + "" : e, t), t);
|
|
4
|
+
class O {
|
|
5
5
|
constructor() {
|
|
6
|
-
|
|
6
|
+
A(this, "defaultProps", {
|
|
7
7
|
interval: 5e3
|
|
8
8
|
});
|
|
9
|
-
|
|
10
|
-
const a = (
|
|
11
|
-
t != null && t.watchIdInterval && (t == null || t.watchIdInterval(
|
|
12
|
-
},
|
|
13
|
-
t != null && t.controlAction && (t == null || t.controlAction(
|
|
9
|
+
A(this, "startActionEvery", (e, t = this.defaultProps) => {
|
|
10
|
+
const a = (r) => {
|
|
11
|
+
t != null && t.watchIdInterval && (t == null || t.watchIdInterval(r));
|
|
12
|
+
}, u = (r) => {
|
|
13
|
+
t != null && t.controlAction && (t == null || t.controlAction(r));
|
|
14
|
+
};
|
|
15
|
+
let l = !0, s, n, I;
|
|
16
|
+
const v = (r = !0) => {
|
|
17
|
+
const p = "Ручное завершение startActionEvery";
|
|
18
|
+
l = !1, clearInterval(s), a(null), r ? n && n({ status: r, msg: p + ": (true)" }) : I && I({ status: r, msg: p + ": (false)" });
|
|
19
|
+
};
|
|
20
|
+
return {
|
|
21
|
+
promise: new Promise((r, p) => {
|
|
22
|
+
n = r, I = p;
|
|
23
|
+
let d = 0, o = 0;
|
|
24
|
+
s = setInterval(
|
|
25
|
+
() => {
|
|
26
|
+
if (d += t.interval, o += 1, t != null && t.cutoffTime && d > t.cutoffTime || t != null && t.countAction && (t == null ? void 0 : t.countAction) < o) {
|
|
27
|
+
l = !1, clearInterval(s), a(null), p({ status: !1, msg: Error("Время загрузки истекло") });
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
e() && (l = !1, clearInterval(s), a(null), r({ status: !0, msg: "cb вернул true" }));
|
|
31
|
+
},
|
|
32
|
+
t.interval < 200 ? 200 : t.interval
|
|
33
|
+
), a(s), u({
|
|
34
|
+
getIsActiveEvent: () => l,
|
|
35
|
+
stop: v
|
|
36
|
+
});
|
|
37
|
+
}),
|
|
38
|
+
stop: v
|
|
14
39
|
};
|
|
15
|
-
return new Promise((s, l) => {
|
|
16
|
-
let n = 0, m = 0;
|
|
17
|
-
const r = {
|
|
18
|
-
isActive: !0
|
|
19
|
-
}, A = setInterval(
|
|
20
|
-
() => {
|
|
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
|
-
r.isActive = !1, clearInterval(A), a(null), l({ status: !1, msg: Error("Время загрузки истекло") });
|
|
23
|
-
return;
|
|
24
|
-
}
|
|
25
|
-
e() && (r.isActive = !1, clearInterval(A), a(null), s({ status: !0, msg: "cb вернул true" }));
|
|
26
|
-
},
|
|
27
|
-
t.interval < 200 ? 200 : t.interval
|
|
28
|
-
);
|
|
29
|
-
a(A), v({
|
|
30
|
-
getIsActiveEvent: () => r.isActive,
|
|
31
|
-
stop: (p) => {
|
|
32
|
-
const d = "Ручное завершение startActionEvery";
|
|
33
|
-
r.isActive = !1, clearInterval(A), a(null), p ? s({ status: p, msg: d + ": (true)" }) : l({ status: p, msg: d + ": (false)" });
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
});
|
|
37
40
|
});
|
|
38
|
-
|
|
39
|
-
let
|
|
41
|
+
A(this, "oneOf", (e, t, { second: a }) => {
|
|
42
|
+
let u = 1;
|
|
40
43
|
e().then(() => {
|
|
41
|
-
|
|
44
|
+
u === 1 && (u = 0);
|
|
42
45
|
});
|
|
43
|
-
let
|
|
44
|
-
|
|
46
|
+
let l = setInterval(() => {
|
|
47
|
+
u === 1 && t(), clearInterval(l);
|
|
45
48
|
}, a * 1e3);
|
|
46
49
|
});
|
|
47
|
-
|
|
48
|
-
let
|
|
49
|
-
e().then((
|
|
50
|
-
|
|
51
|
-
}).catch((
|
|
52
|
-
|
|
50
|
+
A(this, "oneOfPromise", (e, t, { second: a }) => new Promise((u, l) => {
|
|
51
|
+
let s = 1, n = { status: !1, msg: "" };
|
|
52
|
+
e().then((v) => {
|
|
53
|
+
s === 1 && (s = 0, u(v));
|
|
54
|
+
}).catch((v) => {
|
|
55
|
+
s === 1 && (s = 0, n.msg = v, l(v));
|
|
53
56
|
});
|
|
54
|
-
let
|
|
55
|
-
if (
|
|
56
|
-
if (
|
|
57
|
-
|
|
57
|
+
let I = setInterval(() => {
|
|
58
|
+
if (s === 1) {
|
|
59
|
+
if (s = 0, typeof t == "function") {
|
|
60
|
+
l({ status: !1, msg: "", ...t(n) });
|
|
58
61
|
return;
|
|
59
62
|
}
|
|
60
|
-
|
|
63
|
+
l({ status: !1, msg: "oneOfPromise reject" });
|
|
61
64
|
}
|
|
62
|
-
clearInterval(
|
|
65
|
+
clearInterval(I);
|
|
63
66
|
}, a * 1e3);
|
|
64
67
|
}));
|
|
65
68
|
}
|
|
66
69
|
}
|
|
67
70
|
export {
|
|
68
|
-
|
|
71
|
+
O as DelaysPromise
|
|
69
72
|
};
|
|
@@ -14,10 +14,13 @@ interface OneOfPromiseReject {
|
|
|
14
14
|
msg: string;
|
|
15
15
|
}
|
|
16
16
|
export interface DelaysPromiseProps {
|
|
17
|
-
startActionEvery: (cb: () => boolean, config: StartActionEveryConfigI) =>
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
startActionEvery: (cb: () => boolean, config: StartActionEveryConfigI) => {
|
|
18
|
+
stop: ControlAction['stop'];
|
|
19
|
+
promise: Promise<{
|
|
20
|
+
status: boolean;
|
|
21
|
+
msg: string;
|
|
22
|
+
}>;
|
|
23
|
+
};
|
|
21
24
|
oneOf: (watchPromise: () => Promise<any>, potentialCaseCB: () => void, config: {
|
|
22
25
|
second: number;
|
|
23
26
|
}) => void;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { WsApi_Options_P } from './deps/WsApi';
|
|
2
|
-
import { SocketApi_Options_P,
|
|
2
|
+
import { SocketApi_Options_P, SocketApi_StateProps_P } from './SocketApi.types';
|
|
3
3
|
|
|
4
4
|
export declare class SocketApi {
|
|
5
5
|
#private;
|
|
@@ -20,9 +20,17 @@ export declare class SocketApi {
|
|
|
20
20
|
private static online;
|
|
21
21
|
private static offline;
|
|
22
22
|
private static splitOptions;
|
|
23
|
-
static getState: () =>
|
|
23
|
+
static getState: () => SocketApi_StateProps_P;
|
|
24
24
|
static on: typeof SocketApi.wsApi.on & typeof SocketApi.events.subscribe;
|
|
25
25
|
static off: typeof SocketApi.wsApi.on & typeof SocketApi.events.subscribe;
|
|
26
|
+
static getRequestSave: () => {
|
|
27
|
+
payload: {
|
|
28
|
+
[key: string]: any;
|
|
29
|
+
action: string;
|
|
30
|
+
};
|
|
31
|
+
reqId: string;
|
|
32
|
+
cb: any;
|
|
33
|
+
}[];
|
|
26
34
|
static getStatusSocket: () => import('./deps/WsApi').WsApiE_StatusConnect_OR;
|
|
27
35
|
static close: () => void;
|
|
28
36
|
static init: (options: WsApi_Options_P & SocketApi_Options_P) => void;
|
|
@@ -1,24 +1,24 @@
|
|
|
1
1
|
var w = Object.defineProperty;
|
|
2
|
-
var C = (
|
|
3
|
-
var n = (
|
|
4
|
-
var f = (
|
|
5
|
-
if (e.has(
|
|
2
|
+
var C = (o, e, s) => e in o ? w(o, e, { enumerable: !0, configurable: !0, writable: !0, value: s }) : o[e] = s;
|
|
3
|
+
var n = (o, e, s) => (C(o, typeof e != "symbol" ? e + "" : e, s), s);
|
|
4
|
+
var f = (o, e, s) => {
|
|
5
|
+
if (e.has(o))
|
|
6
6
|
throw TypeError("Cannot add the same private member more than once");
|
|
7
|
-
e instanceof WeakSet ? e.add(
|
|
7
|
+
e instanceof WeakSet ? e.add(o) : e.set(o, s);
|
|
8
8
|
};
|
|
9
9
|
import { DelaysPromise as R } from "../DelaysPromise/DelaysPromise.js";
|
|
10
|
-
import { NetworkInformationCordova as
|
|
11
|
-
import { NetworkInformationPC as
|
|
10
|
+
import { NetworkInformationCordova as v } from "../Utils/NetworkInformation/classes/NetworkInformationCordova.js";
|
|
11
|
+
import { NetworkInformationPC as d } from "../Utils/NetworkInformation/classes/NetworkInformationPC.js";
|
|
12
12
|
import { EventSubscribers as g } from "../Utils/EventSubscribers/EventSubscribers.js";
|
|
13
13
|
import { NetworkInformation as O } from "../Utils/NetworkInformation/NetworkInformation.js";
|
|
14
14
|
import { WsApi as S } from "./deps/WsApi/WsApi.js";
|
|
15
15
|
const I = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
|
|
16
|
-
function m(
|
|
17
|
-
return I.test(
|
|
16
|
+
function m(o) {
|
|
17
|
+
return I.test(o);
|
|
18
18
|
}
|
|
19
19
|
function u() {
|
|
20
|
-
var
|
|
21
|
-
return URL.revokeObjectURL(
|
|
20
|
+
var o = URL.createObjectURL(new Blob()), e = o.toString();
|
|
21
|
+
return URL.revokeObjectURL(o), e.split(/[:\/]/g).pop().toLowerCase();
|
|
22
22
|
}
|
|
23
23
|
u.valid = m;
|
|
24
24
|
var r, A;
|
|
@@ -45,10 +45,10 @@ const t = class t {
|
|
|
45
45
|
t.state.isDisconnect || (t.setState({ isDisconnect: !0 }), console.log("DISCONNECT WS"), t.wsApi.disconnect(), t.resetState());
|
|
46
46
|
}
|
|
47
47
|
static send(e, s) {
|
|
48
|
-
const { action:
|
|
48
|
+
const { action: i, ...c } = e, a = u();
|
|
49
49
|
t.wsApi.setRequestSave({
|
|
50
50
|
reqId: a,
|
|
51
|
-
payload: { action:
|
|
51
|
+
payload: { action: i, ...c },
|
|
52
52
|
cb: s
|
|
53
53
|
});
|
|
54
54
|
const l = t.wsApi.getSocket();
|
|
@@ -71,7 +71,7 @@ r = new WeakSet(), A = function() {
|
|
|
71
71
|
isNetworkStatus: navigator.onLine
|
|
72
72
|
}), n(t, "options", {
|
|
73
73
|
isReConnectNetworkOnline: !1
|
|
74
|
-
}), n(t, "wsApi", new S()), n(t, "delay", new R()), n(t, "internet", new O([new
|
|
74
|
+
}), n(t, "wsApi", new S()), n(t, "delay", new R()), n(t, "internet", new O([new d(), new v()])), n(t, "events", new g(["timeOffReConnect", "reConnect"])), n(t, "saveID", {
|
|
75
75
|
idReConnect: null,
|
|
76
76
|
checkConnect: null
|
|
77
77
|
}), n(t, "stateDefault", t.copyState(t.state)), n(t, "setInfoConnect", (e) => {
|
|
@@ -81,9 +81,9 @@ r = new WeakSet(), A = function() {
|
|
|
81
81
|
}), n(t, "offline", () => {
|
|
82
82
|
t.setState({ isNetworkStatus: !1 }), t.state.isActiveReConnect && t.stopReConnect(!1);
|
|
83
83
|
}), n(t, "splitOptions", (e) => Object.entries(e).reduce(
|
|
84
|
-
(s, [
|
|
84
|
+
(s, [i, c]) => {
|
|
85
85
|
const a = t.wsApi.getOptions();
|
|
86
|
-
return
|
|
86
|
+
return i in a ? { ...s, WsOptions: { ...s.WsOptions, [i]: c } } : { ...s, SocketApiOptions: { ...s.SocketApiOptions, [i]: c } };
|
|
87
87
|
},
|
|
88
88
|
{ WsOptions: {}, SocketApiOptions: {} }
|
|
89
89
|
)), /*---------------------------------------------------------------------------------------------------------------------------*/
|
|
@@ -91,20 +91,14 @@ n(t, "getState", () => t.state), n(t, "on", (e, s) => {
|
|
|
91
91
|
t.wsApi.getRegisteredEvents().includes(e) ? t.wsApi.on(e, s) : t.events.subscribe(e, s);
|
|
92
92
|
}), n(t, "off", (e, s) => {
|
|
93
93
|
t.wsApi.getRegisteredEvents().includes(e) ? t.wsApi.off(e, s) : t.events.unsubscribe(e, s);
|
|
94
|
-
}),
|
|
95
|
-
n(t, "getStatusSocket", t.wsApi.getStatusSocket), n(t, "close", () => {
|
|
94
|
+
}), n(t, "getRequestSave", t.wsApi.getRequestSave), n(t, "getStatusSocket", t.wsApi.getStatusSocket), n(t, "close", () => {
|
|
96
95
|
t.state.isActiveReConnect ? t.stopReConnect(!1) : t.wsApi.close();
|
|
97
96
|
}), n(t, "init", (e) => {
|
|
98
|
-
const { WsOptions: s, SocketApiOptions:
|
|
97
|
+
const { WsOptions: s, SocketApiOptions: i } = t.splitOptions(e);
|
|
99
98
|
t.internet.run((c) => {
|
|
100
99
|
c ? t.online() : t.offline();
|
|
101
|
-
}), t.setOptions(
|
|
100
|
+
}), t.setOptions(i), t.wsApi.init(s);
|
|
102
101
|
}), /*------------------------------------------------------------------------------------------------------*/
|
|
103
|
-
// useEffect(() => {
|
|
104
|
-
// if((isReConnectSocket && (!isNetworkStatus || statusWS === 'ready'))){
|
|
105
|
-
// SocketApi.stopReConnect();
|
|
106
|
-
// }
|
|
107
|
-
// },[isReConnectSocket, isNetworkStatus, statusWS]);
|
|
108
102
|
n(t, "socketReConnect", () => {
|
|
109
103
|
if (t.wsApi.getIsInitWS())
|
|
110
104
|
if (console.log("reconnect"), t.saveID.idReConnect)
|
|
@@ -117,14 +111,14 @@ n(t, "socketReConnect", () => {
|
|
|
117
111
|
{
|
|
118
112
|
interval: e,
|
|
119
113
|
countAction: s,
|
|
120
|
-
watchIdInterval: (
|
|
121
|
-
t.saveID.idReConnect =
|
|
114
|
+
watchIdInterval: (c) => {
|
|
115
|
+
t.saveID.idReConnect = c;
|
|
122
116
|
},
|
|
123
|
-
controlAction: ({ stop:
|
|
124
|
-
t.stopReConnect =
|
|
117
|
+
controlAction: ({ stop: c, getIsActiveEvent: a }) => {
|
|
118
|
+
t.stopReConnect = c;
|
|
125
119
|
}
|
|
126
120
|
}
|
|
127
|
-
).then(t.setInfoConnect).catch(t.setInfoConnect);
|
|
121
|
+
).promise.then(t.setInfoConnect).catch(t.setInfoConnect);
|
|
128
122
|
}
|
|
129
123
|
});
|
|
130
124
|
let p = t;
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
+
import { WsApiE_StatusConnect_OR } from './deps/WsApi';
|
|
2
|
+
|
|
1
3
|
export interface SocketApi_Options_P {
|
|
2
4
|
isReConnectNetworkOnline?: boolean;
|
|
3
5
|
}
|
|
4
|
-
type
|
|
5
|
-
export type
|
|
6
|
+
type SocketApi_StateProps_OR = 'isDisconnect' | 'isActiveReConnect' | 'isOfflineSocket' | 'isReady' | 'isNetworkStatus';
|
|
7
|
+
export type SocketApi_StateProps_P = Record<SocketApi_StateProps_OR, boolean>;
|
|
8
|
+
export type SocketApi_StatusConnect_OR = WsApiE_StatusConnect_OR;
|
|
6
9
|
export {};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export * from './SocketApi';
|
|
2
|
-
export { type
|
|
2
|
+
export { type SocketApi_StateProps_P, type SocketApi_StatusConnect_OR } from './SocketApi.types';
|
package/package.json
CHANGED
|
@@ -2,16 +2,16 @@
|
|
|
2
2
|
"name": "dev-classes",
|
|
3
3
|
"private": false,
|
|
4
4
|
"author": "SinGlEBW",
|
|
5
|
+
"homepage": "https://github.com/SinGlEBW/dev-classes#readme",
|
|
6
|
+
"bugs": {
|
|
7
|
+
"url": "https://github.com/SinGlEBW/dev-classes/issues"
|
|
8
|
+
},
|
|
5
9
|
"repository": {
|
|
6
10
|
"type": "git",
|
|
7
11
|
"url": "git+https://github.com/SinGlEBW/dev-classes.git"
|
|
8
12
|
},
|
|
9
|
-
"bugs": {
|
|
10
|
-
"url": "https://github.com/SinGlEBW/dev-classes/issues"
|
|
11
|
-
},
|
|
12
|
-
"homepage": "https://github.com/SinGlEBW/dev-classes#readme",
|
|
13
13
|
"license": "MIT",
|
|
14
|
-
"version": "1.3.
|
|
14
|
+
"version": "1.3.29",
|
|
15
15
|
"type": "module",
|
|
16
16
|
"module": "./dist/index.js",
|
|
17
17
|
"main": "./dist/index.js",
|
|
@@ -38,7 +38,8 @@
|
|
|
38
38
|
"scripts": {
|
|
39
39
|
"start": "vite",
|
|
40
40
|
"build": "tsc && vite build",
|
|
41
|
-
"preview": "vite preview"
|
|
41
|
+
"preview": "vite preview",
|
|
42
|
+
"publish": "node publishVersion.js"
|
|
42
43
|
},
|
|
43
44
|
"devDependencies": {
|
|
44
45
|
"@types/js-cookie": "^3.0.6",
|