openapi-ff 0.1.1 → 0.1.3

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/README.md CHANGED
@@ -114,7 +114,11 @@ import { zodContract } from "@farfetched/zod";
114
114
 
115
115
  const { createApiEffectWithContract } = createClient(fetchClient, {
116
116
  createContract(method, path) {
117
- const { response } = (EndpointByMethod as any)[method][path];
117
+ const endpoints = EndpointByMethod[method] as any;
118
+ const response = endpoints[path]?.response;
119
+ if (!response) {
120
+ throw new Error(`Response schema for route "${method} ${path}" doesn't exist`);
121
+ }
118
122
  return zodContract(response);
119
123
  },
120
124
  });
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const p=require("effector"),l=require("@farfetched/core"),h="API";function C(t){return{...t,errorType:h,explanation:"Request was finished with unsuccessful HTTP code"}}function A(t){var e;return((e=t.error)==null?void 0:e.errorType)===h}function g(t,e={}){const u=(s,a,r)=>{const w=s.toUpperCase(),E=t[w];return p.createEffect(async i=>{var f;const{data:T,error:o,response:n}=await E(a,((f=r==null?void 0:r.mapParams)==null?void 0:f.call(r,i))??i).catch(c=>{throw l.networkError({reason:(c==null?void 0:c.message)??null,cause:c})});if(o!=null&&o!=="")throw C({status:n.status,statusText:n.statusText,response:o});if(!n.ok)throw l.httpError({status:n.status,statusText:n.statusText,response:null});return T})};return{createApiEffect:u,createApiEffectWithContract:(s,a,r)=>{if(e.createContract==null)throw new Error("'createContract' is missing in config");return{effect:u(s,a,r),contract:e.createContract(s,a.toString())}}}}exports.createClient=g;exports.isApiError=A;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const p=require("effector"),l=require("@farfetched/core"),h="API";function C(t){return{...t,errorType:h,explanation:"Request was finished with unsuccessful HTTP code"}}function A(t){var e;return((e=t.error)==null?void 0:e.errorType)===h}function m(t,e={}){const u=(s,a,r)=>{const w=s.toUpperCase(),E=t[w];return p.createEffect(async f=>{var i;const{data:T,error:o,response:n}=await E(a,((i=r==null?void 0:r.mapParams)==null?void 0:i.call(r,f))??f).catch(c=>{throw l.networkError({reason:(c==null?void 0:c.message)??null,cause:c})});if(o!=null&&o!=="")throw C({status:n.status,statusText:n.statusText,response:o});if(!n.ok)throw l.httpError({status:n.status,statusText:n.statusText,response:null});return T})};return{createApiEffect:u,createApiEffectWithContract:(s,a,r)=>{if(e.createContract==null)throw new Error("'createContract' is missing in config");return{effect:u(s,a,r),contract:e.createContract(s,a)}}}}exports.createClient=m;exports.isApiError=A;
@@ -29,10 +29,10 @@ declare type CreateApiEffectWithContract<Paths extends Record<string, Record<Htt
29
29
  contract: Contract<unknown, Response["data"]>;
30
30
  };
31
31
 
32
- export declare function createClient<Paths extends {}, Media extends MediaType = MediaType>(client: Client<Paths, Media>, config?: EffectorClientOptions): OpenapiEffectorClient<Paths, Media>;
32
+ export declare function createClient<Paths extends {}, Media extends MediaType = MediaType>(client: Client<Paths, Media>, config?: EffectorClientOptions<Paths>): OpenapiEffectorClient<Paths, Media>;
33
33
 
34
- declare type EffectorClientOptions = {
35
- createContract?: (method: HttpMethod, path: string) => Contract<unknown, unknown>;
34
+ declare type EffectorClientOptions<Paths extends Record<string, Record<HttpMethod, {}>>> = {
35
+ createContract?: <Method extends HttpMethod, Path extends PathsWithMethod<Paths, Method>>(method: Method, path: Path) => Contract<unknown, unknown>;
36
36
  };
37
37
 
38
38
  declare type InitOrPrependInit<Init, PrependInit, Options extends CreateApiEffectOptions<Init>> = Options extends {
@@ -29,10 +29,10 @@ declare type CreateApiEffectWithContract<Paths extends Record<string, Record<Htt
29
29
  contract: Contract<unknown, Response["data"]>;
30
30
  };
31
31
 
32
- export declare function createClient<Paths extends {}, Media extends MediaType = MediaType>(client: Client<Paths, Media>, config?: EffectorClientOptions): OpenapiEffectorClient<Paths, Media>;
32
+ export declare function createClient<Paths extends {}, Media extends MediaType = MediaType>(client: Client<Paths, Media>, config?: EffectorClientOptions<Paths>): OpenapiEffectorClient<Paths, Media>;
33
33
 
34
- declare type EffectorClientOptions = {
35
- createContract?: (method: HttpMethod, path: string) => Contract<unknown, unknown>;
34
+ declare type EffectorClientOptions<Paths extends Record<string, Record<HttpMethod, {}>>> = {
35
+ createContract?: <Method extends HttpMethod, Path extends PathsWithMethod<Paths, Method>>(method: Method, path: Path) => Contract<unknown, unknown>;
36
36
  };
37
37
 
38
38
  declare type InitOrPrependInit<Init, PrependInit, Options extends CreateApiEffectOptions<Init>> = Options extends {
@@ -12,7 +12,7 @@ function P(t) {
12
12
  var e;
13
13
  return ((e = t.error) == null ? void 0 : e.errorType) === l;
14
14
  }
15
- function g(t, e = {}) {
15
+ function y(t, e = {}) {
16
16
  const f = (a, s, r) => {
17
17
  const h = a.toUpperCase(), p = t[h];
18
18
  return m(async (u) => {
@@ -48,12 +48,12 @@ function g(t, e = {}) {
48
48
  throw new Error("'createContract' is missing in config");
49
49
  return {
50
50
  effect: f(a, s, r),
51
- contract: e.createContract(a, s.toString())
51
+ contract: e.createContract(a, s)
52
52
  };
53
53
  }
54
54
  };
55
55
  }
56
56
  export {
57
- g as createClient,
57
+ y as createClient,
58
58
  P as isApiError
59
59
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "openapi-ff",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "license": "MIT",
5
5
  "scripts": {
6
6
  "test": "vitest run --typecheck",