@ancon/wildcat-utils 1.53.0 → 1.54.0-check-optimizations.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/check/getOrganizedCheckItemModifications.d.ts +2 -2
- package/check/getOrganizedCheckItemModifications.js +1 -1
- package/check/getOrganizedCheckItemModifications.mjs +74 -68
- package/check/getUniqueCheckItemModificationId.d.ts +2 -2
- package/check/getUniqueCheckItemModificationId.js +1 -1
- package/check/getUniqueCheckItemModificationId.mjs +5 -5
- package/multilingual/createLocalizedCheckDetails.d.ts +2 -2
- package/multilingual/createLocalizedCheckDetails.js +1 -1
- package/multilingual/createLocalizedCheckDetails.mjs +31 -27
- package/package.json +1 -1
- package/signalr/SignalR.d.ts +21 -1
- package/signalr/SignalR.js +1 -1
- package/signalr/SignalR.mjs +108 -74
- package/signalr/createUseSignalRHook.d.ts +1 -1
- package/signalr/createUseSignalRHook.js +1 -1
- package/signalr/createUseSignalRHook.mjs +69 -64
- package/signalr/types.d.ts +2 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { CheckItemV2 } from '@ancon/wildcat-types';
|
|
2
2
|
import { OrganizedCheckItemModification } from './types';
|
|
3
3
|
/**
|
|
4
4
|
* Organizes all check item modifications including addon products into a array for easier visual representation.
|
|
@@ -7,4 +7,4 @@ import { OrganizedCheckItemModification } from './types';
|
|
|
7
7
|
* @param addOnProducts - The list of check item add-on products.
|
|
8
8
|
* @returns An array where the modifications are sorted by their modification kind and positions.
|
|
9
9
|
*/
|
|
10
|
-
export default function getOrganizedCheckItemModifications(currency: string, modifications:
|
|
10
|
+
export default function getOrganizedCheckItemModifications(currency: string, modifications: CheckItemV2['modifications'] | undefined, addOnProducts: CheckItemV2['addOnProducts'] | undefined): OrganizedCheckItemModification[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const h=require("@ancon/wildcat-types"),M=require("../toString-b771abdf.js"),P=require("../identity-58f9497d.js"),x=require("../_baseIteratee-374c60ca.js"),k=require("../_getTag-3d3032da.js"),$=require("../isObjectLike-963267e9.js"),O=require("./getUniqueCheckItemModificationId.js");require("../_baseIsEqual-7e335f42.js");require("../isObject-361bd834.js");function L(n){return function(i,r,e){for(var d=-1,t=Object(i),o=e(i),c=o.length;c--;){var a=o[n?c:++d];if(r(t[a],a,t)===!1)break}return i}}var E=L();const _=E;function G(n,i){return n&&_(n,i,k.keys)}function Q(n,i){return function(r,e){if(r==null)return r;if(!k.isArrayLike(r))return n(r,e);for(var d=r.length,t=i?d:-1,o=Object(r);(i?t--:++t<d)&&e(o[t],t,o)!==!1;);return r}}var U=Q(G);const Z=U;function z(n,i){var r=-1,e=k.isArrayLike(n)?Array(n.length):[];return Z(n,function(d,t,o){e[++r]=i(d,t,o)}),e}function V(n,i){var r=n.length;for(n.sort(i);r--;)n[r]=n[r].value;return n}function j(n,i){if(n!==i){var r=n!==void 0,e=n===null,d=n===n,t=M.isSymbol(n),o=i!==void 0,c=i===null,a=i===i,u=M.isSymbol(i);if(!c&&!u&&!t&&n>i||t&&o&&a&&!c&&!u||e&&o&&a||!r&&a||!d)return 1;if(!e&&!t&&!u&&n<i||u&&r&&d&&!e&&!t||c&&r&&d||!o&&d||!a)return-1}return 0}function H(n,i,r){for(var e=-1,d=n.criteria,t=i.criteria,o=d.length,c=r.length;++e<o;){var a=j(d[e],t[e]);if(a){if(e>=c)return a;var u=r[e];return a*(u=="desc"?-1:1)}}return n.index-i.index}function J(n,i,r){i.length?i=M.arrayMap(i,function(t){return $.isArray(t)?function(o){return P.baseGet(o,t.length===1?t[0]:t)}:t}):i=[P.identity];var e=-1;i=M.arrayMap(i,k.baseUnary(x.baseIteratee));var d=z(n,function(t,o,c){var a=M.arrayMap(i,function(u){return u(t)});return{criteria:a,index:++e,value:t}});return V(d,function(t,o){return H(t,o,r)})}function C(n,i,r,e){return n==null?[]:($.isArray(i)||(i=i==null?[]:[i]),r=e?void 0:r,$.isArray(r)||(r=r==null?[]:[r]),J(n,i,r))}function K(n,i,r){const{add:e,replace:d,remove:t}=i.reduce((a,u)=>{const{modification:A,position:s,freeAmount:f,name:y,quantity:p,cost:g,replacementName:T}=u,m=g===0;if(u.modification===h.ModificationType.Add){(f>0||m)&&a.add.push({id:O(u,"-free"),modificationType:A,name:y,freeAmount:m?p:f,quantity:m?p:f,currency:n,position:s,cost:0});const q=p-f;q>0&&!m&&a.add.push({id:O(u),modificationType:A,name:y,quantity:q,freeAmount:0,currency:n,position:s,cost:g*q})}return u.modification===h.ModificationType.Replace&&a.replace.push({id:O(u),modificationType:A,name:y,replacementName:T,freeAmount:f,quantity:p,currency:n,position:s,cost:g}),u.modification===h.ModificationType.Remove&&a.remove.push({id:O(u),modificationType:A,name:y,freeAmount:f,quantity:p,currency:n,position:s,cost:g}),a},{add:[],replace:[],remove:[]}),o=(r
|
|
1
|
+
"use strict";const h=require("@ancon/wildcat-types"),M=require("../toString-b771abdf.js"),P=require("../identity-58f9497d.js"),x=require("../_baseIteratee-374c60ca.js"),k=require("../_getTag-3d3032da.js"),$=require("../isObjectLike-963267e9.js"),O=require("./getUniqueCheckItemModificationId.js");require("../_baseIsEqual-7e335f42.js");require("../isObject-361bd834.js");function L(n){return function(i,r,e){for(var d=-1,t=Object(i),o=e(i),c=o.length;c--;){var a=o[n?c:++d];if(r(t[a],a,t)===!1)break}return i}}var E=L();const _=E;function G(n,i){return n&&_(n,i,k.keys)}function Q(n,i){return function(r,e){if(r==null)return r;if(!k.isArrayLike(r))return n(r,e);for(var d=r.length,t=i?d:-1,o=Object(r);(i?t--:++t<d)&&e(o[t],t,o)!==!1;);return r}}var U=Q(G);const Z=U;function z(n,i){var r=-1,e=k.isArrayLike(n)?Array(n.length):[];return Z(n,function(d,t,o){e[++r]=i(d,t,o)}),e}function V(n,i){var r=n.length;for(n.sort(i);r--;)n[r]=n[r].value;return n}function j(n,i){if(n!==i){var r=n!==void 0,e=n===null,d=n===n,t=M.isSymbol(n),o=i!==void 0,c=i===null,a=i===i,u=M.isSymbol(i);if(!c&&!u&&!t&&n>i||t&&o&&a&&!c&&!u||e&&o&&a||!r&&a||!d)return 1;if(!e&&!t&&!u&&n<i||u&&r&&d&&!e&&!t||c&&r&&d||!o&&d||!a)return-1}return 0}function H(n,i,r){for(var e=-1,d=n.criteria,t=i.criteria,o=d.length,c=r.length;++e<o;){var a=j(d[e],t[e]);if(a){if(e>=c)return a;var u=r[e];return a*(u=="desc"?-1:1)}}return n.index-i.index}function J(n,i,r){i.length?i=M.arrayMap(i,function(t){return $.isArray(t)?function(o){return P.baseGet(o,t.length===1?t[0]:t)}:t}):i=[P.identity];var e=-1;i=M.arrayMap(i,k.baseUnary(x.baseIteratee));var d=z(n,function(t,o,c){var a=M.arrayMap(i,function(u){return u(t)});return{criteria:a,index:++e,value:t}});return V(d,function(t,o){return H(t,o,r)})}function C(n,i,r,e){return n==null?[]:($.isArray(i)||(i=i==null?[]:[i]),r=e?void 0:r,$.isArray(r)||(r=r==null?[]:[r]),J(n,i,r))}function K(n,i,r){const{add:e,replace:d,remove:t}=(i??[]).reduce((a,u)=>{const{modification:A,position:s,freeAmount:f,name:y="",quantity:p,cost:g,replacementName:T}=u,m=g===0;if(u.modification===h.ModificationType.Add){(f>0||m)&&a.add.push({id:O(u,"-free"),modificationType:A,name:y,freeAmount:m?p:f,quantity:m?p:f,currency:n,position:s,cost:0});const q=p-f;q>0&&!m&&a.add.push({id:O(u),modificationType:A,name:y,quantity:q,freeAmount:0,currency:n,position:s,cost:g*q})}return u.modification===h.ModificationType.Replace&&a.replace.push({id:O(u),modificationType:A,name:y,replacementName:T,freeAmount:f,quantity:p,currency:n,position:s,cost:g}),u.modification===h.ModificationType.Remove&&a.remove.push({id:O(u),modificationType:A,name:y,freeAmount:f,quantity:p,currency:n,position:s,cost:g}),a},{add:[],replace:[],remove:[]}),o=(r??[]).reduce((a,u)=>{const{product:A,freeAmount:s=0,quantity:f,position:y,addOnGroupId:p,productPriceInclTax:g}=u,{hasVariants:T,variantName:m="",productName:q="",productId:B,variantId:F}=A??{},b=g.unitPrice===0;(s>0||b)&&a.push({id:`${p}-${B}-free`,modificationType:h.ModificationType.Add,name:T?m:q,freeAmount:b?f:s,quantity:b?f:s,currency:n,position:y,cost:0,variantId:F});const w=f-s;return w>0&&!b&&a.push({id:`${p}-${B}`,modificationType:h.ModificationType.Add,name:T?m:q,freeAmount:0,quantity:w,currency:n,position:y,cost:g.unitPrice*w,variantId:F}),a},[]);return[...C([...e,...o],["position"],["asc"]),...C(d,["position"],["asc"]),...C(t,["position"],["asc"])]}module.exports=K;
|
|
@@ -8,10 +8,10 @@ import T from "./getUniqueCheckItemModificationId.mjs";
|
|
|
8
8
|
import "../_baseIsEqual-4ee44a4c.mjs";
|
|
9
9
|
import "../isObject-b8638513.mjs";
|
|
10
10
|
function U(n) {
|
|
11
|
-
return function(i, t,
|
|
12
|
-
for (var
|
|
13
|
-
var
|
|
14
|
-
if (t(r[
|
|
11
|
+
return function(i, t, o) {
|
|
12
|
+
for (var d = -1, r = Object(i), u = o(i), f = u.length; f--; ) {
|
|
13
|
+
var a = u[n ? f : ++d];
|
|
14
|
+
if (t(r[a], a, r) === !1)
|
|
15
15
|
break;
|
|
16
16
|
}
|
|
17
17
|
return i;
|
|
@@ -23,12 +23,12 @@ function V(n, i) {
|
|
|
23
23
|
return n && z(n, i, L);
|
|
24
24
|
}
|
|
25
25
|
function H(n, i) {
|
|
26
|
-
return function(t,
|
|
26
|
+
return function(t, o) {
|
|
27
27
|
if (t == null)
|
|
28
28
|
return t;
|
|
29
29
|
if (!P(t))
|
|
30
|
-
return n(t,
|
|
31
|
-
for (var
|
|
30
|
+
return n(t, o);
|
|
31
|
+
for (var d = t.length, r = i ? d : -1, u = Object(t); (i ? r-- : ++r < d) && o(u[r], r, u) !== !1; )
|
|
32
32
|
;
|
|
33
33
|
return t;
|
|
34
34
|
};
|
|
@@ -36,10 +36,10 @@ function H(n, i) {
|
|
|
36
36
|
var J = H(V);
|
|
37
37
|
const K = J;
|
|
38
38
|
function W(n, i) {
|
|
39
|
-
var t = -1,
|
|
40
|
-
return K(n, function(
|
|
41
|
-
|
|
42
|
-
}),
|
|
39
|
+
var t = -1, o = P(n) ? Array(n.length) : [];
|
|
40
|
+
return K(n, function(d, r, u) {
|
|
41
|
+
o[++t] = i(d, r, u);
|
|
42
|
+
}), o;
|
|
43
43
|
}
|
|
44
44
|
function X(n, i) {
|
|
45
45
|
var t = n.length;
|
|
@@ -49,22 +49,22 @@ function X(n, i) {
|
|
|
49
49
|
}
|
|
50
50
|
function Y(n, i) {
|
|
51
51
|
if (n !== i) {
|
|
52
|
-
var t = n !== void 0,
|
|
53
|
-
if (!f && !
|
|
52
|
+
var t = n !== void 0, o = n === null, d = n === n, r = F(n), u = i !== void 0, f = i === null, a = i === i, e = F(i);
|
|
53
|
+
if (!f && !e && !r && n > i || r && u && a && !f && !e || o && u && a || !t && a || !d)
|
|
54
54
|
return 1;
|
|
55
|
-
if (!
|
|
55
|
+
if (!o && !r && !e && n < i || e && t && d && !o && !r || f && t && d || !u && d || !a)
|
|
56
56
|
return -1;
|
|
57
57
|
}
|
|
58
58
|
return 0;
|
|
59
59
|
}
|
|
60
60
|
function _(n, i, t) {
|
|
61
|
-
for (var
|
|
62
|
-
var
|
|
63
|
-
if (
|
|
64
|
-
if (
|
|
65
|
-
return
|
|
66
|
-
var
|
|
67
|
-
return
|
|
61
|
+
for (var o = -1, d = n.criteria, r = i.criteria, u = d.length, f = t.length; ++o < u; ) {
|
|
62
|
+
var a = Y(d[o], r[o]);
|
|
63
|
+
if (a) {
|
|
64
|
+
if (o >= f)
|
|
65
|
+
return a;
|
|
66
|
+
var e = t[o];
|
|
67
|
+
return a * (e == "desc" ? -1 : 1);
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
70
|
return n.index - i.index;
|
|
@@ -75,104 +75,110 @@ function j(n, i, t) {
|
|
|
75
75
|
return E(u, r.length === 1 ? r[0] : r);
|
|
76
76
|
} : r;
|
|
77
77
|
}) : i = [x];
|
|
78
|
-
var
|
|
78
|
+
var o = -1;
|
|
79
79
|
i = q(i, Q(G));
|
|
80
|
-
var
|
|
81
|
-
var
|
|
82
|
-
return
|
|
80
|
+
var d = W(n, function(r, u, f) {
|
|
81
|
+
var a = q(i, function(e) {
|
|
82
|
+
return e(r);
|
|
83
83
|
});
|
|
84
|
-
return { criteria:
|
|
84
|
+
return { criteria: a, index: ++o, value: r };
|
|
85
85
|
});
|
|
86
|
-
return X(
|
|
86
|
+
return X(d, function(r, u) {
|
|
87
87
|
return _(r, u, t);
|
|
88
88
|
});
|
|
89
89
|
}
|
|
90
|
-
function C(n, i, t,
|
|
91
|
-
return n == null ? [] : ($(i) || (i = i == null ? [] : [i]), t =
|
|
90
|
+
function C(n, i, t, o) {
|
|
91
|
+
return n == null ? [] : ($(i) || (i = i == null ? [] : [i]), t = o ? void 0 : t, $(t) || (t = t == null ? [] : [t]), j(n, i, t));
|
|
92
92
|
}
|
|
93
93
|
function rn(n, i, t) {
|
|
94
|
-
const { add:
|
|
95
|
-
(
|
|
94
|
+
const { add: o, replace: d, remove: r } = (i ?? []).reduce(
|
|
95
|
+
(a, e) => {
|
|
96
96
|
const {
|
|
97
97
|
modification: h,
|
|
98
|
-
position:
|
|
99
|
-
freeAmount:
|
|
100
|
-
name: m,
|
|
98
|
+
position: c,
|
|
99
|
+
freeAmount: p,
|
|
100
|
+
name: m = "",
|
|
101
101
|
quantity: s,
|
|
102
102
|
cost: g,
|
|
103
103
|
replacementName: O
|
|
104
|
-
} =
|
|
105
|
-
if (
|
|
106
|
-
(
|
|
107
|
-
id: T(
|
|
104
|
+
} = e, A = g === 0;
|
|
105
|
+
if (e.modification === y.Add) {
|
|
106
|
+
(p > 0 || A) && a.add.push({
|
|
107
|
+
id: T(e, "-free"),
|
|
108
108
|
modificationType: h,
|
|
109
109
|
name: m,
|
|
110
|
-
freeAmount: A ? s :
|
|
111
|
-
quantity: A ? s :
|
|
110
|
+
freeAmount: A ? s : p,
|
|
111
|
+
quantity: A ? s : p,
|
|
112
112
|
currency: n,
|
|
113
|
-
position:
|
|
113
|
+
position: c,
|
|
114
114
|
cost: 0
|
|
115
115
|
});
|
|
116
|
-
const b = s -
|
|
117
|
-
b > 0 && !A &&
|
|
118
|
-
id: T(
|
|
116
|
+
const b = s - p;
|
|
117
|
+
b > 0 && !A && a.add.push({
|
|
118
|
+
id: T(e),
|
|
119
119
|
modificationType: h,
|
|
120
120
|
name: m,
|
|
121
121
|
quantity: b,
|
|
122
122
|
freeAmount: 0,
|
|
123
123
|
currency: n,
|
|
124
|
-
position:
|
|
124
|
+
position: c,
|
|
125
125
|
cost: g * b
|
|
126
126
|
});
|
|
127
127
|
}
|
|
128
|
-
return
|
|
129
|
-
id: T(
|
|
128
|
+
return e.modification === y.Replace && a.replace.push({
|
|
129
|
+
id: T(e),
|
|
130
130
|
modificationType: h,
|
|
131
131
|
name: m,
|
|
132
132
|
replacementName: O,
|
|
133
|
-
freeAmount:
|
|
133
|
+
freeAmount: p,
|
|
134
134
|
quantity: s,
|
|
135
135
|
currency: n,
|
|
136
|
-
position:
|
|
136
|
+
position: c,
|
|
137
137
|
cost: g
|
|
138
|
-
}),
|
|
139
|
-
id: T(
|
|
138
|
+
}), e.modification === y.Remove && a.remove.push({
|
|
139
|
+
id: T(e),
|
|
140
140
|
modificationType: h,
|
|
141
141
|
name: m,
|
|
142
|
-
freeAmount:
|
|
142
|
+
freeAmount: p,
|
|
143
143
|
quantity: s,
|
|
144
144
|
currency: n,
|
|
145
|
-
position:
|
|
145
|
+
position: c,
|
|
146
146
|
cost: g
|
|
147
|
-
}),
|
|
147
|
+
}), a;
|
|
148
148
|
},
|
|
149
149
|
{
|
|
150
150
|
add: [],
|
|
151
151
|
replace: [],
|
|
152
152
|
remove: []
|
|
153
153
|
}
|
|
154
|
-
), u = (t
|
|
154
|
+
), u = (t ?? []).reduce((a, e) => {
|
|
155
155
|
const {
|
|
156
156
|
product: h,
|
|
157
|
-
|
|
158
|
-
quantity:
|
|
159
|
-
|
|
157
|
+
freeAmount: c = 0,
|
|
158
|
+
quantity: p,
|
|
159
|
+
position: m,
|
|
160
160
|
addOnGroupId: s,
|
|
161
161
|
productPriceInclTax: g
|
|
162
|
-
} =
|
|
163
|
-
|
|
162
|
+
} = e, {
|
|
163
|
+
hasVariants: O,
|
|
164
|
+
variantName: A = "",
|
|
165
|
+
productName: b = "",
|
|
166
|
+
productId: w,
|
|
167
|
+
variantId: B
|
|
168
|
+
} = h ?? {}, M = g.unitPrice === 0;
|
|
169
|
+
(c > 0 || M) && a.push({
|
|
164
170
|
id: `${s}-${w}-free`,
|
|
165
171
|
modificationType: y.Add,
|
|
166
172
|
name: O ? A : b,
|
|
167
|
-
freeAmount: M ?
|
|
168
|
-
quantity: M ?
|
|
173
|
+
freeAmount: M ? p : c,
|
|
174
|
+
quantity: M ? p : c,
|
|
169
175
|
currency: n,
|
|
170
176
|
position: m,
|
|
171
177
|
cost: 0,
|
|
172
178
|
variantId: B
|
|
173
179
|
});
|
|
174
|
-
const k =
|
|
175
|
-
return k > 0 && !M &&
|
|
180
|
+
const k = p - c;
|
|
181
|
+
return k > 0 && !M && a.push({
|
|
176
182
|
id: `${s}-${w}`,
|
|
177
183
|
modificationType: y.Add,
|
|
178
184
|
name: O ? A : b,
|
|
@@ -180,13 +186,13 @@ function rn(n, i, t) {
|
|
|
180
186
|
quantity: k,
|
|
181
187
|
currency: n,
|
|
182
188
|
position: m,
|
|
183
|
-
cost: g.unitPrice
|
|
189
|
+
cost: g.unitPrice * k,
|
|
184
190
|
variantId: B
|
|
185
|
-
}),
|
|
191
|
+
}), a;
|
|
186
192
|
}, []);
|
|
187
193
|
return [
|
|
188
|
-
...C([...
|
|
189
|
-
...C(
|
|
194
|
+
...C([...o, ...u], ["position"], ["asc"]),
|
|
195
|
+
...C(d, ["position"], ["asc"]),
|
|
190
196
|
...C(r, ["position"], ["asc"])
|
|
191
197
|
];
|
|
192
198
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { CheckItemModificationV2 } from '@ancon/wildcat-types';
|
|
2
2
|
/**
|
|
3
3
|
* Generate a unique ID for a Check Item Modification
|
|
4
4
|
* @param modification - Check Item Modification
|
|
5
5
|
* @param suffix - Optional suffix to append to the ID
|
|
6
6
|
* @returns Unique ID string
|
|
7
7
|
*/
|
|
8
|
-
export default function getUniqueCheckItemModificationId(modification:
|
|
8
|
+
export default function getUniqueCheckItemModificationId(modification: CheckItemModificationV2, suffix?: string): string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";function
|
|
1
|
+
"use strict";function p(n,e){const{modification:i,ingredientId:o,replaceId:$,addOnGroupId:c,quantity:d,cost:a,freeAmount:r,name:t="",replacementName:m,position:u}=n;return`modification-${i}-${o}-${$??0}-${c??null}-${d}-${a}-${r}-${t}-${m??t}-${u}${e?`-${e}`:""}`}module.exports=p;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
function
|
|
1
|
+
function p(n, e) {
|
|
2
2
|
const {
|
|
3
3
|
modification: i,
|
|
4
4
|
ingredientId: o,
|
|
@@ -7,12 +7,12 @@ function u(n, e) {
|
|
|
7
7
|
quantity: d,
|
|
8
8
|
cost: c,
|
|
9
9
|
freeAmount: r,
|
|
10
|
-
name: t,
|
|
10
|
+
name: t = "",
|
|
11
11
|
replacementName: m,
|
|
12
|
-
position:
|
|
12
|
+
position: u
|
|
13
13
|
} = n;
|
|
14
|
-
return `modification-${i}-${o}-${$ ?? 0}-${a}-${d}-${c}-${r}-${t}-${m ?? t}-${
|
|
14
|
+
return `modification-${i}-${o}-${$ ?? 0}-${a ?? null}-${d}-${c}-${r}-${t}-${m ?? t}-${u}${e ? `-${e}` : ""}`;
|
|
15
15
|
}
|
|
16
16
|
export {
|
|
17
|
-
|
|
17
|
+
p as default
|
|
18
18
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { CheckDetailsV2 } from '@ancon/wildcat-types';
|
|
2
2
|
/**
|
|
3
3
|
* This creates localized check details by replacing following properties with localized values based on current app language.
|
|
4
4
|
* Affected properties on each check item (and its sub-items):
|
|
@@ -12,5 +12,5 @@ import { CheckDetails } from '@ancon/wildcat-types';
|
|
|
12
12
|
* @param locale - locale to be used for localization
|
|
13
13
|
* @returns localized check details
|
|
14
14
|
*/
|
|
15
|
-
declare function createLocalizedCheckDetails(checkDetails:
|
|
15
|
+
declare function createLocalizedCheckDetails(checkDetails: CheckDetailsV2, locale: string): CheckDetailsV2;
|
|
16
16
|
export default createLocalizedCheckDetails;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const
|
|
1
|
+
"use strict";const r=require("@ancon/wildcat-types");function d(e){switch(e){case"sv":return r.IETFLanguageTag.Swedish;case"nb":return r.IETFLanguageTag.Norwegian;case"en":return r.IETFLanguageTag.English;default:return null}}function s(e,a){var t,i;if(e){const c=e,n=(t=e.localizedProductNames)==null?void 0:t[a],o=(i=e.localizedVariantNames)==null?void 0:i[a];return n&&(c.productName=n),o&&(c.variantName=o),c}return e}function m(e,a){var n,o;const t=e,i=(n=e.localizedNames)==null?void 0:n[a],c=(o=e.localizedReplacementNames)==null?void 0:o[a];return i&&(t.name=i),c&&(t.replacementName=c),t}function z(e,a){const t=e;return t.product=s(e.product,a),t}function u(e,a){const t=e,{product:i,modifications:c,addOnProducts:n,subCheckItems:o}=e;return t.product=s(i,a),c!=null&&c.length&&(t.modifications=c.map(l=>m(l,a))),n!=null&&n.length&&(t.addOnProducts=n==null?void 0:n.map(l=>z(l,a))),o!=null&&o.length&&(t.subCheckItems=o.map(l=>u(l,a))),t}function f(e,a){var i;const t=d(a);if(t){const c=e;return c.items=(i=e.items)==null?void 0:i.map(n=>u(n,t)),c}return e}module.exports=f;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { IETFLanguageTag as r } from "@ancon/wildcat-types";
|
|
2
|
-
function
|
|
2
|
+
function m(e) {
|
|
3
3
|
switch (e) {
|
|
4
4
|
case "sv":
|
|
5
5
|
return r.Swedish;
|
|
@@ -11,43 +11,47 @@ function u(e) {
|
|
|
11
11
|
return null;
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
|
-
function
|
|
15
|
-
var
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
function u(e, a) {
|
|
15
|
+
var t, i;
|
|
16
|
+
if (e) {
|
|
17
|
+
const c = e, n = (t = e.localizedProductNames) == null ? void 0 : t[a], o = (i = e.localizedVariantNames) == null ? void 0 : i[a];
|
|
18
|
+
return n && (c.productName = n), o && (c.variantName = o), c;
|
|
19
|
+
}
|
|
20
|
+
return e;
|
|
18
21
|
}
|
|
19
|
-
function
|
|
20
|
-
var
|
|
21
|
-
const t = e,
|
|
22
|
-
return
|
|
22
|
+
function s(e, a) {
|
|
23
|
+
var n, o;
|
|
24
|
+
const t = e, i = (n = e.localizedNames) == null ? void 0 : n[a], c = (o = e.localizedReplacementNames) == null ? void 0 : o[a];
|
|
25
|
+
return i && (t.name = i), c && (t.replacementName = c), t;
|
|
23
26
|
}
|
|
24
|
-
function f(e,
|
|
27
|
+
function f(e, a) {
|
|
25
28
|
const t = e;
|
|
26
|
-
return t.product =
|
|
29
|
+
return t.product = u(
|
|
27
30
|
e.product,
|
|
28
|
-
|
|
31
|
+
a
|
|
29
32
|
), t;
|
|
30
33
|
}
|
|
31
|
-
function
|
|
32
|
-
const t = e, { product:
|
|
33
|
-
return t.product =
|
|
34
|
-
(l) =>
|
|
35
|
-
)),
|
|
36
|
-
(l) => f(l,
|
|
37
|
-
)),
|
|
38
|
-
(l) =>
|
|
34
|
+
function d(e, a) {
|
|
35
|
+
const t = e, { product: i, modifications: c, addOnProducts: n, subCheckItems: o } = e;
|
|
36
|
+
return t.product = u(i, a), c != null && c.length && (t.modifications = c.map(
|
|
37
|
+
(l) => s(l, a)
|
|
38
|
+
)), n != null && n.length && (t.addOnProducts = n == null ? void 0 : n.map(
|
|
39
|
+
(l) => f(l, a)
|
|
40
|
+
)), o != null && o.length && (t.subCheckItems = o.map(
|
|
41
|
+
(l) => d(l, a)
|
|
39
42
|
)), t;
|
|
40
43
|
}
|
|
41
|
-
function
|
|
42
|
-
|
|
44
|
+
function N(e, a) {
|
|
45
|
+
var i;
|
|
46
|
+
const t = m(a);
|
|
43
47
|
if (t) {
|
|
44
|
-
const
|
|
45
|
-
return
|
|
46
|
-
(
|
|
47
|
-
),
|
|
48
|
+
const c = e;
|
|
49
|
+
return c.items = (i = e.items) == null ? void 0 : i.map(
|
|
50
|
+
(n) => d(n, t)
|
|
51
|
+
), c;
|
|
48
52
|
}
|
|
49
53
|
return e;
|
|
50
54
|
}
|
|
51
55
|
export {
|
|
52
|
-
|
|
56
|
+
N as default
|
|
53
57
|
};
|
package/package.json
CHANGED
package/signalr/SignalR.d.ts
CHANGED
|
@@ -11,10 +11,17 @@ declare class SignalR {
|
|
|
11
11
|
private backoff;
|
|
12
12
|
private reconnectAttempt;
|
|
13
13
|
private shouldReconnect;
|
|
14
|
+
private isReconnecting;
|
|
15
|
+
private pendingJoins;
|
|
14
16
|
groups: string[];
|
|
15
17
|
constructor(options: SignalRConfig);
|
|
16
18
|
info: (message: string, data?: any) => void;
|
|
17
19
|
private generateBackoff;
|
|
20
|
+
private getNextBackoffMs;
|
|
21
|
+
/**
|
|
22
|
+
* Keep trying to connect, with backoff, until connected or `disconnect()` is called.
|
|
23
|
+
* Only one reconnect loop runs at a time.
|
|
24
|
+
*/
|
|
18
25
|
private reconnect;
|
|
19
26
|
private buildInitialListeners;
|
|
20
27
|
/**
|
|
@@ -26,6 +33,14 @@ declare class SignalR {
|
|
|
26
33
|
private skipSignal;
|
|
27
34
|
private enhanceListener;
|
|
28
35
|
setClientId: (clientId: string | undefined) => void;
|
|
36
|
+
/**
|
|
37
|
+
* Start the hub connection.
|
|
38
|
+
*
|
|
39
|
+
* @param throwError Rethrow a failed start and do nothing else.
|
|
40
|
+
* Without it, a failed start emits `disconnected` and keeps retrying with backoff
|
|
41
|
+
* until it connects or `disconnect()` is called; the returned promise settles
|
|
42
|
+
* when that happens.
|
|
43
|
+
*/
|
|
29
44
|
connect: (throwError?: boolean) => Promise<void>;
|
|
30
45
|
disconnect: () => Promise<void>;
|
|
31
46
|
/**
|
|
@@ -52,7 +67,12 @@ declare class SignalR {
|
|
|
52
67
|
* @param listener Signal listener function
|
|
53
68
|
*/
|
|
54
69
|
removeSignalListener: (signal: SignalRSignalName, listener: SignalREventListener) => void;
|
|
55
|
-
|
|
70
|
+
/**
|
|
71
|
+
* Join a group. A group that is already joined, or being joined, is not joined again.
|
|
72
|
+
* @returns Whether the group is joined
|
|
73
|
+
*/
|
|
74
|
+
joinGroup: (group: string) => Promise<boolean>;
|
|
75
|
+
private invokeJoinGroup;
|
|
56
76
|
leaveGroup: (group: string) => Promise<void>;
|
|
57
77
|
leaveAllGroups: () => Promise<void>;
|
|
58
78
|
getHubConnectionId: () => string | null;
|
package/signalr/SignalR.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var l=Object.defineProperty;var f=(r,e,n)=>e in r?l(r,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):r[e]=n;var t=(r,e,n)=>(f(r,typeof e!="symbol"?e+"":e,n),n);const h=require("@microsoft/signalr"),a=require("@ancon/wildcat-types"),d=require("../shared/wait.js"),u=require("../api/generateBackoffWithEqualJitter.js");require("axios");require("../number/randomIntFromInterval.js");class g{constructor(e){t(this,"internalEvents");t(this,"signalREvents");t(this,"hubConnection");t(this,"clientId");t(this,"logger");t(this,"backoff",[]);t(this,"reconnectAttempt",0);t(this,"shouldReconnect",!0);t(this,"isReconnecting",!1);t(this,"pendingJoins",new Map);t(this,"groups");t(this,"info",(e,n)=>{var i;(i=this.logger)==null||i.info(e,n)});t(this,"generateBackoff",()=>{this.backoff=u(50,500,5e3),this.info("Generated new backoff")});t(this,"getNextBackoffMs",()=>{this.backoff[this.reconnectAttempt]==null&&(this.reconnectAttempt>0&&this.info("Ran out of backoff intervals, restarting backoff..."),this.reconnectAttempt=0,this.generateBackoff());const e=this.backoff[this.reconnectAttempt];if(e==null)throw new Error("Could not resolve ms from backoff");return e});t(this,"reconnect",async()=>{if(!this.isReconnecting){this.isReconnecting=!0;try{for(;this.shouldReconnect;)try{this.info("Attempting to reconnect...",{attempt:this.reconnectAttempt+1}),await this.connect(!0),this.info("Reconnected"),this.reconnectAttempt=0;return}catch{if(!this.shouldReconnect)break;await d(this.getNextBackoffMs()),this.reconnectAttempt+=1}}finally{this.isReconnecting=!1}}});t(this,"buildInitialListeners",()=>{this.hubConnection.onclose(()=>{this.groups=[],this.info("Hub connection closed"),this.emitEvent("disconnected"),this.reconnect()}),this.hubConnection.onreconnected(()=>this.emitEvent("reconnected"))});t(this,"emitEvent",(e,...n)=>{if(this.internalEvents.has(e)){this.info(`Emitting event "${e}"`);const i=this.internalEvents.get(e);i&&i.forEach(s=>s(...n))}else this.info(`Failed to emit event "${e}". There were no listeners.`)});t(this,"skipSignal",(e,n)=>{this.info(`Skipped signal "${e}"`,n)});t(this,"enhanceListener",(e,n,i)=>s=>{const o=JSON.parse(s),c=i&&o.clientId&&o.clientId===this.clientId;return c||this.info(`Received signal "${e}"`,s),c?this.skipSignal(e,s):n(o)});t(this,"setClientId",e=>{this.clientId=e});t(this,"connect",async(e=!1)=>{try{this.info("Connecting..."),await this.hubConnection.start(),this.info("Connected"),this.emitEvent("connected")}catch(n){if(this.info("Failed to connect"),e)throw n;this.shouldReconnect&&(this.emitEvent("disconnected"),await this.reconnect())}});t(this,"disconnect",async()=>{try{this.shouldReconnect=!1,this.info("Disconnecting..."),await this.hubConnection.stop(),this.info("Disconnected"),this.emitEvent("disconnected")}catch{this.info("Failed to disconnect")}});t(this,"addEventListener",(e,n)=>{this.internalEvents.has(e)||this.internalEvents.set(e,[]);const i=this.internalEvents.get(e);return i&&i.push(n),()=>this.removeEventListener(e,n)});t(this,"removeEventListener",(e,n)=>{var i;if(this.internalEvents.has(e)){const s=this.internalEvents.get(e),o=((i=s==null?void 0:s.indexOf)==null?void 0:i.call(s,n))??-1;o>=0?(s.splice(o,1),this.info(`Removed event listener for event "${e}"`)):this.info(`Failed to remove event listener for event "${e}". Specified listener was not found.`)}else this.info(`Failed to remove event listener for event "${e}". Event doesn't have any listeners.`)});t(this,"addSignalListener",(e,n,i=!0)=>{this.signalREvents.has(e)||this.signalREvents.set(e,[]);const s=this.signalREvents.get(e),o=this.enhanceListener(e,n,i);return s&&s.push(o),this.hubConnection.on(e,o),this.info(`Added signal listener for signal "${e}"`),()=>this.removeSignalListener(e,o)});t(this,"removeSignalListener",(e,n)=>{var i;if(this.signalREvents.has(e)){const s=this.signalREvents.get(e),o=((i=s==null?void 0:s.indexOf)==null?void 0:i.call(s,n))??-1;o>=0?(this.hubConnection.off(e,n),s.splice(o,1),this.info(`Removed signal listener for signal "${e}"`)):this.info(`Failed to remove signal listener for signal "${e}". Specified listener was not found.`)}else this.info(`Failed to remove signal listener for signal "${e}". Signal doesn't have any listeners.`)});t(this,"joinGroup",async e=>{const n=this.pendingJoins.get(e);if(n)return n;if(this.groups.includes(e))return!0;const i=this.invokeJoinGroup(e).finally(()=>{this.pendingJoins.delete(e)});return this.pendingJoins.set(e,i),i});t(this,"invokeJoinGroup",async e=>{this.info(`Joining group "${e}"...`),this.groups.push(e);try{return await this.hubConnection.invoke(a.SignalRMethodName.JoinGroup,e),this.info(`Joined group "${e}"`),!0}catch(n){this.info(`Failed to join group "${e}"`,n);const i=this.groups.indexOf(e);return i>=0&&this.groups.splice(i,1),!1}});t(this,"leaveGroup",async e=>{this.info(`Leaving group "${e}"...`);const n=this.groups.indexOf(e);n>=0&&this.groups.splice(n,1);try{await this.hubConnection.invoke(a.SignalRMethodName.LeaveGroup,e),this.info(`Left group "${e}"`)}catch(i){this.groups.indexOf(e)<0&&this.groups.push(e),this.info(`Failed to leave group "${e}"`,i)}});t(this,"leaveAllGroups",async()=>{this.info(`Leaving all (${this.groups.length}) groups...`);const e=[...this.groups].map(n=>this.leaveGroup(n));await Promise.all(e),this.info("Left all groups")});t(this,"getHubConnectionId",()=>this.hubConnection.connectionId);this.internalEvents=new Map,this.signalREvents=new Map,this.groups=[],e.enableLogging&&(this.logger=e.logger),this.hubConnection=new h.HubConnectionBuilder().withUrl(`${e.signalRApiUrl}/${e.hub}`).configureLogging(h.LogLevel.None).build(),e.serverTimeoutInMilliseconds!=null&&(this.hubConnection.serverTimeoutInMilliseconds=e.serverTimeoutInMilliseconds),e.keepAliveIntervalInMilliseconds!=null&&(this.hubConnection.keepAliveIntervalInMilliseconds=e.keepAliveIntervalInMilliseconds),this.buildInitialListeners()}}module.exports=g;
|
package/signalr/SignalR.mjs
CHANGED
|
@@ -1,55 +1,64 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
import { HubConnectionBuilder as
|
|
1
|
+
var l = Object.defineProperty;
|
|
2
|
+
var a = (r, e, n) => e in r ? l(r, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : r[e] = n;
|
|
3
|
+
var t = (r, e, n) => (a(r, typeof e != "symbol" ? e + "" : e, n), n);
|
|
4
|
+
import { HubConnectionBuilder as f, LogLevel as d } from "@microsoft/signalr";
|
|
5
5
|
import { SignalRMethodName as h } from "@ancon/wildcat-types";
|
|
6
|
-
import
|
|
6
|
+
import u from "../shared/wait.mjs";
|
|
7
7
|
import g from "../api/generateBackoffWithEqualJitter.mjs";
|
|
8
8
|
import "axios";
|
|
9
9
|
import "../number/randomIntFromInterval.mjs";
|
|
10
|
-
class
|
|
10
|
+
class w {
|
|
11
11
|
constructor(e) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
12
|
+
t(this, "internalEvents");
|
|
13
|
+
t(this, "signalREvents");
|
|
14
|
+
t(this, "hubConnection");
|
|
15
|
+
t(this, "clientId");
|
|
16
|
+
t(this, "logger");
|
|
17
|
+
t(this, "backoff", []);
|
|
18
|
+
t(this, "reconnectAttempt", 0);
|
|
19
|
+
t(this, "shouldReconnect", !0);
|
|
20
|
+
t(this, "isReconnecting", !1);
|
|
21
|
+
t(this, "pendingJoins", /* @__PURE__ */ new Map());
|
|
22
|
+
t(this, "groups");
|
|
23
|
+
t(this, "info", (e, n) => {
|
|
22
24
|
var i;
|
|
23
|
-
(i = this.logger) == null || i.info(e,
|
|
25
|
+
(i = this.logger) == null || i.info(e, n);
|
|
24
26
|
});
|
|
25
|
-
|
|
27
|
+
t(this, "generateBackoff", () => {
|
|
26
28
|
this.backoff = g(50, 500, 5e3), this.info("Generated new backoff");
|
|
27
29
|
});
|
|
28
|
-
|
|
29
|
-
|
|
30
|
+
t(this, "getNextBackoffMs", () => {
|
|
31
|
+
this.backoff[this.reconnectAttempt] == null && (this.reconnectAttempt > 0 && this.info("Ran out of backoff intervals, restarting backoff..."), this.reconnectAttempt = 0, this.generateBackoff());
|
|
32
|
+
const e = this.backoff[this.reconnectAttempt];
|
|
33
|
+
if (e == null)
|
|
34
|
+
throw new Error("Could not resolve ms from backoff");
|
|
35
|
+
return e;
|
|
36
|
+
});
|
|
37
|
+
/**
|
|
38
|
+
* Keep trying to connect, with backoff, until connected or `disconnect()` is called.
|
|
39
|
+
* Only one reconnect loop runs at a time.
|
|
40
|
+
*/
|
|
41
|
+
t(this, "reconnect", async () => {
|
|
42
|
+
if (!this.isReconnecting) {
|
|
43
|
+
this.isReconnecting = !0;
|
|
30
44
|
try {
|
|
31
|
-
this.
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
if (t != null)
|
|
45
|
-
await a(t);
|
|
46
|
-
else
|
|
47
|
-
throw new Error("Could not resolve ms from backoff");
|
|
48
|
-
}
|
|
49
|
-
this.reconnectAttempt += 1, await this.reconnect();
|
|
45
|
+
for (; this.shouldReconnect; )
|
|
46
|
+
try {
|
|
47
|
+
this.info("Attempting to reconnect...", {
|
|
48
|
+
attempt: this.reconnectAttempt + 1
|
|
49
|
+
}), await this.connect(!0), this.info("Reconnected"), this.reconnectAttempt = 0;
|
|
50
|
+
return;
|
|
51
|
+
} catch {
|
|
52
|
+
if (!this.shouldReconnect)
|
|
53
|
+
break;
|
|
54
|
+
await u(this.getNextBackoffMs()), this.reconnectAttempt += 1;
|
|
55
|
+
}
|
|
56
|
+
} finally {
|
|
57
|
+
this.isReconnecting = !1;
|
|
50
58
|
}
|
|
59
|
+
}
|
|
51
60
|
});
|
|
52
|
-
|
|
61
|
+
t(this, "buildInitialListeners", () => {
|
|
53
62
|
this.hubConnection.onclose(() => {
|
|
54
63
|
this.groups = [], this.info("Hub connection closed"), this.emitEvent("disconnected"), this.reconnect();
|
|
55
64
|
}), this.hubConnection.onreconnected(() => this.emitEvent("reconnected"));
|
|
@@ -59,33 +68,42 @@ class $ {
|
|
|
59
68
|
* @param event Event to emit
|
|
60
69
|
* @param args Arguments to send to the listeners
|
|
61
70
|
*/
|
|
62
|
-
|
|
71
|
+
t(this, "emitEvent", (e, ...n) => {
|
|
63
72
|
if (this.internalEvents.has(e)) {
|
|
64
73
|
this.info(`Emitting event "${e}"`);
|
|
65
74
|
const i = this.internalEvents.get(e);
|
|
66
|
-
i && i.forEach((s) => s(...
|
|
75
|
+
i && i.forEach((s) => s(...n));
|
|
67
76
|
} else
|
|
68
77
|
this.info(`Failed to emit event "${e}". There were no listeners.`);
|
|
69
78
|
});
|
|
70
|
-
|
|
71
|
-
this.info(`Skipped signal "${e}"`,
|
|
79
|
+
t(this, "skipSignal", (e, n) => {
|
|
80
|
+
this.info(`Skipped signal "${e}"`, n);
|
|
72
81
|
});
|
|
73
|
-
|
|
82
|
+
t(this, "enhanceListener", (e, n, i) => (s) => {
|
|
74
83
|
const o = JSON.parse(s), c = i && o.clientId && o.clientId === this.clientId;
|
|
75
|
-
return c || this.info(`Received signal "${e}"`, s), c ? this.skipSignal(e, s) :
|
|
84
|
+
return c || this.info(`Received signal "${e}"`, s), c ? this.skipSignal(e, s) : n(o);
|
|
76
85
|
});
|
|
77
|
-
|
|
86
|
+
t(this, "setClientId", (e) => {
|
|
78
87
|
this.clientId = e;
|
|
79
88
|
});
|
|
80
|
-
|
|
89
|
+
/**
|
|
90
|
+
* Start the hub connection.
|
|
91
|
+
*
|
|
92
|
+
* @param throwError Rethrow a failed start and do nothing else.
|
|
93
|
+
* Without it, a failed start emits `disconnected` and keeps retrying with backoff
|
|
94
|
+
* until it connects or `disconnect()` is called; the returned promise settles
|
|
95
|
+
* when that happens.
|
|
96
|
+
*/
|
|
97
|
+
t(this, "connect", async (e = !1) => {
|
|
81
98
|
try {
|
|
82
99
|
this.info("Connecting..."), await this.hubConnection.start(), this.info("Connected"), this.emitEvent("connected");
|
|
83
|
-
} catch (
|
|
100
|
+
} catch (n) {
|
|
84
101
|
if (this.info("Failed to connect"), e)
|
|
85
|
-
throw
|
|
102
|
+
throw n;
|
|
103
|
+
this.shouldReconnect && (this.emitEvent("disconnected"), await this.reconnect());
|
|
86
104
|
}
|
|
87
105
|
});
|
|
88
|
-
|
|
106
|
+
t(this, "disconnect", async () => {
|
|
89
107
|
try {
|
|
90
108
|
this.shouldReconnect = !1, this.info("Disconnecting..."), await this.hubConnection.stop(), this.info("Disconnected"), this.emitEvent("disconnected");
|
|
91
109
|
} catch {
|
|
@@ -97,20 +115,20 @@ class $ {
|
|
|
97
115
|
* @param event Event to listen on
|
|
98
116
|
* @param listener Event listener function
|
|
99
117
|
*/
|
|
100
|
-
|
|
118
|
+
t(this, "addEventListener", (e, n) => {
|
|
101
119
|
this.internalEvents.has(e) || this.internalEvents.set(e, []);
|
|
102
120
|
const i = this.internalEvents.get(e);
|
|
103
|
-
return i && i.push(
|
|
121
|
+
return i && i.push(n), () => this.removeEventListener(e, n);
|
|
104
122
|
});
|
|
105
123
|
/**
|
|
106
124
|
* Remove internal event listener
|
|
107
125
|
* @param event Event to stop listening to
|
|
108
126
|
* @param listener Event listener function
|
|
109
127
|
*/
|
|
110
|
-
|
|
128
|
+
t(this, "removeEventListener", (e, n) => {
|
|
111
129
|
var i;
|
|
112
130
|
if (this.internalEvents.has(e)) {
|
|
113
|
-
const s = this.internalEvents.get(e), o = ((i = s == null ? void 0 : s.indexOf) == null ? void 0 : i.call(s,
|
|
131
|
+
const s = this.internalEvents.get(e), o = ((i = s == null ? void 0 : s.indexOf) == null ? void 0 : i.call(s, n)) ?? -1;
|
|
114
132
|
o >= 0 ? (s.splice(o, 1), this.info(`Removed event listener for event "${e}"`)) : this.info(
|
|
115
133
|
`Failed to remove event listener for event "${e}". Specified listener was not found.`
|
|
116
134
|
);
|
|
@@ -124,11 +142,11 @@ class $ {
|
|
|
124
142
|
* @param signal Signal name
|
|
125
143
|
* @param listener Signal listener function
|
|
126
144
|
*/
|
|
127
|
-
|
|
145
|
+
t(this, "addSignalListener", (e, n, i = !0) => {
|
|
128
146
|
this.signalREvents.has(e) || this.signalREvents.set(e, []);
|
|
129
147
|
const s = this.signalREvents.get(e), o = this.enhanceListener(
|
|
130
148
|
e,
|
|
131
|
-
|
|
149
|
+
n,
|
|
132
150
|
i
|
|
133
151
|
);
|
|
134
152
|
return s && s.push(o), this.hubConnection.on(e, o), this.info(`Added signal listener for signal "${e}"`), () => this.removeSignalListener(e, o);
|
|
@@ -138,11 +156,11 @@ class $ {
|
|
|
138
156
|
* @param signal Signal name
|
|
139
157
|
* @param listener Signal listener function
|
|
140
158
|
*/
|
|
141
|
-
|
|
159
|
+
t(this, "removeSignalListener", (e, n) => {
|
|
142
160
|
var i;
|
|
143
161
|
if (this.signalREvents.has(e)) {
|
|
144
|
-
const s = this.signalREvents.get(e), o = ((i = s == null ? void 0 : s.indexOf) == null ? void 0 : i.call(s,
|
|
145
|
-
o >= 0 ? (this.hubConnection.off(e,
|
|
162
|
+
const s = this.signalREvents.get(e), o = ((i = s == null ? void 0 : s.indexOf) == null ? void 0 : i.call(s, n)) ?? -1;
|
|
163
|
+
o >= 0 ? (this.hubConnection.off(e, n), s.splice(o, 1), this.info(`Removed signal listener for signal "${e}"`)) : this.info(
|
|
146
164
|
`Failed to remove signal listener for signal "${e}". Specified listener was not found.`
|
|
147
165
|
);
|
|
148
166
|
} else
|
|
@@ -150,34 +168,50 @@ class $ {
|
|
|
150
168
|
`Failed to remove signal listener for signal "${e}". Signal doesn't have any listeners.`
|
|
151
169
|
);
|
|
152
170
|
});
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
171
|
+
/**
|
|
172
|
+
* Join a group. A group that is already joined, or being joined, is not joined again.
|
|
173
|
+
* @returns Whether the group is joined
|
|
174
|
+
*/
|
|
175
|
+
t(this, "joinGroup", async (e) => {
|
|
176
|
+
const n = this.pendingJoins.get(e);
|
|
177
|
+
if (n)
|
|
178
|
+
return n;
|
|
179
|
+
if (this.groups.includes(e))
|
|
180
|
+
return !0;
|
|
181
|
+
const i = this.invokeJoinGroup(e).finally(() => {
|
|
182
|
+
this.pendingJoins.delete(e);
|
|
183
|
+
});
|
|
184
|
+
return this.pendingJoins.set(e, i), i;
|
|
185
|
+
});
|
|
186
|
+
t(this, "invokeJoinGroup", async (e) => {
|
|
187
|
+
this.info(`Joining group "${e}"...`), this.groups.push(e);
|
|
156
188
|
try {
|
|
157
|
-
await this.hubConnection.invoke(h.JoinGroup, e), this.info(`Joined group "${e}"`);
|
|
158
|
-
} catch (
|
|
159
|
-
this.info(`Failed to join group "${e}"`,
|
|
189
|
+
return await this.hubConnection.invoke(h.JoinGroup, e), this.info(`Joined group "${e}"`), !0;
|
|
190
|
+
} catch (n) {
|
|
191
|
+
this.info(`Failed to join group "${e}"`, n);
|
|
192
|
+
const i = this.groups.indexOf(e);
|
|
193
|
+
return i >= 0 && this.groups.splice(i, 1), !1;
|
|
160
194
|
}
|
|
161
195
|
});
|
|
162
|
-
|
|
196
|
+
t(this, "leaveGroup", async (e) => {
|
|
163
197
|
this.info(`Leaving group "${e}"...`);
|
|
164
|
-
const
|
|
165
|
-
|
|
198
|
+
const n = this.groups.indexOf(e);
|
|
199
|
+
n >= 0 && this.groups.splice(n, 1);
|
|
166
200
|
try {
|
|
167
201
|
await this.hubConnection.invoke(h.LeaveGroup, e), this.info(`Left group "${e}"`);
|
|
168
202
|
} catch (i) {
|
|
169
203
|
this.groups.indexOf(e) < 0 && this.groups.push(e), this.info(`Failed to leave group "${e}"`, i);
|
|
170
204
|
}
|
|
171
205
|
});
|
|
172
|
-
|
|
206
|
+
t(this, "leaveAllGroups", async () => {
|
|
173
207
|
this.info(`Leaving all (${this.groups.length}) groups...`);
|
|
174
|
-
const e = [...this.groups].map((
|
|
208
|
+
const e = [...this.groups].map((n) => this.leaveGroup(n));
|
|
175
209
|
await Promise.all(e), this.info("Left all groups");
|
|
176
210
|
});
|
|
177
|
-
|
|
178
|
-
this.internalEvents = /* @__PURE__ */ new Map(), this.signalREvents = /* @__PURE__ */ new Map(), this.groups = [], e.enableLogging && (this.logger = e.logger), this.hubConnection = new
|
|
211
|
+
t(this, "getHubConnectionId", () => this.hubConnection.connectionId);
|
|
212
|
+
this.internalEvents = /* @__PURE__ */ new Map(), this.signalREvents = /* @__PURE__ */ new Map(), this.groups = [], e.enableLogging && (this.logger = e.logger), this.hubConnection = new f().withUrl(`${e.signalRApiUrl}/${e.hub}`).configureLogging(d.None).build(), e.serverTimeoutInMilliseconds != null && (this.hubConnection.serverTimeoutInMilliseconds = e.serverTimeoutInMilliseconds), e.keepAliveIntervalInMilliseconds != null && (this.hubConnection.keepAliveIntervalInMilliseconds = e.keepAliveIntervalInMilliseconds), this.buildInitialListeners();
|
|
179
213
|
}
|
|
180
214
|
}
|
|
181
215
|
export {
|
|
182
|
-
|
|
216
|
+
w as default
|
|
183
217
|
};
|
|
@@ -19,7 +19,7 @@ declare type ReduxHooksArg = Partial<{
|
|
|
19
19
|
declare function createUseSignalRHook<RootState = unknown>(signalRConfig: SignalRHookConfig, selectors?: ReduxSelectorsArg<RootState>, actions?: ReduxActionsArg, hooks?: ReduxHooksArg): {
|
|
20
20
|
useSignalR: (hub: SignalRHubName) => {
|
|
21
21
|
isHubConnected: boolean;
|
|
22
|
-
join: (group: string) => Promise<
|
|
22
|
+
join: (group: string) => Promise<boolean>;
|
|
23
23
|
leave: (group: string) => Promise<void>;
|
|
24
24
|
subscribe: (signal: SignalRSignalName, listener: SignalREventListener, shouldSkipOwnClient?: boolean) => (() => void);
|
|
25
25
|
unsubscribe: (signal: SignalRSignalName, listener: SignalREventListener) => void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const n=require("react"),
|
|
1
|
+
"use strict";const n=require("react"),I=require("react-redux"),h=require("../noop-7ea3b37b.js"),J=l=>Object.freeze(Object.defineProperty({__proto__:null,default:l},Symbol.toStringTag,{value:"Module"}));function K(l,_,j,q){const{logger:w,enableLogging:D,serverTimeoutInMilliseconds:M,keepAliveIntervalInMilliseconds:m}=l;let{signalRApiUrl:v}=l;const{clientIdSelector:x,isSignalROnlineSelector:c}=_??{},{setIsSignalROnlineAction:a}=j??{},{useAppStore:G=I.useStore,useAppDispatch:P=I.useDispatch,useAppSelector:T=I.useSelector}=q??{},b=new Set;function z(o){const[f,N]=n.useState(v),[e,B]=n.useState(null),d=G(),p=P(),C=T(x??(()=>{})),[u,F]=n.useState(!1),[r,E]=n.useState(!1),k=n.useRef(u),S=n.useCallback(()=>{(c==null?void 0:c(d.getState()))===!1&&a&&p(a({isSignalROnline:!0})),r||E(!0)},[p,r,d]),A=S,H=n.useCallback(()=>{(c==null?void 0:c(d.getState()))===!0&&a&&p(a({isSignalROnline:!1})),r&&E(!1)},[p,r,d]),O=n.useCallback(async t=>e?e.joinGroup(t):!1,[e]),y=n.useCallback(async t=>{e&&e.groups.indexOf(t)>=0&&await(e==null?void 0:e.leaveGroup(t))},[e]),L=n.useCallback((t,s,i)=>e?e==null?void 0:e.addSignalListener(t,s,i):h.noop,[e]),U=n.useCallback((t,s)=>{e&&e.removeSignalListener(t,s)},[e]),g=n.useCallback(()=>e?e.getHubConnectionId():null,[e]);return n.useEffect(()=>{let t=!1;return Promise.resolve().then(()=>J(require("./SignalR.js"))).then(({default:s})=>{t||B(new s({signalRApiUrl:f,hub:o,logger:w,enableLogging:D,serverTimeoutInMilliseconds:M,keepAliveIntervalInMilliseconds:m}))}),()=>{t=!0}},[o,f]),n.useEffect(()=>{function t(s){N(s)}return b.add(t),()=>{b.delete(t)}},[]),n.useEffect(()=>{k.current=u},[u]),n.useEffect(()=>{const t=e==null?void 0:e.addEventListener("connected",S),s=e==null?void 0:e.addEventListener("reconnected",A),i=e==null?void 0:e.addEventListener("disconnected",H);return e&&!k.current&&F(!0),()=>{t==null||t(),s==null||s(),i==null||i()}},[e,S,H,A]),n.useEffect(()=>{e==null||e.setClientId(C||void 0)},[e,C]),n.useEffect(()=>{async function t(){await(e==null?void 0:e.connect())}u&&t()},[e,u]),n.useEffect(()=>()=>{e==null||e.leaveAllGroups().then(()=>{e==null||e.disconnect()}).catch(h.noop).finally(()=>{e==null||e.disconnect().catch(h.noop)})},[e]),n.useMemo(()=>({isHubConnected:r,join:O,leave:y,subscribe:L,unsubscribe:U,getHubConnectionId:g}),[r,O,y,L,U,g])}return{useSignalR:z,setUrl(o){v=o,b.forEach(f=>{f(o)})}}}module.exports=K;
|
|
@@ -1,122 +1,127 @@
|
|
|
1
|
-
import { useState as
|
|
2
|
-
import { useStore as
|
|
3
|
-
import { n as
|
|
4
|
-
function
|
|
5
|
-
const {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
1
|
+
import { useState as I, useRef as Q, useCallback as r, useEffect as s, useMemo as V } from "react";
|
|
2
|
+
import { useStore as W, useDispatch as X, useSelector as Y } from "react-redux";
|
|
3
|
+
import { n as h } from "../noop-378485d5.mjs";
|
|
4
|
+
function ee(v, k, D, G) {
|
|
5
|
+
const {
|
|
6
|
+
logger: M,
|
|
7
|
+
enableLogging: j,
|
|
8
|
+
serverTimeoutInMilliseconds: x,
|
|
9
|
+
keepAliveIntervalInMilliseconds: T
|
|
10
|
+
} = v;
|
|
11
|
+
let { signalRApiUrl: A } = v;
|
|
12
|
+
const { clientIdSelector: q, isSignalROnlineSelector: c } = k ?? {}, { setIsSignalROnlineAction: a } = D ?? {}, {
|
|
13
|
+
useAppStore: z = W,
|
|
14
|
+
useAppDispatch: B = X,
|
|
15
|
+
useAppSelector: F = Y
|
|
16
|
+
} = G ?? {}, S = /* @__PURE__ */ new Set();
|
|
17
|
+
function J(i) {
|
|
18
|
+
const [d, K] = I(A), [e, N] = I(null), f = z(), p = B(), H = F(q ?? (() => {
|
|
19
|
+
})), [u, P] = I(!1), [o, m] = I(!1), L = Q(u), b = r(() => {
|
|
20
|
+
(c == null ? void 0 : c(f.getState())) === !1 && a && p(a({ isSignalROnline: !0 })), o || m(!0);
|
|
21
|
+
}, [p, o, f]), U = b, C = r(() => {
|
|
22
|
+
(c == null ? void 0 : c(f.getState())) === !0 && a && p(a({ isSignalROnline: !1 })), o && m(!1);
|
|
23
|
+
}, [p, o, f]), E = r(
|
|
24
|
+
async (t) => e ? e.joinGroup(t) : !1,
|
|
22
25
|
[e]
|
|
23
|
-
),
|
|
26
|
+
), O = r(
|
|
24
27
|
async (t) => {
|
|
25
28
|
e && e.groups.indexOf(t) >= 0 && await (e == null ? void 0 : e.leaveGroup(t));
|
|
26
29
|
},
|
|
27
30
|
[e]
|
|
28
|
-
),
|
|
29
|
-
(t, n,
|
|
31
|
+
), g = r(
|
|
32
|
+
(t, n, l) => e ? e == null ? void 0 : e.addSignalListener(
|
|
30
33
|
t,
|
|
31
34
|
n,
|
|
32
|
-
|
|
33
|
-
) :
|
|
35
|
+
l
|
|
36
|
+
) : h,
|
|
34
37
|
[e]
|
|
35
|
-
),
|
|
38
|
+
), w = r(
|
|
36
39
|
(t, n) => {
|
|
37
40
|
e && e.removeSignalListener(t, n);
|
|
38
41
|
},
|
|
39
42
|
[e]
|
|
40
|
-
),
|
|
41
|
-
return
|
|
43
|
+
), y = r(() => e ? e.getHubConnectionId() : null, [e]);
|
|
44
|
+
return s(() => {
|
|
42
45
|
let t = !1;
|
|
43
46
|
return import("./SignalR.mjs").then(({ default: n }) => {
|
|
44
|
-
t ||
|
|
47
|
+
t || N(
|
|
45
48
|
new n({
|
|
46
|
-
signalRApiUrl:
|
|
49
|
+
signalRApiUrl: d,
|
|
47
50
|
hub: i,
|
|
48
|
-
logger:
|
|
49
|
-
enableLogging:
|
|
51
|
+
logger: M,
|
|
52
|
+
enableLogging: j,
|
|
53
|
+
serverTimeoutInMilliseconds: x,
|
|
54
|
+
keepAliveIntervalInMilliseconds: T
|
|
50
55
|
})
|
|
51
56
|
);
|
|
52
57
|
}), () => {
|
|
53
58
|
t = !0;
|
|
54
59
|
};
|
|
55
|
-
}, [i,
|
|
60
|
+
}, [i, d]), s(() => {
|
|
56
61
|
function t(n) {
|
|
57
|
-
|
|
62
|
+
K(n);
|
|
58
63
|
}
|
|
59
|
-
return
|
|
60
|
-
|
|
64
|
+
return S.add(t), () => {
|
|
65
|
+
S.delete(t);
|
|
61
66
|
};
|
|
62
|
-
}, []),
|
|
63
|
-
|
|
64
|
-
}, [u]),
|
|
67
|
+
}, []), s(() => {
|
|
68
|
+
L.current = u;
|
|
69
|
+
}, [u]), s(() => {
|
|
65
70
|
const t = e == null ? void 0 : e.addEventListener(
|
|
66
71
|
"connected",
|
|
67
|
-
|
|
72
|
+
b
|
|
68
73
|
), n = e == null ? void 0 : e.addEventListener(
|
|
69
74
|
"reconnected",
|
|
70
|
-
|
|
71
|
-
),
|
|
75
|
+
U
|
|
76
|
+
), l = e == null ? void 0 : e.addEventListener(
|
|
72
77
|
"disconnected",
|
|
73
78
|
C
|
|
74
79
|
);
|
|
75
|
-
return e && !
|
|
76
|
-
t == null || t(), n == null || n(),
|
|
80
|
+
return e && !L.current && P(!0), () => {
|
|
81
|
+
t == null || t(), n == null || n(), l == null || l();
|
|
77
82
|
};
|
|
78
83
|
}, [
|
|
79
84
|
e,
|
|
80
|
-
|
|
85
|
+
b,
|
|
81
86
|
C,
|
|
82
|
-
|
|
83
|
-
]),
|
|
84
|
-
e == null || e.setClientId(
|
|
85
|
-
}, [e,
|
|
87
|
+
U
|
|
88
|
+
]), s(() => {
|
|
89
|
+
e == null || e.setClientId(H || void 0);
|
|
90
|
+
}, [e, H]), s(() => {
|
|
86
91
|
async function t() {
|
|
87
92
|
await (e == null ? void 0 : e.connect());
|
|
88
93
|
}
|
|
89
94
|
u && t();
|
|
90
|
-
}, [e, u]),
|
|
95
|
+
}, [e, u]), s(
|
|
91
96
|
() => () => {
|
|
92
97
|
e == null || e.leaveAllGroups().then(() => {
|
|
93
98
|
e == null || e.disconnect();
|
|
94
|
-
}).catch(
|
|
95
|
-
e == null || e.disconnect().catch(
|
|
99
|
+
}).catch(h).finally(() => {
|
|
100
|
+
e == null || e.disconnect().catch(h);
|
|
96
101
|
});
|
|
97
102
|
},
|
|
98
103
|
[e]
|
|
99
|
-
),
|
|
104
|
+
), V(
|
|
100
105
|
() => ({
|
|
101
106
|
isHubConnected: o,
|
|
102
|
-
join:
|
|
103
|
-
leave:
|
|
104
|
-
subscribe:
|
|
105
|
-
unsubscribe:
|
|
106
|
-
getHubConnectionId:
|
|
107
|
+
join: E,
|
|
108
|
+
leave: O,
|
|
109
|
+
subscribe: g,
|
|
110
|
+
unsubscribe: w,
|
|
111
|
+
getHubConnectionId: y
|
|
107
112
|
}),
|
|
108
|
-
[o, O,
|
|
113
|
+
[o, E, O, g, w, y]
|
|
109
114
|
);
|
|
110
115
|
}
|
|
111
116
|
return {
|
|
112
|
-
useSignalR:
|
|
117
|
+
useSignalR: J,
|
|
113
118
|
setUrl(i) {
|
|
114
|
-
|
|
115
|
-
|
|
119
|
+
A = i, S.forEach((d) => {
|
|
120
|
+
d(i);
|
|
116
121
|
});
|
|
117
122
|
}
|
|
118
123
|
};
|
|
119
124
|
}
|
|
120
125
|
export {
|
|
121
|
-
|
|
126
|
+
ee as default
|
|
122
127
|
};
|
package/signalr/types.d.ts
CHANGED
|
@@ -12,5 +12,7 @@ export declare type SignalRConfig = {
|
|
|
12
12
|
enableLogging?: boolean;
|
|
13
13
|
/** @default 30000 */
|
|
14
14
|
serverTimeoutInMilliseconds?: number;
|
|
15
|
+
/** @default 15000 */
|
|
16
|
+
keepAliveIntervalInMilliseconds?: number;
|
|
15
17
|
};
|
|
16
18
|
export declare type SignalRHookConfig = Omit<SignalRConfig, 'hub'>;
|