@zokugun/xtry 0.11.5 → 0.11.6
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 +1 -1
- package/lib/cjs/defer.cjs +8 -8
- package/lib/cjs/defer.d.cts +8 -8
- package/lib/esm/defer.d.mts +8 -8
- package/lib/esm/defer.mjs +8 -8
- package/package.json +18 -11
package/README.md
CHANGED
|
@@ -146,7 +146,7 @@ To minimize allocations when returning the same `Success` shape, you can reuse t
|
|
|
146
146
|
|
|
147
147
|
### Try helpers
|
|
148
148
|
|
|
149
|
-
```
|
|
149
|
+
```typescript
|
|
150
150
|
function xtry<T, E>(func: (() => MaybePromise<T>) | Promise<T>, handler?: (error: unknown) => void | E): MaybePromise<Result<T, E>>;
|
|
151
151
|
function xtry<T, E>(iterable: (() => Iterable<T>) | Iterable<T>, handler?: (error: unknown) => void | E): Iterable<Result<T, E>>;
|
|
152
152
|
function xtry<T, E>(iterable: (() => AsyncIterable<T>) | AsyncIterable<T>, handler?: (error: unknown) => void | E): AsyncIterable<Result<T, E>>;
|
package/lib/cjs/defer.cjs
CHANGED
|
@@ -6,7 +6,7 @@ exports.xdeferSync = xdeferSync;
|
|
|
6
6
|
const result_js_1 = require("./result.cjs");
|
|
7
7
|
const is_promise_like_js_1 = require("./utils/is-promise-like.cjs");
|
|
8
8
|
/* eslint-enable @typescript-eslint/unified-signatures */
|
|
9
|
-
function xdefer(callback,
|
|
9
|
+
function xdefer(callback, thisArg, ...args) {
|
|
10
10
|
// eslint-disable-next-line @typescript-eslint/promise-function-async
|
|
11
11
|
return ((result) => {
|
|
12
12
|
const finalize = (deferResult) => {
|
|
@@ -20,8 +20,8 @@ function xdefer(callback, bind, ...args) {
|
|
|
20
20
|
};
|
|
21
21
|
let deferredValue;
|
|
22
22
|
if (callback instanceof Function) {
|
|
23
|
-
if (
|
|
24
|
-
deferredValue = Reflect.apply(callback,
|
|
23
|
+
if (thisArg) {
|
|
24
|
+
deferredValue = Reflect.apply(callback, thisArg, args);
|
|
25
25
|
}
|
|
26
26
|
else {
|
|
27
27
|
deferredValue = callback(...args);
|
|
@@ -37,14 +37,14 @@ function xdefer(callback, bind, ...args) {
|
|
|
37
37
|
});
|
|
38
38
|
}
|
|
39
39
|
/* eslint-enable @typescript-eslint/unified-signatures */
|
|
40
|
-
function xdeferAsync(callback,
|
|
40
|
+
function xdeferAsync(callback, thisArg, ...args) {
|
|
41
41
|
return (async (result) => {
|
|
42
42
|
let deferResult;
|
|
43
43
|
if (callback instanceof Promise) {
|
|
44
44
|
deferResult = await callback;
|
|
45
45
|
}
|
|
46
|
-
else if (
|
|
47
|
-
deferResult = await callback.apply(
|
|
46
|
+
else if (thisArg) {
|
|
47
|
+
deferResult = await callback.apply(thisArg, args);
|
|
48
48
|
}
|
|
49
49
|
else {
|
|
50
50
|
deferResult = await callback(...args);
|
|
@@ -59,9 +59,9 @@ function xdeferAsync(callback, bind, ...args) {
|
|
|
59
59
|
});
|
|
60
60
|
}
|
|
61
61
|
/* eslint-enable @typescript-eslint/unified-signatures */
|
|
62
|
-
function xdeferSync(callback,
|
|
62
|
+
function xdeferSync(callback, thisArg, ...args) {
|
|
63
63
|
return ((result) => {
|
|
64
|
-
const deferResult =
|
|
64
|
+
const deferResult = thisArg ? callback.apply(thisArg, args) : callback(...args);
|
|
65
65
|
if (deferResult.fails) {
|
|
66
66
|
if (result?.fails) {
|
|
67
67
|
return result;
|
package/lib/cjs/defer.d.cts
CHANGED
|
@@ -12,17 +12,17 @@ export type XDeferSync<E> = {
|
|
|
12
12
|
<F>(result: Failure<F>): Failure<F>;
|
|
13
13
|
<T, F>(result: Result<T, F>): Result<T, E | F>;
|
|
14
14
|
};
|
|
15
|
-
export declare function xdefer<E, Args extends unknown[]>(callback: NonPromiseCallback<Result<void, E>, Args>,
|
|
16
|
-
export declare function xdefer<E, Args extends unknown[]>(callback: NonPromiseCallback<Result<unknown, E>, Args>,
|
|
15
|
+
export declare function xdefer<E, Args extends unknown[]>(callback: NonPromiseCallback<Result<void, E>, Args>, thisArg?: object | null, ...args: Args): XDeferSync<E>;
|
|
16
|
+
export declare function xdefer<E, Args extends unknown[]>(callback: NonPromiseCallback<Result<unknown, E>, Args>, thisArg?: object | null, ...args: Args): XDeferSync<E>;
|
|
17
17
|
export declare function xdefer<E>(callback: Promise<Result<void, E>>): XDeferAsync<E>;
|
|
18
18
|
export declare function xdefer<E>(callback: Promise<Result<unknown, E>>): XDeferAsync<E>;
|
|
19
|
-
export declare function xdefer<E, Args extends unknown[]>(callback: (...args: Args) => Promise<Result<void, E>>,
|
|
20
|
-
export declare function xdefer<E, Args extends unknown[]>(callback: (...args: Args) => Promise<Result<unknown, E>>,
|
|
19
|
+
export declare function xdefer<E, Args extends unknown[]>(callback: (...args: Args) => Promise<Result<void, E>>, thisArg?: object | null, ...args: Args): XDeferAsync<E>;
|
|
20
|
+
export declare function xdefer<E, Args extends unknown[]>(callback: (...args: Args) => Promise<Result<unknown, E>>, thisArg?: object | null, ...args: Args): XDeferAsync<E>;
|
|
21
21
|
export declare function xdeferAsync<E>(callback: Promise<Result<void, E>>): XDeferAsync<E>;
|
|
22
22
|
export declare function xdeferAsync<E>(callback: Promise<Result<unknown, E>>): XDeferAsync<E>;
|
|
23
|
-
export declare function xdeferAsync<E, Args extends unknown[]>(callback: (...args: Args) => Promise<Result<void, E>>,
|
|
24
|
-
export declare function xdeferAsync<E, Args extends unknown[]>(callback: (...args: Args) => Promise<Result<unknown, E>>,
|
|
23
|
+
export declare function xdeferAsync<E, Args extends unknown[]>(callback: (...args: Args) => Promise<Result<void, E>>, thisArg?: object | null, ...args: Args): XDeferAsync<E>;
|
|
24
|
+
export declare function xdeferAsync<E, Args extends unknown[]>(callback: (...args: Args) => Promise<Result<unknown, E>>, thisArg?: object | null, ...args: Args): XDeferAsync<E>;
|
|
25
25
|
export declare function xdeferSync<E>(callback: NonPromiseCallback<Result<void, E>>): XDeferSync<E>;
|
|
26
26
|
export declare function xdeferSync<E>(callback: NonPromiseCallback<Result<unknown, E>>): XDeferSync<E>;
|
|
27
|
-
export declare function xdeferSync<E, Args extends unknown[]>(callback: NonPromiseCallback<Result<void, E>, Args>,
|
|
28
|
-
export declare function xdeferSync<E, Args extends unknown[]>(callback: NonPromiseCallback<Result<unknown, E>, Args>,
|
|
27
|
+
export declare function xdeferSync<E, Args extends unknown[]>(callback: NonPromiseCallback<Result<void, E>, Args>, thisArg?: object | null, ...args: Args): XDeferSync<E>;
|
|
28
|
+
export declare function xdeferSync<E, Args extends unknown[]>(callback: NonPromiseCallback<Result<unknown, E>, Args>, thisArg?: object | null, ...args: Args): XDeferSync<E>;
|
package/lib/esm/defer.d.mts
CHANGED
|
@@ -12,17 +12,17 @@ export type XDeferSync<E> = {
|
|
|
12
12
|
<F>(result: Failure<F>): Failure<F>;
|
|
13
13
|
<T, F>(result: Result<T, F>): Result<T, E | F>;
|
|
14
14
|
};
|
|
15
|
-
export declare function xdefer<E, Args extends unknown[]>(callback: NonPromiseCallback<Result<void, E>, Args>,
|
|
16
|
-
export declare function xdefer<E, Args extends unknown[]>(callback: NonPromiseCallback<Result<unknown, E>, Args>,
|
|
15
|
+
export declare function xdefer<E, Args extends unknown[]>(callback: NonPromiseCallback<Result<void, E>, Args>, thisArg?: object | null, ...args: Args): XDeferSync<E>;
|
|
16
|
+
export declare function xdefer<E, Args extends unknown[]>(callback: NonPromiseCallback<Result<unknown, E>, Args>, thisArg?: object | null, ...args: Args): XDeferSync<E>;
|
|
17
17
|
export declare function xdefer<E>(callback: Promise<Result<void, E>>): XDeferAsync<E>;
|
|
18
18
|
export declare function xdefer<E>(callback: Promise<Result<unknown, E>>): XDeferAsync<E>;
|
|
19
|
-
export declare function xdefer<E, Args extends unknown[]>(callback: (...args: Args) => Promise<Result<void, E>>,
|
|
20
|
-
export declare function xdefer<E, Args extends unknown[]>(callback: (...args: Args) => Promise<Result<unknown, E>>,
|
|
19
|
+
export declare function xdefer<E, Args extends unknown[]>(callback: (...args: Args) => Promise<Result<void, E>>, thisArg?: object | null, ...args: Args): XDeferAsync<E>;
|
|
20
|
+
export declare function xdefer<E, Args extends unknown[]>(callback: (...args: Args) => Promise<Result<unknown, E>>, thisArg?: object | null, ...args: Args): XDeferAsync<E>;
|
|
21
21
|
export declare function xdeferAsync<E>(callback: Promise<Result<void, E>>): XDeferAsync<E>;
|
|
22
22
|
export declare function xdeferAsync<E>(callback: Promise<Result<unknown, E>>): XDeferAsync<E>;
|
|
23
|
-
export declare function xdeferAsync<E, Args extends unknown[]>(callback: (...args: Args) => Promise<Result<void, E>>,
|
|
24
|
-
export declare function xdeferAsync<E, Args extends unknown[]>(callback: (...args: Args) => Promise<Result<unknown, E>>,
|
|
23
|
+
export declare function xdeferAsync<E, Args extends unknown[]>(callback: (...args: Args) => Promise<Result<void, E>>, thisArg?: object | null, ...args: Args): XDeferAsync<E>;
|
|
24
|
+
export declare function xdeferAsync<E, Args extends unknown[]>(callback: (...args: Args) => Promise<Result<unknown, E>>, thisArg?: object | null, ...args: Args): XDeferAsync<E>;
|
|
25
25
|
export declare function xdeferSync<E>(callback: NonPromiseCallback<Result<void, E>>): XDeferSync<E>;
|
|
26
26
|
export declare function xdeferSync<E>(callback: NonPromiseCallback<Result<unknown, E>>): XDeferSync<E>;
|
|
27
|
-
export declare function xdeferSync<E, Args extends unknown[]>(callback: NonPromiseCallback<Result<void, E>, Args>,
|
|
28
|
-
export declare function xdeferSync<E, Args extends unknown[]>(callback: NonPromiseCallback<Result<unknown, E>, Args>,
|
|
27
|
+
export declare function xdeferSync<E, Args extends unknown[]>(callback: NonPromiseCallback<Result<void, E>, Args>, thisArg?: object | null, ...args: Args): XDeferSync<E>;
|
|
28
|
+
export declare function xdeferSync<E, Args extends unknown[]>(callback: NonPromiseCallback<Result<unknown, E>, Args>, thisArg?: object | null, ...args: Args): XDeferSync<E>;
|
package/lib/esm/defer.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ok } from './result.mjs';
|
|
2
2
|
import { isPromiseLike } from './utils/is-promise-like.mjs';
|
|
3
3
|
/* eslint-enable @typescript-eslint/unified-signatures */
|
|
4
|
-
export function xdefer(callback,
|
|
4
|
+
export function xdefer(callback, thisArg, ...args) {
|
|
5
5
|
// eslint-disable-next-line @typescript-eslint/promise-function-async
|
|
6
6
|
return ((result) => {
|
|
7
7
|
const finalize = (deferResult) => {
|
|
@@ -15,8 +15,8 @@ export function xdefer(callback, bind, ...args) {
|
|
|
15
15
|
};
|
|
16
16
|
let deferredValue;
|
|
17
17
|
if (callback instanceof Function) {
|
|
18
|
-
if (
|
|
19
|
-
deferredValue = Reflect.apply(callback,
|
|
18
|
+
if (thisArg) {
|
|
19
|
+
deferredValue = Reflect.apply(callback, thisArg, args);
|
|
20
20
|
}
|
|
21
21
|
else {
|
|
22
22
|
deferredValue = callback(...args);
|
|
@@ -32,14 +32,14 @@ export function xdefer(callback, bind, ...args) {
|
|
|
32
32
|
});
|
|
33
33
|
}
|
|
34
34
|
/* eslint-enable @typescript-eslint/unified-signatures */
|
|
35
|
-
export function xdeferAsync(callback,
|
|
35
|
+
export function xdeferAsync(callback, thisArg, ...args) {
|
|
36
36
|
return (async (result) => {
|
|
37
37
|
let deferResult;
|
|
38
38
|
if (callback instanceof Promise) {
|
|
39
39
|
deferResult = await callback;
|
|
40
40
|
}
|
|
41
|
-
else if (
|
|
42
|
-
deferResult = await callback.apply(
|
|
41
|
+
else if (thisArg) {
|
|
42
|
+
deferResult = await callback.apply(thisArg, args);
|
|
43
43
|
}
|
|
44
44
|
else {
|
|
45
45
|
deferResult = await callback(...args);
|
|
@@ -54,9 +54,9 @@ export function xdeferAsync(callback, bind, ...args) {
|
|
|
54
54
|
});
|
|
55
55
|
}
|
|
56
56
|
/* eslint-enable @typescript-eslint/unified-signatures */
|
|
57
|
-
export function xdeferSync(callback,
|
|
57
|
+
export function xdeferSync(callback, thisArg, ...args) {
|
|
58
58
|
return ((result) => {
|
|
59
|
-
const deferResult =
|
|
59
|
+
const deferResult = thisArg ? callback.apply(thisArg, args) : callback(...args);
|
|
60
60
|
if (deferResult.fails) {
|
|
61
61
|
if (result?.fails) {
|
|
62
62
|
return result;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zokugun/xtry",
|
|
3
3
|
"description": "simple try/catch wrapper returning Result",
|
|
4
|
-
"version": "0.11.
|
|
4
|
+
"version": "0.11.6",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Baptiste Augrain",
|
|
7
7
|
"email": "daiyam@zokugun.org"
|
|
@@ -63,51 +63,58 @@
|
|
|
63
63
|
"audit:fix": "npm audit fix --min-release-age=0",
|
|
64
64
|
"build": "npm run clean && npm run build:lib",
|
|
65
65
|
"build:lib": "tsc-leda generate",
|
|
66
|
-
"build:package": "tsc-leda update-package",
|
|
66
|
+
"build:package": "tsc-leda update-package && npm run lint:package",
|
|
67
67
|
"ci:lint": "zizmor .",
|
|
68
68
|
"ci:lint:fix": "zizmor . --fix=all",
|
|
69
69
|
"clean": "rimraf .src .test lib",
|
|
70
70
|
"compile:src": "tsc -p src",
|
|
71
71
|
"compile:test": "tsc -p test",
|
|
72
72
|
"lint": "xo",
|
|
73
|
-
"lint:all": "
|
|
73
|
+
"lint:all": "npm audit && npm run lint:package && npm run ci:lint && npm run lint",
|
|
74
74
|
"lint:fix": "xo --fix",
|
|
75
|
+
"lint:package": "fixpack || true",
|
|
75
76
|
"prepack": "npm run build",
|
|
76
|
-
"prepare": "husky;
|
|
77
|
+
"prepare": "husky; npm run lint:package",
|
|
77
78
|
"release": "release-it",
|
|
78
79
|
"test": "vitest run --reporter tree",
|
|
79
80
|
"test:coverage": "vitest run --reporter tree --coverage --coverage.reporter text",
|
|
80
81
|
"test:ui": "vitest --ui --coverage",
|
|
81
82
|
"test:watch": "vitest",
|
|
82
83
|
"update:artifacts": "artifact update",
|
|
83
|
-
"update:ci": "PINACT_MIN_AGE=7 pinact run",
|
|
84
|
-
"update:deps": "taze",
|
|
84
|
+
"update:ci": "PINACT_MIN_AGE=7 pinact run --update",
|
|
85
|
+
"update:deps": "taze --all",
|
|
85
86
|
"watch:build": "tsc-watch -p src --onSuccess 'npm run build'",
|
|
86
87
|
"watch:src": "tsc-watch -p src",
|
|
87
88
|
"watch:test": "tsc-watch -p test"
|
|
88
89
|
},
|
|
89
90
|
"dependencies": {},
|
|
90
91
|
"devDependencies": {
|
|
91
|
-
"@commitlint/cli": "
|
|
92
|
-
"@commitlint/config-conventional": "
|
|
92
|
+
"@commitlint/cli": "20.5.3",
|
|
93
|
+
"@commitlint/config-conventional": "20.5.3",
|
|
93
94
|
"@types/fs-extra": "11.0.4",
|
|
94
95
|
"@types/node": "20.19.39",
|
|
95
96
|
"@vitest/coverage-v8": "4.1.5",
|
|
96
97
|
"@vitest/ui": "4.1.5",
|
|
97
|
-
"@zokugun/fs-extra-plus": "0.
|
|
98
|
-
"@zokugun/tsc-leda": "0.
|
|
98
|
+
"@zokugun/fs-extra-plus": "0.4.1",
|
|
99
|
+
"@zokugun/tsc-leda": "0.4.1",
|
|
99
100
|
"fixpack": "4.0.0",
|
|
100
101
|
"fs-extra": "11.3.4",
|
|
101
102
|
"globby": "16.2.0",
|
|
102
103
|
"husky": "9.1.7",
|
|
103
104
|
"lint-staged": "16.4.0",
|
|
104
|
-
"release-it": "20.0.
|
|
105
|
+
"release-it": "20.0.1",
|
|
106
|
+
"rimraf": "6.1.3",
|
|
105
107
|
"taze": "19.11.0",
|
|
106
108
|
"tsc-watch": "7.2.0",
|
|
107
109
|
"typescript": "5.9.3",
|
|
108
110
|
"vitest": "4.1.5",
|
|
109
111
|
"xo": "0.60.0"
|
|
110
112
|
},
|
|
113
|
+
"overrides": {
|
|
114
|
+
"ajv": {
|
|
115
|
+
"fast-uri": "3.1.2"
|
|
116
|
+
}
|
|
117
|
+
},
|
|
111
118
|
"keywords": [
|
|
112
119
|
"catch",
|
|
113
120
|
"error",
|