@rest-hooks/endpoint
Advanced tools
Comparing version 0.6.1 to 0.7.0
@@ -6,2 +6,11 @@ # Change Log | ||
## 0.7.0 (2020-08-12) | ||
* fix: Only export AbstractInstanceType in type-world (#396) ([131fa45](https://github.com/coinbase/rest-hooks/commit/131fa45)), closes [#396](https://github.com/coinbase/rest-hooks/issues/396) | ||
* feat: Simple AbortController integration (#392) ([899563d](https://github.com/coinbase/rest-hooks/commit/899563d)), closes [#392](https://github.com/coinbase/rest-hooks/issues/392) | ||
## <small>0.6.1 (2020-08-09)</small> | ||
@@ -8,0 +17,0 @@ |
@@ -197,8 +197,2 @@ 'use strict'; | ||
Object.defineProperty(exports, 'AbstractInstanceType', { | ||
enumerable: true, | ||
get: function () { | ||
return normalizr.AbstractInstanceType; | ||
} | ||
}); | ||
Object.defineProperty(exports, 'DELETED', { | ||
@@ -205,0 +199,0 @@ enumerable: true, |
@@ -1,1 +0,1 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@rest-hooks/normalizr")):"function"==typeof define&&define.amd?define(["exports","@rest-hooks/normalizr"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).restHookCore={},e.normalizr)}(this,(function(e,t){"use strict";function n(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function r(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,e.__proto__=t}function o(e){return(o=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function i(e,t){return(i=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function c(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(e){return!1}}function u(e,t,n){return(u=c()?Reflect.construct:function(e,t,n){var r=[null];r.push.apply(r,t);var o=new(Function.bind.apply(e,r));return n&&i(o,n.prototype),o}).apply(null,arguments)}function f(e){var t="function"==typeof Map?new Map:void 0;return(f=function(e){if(null===e||(n=e,-1===Function.toString.call(n).indexOf("[native code]")))return e;var n;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,r)}function r(){return u(e,arguments,o(this).constructor)}return r.prototype=Object.create(e.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),i(r,e)})(e)}function s(e,t){e.type=e.sideEffect?"mutate":"read",e.options=Object.assign({},t),delete e.options.key,delete e.options.schema,delete e.options.sideEffect,delete e.options.fetch,delete e.options.getFetchKey,delete e.options.options,0===Object.keys(e.options).length&&delete e.options,void 0===e.schema&&(e.schema=null)}var p=function(e){function t(t,r){var o;return(o=e.call(this,"return arguments.callee.fetch.apply(arguments.callee, arguments)")||this).getFetchKey=function(e){return o.key(e)},t&&(o.fetch=t),Object.assign(n(o),r),s(n(o),r),o}r(t,e);var o=t.prototype;return o.key=function(e){return this.fetch.name+" "+JSON.stringify(e)},o.extend=function(e){var t=function(e){function t(){return e.apply(this,arguments)||this}return r(t,e),t}(this.constructor);Object.assign(t.prototype,this);var n=new t(e.fetch,e);return s(n,Object.assign({},this.options,e)),n},t}(f(Function)),a=function(){function e(e,t){var n=this;this.getFetchKey=function(e){return n.key(e)},this.schema=e,t&&(this.key=t)}return e.prototype.key=function(e){return JSON.stringify(e)},e}();Object.defineProperty(e,"AbstractInstanceType",{enumerable:!0,get:function(){return t.AbstractInstanceType}}),Object.defineProperty(e,"DELETED",{enumerable:!0,get:function(){return t.DELETED}}),Object.defineProperty(e,"Entity",{enumerable:!0,get:function(){return t.Entity}}),Object.defineProperty(e,"Schema",{enumerable:!0,get:function(){return t.Schema}}),Object.defineProperty(e,"SimpleRecord",{enumerable:!0,get:function(){return t.SimpleRecord}}),Object.defineProperty(e,"denormalize",{enumerable:!0,get:function(){return t.denormalize}}),Object.defineProperty(e,"isEntity",{enumerable:!0,get:function(){return t.isEntity}}),Object.defineProperty(e,"normalize",{enumerable:!0,get:function(){return t.normalize}}),Object.defineProperty(e,"schema",{enumerable:!0,get:function(){return t.schema}}),e.Endpoint=p,e.Index=a,Object.defineProperty(e,"__esModule",{value:!0})})); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@rest-hooks/normalizr")):"function"==typeof define&&define.amd?define(["exports","@rest-hooks/normalizr"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).restHookCore={},e.normalizr)}(this,(function(e,t){"use strict";function n(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function r(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,e.__proto__=t}function o(e){return(o=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function i(e,t){return(i=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function c(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(e){return!1}}function u(e,t,n){return(u=c()?Reflect.construct:function(e,t,n){var r=[null];r.push.apply(r,t);var o=new(Function.bind.apply(e,r));return n&&i(o,n.prototype),o}).apply(null,arguments)}function f(e){var t="function"==typeof Map?new Map:void 0;return(f=function(e){if(null===e||(n=e,-1===Function.toString.call(n).indexOf("[native code]")))return e;var n;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,r)}function r(){return u(e,arguments,o(this).constructor)}return r.prototype=Object.create(e.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),i(r,e)})(e)}function s(e,t){e.type=e.sideEffect?"mutate":"read",e.options=Object.assign({},t),delete e.options.key,delete e.options.schema,delete e.options.sideEffect,delete e.options.fetch,delete e.options.getFetchKey,delete e.options.options,0===Object.keys(e.options).length&&delete e.options,void 0===e.schema&&(e.schema=null)}var p=function(e){function t(t,r){var o;return(o=e.call(this,"return arguments.callee.fetch.apply(arguments.callee, arguments)")||this).getFetchKey=function(e){return o.key(e)},t&&(o.fetch=t),Object.assign(n(o),r),s(n(o),r),o}r(t,e);var o=t.prototype;return o.key=function(e){return this.fetch.name+" "+JSON.stringify(e)},o.extend=function(e){var t=function(e){function t(){return e.apply(this,arguments)||this}return r(t,e),t}(this.constructor);Object.assign(t.prototype,this);var n=new t(e.fetch,e);return s(n,Object.assign({},this.options,e)),n},t}(f(Function)),a=function(){function e(e,t){var n=this;this.getFetchKey=function(e){return n.key(e)},this.schema=e,t&&(this.key=t)}return e.prototype.key=function(e){return JSON.stringify(e)},e}();Object.defineProperty(e,"DELETED",{enumerable:!0,get:function(){return t.DELETED}}),Object.defineProperty(e,"Entity",{enumerable:!0,get:function(){return t.Entity}}),Object.defineProperty(e,"Schema",{enumerable:!0,get:function(){return t.Schema}}),Object.defineProperty(e,"SimpleRecord",{enumerable:!0,get:function(){return t.SimpleRecord}}),Object.defineProperty(e,"denormalize",{enumerable:!0,get:function(){return t.denormalize}}),Object.defineProperty(e,"isEntity",{enumerable:!0,get:function(){return t.isEntity}}),Object.defineProperty(e,"normalize",{enumerable:!0,get:function(){return t.normalize}}),Object.defineProperty(e,"schema",{enumerable:!0,get:function(){return t.schema}}),e.Endpoint=p,e.Index=a,Object.defineProperty(e,"__esModule",{value:!0})})); |
export type { EndpointInterface, ReadEndpoint, MutateEndpoint, IndexInterface, IndexParams, ArrayElement, } from './interface'; | ||
export type { EndpointOptions, EndpointInstance } from './endpoint'; | ||
export type { Normalize, NormalizeNullable, Denormalize, DenormalizeNullable, } from './normal'; | ||
export { normalize, denormalize, schema, AbstractInstanceType, Schema, Entity, isEntity, SimpleRecord, DELETED, } from '@rest-hooks/normalizr'; | ||
export { normalize, denormalize, schema, Schema, Entity, isEntity, SimpleRecord, DELETED, } from '@rest-hooks/normalizr'; | ||
export type { AbstractInstanceType } from '@rest-hooks/normalizr'; | ||
export type { EndpointExtraOptions, FetchFunction, OptimisticUpdateParams, UpdateFunction, SchemaDetail, SchemaList, } from './types'; | ||
@@ -6,0 +7,0 @@ export type { ResolveType, EndpointParam, InferReturn } from './utility'; |
@@ -1,4 +0,4 @@ | ||
export { normalize, denormalize, schema, AbstractInstanceType, Schema, Entity, isEntity, SimpleRecord, DELETED } from '@rest-hooks/normalizr'; | ||
export { normalize, denormalize, schema, Schema, Entity, isEntity, SimpleRecord, DELETED } from '@rest-hooks/normalizr'; | ||
export { default as Endpoint } from './endpoint'; | ||
export { default as Index } from './indexEndpoint'; | ||
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uL3NyYy9pbmRleC50cyJdLCJuYW1lcyI6WyJub3JtYWxpemUiLCJkZW5vcm1hbGl6ZSIsInNjaGVtYSIsIkFic3RyYWN0SW5zdGFuY2VUeXBlIiwiU2NoZW1hIiwiRW50aXR5IiwiaXNFbnRpdHkiLCJTaW1wbGVSZWNvcmQiLCJERUxFVEVEIiwiZGVmYXVsdCIsIkVuZHBvaW50IiwiSW5kZXgiXSwibWFwcGluZ3MiOiJBQWVBLFNBQ0VBLFNBREYsRUFFRUMsV0FGRixFQUdFQyxNQUhGLEVBSUVDLG9CQUpGLEVBS0VDLE1BTEYsRUFNRUMsTUFORixFQU9FQyxRQVBGLEVBUUVDLFlBUkYsRUFTRUMsT0FURixRQVVPLHVCQVZQO0FBcUJBLFNBQVNDLE9BQU8sSUFBSUMsUUFBcEIsUUFBb0MsWUFBcEM7QUFDQSxTQUFTRCxPQUFPLElBQUlFLEtBQXBCLFFBQWlDLGlCQUFqQyIsInNvdXJjZXNDb250ZW50IjpbImV4cG9ydCB0eXBlIHtcbiAgRW5kcG9pbnRJbnRlcmZhY2UsXG4gIFJlYWRFbmRwb2ludCxcbiAgTXV0YXRlRW5kcG9pbnQsXG4gIEluZGV4SW50ZXJmYWNlLFxuICBJbmRleFBhcmFtcyxcb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tzL25vcm1hbGl6cic7XG5leHBvcnQgdHlwZSB7IEFic3RyYWN0SW5zdGFuY2VUeXBlIH0gZnJvbSAnQHJlc3QtaG9va3Mvbm9ybWFsaXpyJztcbmV4cG9ydCB0eXBlIHtcbiAgRW5kcG9pbnRFeHRyYU9wdGlvbnMsXG4gIEZldGNoRnVuY3Rpb24sXG4gIE9wdGltaXN0aWNVcGRhdGVQYXJhbXMsXG4gIFVwZGF0ZUZ1bmN0aW9uLFxuICBTY2hlbWFEZXRhaWwsXG4gIFNjaGVtYUxpc3QsXG59IGZyb20gJy4vdHlwZXMnO1xuZXhwb3J0IHR5cGUgeyBSZXNvbHZlVHlwZSwgRW5kcG9pbnRQYXJhbSwgSW5mZXJSZXR1cm4gfSBmcm9tICcuL3V0aWxpdHknO1xuXG5leHBvcnQgeyBkZWZhdWx0IGFzIEVuZHBvaW50IH0gZnJvbSAnLi9lbmRwb2ludCc7XG5leHBvcnQgeyBkZWZhdWx0IGFzIEluZGV4IH0gZnJvbSAnLi9pbmRleEVuZHBvaW50JztcbiJdfQ== |
{ | ||
"name": "@rest-hooks/endpoint", | ||
"version": "0.6.1", | ||
"version": "0.7.0", | ||
"description": "Declarative Network Interface Definitions", | ||
@@ -57,3 +57,3 @@ "sideEffects": false, | ||
}, | ||
"gitHead": "fd8e457af82610927a6a120e02801f0f59d29150" | ||
"gitHead": "ccbc14d40811b2d0a5f3f9c04a5a6345e1d15e2a" | ||
} |
@@ -397,2 +397,37 @@ import nock from 'nock'; | ||
describe('AbortController', () => { | ||
const url = ({ id }: { id: string }) => `/users/${id}`; | ||
const UserDetail = new Endpoint( | ||
function ({ id }: { id: string }) { | ||
const init: RequestInit = {}; | ||
if (this.signal) { | ||
init.signal = this.signal; | ||
} | ||
return fetch(this.url({ id }), init).then(res => res.json()) as Promise< | ||
typeof payload | ||
>; | ||
}, | ||
{ | ||
url, | ||
signal: undefined as AbortSignal | undefined, | ||
}, | ||
); | ||
it('should work without signal', async () => { | ||
const user = await UserDetail({ id: payload.id }); | ||
expect(user.username).toBe(payload.username); | ||
}); | ||
it('should reject when aborted', () => { | ||
const abort = new AbortController(); | ||
const AbortUser = UserDetail.extend({ signal: abort.signal }); | ||
expect(async () => { | ||
const promise = AbortUser({ id: payload.id }); | ||
abort.abort(); | ||
return await promise; | ||
}).rejects.toMatchInlineSnapshot(`[AbortError: Aborted]`); | ||
}); | ||
}); | ||
describe('class', () => { | ||
@@ -399,0 +434,0 @@ /*class ResourceEndpoint< |
@@ -20,3 +20,2 @@ export type { | ||
schema, | ||
AbstractInstanceType, | ||
Schema, | ||
@@ -28,2 +27,3 @@ Entity, | ||
} from '@rest-hooks/normalizr'; | ||
export type { AbstractInstanceType } from '@rest-hooks/normalizr'; | ||
export type { | ||
@@ -30,0 +30,0 @@ EndpointExtraOptions, |
Sorry, the diff of this file is not supported yet
92266
1385