@v1nt1248/3nclient-lib 0.3.15 → 0.3.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ui3n-utils.js +17 -18
- package/dist/utils/execute-function.d.ts +7 -12
- package/package.json +1 -1
package/dist/ui3n-utils.js
CHANGED
|
@@ -4199,30 +4199,29 @@ var Me = class extends Error {
|
|
|
4199
4199
|
}
|
|
4200
4200
|
};
|
|
4201
4201
|
async function J(e) {
|
|
4202
|
-
let { fn: t, fnArgs: n,
|
|
4203
|
-
for (let e = 1; e <=
|
|
4204
|
-
let
|
|
4202
|
+
let { fn: t, fnArgs: n, passSignal: r = !1, defaultValue: i, doesErrorPropagateStop: a = !1, timeoutValue: o = 5e3, retryCount: s = 0, retryDelay: c = 1e3, errorText: l = "An error occurred while executing the function.", actionIfError: u, actionIfSuccess: d, actionInFinally: f } = e, p = n, m = s + 1, h;
|
|
4203
|
+
for (let e = 1; e <= m; e++) {
|
|
4204
|
+
let n = new AbortController(), i = null;
|
|
4205
4205
|
try {
|
|
4206
|
-
let s = new Promise((t,
|
|
4207
|
-
|
|
4208
|
-
|
|
4206
|
+
let a = (async () => r ? t(n.signal, ...p) : t(...p))(), s = new Promise((t, r) => {
|
|
4207
|
+
o > 0 && (i = setTimeout(() => {
|
|
4208
|
+
n.abort(), r(new Me(`Attempt ${e}/${m} timed out.`, {
|
|
4209
4209
|
cause: "timeout",
|
|
4210
|
-
fnArgs:
|
|
4210
|
+
fnArgs: p
|
|
4211
4211
|
}));
|
|
4212
|
-
},
|
|
4213
|
-
}), c =
|
|
4214
|
-
return
|
|
4212
|
+
}, o));
|
|
4213
|
+
}), c = await Promise.race([a, s]);
|
|
4214
|
+
return i && clearTimeout(i), d?.(), f?.(), c;
|
|
4215
4215
|
} catch (t) {
|
|
4216
|
-
|
|
4217
|
-
console.warn(`Attempt ${e} failed. Retrying in ${s}ms...`, t), s > 0 && await b(s);
|
|
4216
|
+
i && clearTimeout(i), h = t, e < m && (console.warn(`[executeFunc] Attempt ${e} failed. Retrying in ${c}ms...`, t), c > 0 && await b(c));
|
|
4218
4217
|
}
|
|
4219
4218
|
}
|
|
4220
|
-
let
|
|
4221
|
-
cause:
|
|
4222
|
-
fnArgs:
|
|
4219
|
+
let g = h instanceof Me && h.cause === "timeout", _ = h?.name === "AbortError" || h?.name === "CanceledError", v = g ? h : new Me(_ ? "Operation aborted" : l, {
|
|
4220
|
+
cause: h,
|
|
4221
|
+
fnArgs: p
|
|
4223
4222
|
});
|
|
4224
|
-
if (console.error(`All ${
|
|
4225
|
-
return
|
|
4223
|
+
if (console.error(`[executeFunc] All ${m} attempts failed.`, v), u?.(v), f?.(), !a) throw v;
|
|
4224
|
+
return i;
|
|
4226
4225
|
}
|
|
4227
4226
|
//#endregion
|
|
4228
4227
|
//#region src/utils/remove-whitespace-in-string.ts
|
|
@@ -7248,4 +7247,4 @@ function jt(e) {
|
|
|
7248
7247
|
return e.replace(/[A-Z]/g, (e) => `_${e.toLowerCase()}`);
|
|
7249
7248
|
}
|
|
7250
7249
|
//#endregion
|
|
7251
|
-
export { g as DIALOGS_KEY,
|
|
7250
|
+
export { g as DIALOGS_KEY, _ as NOTIFICATIONS_KEY, T as NamedProcs, Et as SQLiteOn3NStorage, w as SingleCyclicProc, x as SingleProc, O as TaskRunner, v as VUEBUS_KEY, lt as b64ToBlob, ut as blobFromDataURL, ct as blobToB64, qe as capitalize, je as copyToClipboard, pt as createVideoThumbnail, y as defer, h as emoticons, J as executeFunc, ft as fileToUint8Array, Ye as formatFileSize, Be as generateColor, ke as getDeliveryErrors, G as getFileExtension, A as getRandomId, ze as hasSlotContent, He as html2text, Ve as invertColor, st as isFileArchive, it as isFileAudio, Qe as isFileImage, tt as isFileVideo, m as mailReg, C as makeSyncedFunc, Re as markSearch, K as mimeTypes, ne as patchTextareaMaxRowsSupport, Ke as prepareDateAsSting, Ne as removeWhitespaceInString, dt as resizeImage, k as round, D as schedulerYield, Fe as selectAll, Le as selectEnd, Ie as selectStart, b as sleep, q as transformFileToWeb3NFile, Ae as transformWeb3nFileToFile, ht as tryOnScopeDispose, X as uint8ToDataURL, mt as unrefElement };
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
type ExtractArgs<F> = F extends (signal: AbortSignal, ...args: infer P) => any ? P : F extends (...args: infer P) => any ? P : never;
|
|
2
|
+
interface BaseProps<F extends (...args: any[]) => any, V> {
|
|
3
3
|
fn: F;
|
|
4
4
|
fnArgs: ExtractArgs<F>;
|
|
5
|
+
passSignal?: boolean;
|
|
5
6
|
timeoutValue?: number;
|
|
6
7
|
retryCount?: number;
|
|
7
8
|
retryDelay?: number;
|
|
@@ -10,20 +11,14 @@ export interface ExecuteFnBaseProps<F extends (...args: any[]) => any, V> {
|
|
|
10
11
|
actionIfSuccess?: () => void;
|
|
11
12
|
actionInFinally?: () => void;
|
|
12
13
|
}
|
|
13
|
-
|
|
14
|
+
interface ExecuteFunctionPropsNoCatchError<F extends (...args: any[]) => any, V = Awaited<ReturnType<F>>> extends BaseProps<F, V> {
|
|
14
15
|
doesErrorPropagateStop: true;
|
|
15
16
|
defaultValue: V;
|
|
16
17
|
}
|
|
17
|
-
|
|
18
|
+
interface ExecuteFunctionPropsCatchError<F extends (...args: any[]) => any, V = Awaited<ReturnType<F>>> extends BaseProps<F, V> {
|
|
18
19
|
doesErrorPropagateStop?: false;
|
|
19
20
|
defaultValue?: undefined;
|
|
20
21
|
}
|
|
21
|
-
|
|
22
|
-
export declare class ExecuteFunctionError extends Error {
|
|
23
|
-
cause: unknown;
|
|
24
|
-
constructor(message: string, data?: {
|
|
25
|
-
cause?: unknown;
|
|
26
|
-
fnArgs?: unknown[];
|
|
27
|
-
});
|
|
28
|
-
}
|
|
22
|
+
type ExecuteFunctionProps<F extends (...args: any[]) => any, V = Awaited<ReturnType<F>>> = ExecuteFunctionPropsCatchError<F, V> | ExecuteFunctionPropsNoCatchError<F, V>;
|
|
29
23
|
export declare function executeFunc<F extends (...args: any[]) => any, V = Awaited<ReturnType<F>>>(props: ExecuteFunctionProps<F, V>): Promise<V>;
|
|
24
|
+
export {};
|