@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.
@@ -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, defaultValue: r, doesErrorPropagateStop: i = !1, timeoutValue: a = 5e3, retryCount: o = 0, retryDelay: s = 1e3, errorText: c = "An error occurred while executing the function.", actionIfError: l, actionIfSuccess: u, actionInFinally: d } = e, f, p = o + 1;
4203
- for (let e = 1; e <= p; e++) {
4204
- let r = new AbortController(), { signal: i } = r, o = null;
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, i) => {
4207
- a <= 0 || (o = setTimeout(() => {
4208
- r.abort(), i(new Me(`Attempt ${e}/${p} timed out.`, {
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: n
4210
+ fnArgs: p
4211
4211
  }));
4212
- }, a));
4213
- }), c = n, l = t.length > c.length ? t(i, ...c) : t(...c), d = await Promise.race([Promise.resolve(l), s]);
4214
- return u?.(), o && clearTimeout(o), d;
4212
+ }, o));
4213
+ }), c = await Promise.race([a, s]);
4214
+ return i && clearTimeout(i), d?.(), f?.(), c;
4215
4215
  } catch (t) {
4216
- if (o && clearTimeout(o), f = t, e === p) break;
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 m = f instanceof Me && f.cause === "timeout", h = f.name === "AbortError" || f.name === "CanceledError", g = m ? f : new Me(h ? "Operation aborted" : c, {
4221
- cause: f,
4222
- fnArgs: n
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 ${p} attempts failed.`, g), l?.(g), !i) throw g;
4225
- return d?.(), r;
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, Me as ExecuteFunctionError, _ 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 };
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
- export type ExtractArgs<F> = F extends (signal: AbortSignal, ...args: infer P) => any ? P : F extends (...args: infer P) => any ? P : never;
2
- export interface ExecuteFnBaseProps<F extends (...args: any[]) => any, V> {
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
- export interface ExecuteFunctionPropsNoCatchError<F extends (...args: any[]) => any, V = Awaited<ReturnType<F>>> extends ExecuteFnBaseProps<F, V> {
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
- export interface ExecuteFunctionPropsCatchError<F extends (...args: any[]) => any, V = Awaited<ReturnType<F>>> extends ExecuteFnBaseProps<F, V> {
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
- export type ExecuteFunctionProps<F extends (...args: any[]) => any, V = Awaited<ReturnType<F>>> = ExecuteFunctionPropsCatchError<F, V> | ExecuteFunctionPropsNoCatchError<F, V>;
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 {};
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@v1nt1248/3nclient-lib",
3
3
  "license": "AGPL-3.0-or-later",
4
4
  "author": "v1nt1248",
5
- "version": "0.3.15",
5
+ "version": "0.3.16",
6
6
  "description": "Library for 3NWeb clients",
7
7
  "type": "module",
8
8
  "files": [