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.
- package/dist/openapi-ff.cjs +1 -1
- package/dist/openapi-ff.d.cts +10 -2
- package/dist/openapi-ff.d.ts +10 -2
- package/dist/openapi-ff.js +40 -39
- package/package.json +5 -1
package/dist/openapi-ff.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
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;
|
package/dist/openapi-ff.d.cts
CHANGED
|
@@ -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 {}>(
|
|
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
|
-
}
|
|
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";
|
package/dist/openapi-ff.d.ts
CHANGED
|
@@ -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 {}>(
|
|
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
|
-
}
|
|
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";
|
package/dist/openapi-ff.js
CHANGED
|
@@ -1,62 +1,63 @@
|
|
|
1
|
-
import { networkError as
|
|
2
|
-
import { createStore as
|
|
3
|
-
import { mergeHeaders as
|
|
4
|
-
const
|
|
5
|
-
function R(
|
|
6
|
-
var
|
|
7
|
-
return ((
|
|
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(
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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:
|
|
15
|
-
source:
|
|
16
|
-
effect: async (
|
|
17
|
-
let
|
|
18
|
-
|
|
19
|
-
const { data:
|
|
20
|
-
throw
|
|
21
|
-
reason: (
|
|
22
|
-
cause:
|
|
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 (
|
|
26
|
-
throw
|
|
27
|
-
status:
|
|
28
|
-
statusText:
|
|
29
|
-
response:
|
|
26
|
+
if (o != null && o !== "")
|
|
27
|
+
throw F({
|
|
28
|
+
status: n.status,
|
|
29
|
+
statusText: n.statusText,
|
|
30
|
+
response: o
|
|
30
31
|
});
|
|
31
|
-
if (!
|
|
32
|
-
throw
|
|
33
|
-
status:
|
|
34
|
-
statusText:
|
|
32
|
+
if (!n.ok)
|
|
33
|
+
throw q({
|
|
34
|
+
status: n.status,
|
|
35
|
+
statusText: n.statusText,
|
|
35
36
|
response: null
|
|
36
37
|
});
|
|
37
|
-
return
|
|
38
|
+
return C;
|
|
38
39
|
}
|
|
39
40
|
}),
|
|
40
|
-
contract: ((
|
|
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
|
|
45
|
+
function F(e) {
|
|
45
46
|
return {
|
|
46
|
-
...
|
|
47
|
-
errorType:
|
|
47
|
+
...e,
|
|
48
|
+
errorType: P,
|
|
48
49
|
explanation: "Request was finished with unsuccessful API response"
|
|
49
50
|
};
|
|
50
51
|
}
|
|
51
|
-
function _(
|
|
52
|
+
function _(e, a) {
|
|
52
53
|
return {
|
|
53
|
-
...
|
|
54
|
-
headers:
|
|
54
|
+
...e,
|
|
55
|
+
headers: v(e.headers, a)
|
|
55
56
|
};
|
|
56
57
|
}
|
|
57
|
-
function
|
|
58
|
+
function H() {
|
|
58
59
|
return {
|
|
59
|
-
isData: (
|
|
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.
|
|
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",
|