@axman/res 0.0.5 → 0.0.7

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/all.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ import { Res } from './res';
2
+ export declare function all<T extends readonly Res<unknown>[] | []>(results: T): Res<{
3
+ [K in keyof T]: T[K] extends Res<infer U> ? U : never;
4
+ }>;
@@ -0,0 +1 @@
1
+ export {};
@@ -1,3 +1,4 @@
1
+ export * from './all';
1
2
  export * from './match';
2
3
  export * from './res';
3
4
  export * from './unwrap';
package/dist/index.cjs.js CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function t(e,r){const[l,u]=e;return u!==null?r.err(u):r.ok(l)}function o(e){return[e,null]}function n(e){return[null,e]}function c(e){return t(e,{ok:r=>r,err:r=>{throw r}})}function i(e){try{return o(e())}catch(r){return r instanceof Error?n(r):n(new Error(String(r)))}}const a=Object.freeze(Object.defineProperty({__proto__:null,err:n,match:t,ok:o,unwrap:c,wrap:i},Symbol.toStringTag,{value:"Module"}));exports.err=n;exports.match=t;exports.ok=o;exports.res=a;exports.unwrap=c;exports.wrap=i;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function o(n){return[n,null]}function e(n){return[null,n]}function i(n){const r=[];for(const t of n){const[u,c]=t;if(c!==null)return[null,c];r.push(u)}return o(r)}function l(n,r){const[t,u]=n;return u!==null?r.err(u):r.ok(t)}function a(n){return l(n,{ok:r=>r,err:r=>{throw r}})}function f(n){try{const r=n();return r instanceof Promise?r.then(t=>o(t)).catch(t=>t instanceof Error?e(t):e(new Error(String(t)))):o(r)}catch(r){return r instanceof Error?e(r):e(new Error(String(r)))}}const s=Object.freeze(Object.defineProperty({__proto__:null,all:i,err:e,match:l,ok:o,unwrap:a,wrap:f},Symbol.toStringTag,{value:"Module"}));exports.all=i;exports.err=e;exports.match=l;exports.ok=o;exports.res=s;exports.unwrap=a;exports.wrap=f;
package/dist/index.es.js CHANGED
@@ -1,7 +1,3 @@
1
- function o(n, r) {
2
- const [c, t] = n;
3
- return t !== null ? r.err(t) : r.ok(c);
4
- }
5
1
  function u(n) {
6
2
  return [n, null];
7
3
  }
@@ -9,33 +5,50 @@ function e(n) {
9
5
  return [null, n];
10
6
  }
11
7
  function i(n) {
12
- return o(n, {
8
+ const r = [];
9
+ for (const t of n) {
10
+ const [o, c] = t;
11
+ if (c !== null)
12
+ return [null, c];
13
+ r.push(o);
14
+ }
15
+ return u(r);
16
+ }
17
+ function l(n, r) {
18
+ const [t, o] = n;
19
+ return o !== null ? r.err(o) : r.ok(t);
20
+ }
21
+ function f(n) {
22
+ return l(n, {
13
23
  ok: (r) => r,
14
24
  err: (r) => {
15
25
  throw r;
16
26
  }
17
27
  });
18
28
  }
19
- function l(n) {
29
+ function s(n) {
20
30
  try {
21
- return u(n());
31
+ const r = n();
32
+ return r instanceof Promise ? r.then((t) => u(t)).catch((t) => t instanceof Error ? e(t) : e(new Error(String(t)))) : u(r);
22
33
  } catch (r) {
23
34
  return r instanceof Error ? e(r) : e(new Error(String(r)));
24
35
  }
25
36
  }
26
- const f = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
37
+ const a = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
27
38
  __proto__: null,
39
+ all: i,
28
40
  err: e,
29
- match: o,
41
+ match: l,
30
42
  ok: u,
31
- unwrap: i,
32
- wrap: l
43
+ unwrap: f,
44
+ wrap: s
33
45
  }, Symbol.toStringTag, { value: "Module" }));
34
46
  export {
47
+ i as all,
35
48
  e as err,
36
- o as match,
49
+ l as match,
37
50
  u as ok,
38
- f as res,
39
- i as unwrap,
40
- l as wrap
51
+ a as res,
52
+ f as unwrap,
53
+ s as wrap
41
54
  };
package/dist/res.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export type Ok<T> = [T, null];
2
2
  export type Err = [null, Error];
3
3
  export type Res<T> = Ok<T> | Err;
4
+ export declare function ok(): Ok<void>;
4
5
  export declare function ok<T>(value: T): Ok<T>;
5
6
  export declare function err(error: Error): Err;
package/dist/wrap.d.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  import { Res } from './res';
2
+ export declare function wrap<T>(fn: () => Promise<T>): Promise<Res<T>>;
2
3
  export declare function wrap<T>(fn: () => T): Res<T>;
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@axman/res",
3
3
  "author": "akhmanov",
4
- "version": "0.0.5",
4
+ "version": "0.0.7",
5
5
  "description": "Go style Result for TypeScript",
6
6
  "license": "MIT",
7
7
  "private": false,