openapi-ff 0.2.1 → 0.2.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.
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("@farfetched/core"),P=require("effector"),I=require("openapi-fetch"),g="API";function p(t){var r;return((r=t.error)==null?void 0:r.errorType)===g}function y(t,r){return{createApiEffect:(f,o,e)=>{var h,E;const w=f.toUpperCase(),x=t[w],A=((h=e==null?void 0:e.mapParams)==null?void 0:h.source)??P.createStore(null),i=!!(e!=null&&e.mapParams),l=!!(e!=null&&e.mapParams.fn),m=i?l?e.mapParams.fn:e.mapParams:null;return{effect:P.attach({source:A,effect:async(T,c)=>{let s=c;i&&(l?s=m(T,c):s=m(c));const{data:q,error:u,response:a}=await x(o,s).catch(n=>{throw d.networkError({reason:(n==null?void 0:n.message)??null,cause:n})});if(u!=null&&u!=="")throw C({status:a.status,statusText:a.statusText,response:u});if(!a.ok)throw d.httpError({status:a.status,statusText:a.statusText,response:null});return q}}),contract:((E=r==null?void 0:r.createContract)==null?void 0:E.call(r,f,o))??F()}}}}function C(t){return{...t,errorType:g,explanation:"Request was finished with unsuccessful API response"}}function S(t,r){return{...t,headers:I.mergeHeaders(t.headers,r)}}function F(){return{isData:t=>!0,getErrorMessages:()=>[]}}exports.createEffectorClient=y;exports.isApiError=p;exports.mergeInitHeaders=S;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const w=require("@farfetched/core"),q=require("effector"),i=require("openapi-fetch"),x="API";function p(e){var a;return((a=e.error)==null?void 0:a.errorType)===x}function S(e,a){let s,t;return e===void 0?(s=i(),t=void 0):typeof e=="object"&&"request"in e?(s=e,t=a):(s=i(),t=e),{createApiEffect:(l,m,r)=>{var P,g;const A=l.toUpperCase(),T=s[A],y=((P=r==null?void 0:r.mapParams)==null?void 0:P.source)??q.createStore(null),d=!!(r!=null&&r.mapParams),h=!!(r!=null&&r.mapParams.fn),E=d?h?r.mapParams.fn:r.mapParams:null;return{effect:q.attach({source:y,effect:async(C,u)=>{let o=u;d&&(h?o=E(C,u):o=E(u));const{data:I,error:f,response:n}=await T(m,o).catch(c=>{throw w.networkError({reason:(c==null?void 0:c.message)??null,cause:c})});if(f!=null&&f!=="")throw b({status:n.status,statusText:n.statusText,response:f});if(!n.ok)throw w.httpError({status:n.status,statusText:n.statusText,response:null});return I}}),contract:((g=t==null?void 0:t.createContract)==null?void 0:g.call(t,l,m))??H()}}}}function b(e){return{...e,errorType:x,explanation:"Request was finished with unsuccessful API response"}}function v(e,a){return{...e,headers:i.mergeHeaders(e.headers,a)}}function H(){return{isData:e=>!0,getErrorMessages:()=>[]}}exports.createEffectorClient=S;exports.isApiError=p;exports.mergeInitHeaders=v;
@@ -53,9 +53,17 @@ declare type CreateApiEffect<Paths extends Record<string, Record<HttpMethod, {}>
53
53
  };
54
54
  };
55
55
 
56
- export declare function createEffectorClient<Paths extends {}>(client: Client<Paths>, options?: {
56
+ export declare function createEffectorClient<Paths extends {}>(): OpenapiEffectorClient<Paths>;
57
+
58
+ export declare function createEffectorClient<Paths extends {}>(client: Client<Paths>): OpenapiEffectorClient<Paths>;
59
+
60
+ export declare function createEffectorClient<Paths extends {}>(client: Client<Paths>, options: EffectorClientOptions<Paths>): OpenapiEffectorClient<Paths>;
61
+
62
+ export declare function createEffectorClient<Paths extends {}>(options: EffectorClientOptions<Paths>): OpenapiEffectorClient<Paths>;
63
+
64
+ declare type EffectorClientOptions<Paths extends {}> = {
57
65
  createContract?: <Method extends HttpMethod, Path extends PathsWithMethod<Paths, Method>>(method: Method, path: Path) => Contract<unknown, unknown>;
58
- }): OpenapiEffectorClient<Paths>;
66
+ };
59
67
 
60
68
  /** 2XX statuses */
61
69
  declare type ErrorStatus = 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 510 | 511 | '5XX' | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 420 | 421 | 422 | 423 | 424 | 425 | 426 | 427 | 428 | 429 | 430 | 431 | 444 | 450 | 451 | 497 | 498 | 499 | '4XX' | "default";
@@ -53,9 +53,17 @@ declare type CreateApiEffect<Paths extends Record<string, Record<HttpMethod, {}>
53
53
  };
54
54
  };
55
55
 
56
- export declare function createEffectorClient<Paths extends {}>(client: Client<Paths>, options?: {
56
+ export declare function createEffectorClient<Paths extends {}>(): OpenapiEffectorClient<Paths>;
57
+
58
+ export declare function createEffectorClient<Paths extends {}>(client: Client<Paths>): OpenapiEffectorClient<Paths>;
59
+
60
+ export declare function createEffectorClient<Paths extends {}>(client: Client<Paths>, options: EffectorClientOptions<Paths>): OpenapiEffectorClient<Paths>;
61
+
62
+ export declare function createEffectorClient<Paths extends {}>(options: EffectorClientOptions<Paths>): OpenapiEffectorClient<Paths>;
63
+
64
+ declare type EffectorClientOptions<Paths extends {}> = {
57
65
  createContract?: <Method extends HttpMethod, Path extends PathsWithMethod<Paths, Method>>(method: Method, path: Path) => Contract<unknown, unknown>;
58
- }): OpenapiEffectorClient<Paths>;
66
+ };
59
67
 
