@rest-hooks/endpoint
Advanced tools
Comparing version 0.4.3 to 0.5.0
@@ -6,2 +6,11 @@ # Change Log | ||
## 0.5.0 (2020-07-27) | ||
* feat: Add @rest-hooks/rest package (#375) ([5e5c125](https://github.com/coinbase/rest-hooks/commit/5e5c125)), closes [#375](https://github.com/coinbase/rest-hooks/issues/375) | ||
* feat: Support helper methods ([c3fb075](https://github.com/coinbase/rest-hooks/commit/c3fb075)) | ||
## <small>0.4.3 (2020-07-22)</small> | ||
@@ -8,0 +17,0 @@ |
@@ -93,3 +93,4 @@ /* eslint-disable @typescript-eslint/ban-types */ | ||
E extends EndpointInstance<any, S, any>, | ||
O extends EndpointExtendOptions<K, any, any>, | ||
O extends EndpointExtendOptions<K, any, any> & | ||
Partial<ThisParameterType<E['fetch']>>, | ||
K extends ( | ||
@@ -96,0 +97,0 @@ this: ThisParameterType< |
{ | ||
"name": "@rest-hooks/endpoint", | ||
"version": "0.4.3", | ||
"version": "0.5.0", | ||
"description": "Declarative Network Interface Definitions", | ||
@@ -57,3 +57,3 @@ "sideEffects": false, | ||
}, | ||
"gitHead": "796bad7931b65611c4c4c1532e851e67ea6ad97b" | ||
"gitHead": "85d6b4b1c05ddecfe055008f64184db9b0a6dda2" | ||
} |
@@ -254,2 +254,29 @@ import nock from 'nock'; | ||
describe('helper members', () => { | ||
it('url helper', async () => { | ||
const url = ({ id }: { id: string }) => `/users/${id}`; | ||
const fetchUsers = function ( | ||
this: { url: (params: { id: string }) => string }, | ||
{ id }: { id: string }, | ||
) { | ||
return fetch(this.url({ id })).then(res => res.json()) as Promise< | ||
typeof payload | ||
>; | ||
}; | ||
// @ts-expect-error | ||
new Endpoint(fetchUsers, { url: '' }); | ||
// @ts-expect-error | ||
new Endpoint(fetchUsers, { url }).extend({ url: 'hi' }); | ||
const UserDetail = new Endpoint(fetchUsers, { url }).extend({ url }); | ||
// check return type and call params | ||
const response = await UserDetail({ id: payload.id }); | ||
expect(response).toEqual(payload); | ||
expect(response.username).toBe(payload.username); | ||
// @ts-expect-error | ||
expect(response.notexist).toBeUndefined(); | ||
}); | ||
}); | ||
/*describe('class', () => { | ||
@@ -256,0 +283,0 @@ describe('auth patterns', () => { |
@@ -93,3 +93,4 @@ /* eslint-disable @typescript-eslint/ban-types */ | ||
E extends EndpointInstance<any, S, any>, | ||
O extends EndpointExtendOptions<K, any, any>, | ||
O extends EndpointExtendOptions<K, any, any> & | ||
Partial<ThisParameterType<E['fetch']>>, | ||
K extends ( | ||
@@ -96,0 +97,0 @@ this: ThisParameterType< |
73195
32
1038