@mkvlrn/result 6.0.1 → 6.0.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/build/index.d.ts +8 -9
- package/build/index.js +20 -36
- package/build/index.js.map +1 -1
- package/package.json +1 -1
package/build/index.d.ts
CHANGED
|
@@ -1,23 +1,22 @@
|
|
|
1
1
|
//#region src/index.d.ts
|
|
2
|
-
type
|
|
2
|
+
type ResultSync<T, E extends Error> = {
|
|
3
3
|
readonly isError: false;
|
|
4
4
|
readonly value: T;
|
|
5
5
|
} | {
|
|
6
6
|
readonly isError: true;
|
|
7
7
|
readonly error: E;
|
|
8
8
|
};
|
|
9
|
-
declare const ok: <T>(value: T) => SyncResult<T, never>;
|
|
10
|
-
declare const err: <E extends Error>(error: E) => SyncResult<never, E>;
|
|
11
|
-
type ResultSync<T, E extends Error> = SyncResult<T, E>;
|
|
12
9
|
declare const ResultSync: {
|
|
13
|
-
ok: typeof ok;
|
|
14
|
-
err: typeof err;
|
|
10
|
+
readonly ok: typeof ok;
|
|
11
|
+
readonly err: typeof err;
|
|
15
12
|
};
|
|
16
|
-
type ResultAsync<T, E extends Error> = Promise<
|
|
13
|
+
type ResultAsync<T, E extends Error> = Promise<ResultSync<T, E>>;
|
|
17
14
|
declare const ResultAsync: {
|
|
18
|
-
ok: typeof ok;
|
|
19
|
-
err: typeof err;
|
|
15
|
+
readonly ok: typeof ok;
|
|
16
|
+
readonly err: typeof err;
|
|
20
17
|
};
|
|
18
|
+
declare function ok<T>(value: T): ResultSync<T, never>;
|
|
19
|
+
declare function err<E extends Error>(error: E): ResultSync<never, E>;
|
|
21
20
|
//#endregion
|
|
22
21
|
export { ResultAsync, ResultSync };
|
|
23
22
|
//# sourceMappingURL=index.d.ts.map
|
package/build/index.js
CHANGED
|
@@ -1,50 +1,34 @@
|
|
|
1
1
|
//#region src/index.ts
|
|
2
|
+
const ResultSync = {
|
|
3
|
+
ok,
|
|
4
|
+
err
|
|
5
|
+
};
|
|
6
|
+
const ResultAsync = {
|
|
7
|
+
ok,
|
|
8
|
+
err
|
|
9
|
+
};
|
|
2
10
|
/**
|
|
3
11
|
* Creates a successful Result with the given value.
|
|
4
12
|
* @param value The success value
|
|
5
13
|
* @returns A Result object representing success
|
|
6
14
|
*/
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
15
|
+
function ok(value) {
|
|
16
|
+
return {
|
|
17
|
+
isError: false,
|
|
18
|
+
value
|
|
19
|
+
};
|
|
20
|
+
}
|
|
11
21
|
/**
|
|
12
22
|
* Creates an error Result with the given error.
|
|
13
23
|
* @param error The error value
|
|
14
24
|
* @returns A Result object representing error
|
|
15
25
|
*/
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
* Creates a successful Result with the given value.
|
|
23
|
-
* @param value The success value
|
|
24
|
-
* @returns A Result object representing success
|
|
25
|
-
*/
|
|
26
|
-
ok,
|
|
27
|
-
/**
|
|
28
|
-
* Creates an error Result with the given error.
|
|
29
|
-
* @param error The error value
|
|
30
|
-
* @returns A Result object representing error
|
|
31
|
-
*/
|
|
32
|
-
err
|
|
33
|
-
};
|
|
34
|
-
const ResultAsync = {
|
|
35
|
-
/**
|
|
36
|
-
* Creates a successful Result with the given value.
|
|
37
|
-
* @param value The success value
|
|
38
|
-
* @returns A Result object representing success
|
|
39
|
-
*/
|
|
40
|
-
ok,
|
|
41
|
-
/**
|
|
42
|
-
* Creates an error Result with the given error.
|
|
43
|
-
* @param error The error value
|
|
44
|
-
* @returns A Result object representing error
|
|
45
|
-
*/
|
|
46
|
-
err
|
|
47
|
-
};
|
|
26
|
+
function err(error) {
|
|
27
|
+
return {
|
|
28
|
+
isError: true,
|
|
29
|
+
error
|
|
30
|
+
};
|
|
31
|
+
}
|
|
48
32
|
//#endregion
|
|
49
33
|
export { ResultAsync, ResultSync };
|
|
50
34
|
|
package/build/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["/**\n * Result type to represent the synchronous outcome of an operation.\n * It can either be a success with a value or an error.\n *\n * It is also an object containing the ok and err functions to\n * make it easier to create Result objects.\n */\nexport type ResultSync<T, E extends Error> =\n | { readonly isError: false; readonly value: T }\n | { readonly isError: true; readonly error: E };\n\nexport const ResultSync = { ok, err } as const;\n\n/**\n * Async version of Result type that wraps a Result in a Promise.\n *\n * It is also an object containing the ok and err functions to\n * make it easier to create Result objects for async workflows.\n */\nexport type ResultAsync<T, E extends Error> = Promise<ResultSync<T, E>>;\n\nexport const ResultAsync = { ok, err } as const;\n\n/**\n * Creates a successful Result with the given value.\n * @param value The success value\n * @returns A Result object representing success\n */\nfunction ok<T>(value: T): ResultSync<T, never> {\n return { isError: false, value };\n}\n\n/**\n * Creates an error Result with the given error.\n * @param error The error value\n * @returns A Result object representing error\n */\nfunction err<E extends Error>(error: E): ResultSync<never, E> {\n return { isError: true, error };\n}\n"],"mappings":";AAWA,MAAa,aAAa;CAAE;CAAI;AAAI;AAUpC,MAAa,cAAc;CAAE;CAAI;AAAI;;;;;;AAOrC,SAAS,GAAM,OAAgC;CAC7C,OAAO;EAAE,SAAS;EAAO;CAAM;AACjC;;;;;;AAOA,SAAS,IAAqB,OAAgC;CAC5D,OAAO;EAAE,SAAS;EAAM;CAAM;AAChC"}
|