60
68
  /** 2XX statuses */
61
69
  declare type ErrorStatus = 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 510 | 511 | '5XX' | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 420 | 421 | 422 | 423 | 424 | 425 | 426 | 427 | 428 | 429 | 430 | 431 | 444 | 450 | 451 | 497 | 498 | 499 | '4XX' | "default";
@@ -1,62 +1,63 @@
1
- import { networkError as g, httpError as p } from "@farfetched/core";
2
- import { createStore as I, attach as C } from "effector";
3
- import { mergeHeaders as q } from "openapi-fetch";
4
- const x = "API";
5
- function R(t) {
6
- var e;
7
- return ((e = t.error) == null ? void 0 : e.errorType) === x;
1
+ import { networkError as I, httpError as q } from "@farfetched/core";
2
+ import { createStore as y, attach as k } from "effector";
3
+ import E, { mergeHeaders as v } from "openapi-fetch";
4
+ const P = "API";
5
+ function R(e) {
6
+ var a;
7
+ return ((a = e.error) == null ? void 0 : a.errorType) === P;
8
8
  }
9
- function U(t, e) {
10
- return { createApiEffect: (f, m, r) => {
11
- var h, w;
12
- const E = f.toUpperCase(), P = t[E], d = ((h = r == null ? void 0 : r.mapParams) == null ? void 0 : h.source) ?? I(null), o = !!(r != null && r.mapParams), l = !!(r != null && r.mapParams.fn), i = o ? l ? r.mapParams.fn : r.mapParams : null;
9
+ function U(e, a) {
10
+ let s, t;
11
+ return e === void 0 ? (s = E(), t = void 0) : typeof e == "object" && "request" in e ? (s = e, t = a) : (s = E(), t = e), { createApiEffect: (m, i, r) => {
12
+ var w, x;
13
+ const p = m.toUpperCase(), A = s[p], T = ((w = r == null ? void 0 : r.mapParams) == null ? void 0 : w.source) ?? y(null), l = !!(r != null && r.mapParams), h = !!(r != null && r.mapParams.fn), d = l ? h ? r.mapParams.fn : r.mapParams : null;
13
14
  return {
14
- effect: C({
15
- source: d,
16
- effect: async (A, s) => {
17
- let c = s;
18
- o && (l ? c = i(A, s) : c = i(s));
19
- const { data: T, error: u, response: a } = await P(m, c).catch((n) => {
20
- throw g({
21
- reason: (n == null ? void 0 : n.message) ?? null,
22
- cause: n
15
+ effect: k({
16
+ source: T,
17
+ effect: async (g, u) => {
18
+ let f = u;
19
+ l && (h ? f = d(g, u) : f = d(u));
20
+ const { data: C, error: o, response: n } = await A(i, f).catch((c) => {
21
+ throw I({
22
+ reason: (c == null ? void 0 : c.message) ?? null,
23
+ cause: c
23
24
  });
24
25
  });
25
- if (u != null && u !== "")
26
- throw y({
27
- status: a.status,
28
- statusText: a.statusText,
29
- response: u
26
+ if (o != null && o !== "")
27
+ throw F({
28
+ status: n.status,
29
+ statusText: n.statusText,
30
+ response: o
30
31
  });
31
- if (!a.ok)
32
- throw p({
33
- status: a.status,
34
- statusText: a.statusText,
32
+ if (!n.ok)
33
+ throw q({
34
+ status: n.status,
35
+ statusText: n.statusText,
35
36
  response: null
36
37
  });
37
- return T;
38
+ return C;
38
39
  }
39
40
  }),
40
- contract: ((w = e == null ? void 0 : e.createContract) == null ? void 0 : w.call(e, f, m)) ?? k()
41
+ contract: ((x = t == null ? void 0 : t.createContract) == null ? void 0 : x.call(t, m, i)) ?? H()
41
42
  };
42
43
  } };
43
44
  }
44
- function y(t) {
45
+ function F(e) {
45
46
  return {
46
- ...t,
47
- errorType: x,
47
+ ...e,
48
+ errorType: P,
48
49
  explanation: "Request was finished with unsuccessful API response"
49
50
  };
50
51
  }
51
- function _(t, e) {
52
+ function _(e, a) {
52
53
  return {
53
- ...t,
54
- headers: q(t.headers, e)
54
+ ...e,
55
+ headers: v(e.headers, a)
55
56
  };
56
57
  }
57
- function k() {
58
+ function H() {
58
59
  return {
59
- isData: (t) => !0,
60
+ isData: (e) => !0,
60
61
  getErrorMessages: () => []
61
62
  };
62
63
  }
package/package.json CHANGED
@@ -1,7 +1,11 @@
1
1
  {
2
2
  "name": "openapi-ff",
3
- "version": "0.2.1",
3
+ "version": "0.2.2",
4
4
  "license": "MIT",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "https://github.com/borolgs/openapi-ff.git"
8
+ },
5
9
  "scripts": {
6
10
  "test": "vitest run --typecheck",
7
11
  "build": "vite build",