@zokugun/xtry 0.6.1 → 0.6.3
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/lib/cjs/async.cjs +23 -0
- package/lib/cjs/async.d.cts +6 -0
- package/lib/cjs/defer.cjs +43 -0
- package/lib/cjs/defer.d.cts +19 -0
- package/lib/cjs/index.cjs +29 -0
- package/lib/cjs/index.d.cts +6 -0
- package/lib/cjs/partial.cjs +53 -0
- package/lib/cjs/partial.d.cts +30 -0
- package/lib/cjs/result.cjs +28 -0
- package/lib/cjs/result.d.cts +21 -0
- package/lib/cjs/stringify-error.cjs +14 -0
- package/lib/cjs/stringify-error.d.cts +4 -0
- package/lib/cjs/sync.cjs +23 -0
- package/lib/cjs/sync.d.cts +6 -0
- package/lib/cjs/try.cjs +51 -0
- package/lib/cjs/try.d.cts +12 -0
- package/lib/cjs/utils/is-promise-like.cjs +8 -0
- package/lib/cjs/utils/types.d.cts +6 -0
- package/lib/esm/async.d.ts +6 -0
- package/lib/esm/async.js +7 -5
- package/lib/esm/defer.d.ts +19 -0
- package/lib/esm/defer.js +38 -42
- package/lib/esm/index.d.ts +6 -0
- package/lib/esm/index.js +7 -5
- package/lib/esm/partial.d.ts +30 -0
- package/lib/esm/partial.js +38 -37
- package/lib/esm/result.d.ts +21 -0
- package/lib/esm/result.js +20 -16
- package/lib/esm/stringify-error.d.ts +4 -0
- package/lib/esm/stringify-error.js +12 -17
- package/lib/esm/sync.d.ts +6 -0
- package/lib/esm/sync.js +7 -5
- package/lib/esm/try.d.ts +12 -0
- package/lib/esm/try.js +46 -62
- package/lib/esm/utils/is-promise-like.js +6 -2
- package/lib/esm/utils/types.d.ts +6 -0
- package/package.json +9 -25
- package/lib/cjs/async.js +0 -25
- package/lib/cjs/defer.js +0 -50
- package/lib/cjs/index.js +0 -31
- package/lib/cjs/partial.js +0 -52
- package/lib/cjs/result.js +0 -23
- package/lib/cjs/stringify-error.js +0 -21
- package/lib/cjs/sync.js +0 -25
- package/lib/cjs/try.js +0 -70
- package/lib/cjs/utils/is-promise-like.js +0 -6
- package/lib/cjs/utils/types.js +0 -2
- package/lib/esm/utils/types.js +0 -1
- package/lib/types/async.d.ts +0 -7
- package/lib/types/defer.d.ts +0 -16
- package/lib/types/index.d.ts +0 -7
- package/lib/types/partial.d.ts +0 -27
- package/lib/types/result.d.ts +0 -18
- package/lib/types/stringify-error.d.ts +0 -1
- package/lib/types/sync.d.ts +0 -7
- package/lib/types/try.d.ts +0 -9
- package/lib/types/utils/is-promise-like.d.ts +0 -3
- package/lib/types/utils/types.d.ts +0 -5
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
const require__home_runner_work_node_xtry_node_xtry_src_result = require('./result.cjs');
|
|
2
|
+
const require__home_runner_work_node_xtry_node_xtry_src_defer = require('./defer.cjs');
|
|
3
|
+
const require__home_runner_work_node_xtry_node_xtry_src_partial = require('./partial.cjs');
|
|
4
|
+
const require__home_runner_work_node_xtry_node_xtry_src_stringify_error = require('./stringify-error.cjs');
|
|
5
|
+
const require__home_runner_work_node_xtry_node_xtry_src_try = require('./try.cjs');
|
|
6
|
+
|
|
7
|
+
exports.OK = require__home_runner_work_node_xtry_node_xtry_src_result.OK;
|
|
8
|
+
exports.OK_FALSE = require__home_runner_work_node_xtry_node_xtry_src_result.OK_FALSE;
|
|
9
|
+
exports.OK_NULL = require__home_runner_work_node_xtry_node_xtry_src_result.OK_NULL;
|
|
10
|
+
exports.OK_TRUE = require__home_runner_work_node_xtry_node_xtry_src_result.OK_TRUE;
|
|
11
|
+
exports.YOK = require__home_runner_work_node_xtry_node_xtry_src_partial.YOK;
|
|
12
|
+
exports.YOK_FALSE = require__home_runner_work_node_xtry_node_xtry_src_partial.YOK_FALSE;
|
|
13
|
+
exports.YOK_NULL = require__home_runner_work_node_xtry_node_xtry_src_partial.YOK_NULL;
|
|
14
|
+
exports.YOK_TRUE = require__home_runner_work_node_xtry_node_xtry_src_partial.YOK_TRUE;
|
|
15
|
+
exports.err = require__home_runner_work_node_xtry_node_xtry_src_result.err;
|
|
16
|
+
exports.ok = require__home_runner_work_node_xtry_node_xtry_src_result.ok;
|
|
17
|
+
exports.stringifyError = require__home_runner_work_node_xtry_node_xtry_src_stringify_error.stringifyError;
|
|
18
|
+
exports.xdefer = require__home_runner_work_node_xtry_node_xtry_src_defer.xdeferAsync;
|
|
19
|
+
exports.xtry = require__home_runner_work_node_xtry_node_xtry_src_try.xtryAsync;
|
|
20
|
+
exports.yep = require__home_runner_work_node_xtry_node_xtry_src_partial.yep;
|
|
21
|
+
exports.yerr = require__home_runner_work_node_xtry_node_xtry_src_partial.yerr;
|
|
22
|
+
exports.yok = require__home_runner_work_node_xtry_node_xtry_src_partial.yok;
|
|
23
|
+
exports.yres = require__home_runner_work_node_xtry_node_xtry_src_partial.yresAsync;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Failure, OK, OK_FALSE, OK_NULL, OK_TRUE, Result, Success, err, ok } from "./result.cjs";
|
|
2
|
+
import { xdeferAsync } from "./defer.cjs";
|
|
3
|
+
import { YFailure, YOK, YOK_FALSE, YOK_NULL, YOK_TRUE, YResult, YSuccess, yep, yerr, yok, yresAsync } from "./partial.cjs";
|
|
4
|
+
import { stringifyError } from "./stringify-error.cjs";
|
|
5
|
+
import { xtryAsync } from "./try.cjs";
|
|
6
|
+
export { type Failure, OK, OK_FALSE, OK_NULL, OK_TRUE, type Result, type Success, type YFailure, YOK, YOK_FALSE, YOK_NULL, YOK_TRUE, type YResult, type YSuccess, err, ok, stringifyError, xdeferAsync as xdefer, xtryAsync as xtry, yep, yerr, yok, yresAsync as yres };
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
const require__home_runner_work_node_xtry_node_xtry_src_result = require('./result.cjs');
|
|
2
|
+
const require__home_runner_work_node_xtry_node_xtry_src_utils_is_promise_like = require('./utils/is-promise-like.cjs');
|
|
3
|
+
|
|
4
|
+
//#region src/defer.ts
|
|
5
|
+
function xdefer(callback) {
|
|
6
|
+
return (result) => {
|
|
7
|
+
const finalize = (deferResult) => {
|
|
8
|
+
if (deferResult.fails) {
|
|
9
|
+
if (result?.fails) return result;
|
|
10
|
+
return deferResult;
|
|
11
|
+
}
|
|
12
|
+
return result ?? require__home_runner_work_node_xtry_node_xtry_src_result.ok();
|
|
13
|
+
};
|
|
14
|
+
const deferredValue = callback instanceof Function ? callback() : callback;
|
|
15
|
+
if (require__home_runner_work_node_xtry_node_xtry_src_utils_is_promise_like.isPromiseLike(deferredValue)) return Promise.resolve(deferredValue).then(finalize);
|
|
16
|
+
return finalize(deferredValue);
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
function xdeferAsync(callback) {
|
|
20
|
+
return async (result) => {
|
|
21
|
+
const deferResult = await (callback instanceof Promise ? callback : callback());
|
|
22
|
+
if (deferResult.fails) {
|
|
23
|
+
if (result?.fails) return result;
|
|
24
|
+
return deferResult;
|
|
25
|
+
}
|
|
26
|
+
return result ?? require__home_runner_work_node_xtry_node_xtry_src_result.ok();
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
function xdeferSync(callback) {
|
|
30
|
+
return (result) => {
|
|
31
|
+
const deferResult = callback();
|
|
32
|
+
if (deferResult.fails) {
|
|
33
|
+
if (result?.fails) return result;
|
|
34
|
+
return deferResult;
|
|
35
|
+
}
|
|
36
|
+
return result ?? require__home_runner_work_node_xtry_node_xtry_src_result.ok();
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
//#endregion
|
|
41
|
+
exports.xdefer = xdefer;
|
|
42
|
+
exports.xdeferAsync = xdeferAsync;
|
|
43
|
+
exports.xdeferSync = xdeferSync;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Result, Success } from "./result.cjs";
|
|
2
|
+
import { NonPromiseCallback, PromiseCallback } from "./utils/types.cjs";
|
|
3
|
+
|
|
4
|
+
//#region src/defer.d.ts
|
|
5
|
+
type DeferAsync<E> = {
|
|
6
|
+
(): Promise<Success<void>>;
|
|
7
|
+
(result: UnknownResult<E>): Promise<UnknownResult<E>>;
|
|
8
|
+
};
|
|
9
|
+
type DeferSync<E> = {
|
|
10
|
+
(): Success<void>;
|
|
11
|
+
(result: UnknownResult<E>): UnknownResult<E>;
|
|
12
|
+
};
|
|
13
|
+
type UnknownResult<E> = Result<unknown, E>;
|
|
14
|
+
declare function xdefer<E>(callback: NonPromiseCallback<UnknownResult<E>>): DeferSync<E>;
|
|
15
|
+
declare function xdefer<E>(callback: PromiseCallback<UnknownResult<E>>): DeferAsync<E>;
|
|
16
|
+
declare function xdeferAsync<E>(callback: PromiseCallback<UnknownResult<E>>): DeferAsync<E>;
|
|
17
|
+
declare function xdeferSync<E>(callback: NonPromiseCallback<UnknownResult<E>>): DeferSync<E>;
|
|
18
|
+
//#endregion
|
|
19
|
+
export { xdefer, xdeferAsync, xdeferSync };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
const require__home_runner_work_node_xtry_node_xtry_src_result = require('./result.cjs');
|
|
2
|
+
const require__home_runner_work_node_xtry_node_xtry_src_defer = require('./defer.cjs');
|
|
3
|
+
const require__home_runner_work_node_xtry_node_xtry_src_partial = require('./partial.cjs');
|
|
4
|
+
const require__home_runner_work_node_xtry_node_xtry_src_stringify_error = require('./stringify-error.cjs');
|
|
5
|
+
const require__home_runner_work_node_xtry_node_xtry_src_try = require('./try.cjs');
|
|
6
|
+
|
|
7
|
+
exports.OK = require__home_runner_work_node_xtry_node_xtry_src_result.OK;
|
|
8
|
+
exports.OK_FALSE = require__home_runner_work_node_xtry_node_xtry_src_result.OK_FALSE;
|
|
9
|
+
exports.OK_NULL = require__home_runner_work_node_xtry_node_xtry_src_result.OK_NULL;
|
|
10
|
+
exports.OK_TRUE = require__home_runner_work_node_xtry_node_xtry_src_result.OK_TRUE;
|
|
11
|
+
exports.YOK = require__home_runner_work_node_xtry_node_xtry_src_partial.YOK;
|
|
12
|
+
exports.YOK_FALSE = require__home_runner_work_node_xtry_node_xtry_src_partial.YOK_FALSE;
|
|
13
|
+
exports.YOK_NULL = require__home_runner_work_node_xtry_node_xtry_src_partial.YOK_NULL;
|
|
14
|
+
exports.YOK_TRUE = require__home_runner_work_node_xtry_node_xtry_src_partial.YOK_TRUE;
|
|
15
|
+
exports.err = require__home_runner_work_node_xtry_node_xtry_src_result.err;
|
|
16
|
+
exports.ok = require__home_runner_work_node_xtry_node_xtry_src_result.ok;
|
|
17
|
+
exports.stringifyError = require__home_runner_work_node_xtry_node_xtry_src_stringify_error.stringifyError;
|
|
18
|
+
exports.xdefer = require__home_runner_work_node_xtry_node_xtry_src_defer.xdefer;
|
|
19
|
+
exports.xdeferAsync = require__home_runner_work_node_xtry_node_xtry_src_defer.xdeferAsync;
|
|
20
|
+
exports.xdeferSync = require__home_runner_work_node_xtry_node_xtry_src_defer.xdeferSync;
|
|
21
|
+
exports.xtry = require__home_runner_work_node_xtry_node_xtry_src_try.xtry;
|
|
22
|
+
exports.xtryAsync = require__home_runner_work_node_xtry_node_xtry_src_try.xtryAsync;
|
|
23
|
+
exports.xtrySync = require__home_runner_work_node_xtry_node_xtry_src_try.xtrySync;
|
|
24
|
+
exports.yep = require__home_runner_work_node_xtry_node_xtry_src_partial.yep;
|
|
25
|
+
exports.yerr = require__home_runner_work_node_xtry_node_xtry_src_partial.yerr;
|
|
26
|
+
exports.yok = require__home_runner_work_node_xtry_node_xtry_src_partial.yok;
|
|
27
|
+
exports.yres = require__home_runner_work_node_xtry_node_xtry_src_partial.yres;
|
|
28
|
+
exports.yresAsync = require__home_runner_work_node_xtry_node_xtry_src_partial.yresAsync;
|
|
29
|
+
exports.yresSync = require__home_runner_work_node_xtry_node_xtry_src_partial.yresSync;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Failure, OK, OK_FALSE, OK_NULL, OK_TRUE, Result, Success, err, ok } from "./result.cjs";
|
|
2
|
+
import { xdefer, xdeferAsync, xdeferSync } from "./defer.cjs";
|
|
3
|
+
import { YFailure, YOK, YOK_FALSE, YOK_NULL, YOK_TRUE, YResult, YSuccess, yep, yerr, yok, yres, yresAsync, yresSync } from "./partial.cjs";
|
|
4
|
+
import { stringifyError } from "./stringify-error.cjs";
|
|
5
|
+
import { xtry, xtryAsync, xtrySync } from "./try.cjs";
|
|
6
|
+
export { type Failure, OK, OK_FALSE, OK_NULL, OK_TRUE, type Result, type Success, type YFailure, YOK, YOK_FALSE, YOK_NULL, YOK_TRUE, type YResult, type YSuccess, err, ok, stringifyError, xdefer, xdeferAsync, xdeferSync, xtry, xtryAsync, xtrySync, yep, yerr, yok, yres, yresAsync, yresSync };
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
const require__home_runner_work_node_xtry_node_xtry_src_utils_is_promise_like = require('./utils/is-promise-like.cjs');
|
|
2
|
+
|
|
3
|
+
//#region src/partial.ts
|
|
4
|
+
function yok(value) {
|
|
5
|
+
return {
|
|
6
|
+
fails: false,
|
|
7
|
+
success: true,
|
|
8
|
+
value,
|
|
9
|
+
error: void 0
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
function yerr(miscue) {
|
|
13
|
+
return {
|
|
14
|
+
fails: false,
|
|
15
|
+
success: false,
|
|
16
|
+
miscue,
|
|
17
|
+
value: void 0,
|
|
18
|
+
error: void 0
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
function yres(result) {
|
|
22
|
+
if (require__home_runner_work_node_xtry_node_xtry_src_utils_is_promise_like.isPromiseLike(result)) return result.then(yresSync);
|
|
23
|
+
return yresSync(result);
|
|
24
|
+
}
|
|
25
|
+
function yresSync(result) {
|
|
26
|
+
if (result.fails) return result;
|
|
27
|
+
return yep(result);
|
|
28
|
+
}
|
|
29
|
+
async function yresAsync(promise) {
|
|
30
|
+
return promise.then(yresSync);
|
|
31
|
+
}
|
|
32
|
+
function yep(result) {
|
|
33
|
+
return {
|
|
34
|
+
...result,
|
|
35
|
+
success: true
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
const YOK = Object.freeze(yok());
|
|
39
|
+
const YOK_NULL = Object.freeze(yok(null));
|
|
40
|
+
const YOK_TRUE = Object.freeze(yok(true));
|
|
41
|
+
const YOK_FALSE = Object.freeze(yok(false));
|
|
42
|
+
|
|
43
|
+
//#endregion
|
|
44
|
+
exports.YOK = YOK;
|
|
45
|
+
exports.YOK_FALSE = YOK_FALSE;
|
|
46
|
+
exports.YOK_NULL = YOK_NULL;
|
|
47
|
+
exports.YOK_TRUE = YOK_TRUE;
|
|
48
|
+
exports.yep = yep;
|
|
49
|
+
exports.yerr = yerr;
|
|
50
|
+
exports.yok = yok;
|
|
51
|
+
exports.yres = yres;
|
|
52
|
+
exports.yresAsync = yresAsync;
|
|
53
|
+
exports.yresSync = yresSync;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Failure, Result, Success } from "./result.cjs";
|
|
2
|
+
import { NotPromise } from "./utils/types.cjs";
|
|
3
|
+
|
|
4
|
+
//#region src/partial.d.ts
|
|
5
|
+
type YResult<T, E, M> = Failure<E> | YSuccess<T> | YFailure<M>;
|
|
6
|
+
type YSuccess<T> = Success<T> & {
|
|
7
|
+
success: true;
|
|
8
|
+
};
|
|
9
|
+
type YFailure<M> = {
|
|
10
|
+
fails: false;
|
|
11
|
+
success: false;
|
|
12
|
+
miscue: M;
|
|
13
|
+
value: undefined;
|
|
14
|
+
error: undefined;
|
|
15
|
+
};
|
|
16
|
+
declare function yok(): YSuccess<void>;
|
|
17
|
+
declare function yok<T>(value: T): YSuccess<T>;
|
|
18
|
+
declare function yerr<M>(miscue: M): YFailure<M>;
|
|
19
|
+
type YRResult<T, E> = Failure<E> | YSuccess<T>;
|
|
20
|
+
declare function yres<T, E>(result: NotPromise<Result<T, E>>): YRResult<T, E>;
|
|
21
|
+
declare function yres<T, E>(result: Promise<Result<T, E>>): Promise<YRResult<T, E>>;
|
|
22
|
+
declare function yresSync<T, E>(result: NotPromise<Result<T, E>>): YRResult<T, E>;
|
|
23
|
+
declare function yresAsync<T, E>(promise: Promise<Result<T, E>>): Promise<YRResult<T, E>>;
|
|
24
|
+
declare function yep<T>(result: Success<T>): YSuccess<T>;
|
|
25
|
+
declare const YOK: Readonly<YSuccess<void>>;
|
|
26
|
+
declare const YOK_NULL: Readonly<YSuccess<any>>;
|
|
27
|
+
declare const YOK_TRUE: Readonly<YSuccess<boolean>>;
|
|
28
|
+
declare const YOK_FALSE: Readonly<YSuccess<boolean>>;
|
|
29
|
+
//#endregion
|
|
30
|
+
export { YFailure, YOK, YOK_FALSE, YOK_NULL, YOK_TRUE, YResult, YSuccess, yep, yerr, yok, yres, yresAsync, yresSync };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/result.ts
|
|
3
|
+
function ok(value) {
|
|
4
|
+
return {
|
|
5
|
+
fails: false,
|
|
6
|
+
value,
|
|
7
|
+
error: void 0
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
function err(error) {
|
|
11
|
+
return {
|
|
12
|
+
fails: true,
|
|
13
|
+
value: void 0,
|
|
14
|
+
error
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
const OK = Object.freeze(ok());
|
|
18
|
+
const OK_NULL = Object.freeze(ok(null));
|
|
19
|
+
const OK_TRUE = Object.freeze(ok(true));
|
|
20
|
+
const OK_FALSE = Object.freeze(ok(false));
|
|
21
|
+
|
|
22
|
+
//#endregion
|
|
23
|
+
exports.OK = OK;
|
|
24
|
+
exports.OK_FALSE = OK_FALSE;
|
|
25
|
+
exports.OK_NULL = OK_NULL;
|
|
26
|
+
exports.OK_TRUE = OK_TRUE;
|
|
27
|
+
exports.err = err;
|
|
28
|
+
exports.ok = ok;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
//#region src/result.d.ts
|
|
2
|
+
type Success<T> = {
|
|
3
|
+
fails: false;
|
|
4
|
+
value: T;
|
|
5
|
+
error: undefined;
|
|
6
|
+
};
|
|
7
|
+
type Failure<E> = {
|
|
8
|
+
fails: true;
|
|
9
|
+
value: undefined;
|
|
10
|
+
error: E;
|
|
11
|
+
};
|
|
12
|
+
type Result<T, E> = Success<T> | Failure<E>;
|
|
13
|
+
declare function ok(): Success<void>;
|
|
14
|
+
declare function ok<T>(value: T): Success<T>;
|
|
15
|
+
declare function err<E>(error: E): Failure<E>;
|
|
16
|
+
declare const OK: Readonly<Success<void>>;
|
|
17
|
+
declare const OK_NULL: Readonly<Success<any>>;
|
|
18
|
+
declare const OK_TRUE: Readonly<Success<boolean>>;
|
|
19
|
+
declare const OK_FALSE: Readonly<Success<boolean>>;
|
|
20
|
+
//#endregion
|
|
21
|
+
export { Failure, OK, OK_FALSE, OK_NULL, OK_TRUE, Result, Success, err, ok };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/stringify-error.ts
|
|
3
|
+
function stringifyError(error) {
|
|
4
|
+
if (typeof error === "string") return error;
|
|
5
|
+
if (error instanceof Error) return error.message ?? String(error);
|
|
6
|
+
try {
|
|
7
|
+
const json = JSON.stringify(error);
|
|
8
|
+
if (typeof json === "string") return json;
|
|
9
|
+
} catch {}
|
|
10
|
+
return String(error);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
//#endregion
|
|
14
|
+
exports.stringifyError = stringifyError;
|
package/lib/cjs/sync.cjs
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
const require__home_runner_work_node_xtry_node_xtry_src_result = require('./result.cjs');
|
|
2
|
+
const require__home_runner_work_node_xtry_node_xtry_src_defer = require('./defer.cjs');
|
|
3
|
+
const require__home_runner_work_node_xtry_node_xtry_src_partial = require('./partial.cjs');
|
|
4
|
+
const require__home_runner_work_node_xtry_node_xtry_src_stringify_error = require('./stringify-error.cjs');
|
|
5
|
+
const require__home_runner_work_node_xtry_node_xtry_src_try = require('./try.cjs');
|
|
6
|
+
|
|
7
|
+
exports.OK = require__home_runner_work_node_xtry_node_xtry_src_result.OK;
|
|
8
|
+
exports.OK_FALSE = require__home_runner_work_node_xtry_node_xtry_src_result.OK_FALSE;
|
|
9
|
+
exports.OK_NULL = require__home_runner_work_node_xtry_node_xtry_src_result.OK_NULL;
|
|
10
|
+
exports.OK_TRUE = require__home_runner_work_node_xtry_node_xtry_src_result.OK_TRUE;
|
|
11
|
+
exports.YOK = require__home_runner_work_node_xtry_node_xtry_src_partial.YOK;
|
|
12
|
+
exports.YOK_FALSE = require__home_runner_work_node_xtry_node_xtry_src_partial.YOK_FALSE;
|
|
13
|
+
exports.YOK_NULL = require__home_runner_work_node_xtry_node_xtry_src_partial.YOK_NULL;
|
|
14
|
+
exports.YOK_TRUE = require__home_runner_work_node_xtry_node_xtry_src_partial.YOK_TRUE;
|
|
15
|
+
exports.err = require__home_runner_work_node_xtry_node_xtry_src_result.err;
|
|
16
|
+
exports.ok = require__home_runner_work_node_xtry_node_xtry_src_result.ok;
|
|
17
|
+
exports.stringifyError = require__home_runner_work_node_xtry_node_xtry_src_stringify_error.stringifyError;
|
|
18
|
+
exports.xdefer = require__home_runner_work_node_xtry_node_xtry_src_defer.xdeferSync;
|
|
19
|
+
exports.xtry = require__home_runner_work_node_xtry_node_xtry_src_try.xtrySync;
|
|
20
|
+
exports.yep = require__home_runner_work_node_xtry_node_xtry_src_partial.yep;
|
|
21
|
+
exports.yerr = require__home_runner_work_node_xtry_node_xtry_src_partial.yerr;
|
|
22
|
+
exports.yok = require__home_runner_work_node_xtry_node_xtry_src_partial.yok;
|
|
23
|
+
exports.yres = require__home_runner_work_node_xtry_node_xtry_src_partial.yresSync;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Failure, OK, OK_FALSE, OK_NULL, OK_TRUE, Result, Success, err, ok } from "./result.cjs";
|
|
2
|
+
import { xdeferSync } from "./defer.cjs";
|
|
3
|
+
import { YFailure, YOK, YOK_FALSE, YOK_NULL, YOK_TRUE, YResult, YSuccess, yep, yerr, yok, yresSync } from "./partial.cjs";
|
|
4
|
+
import { stringifyError } from "./stringify-error.cjs";
|
|
5
|
+
import { xtrySync } from "./try.cjs";
|
|
6
|
+
export { type Failure, OK, OK_FALSE, OK_NULL, OK_TRUE, type Result, type Success, type YFailure, YOK, YOK_FALSE, YOK_NULL, YOK_TRUE, type YResult, type YSuccess, err, ok, stringifyError, xdeferSync as xdefer, xtrySync as xtry, yep, yerr, yok, yresSync as yres };
|
package/lib/cjs/try.cjs
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
const require__home_runner_work_node_xtry_node_xtry_src_result = require('./result.cjs');
|
|
2
|
+
const require__home_runner_work_node_xtry_node_xtry_src_utils_is_promise_like = require('./utils/is-promise-like.cjs');
|
|
3
|
+
|
|
4
|
+
//#region src/try.ts
|
|
5
|
+
function xtry(func, handler) {
|
|
6
|
+
const run = func instanceof Function ? func : () => func;
|
|
7
|
+
const handleError = (error) => {
|
|
8
|
+
if (handler) {
|
|
9
|
+
const newError = handler(error);
|
|
10
|
+
if (newError !== void 0) return require__home_runner_work_node_xtry_node_xtry_src_result.err(newError);
|
|
11
|
+
}
|
|
12
|
+
return require__home_runner_work_node_xtry_node_xtry_src_result.err(error);
|
|
13
|
+
};
|
|
14
|
+
const handleSuccess = (value) => require__home_runner_work_node_xtry_node_xtry_src_result.ok(value);
|
|
15
|
+
try {
|
|
16
|
+
const value = run();
|
|
17
|
+
if (require__home_runner_work_node_xtry_node_xtry_src_utils_is_promise_like.isPromiseLike(value)) return Promise.resolve(value).then(handleSuccess, handleError);
|
|
18
|
+
return require__home_runner_work_node_xtry_node_xtry_src_result.ok(value);
|
|
19
|
+
} catch (error) {
|
|
20
|
+
return handleError(error);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
function xtrySync(func, handler) {
|
|
24
|
+
try {
|
|
25
|
+
const value = func();
|
|
26
|
+
return require__home_runner_work_node_xtry_node_xtry_src_result.ok(value);
|
|
27
|
+
} catch (error) {
|
|
28
|
+
if (handler) {
|
|
29
|
+
const newError = handler(error);
|
|
30
|
+
if (newError !== void 0) return require__home_runner_work_node_xtry_node_xtry_src_result.err(newError);
|
|
31
|
+
}
|
|
32
|
+
return require__home_runner_work_node_xtry_node_xtry_src_result.err(error);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
async function xtryAsync(func, handler) {
|
|
36
|
+
try {
|
|
37
|
+
const value = await (func instanceof Promise ? func : Promise.resolve().then(func));
|
|
38
|
+
return require__home_runner_work_node_xtry_node_xtry_src_result.ok(value);
|
|
39
|
+
} catch (error) {
|
|
40
|
+
if (handler) {
|
|
41
|
+
const newError = handler(error);
|
|
42
|
+
if (newError !== void 0) return require__home_runner_work_node_xtry_node_xtry_src_result.err(newError);
|
|
43
|
+
}
|
|
44
|
+
return require__home_runner_work_node_xtry_node_xtry_src_result.err(error);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
//#endregion
|
|
49
|
+
exports.xtry = xtry;
|
|
50
|
+
exports.xtryAsync = xtryAsync;
|
|
51
|
+
exports.xtrySync = xtrySync;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Result } from "./result.cjs";
|
|
2
|
+
import { NonPromiseCallback, PromiseCallback } from "./utils/types.cjs";
|
|
3
|
+
|
|
4
|
+
//#region src/try.d.ts
|
|
5
|
+
type ErrorHandler<T> = (error: unknown) => T | undefined;
|
|
6
|
+
type VoidableResult<T, E> = E extends void ? Result<T, unknown> : Result<T, E>;
|
|
7
|
+
declare function xtry<T, E = unknown>(func: NonPromiseCallback<T>, handler?: ErrorHandler<E>): VoidableResult<T, E>;
|
|
8
|
+
declare function xtry<T, E = unknown>(func: PromiseCallback<T>, handler?: ErrorHandler<E>): Promise<VoidableResult<T, E>>;
|
|
9
|
+
declare function xtrySync<T, E = unknown>(func: NonPromiseCallback<T>, handler?: ErrorHandler<E>): VoidableResult<T, E>;
|
|
10
|
+
declare function xtryAsync<T, E = unknown>(func: PromiseCallback<T>, handler?: ErrorHandler<E>): Promise<VoidableResult<T, E>>;
|
|
11
|
+
//#endregion
|
|
12
|
+
export { xtry, xtryAsync, xtrySync };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
//#region src/utils/types.d.ts
|
|
2
|
+
type NotPromise<T> = Exclude<T, Promise<unknown>>;
|
|
3
|
+
type NonPromiseCallback<T> = () => NotPromise<T>;
|
|
4
|
+
type PromiseCallback<T> = (() => Promise<T>) | Promise<T>;
|
|
5
|
+
//#endregion
|
|
6
|
+
export { NonPromiseCallback, NotPromise, PromiseCallback };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Failure, OK$1 as OK, OK_FALSE$1 as OK_FALSE, OK_NULL$1 as OK_NULL, OK_TRUE$1 as OK_TRUE, Result, Success, err$1 as err, ok$1 as ok } from "./result.js";
|
|
2
|
+
import { xdeferAsync$1 as xdeferAsync } from "./defer.js";
|
|
3
|
+
import { YFailure, YOK$1 as YOK, YOK_FALSE$1 as YOK_FALSE, YOK_NULL$1 as YOK_NULL, YOK_TRUE$1 as YOK_TRUE, YResult, YSuccess, yep$1 as yep, yerr$1 as yerr, yok$1 as yok, yresAsync$1 as yresAsync } from "./partial.js";
|
|
4
|
+
import { stringifyError$1 as stringifyError } from "./stringify-error.js";
|
|
5
|
+
import { xtryAsync$1 as xtryAsync } from "./try.js";
|
|
6
|
+
export { type Failure, OK, OK_FALSE, OK_NULL, OK_TRUE, type Result, type Success, type YFailure, YOK, YOK_FALSE, YOK_NULL, YOK_TRUE, type YResult, type YSuccess, err, ok, stringifyError, xdeferAsync as xdefer, xtryAsync as xtry, yep, yerr, yok, yresAsync as yres };
|
package/lib/esm/async.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { OK, OK_FALSE, OK_NULL, OK_TRUE, err, ok } from "./result.js";
|
|
2
|
+
import { xdeferAsync } from "./defer.js";
|
|
3
|
+
import { YOK, YOK_FALSE, YOK_NULL, YOK_TRUE, yep, yerr, yok, yresAsync } from "./partial.js";
|
|
4
|
+
import { stringifyError } from "./stringify-error.js";
|
|
5
|
+
import { xtryAsync } from "./try.js";
|
|
6
|
+
|
|
7
|
+
export { OK, OK_FALSE, OK_NULL, OK_TRUE, YOK, YOK_FALSE, YOK_NULL, YOK_TRUE, err, ok, stringifyError, xdeferAsync as xdefer, xtryAsync as xtry, yep, yerr, yok, yresAsync as yres };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Result, Success } from "./result.js";
|
|
2
|
+
import { NonPromiseCallback, PromiseCallback } from "./utils/types.js";
|
|
3
|
+
|
|
4
|
+
//#region src/defer.d.ts
|
|
5
|
+
type DeferAsync<E> = {
|
|
6
|
+
(): Promise<Success<void>>;
|
|
7
|
+
(result: UnknownResult<E>): Promise<UnknownResult<E>>;
|
|
8
|
+
};
|
|
9
|
+
type DeferSync<E> = {
|
|
10
|
+
(): Success<void>;
|
|
11
|
+
(result: UnknownResult<E>): UnknownResult<E>;
|
|
12
|
+
};
|
|
13
|
+
type UnknownResult<E> = Result<unknown, E>;
|
|
14
|
+
declare function xdefer<E>(callback: NonPromiseCallback<UnknownResult<E>>): DeferSync<E>;
|
|
15
|
+
declare function xdefer<E>(callback: PromiseCallback<UnknownResult<E>>): DeferAsync<E>;
|
|
16
|
+
declare function xdeferAsync<E>(callback: PromiseCallback<UnknownResult<E>>): DeferAsync<E>;
|
|
17
|
+
declare function xdeferSync<E>(callback: NonPromiseCallback<UnknownResult<E>>): DeferSync<E>;
|
|
18
|
+
//#endregion
|
|
19
|
+
export { xdefer as xdefer$1, xdeferAsync as xdeferAsync$1, xdeferSync as xdeferSync$1 };
|
package/lib/esm/defer.js
CHANGED
|
@@ -1,45 +1,41 @@
|
|
|
1
|
-
import { ok } from
|
|
2
|
-
import { isPromiseLike } from
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
19
|
-
return finalize(deferredValue);
|
|
20
|
-
});
|
|
1
|
+
import { ok } from "./result.js";
|
|
2
|
+
import { isPromiseLike } from "./utils/is-promise-like.js";
|
|
3
|
+
|
|
4
|
+
//#region src/defer.ts
|
|
5
|
+
function xdefer(callback) {
|
|
6
|
+
return (result) => {
|
|
7
|
+
const finalize = (deferResult) => {
|
|
8
|
+
if (deferResult.fails) {
|
|
9
|
+
if (result?.fails) return result;
|
|
10
|
+
return deferResult;
|
|
11
|
+
}
|
|
12
|
+
return result ?? ok();
|
|
13
|
+
};
|
|
14
|
+
const deferredValue = callback instanceof Function ? callback() : callback;
|
|
15
|
+
if (isPromiseLike(deferredValue)) return Promise.resolve(deferredValue).then(finalize);
|
|
16
|
+
return finalize(deferredValue);
|
|
17
|
+
};
|
|
21
18
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
return result ?? ok();
|
|
32
|
-
});
|
|
19
|
+
function xdeferAsync(callback) {
|
|
20
|
+
return async (result) => {
|
|
21
|
+
const deferResult = await (callback instanceof Promise ? callback : callback());
|
|
22
|
+
if (deferResult.fails) {
|
|
23
|
+
if (result?.fails) return result;
|
|
24
|
+
return deferResult;
|
|
25
|
+
}
|
|
26
|
+
return result ?? ok();
|
|
27
|
+
};
|
|
33
28
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
return result ?? ok();
|
|
44
|
-
});
|
|
29
|
+
function xdeferSync(callback) {
|
|
30
|
+
return (result) => {
|
|
31
|
+
const deferResult = callback();
|
|
32
|
+
if (deferResult.fails) {
|
|
33
|
+
if (result?.fails) return result;
|
|
34
|
+
return deferResult;
|
|
35
|
+
}
|
|
36
|
+
return result ?? ok();
|
|
37
|
+
};
|
|
45
38
|
}
|
|
39
|
+
|
|
40
|
+
//#endregion
|
|
41
|
+
export { xdefer, xdeferAsync, xdeferSync };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Failure, OK$1 as OK, OK_FALSE$1 as OK_FALSE, OK_NULL$1 as OK_NULL, OK_TRUE$1 as OK_TRUE, Result, Success, err$1 as err, ok$1 as ok } from "./result.js";
|
|
2
|
+
import { xdefer$1 as xdefer, xdeferAsync$1 as xdeferAsync, xdeferSync$1 as xdeferSync } from "./defer.js";
|
|
3
|
+
import { YFailure, YOK$1 as YOK, YOK_FALSE$1 as YOK_FALSE, YOK_NULL$1 as YOK_NULL, YOK_TRUE$1 as YOK_TRUE, YResult, YSuccess, yep$1 as yep, yerr$1 as yerr, yok$1 as yok, yres$1 as yres, yresAsync$1 as yresAsync, yresSync$1 as yresSync } from "./partial.js";
|
|
4
|
+
import { stringifyError$1 as stringifyError } from "./stringify-error.js";
|
|
5
|
+
import { xtry$1 as xtry, xtryAsync$1 as xtryAsync, xtrySync$1 as xtrySync } from "./try.js";
|
|
6
|
+
export { type Failure, OK, OK_FALSE, OK_NULL, OK_TRUE, type Result, type Success, type YFailure, YOK, YOK_FALSE, YOK_NULL, YOK_TRUE, type YResult, type YSuccess, err, ok, stringifyError, xdefer, xdeferAsync, xdeferSync, xtry, xtryAsync, xtrySync, yep, yerr, yok, yres, yresAsync, yresSync };
|
package/lib/esm/index.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { OK, OK_FALSE, OK_NULL, OK_TRUE, err, ok } from "./result.js";
|
|
2
|
+
import { xdefer, xdeferAsync, xdeferSync } from "./defer.js";
|
|
3
|
+
import { YOK, YOK_FALSE, YOK_NULL, YOK_TRUE, yep, yerr, yok, yres, yresAsync, yresSync } from "./partial.js";
|
|
4
|
+
import { stringifyError } from "./stringify-error.js";
|
|
5
|
+
import { xtry, xtryAsync, xtrySync } from "./try.js";
|
|
6
|
+
|
|
7
|
+
export { OK, OK_FALSE, OK_NULL, OK_TRUE, YOK, YOK_FALSE, YOK_NULL, YOK_TRUE, err, ok, stringifyError, xdefer, xdeferAsync, xdeferSync, xtry, xtryAsync, xtrySync, yep, yerr, yok, yres, yresAsync, yresSync };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Failure, Result, Success } from "./result.js";
|
|
2
|
+
import { NotPromise } from "./utils/types.js";
|
|
3
|
+
|
|
4
|
+
//#region src/partial.d.ts
|
|
5
|
+
type YResult<T, E, M> = Failure<E> | YSuccess<T> | YFailure<M>;
|
|
6
|
+
type YSuccess<T> = Success<T> & {
|
|
7
|
+
success: true;
|
|
8
|
+
};
|
|
9
|
+
type YFailure<M> = {
|
|
10
|
+
fails: false;
|
|
11
|
+
success: false;
|
|
12
|
+
miscue: M;
|
|
13
|
+
value: undefined;
|
|
14
|
+
error: undefined;
|
|
15
|
+
};
|
|
16
|
+
declare function yok(): YSuccess<void>;
|
|
17
|
+
declare function yok<T>(value: T): YSuccess<T>;
|
|
18
|
+
declare function yerr<M>(miscue: M): YFailure<M>;
|
|
19
|
+
type YRResult<T, E> = Failure<E> | YSuccess<T>;
|
|
20
|
+
declare function yres<T, E>(result: NotPromise<Result<T, E>>): YRResult<T, E>;
|
|
21
|
+
declare function yres<T, E>(result: Promise<Result<T, E>>): Promise<YRResult<T, E>>;
|
|
22
|
+
declare function yresSync<T, E>(result: NotPromise<Result<T, E>>): YRResult<T, E>;
|
|
23
|
+
declare function yresAsync<T, E>(promise: Promise<Result<T, E>>): Promise<YRResult<T, E>>;
|
|
24
|
+
declare function yep<T>(result: Success<T>): YSuccess<T>;
|
|
25
|
+
declare const YOK: Readonly<YSuccess<void>>;
|
|
26
|
+
declare const YOK_NULL: Readonly<YSuccess<any>>;
|
|
27
|
+
declare const YOK_TRUE: Readonly<YSuccess<boolean>>;
|
|
28
|
+
declare const YOK_FALSE: Readonly<YSuccess<boolean>>;
|
|
29
|
+
//#endregion
|
|
30
|
+
export { YFailure, YOK as YOK$1, YOK_FALSE as YOK_FALSE$1, YOK_NULL as YOK_NULL$1, YOK_TRUE as YOK_TRUE$1, YResult, YSuccess, yep as yep$1, yerr as yerr$1, yok as yok$1, yres as yres$1, yresAsync as yresAsync$1, yresSync as yresSync$1 };
|