@mkvlrn/result 6.0.0 → 6.0.1

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.
@@ -0,0 +1,23 @@
1
+ //#region src/index.d.ts
2
+ type SyncResult<T, E extends Error> = {
3
+ readonly isError: false;
4
+ readonly value: T;
5
+ } | {
6
+ readonly isError: true;
7
+ readonly error: E;
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
+ declare const ResultSync: {
13
+ ok: typeof ok;
14
+ err: typeof err;
15
+ };
16
+ type ResultAsync<T, E extends Error> = Promise<SyncResult<T, E>>;
17
+ declare const ResultAsync: {
18
+ ok: typeof ok;
19
+ err: typeof err;
20
+ };
21
+ //#endregion
22
+ export { ResultAsync, ResultSync };
23
+ //# sourceMappingURL=index.d.ts.map
package/build/index.js ADDED
@@ -0,0 +1,51 @@
1
+ //#region src/index.ts
2
+ /**
3
+ * Creates a successful Result with the given value.
4
+ * @param value The success value
5
+ * @returns A Result object representing success
6
+ */
7
+ const ok = (value) => ({
8
+ isError: false,
9
+ value
10
+ });
11
+ /**
12
+ * Creates an error Result with the given error.
13
+ * @param error The error value
14
+ * @returns A Result object representing error
15
+ */
16
+ const err = (error) => ({
17
+ isError: true,
18
+ error
19
+ });
20
+ const ResultSync = {
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
+ };
48
+ //#endregion
49
+ export { ResultAsync, ResultSync };
50
+
51
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["type SyncResult<T, E extends Error> =\n | { readonly isError: false; readonly value: T }\n | { readonly isError: true; readonly error: E };\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 */\nconst ok = <T>(value: T): SyncResult<T, never> => ({\n isError: false,\n 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 */\nconst err = <E extends Error>(error: E): SyncResult<never, E> => ({\n isError: true,\n error,\n});\n\n/**\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> = SyncResult<T, E>;\n\nexport const ResultSync = {\n /**\n * Creates a successful Result with the given value.\n * @param value The success value\n * @returns A Result object representing success\n */\n ok,\n /**\n * Creates an error Result with the given error.\n * @param error The error value\n * @returns A Result object representing error\n */\n err,\n};\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<SyncResult<T, E>>;\n\nexport const ResultAsync = {\n /**\n * Creates a successful Result with the given value.\n * @param value The success value\n * @returns A Result object representing success\n */\n ok,\n /**\n * Creates an error Result with the given error.\n * @param error The error value\n * @returns A Result object representing error\n */\n err,\n};\n"],"mappings":";;;;;;AASA,MAAM,MAAS,WAAoC;CACjD,SAAS;CACT;AACF;;;;;;AAOA,MAAM,OAAwB,WAAoC;CAChE,SAAS;CACT;AACF;AAWA,MAAa,aAAa;;;;;;CAMxB;;;;;;CAMA;AACF;AAUA,MAAa,cAAc;;;;;;CAMzB;;;;;;CAMA;AACF"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@mkvlrn/result",
3
3
  "description": "Simple Result type/pattern for TypeScript",
4
- "version": "6.0.0",
4
+ "version": "6.0.1",
5
5
  "license": "MIT",
6
6
  "type": "module",
7
7
  "author": "Mike Valeriano <mkvlrn@gmail.com>",
@@ -34,5 +34,8 @@
34
34
  "tsdown": "0.22.14",
35
35
  "typescript": "^7.0.2",
36
36
  "vitest": "^4.1.10"
37
+ },
38
+ "scripts": {
39
+ "build": "tsdown"
37
40
  }
38
41
  }