@jsnw/common-utils 1.5.0 → 1.5.2
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/index.cjs +8 -1
- package/dist/index.d.cts +6 -2
- package/dist/index.d.mts +6 -2
- package/dist/index.mjs +8 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -119,7 +119,14 @@ function createInFlightDeduper() {
|
|
|
119
119
|
__promises.set(key, promise);
|
|
120
120
|
return promise;
|
|
121
121
|
}
|
|
122
|
-
|
|
122
|
+
function maybeIdempotent(p, fn) {
|
|
123
|
+
if (p.idempotencyId) return use(p.idempotencyId, fn);
|
|
124
|
+
return Promise.resolve(fn());
|
|
125
|
+
}
|
|
126
|
+
return {
|
|
127
|
+
use,
|
|
128
|
+
maybeIdempotent
|
|
129
|
+
};
|
|
123
130
|
}
|
|
124
131
|
//#endregion
|
|
125
132
|
//#region src/resultify.ts
|
package/dist/index.d.cts
CHANGED
|
@@ -67,8 +67,12 @@ declare const wait: (wait_ms: number, signal?: AbortSignal) => Promise<void>;
|
|
|
67
67
|
declare function isObjectEmpty(obj: object): boolean;
|
|
68
68
|
//#endregion
|
|
69
69
|
//#region src/createInFlightDeduper.d.ts
|
|
70
|
+
type WithIdempotencyId = {
|
|
71
|
+
idempotencyId?: string;
|
|
72
|
+
};
|
|
70
73
|
type InFlightDeduper = {
|
|
71
|
-
use: <
|
|
74
|
+
use: <R extends any>(key: string, fn: () => R | Promise<R>) => Promise<Awaited<R>>;
|
|
75
|
+
maybeIdempotent: <R extends any>(p: WithIdempotencyId, fn: () => R | Promise<R>) => Promise<Awaited<R>>;
|
|
72
76
|
};
|
|
73
77
|
/**
|
|
74
78
|
* Creates a deduplicator for in-flight promises or sync functions.
|
|
@@ -190,4 +194,4 @@ declare const promisify: <F extends (...args: any[]) => any>(fn: F, ...args: Par
|
|
|
190
194
|
*/
|
|
191
195
|
declare const clamp: (num: number, min: number, max: number) => number;
|
|
192
196
|
//#endregion
|
|
193
|
-
export { DeferredPromise, ErrorResult, InFlightDeduper, Monitor, MonitorMark, MonitorResult, PerfmonError, PerfmonResult, WithPerfmonReturn, chunk, chunkStr, clamp, createInFlightDeduper, defer, ignorePromise, isAbortError, isObjectEmpty, noop, promisify, resultify, trySettlePromises, wait, withPerfmon };
|
|
197
|
+
export { DeferredPromise, ErrorResult, InFlightDeduper, Monitor, MonitorMark, MonitorResult, PerfmonError, PerfmonResult, WithIdempotencyId, WithPerfmonReturn, chunk, chunkStr, clamp, createInFlightDeduper, defer, ignorePromise, isAbortError, isObjectEmpty, noop, promisify, resultify, trySettlePromises, wait, withPerfmon };
|
package/dist/index.d.mts
CHANGED
|
@@ -67,8 +67,12 @@ declare const wait: (wait_ms: number, signal?: AbortSignal) => Promise<void>;
|
|
|
67
67
|
declare function isObjectEmpty(obj: object): boolean;
|
|
68
68
|
//#endregion
|
|
69
69
|
//#region src/createInFlightDeduper.d.ts
|
|
70
|
+
type WithIdempotencyId = {
|
|
71
|
+
idempotencyId?: string;
|
|
72
|
+
};
|
|
70
73
|
type InFlightDeduper = {
|
|
71
|
-
use: <
|
|
74
|
+
use: <R extends any>(key: string, fn: () => R | Promise<R>) => Promise<Awaited<R>>;
|
|
75
|
+
maybeIdempotent: <R extends any>(p: WithIdempotencyId, fn: () => R | Promise<R>) => Promise<Awaited<R>>;
|
|
72
76
|
};
|
|
73
77
|
/**
|
|
74
78
|
* Creates a deduplicator for in-flight promises or sync functions.
|
|
@@ -190,4 +194,4 @@ declare const promisify: <F extends (...args: any[]) => any>(fn: F, ...args: Par
|
|
|
190
194
|
*/
|
|
191
195
|
declare const clamp: (num: number, min: number, max: number) => number;
|
|
192
196
|
//#endregion
|
|
193
|
-
export { DeferredPromise, ErrorResult, InFlightDeduper, Monitor, MonitorMark, MonitorResult, PerfmonError, PerfmonResult, WithPerfmonReturn, chunk, chunkStr, clamp, createInFlightDeduper, defer, ignorePromise, isAbortError, isObjectEmpty, noop, promisify, resultify, trySettlePromises, wait, withPerfmon };
|
|
197
|
+
export { DeferredPromise, ErrorResult, InFlightDeduper, Monitor, MonitorMark, MonitorResult, PerfmonError, PerfmonResult, WithIdempotencyId, WithPerfmonReturn, chunk, chunkStr, clamp, createInFlightDeduper, defer, ignorePromise, isAbortError, isObjectEmpty, noop, promisify, resultify, trySettlePromises, wait, withPerfmon };
|
package/dist/index.mjs
CHANGED
|
@@ -118,7 +118,14 @@ function createInFlightDeduper() {
|
|
|
118
118
|
__promises.set(key, promise);
|
|
119
119
|
return promise;
|
|
120
120
|
}
|
|
121
|
-
|
|
121
|
+
function maybeIdempotent(p, fn) {
|
|
122
|
+
if (p.idempotencyId) return use(p.idempotencyId, fn);
|
|
123
|
+
return Promise.resolve(fn());
|
|
124
|
+
}
|
|
125
|
+
return {
|
|
126
|
+
use,
|
|
127
|
+
maybeIdempotent
|
|
128
|
+
};
|
|
122
129
|
}
|
|
123
130
|
//#endregion
|
|
124
131
|
//#region src/resultify.ts
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jsnw/common-utils",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.2",
|
|
4
4
|
"description": "Lightweight JavaScript/TypeScript utilities with async helpers, array and string operations",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"homepage": "https://github.com/pvbaliuk/jsn-utils#readme",
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@types/jest": "^30.0.0",
|
|
44
|
-
"@types/node": "^24.13.
|
|
44
|
+
"@types/node": "^24.13.4",
|
|
45
45
|
"jest": "^30.5.1",
|
|
46
46
|
"ts-jest": "^29.4.12",
|
|
47
47
|
"tsdown": "^0.22.14",
|