@rest-hooks/endpoint
Advanced tools
Comparing version 0.3.2 to 0.4.0
@@ -6,2 +6,14 @@ # Change Log | ||
## 0.4.0 (2020-07-14) | ||
* enhance: Resource uses endpoint (#365) ([4472106](https://github.com/coinbase/rest-hooks/commit/4472106)), closes [#365](https://github.com/coinbase/rest-hooks/issues/365) | ||
### BREAKING CHANGE | ||
* getFetchOptions() -> getEndpointExtra() | ||
## <small>0.3.2 (2020-07-14)</small> | ||
@@ -8,0 +20,0 @@ |
@@ -121,2 +121,11 @@ 'use strict'; | ||
_this.type = _this.sideEffect ? 'mutate' : 'read'; | ||
_this.options = Object.assign({}, options); | ||
delete _this.options.key; | ||
delete _this.options.schema; | ||
delete _this.options.sideEffect; | ||
if (Object.keys(_this.options).length === 0) { | ||
delete _this.options; | ||
} | ||
return _this; | ||
@@ -134,3 +143,13 @@ } | ||
var optionsToPass = Object.assign({}, this, options); | ||
/** The following is for compatibility with FetchShape */ | ||
var optionsCopy = Object.assign({}, options); | ||
delete optionsCopy.key; | ||
delete optionsCopy.schema; | ||
delete optionsCopy.sideEffect; | ||
var optionsToPass = Object.assign({}, this, options, { | ||
/** The following is for compatibility with FetchShape */ | ||
options: Object.assign({}, this.options, { | ||
optionsCopy: optionsCopy | ||
}) | ||
}); | ||
return new this.constructor((_options$fetch = options.fetch) != null ? _options$fetch : this.fetch, optionsToPass); | ||
@@ -137,0 +156,0 @@ } |
@@ -1,1 +0,1 @@ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t=t||self).restHookCore={})}(this,(function(t){"use strict";function e(t){return(e=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function n(t,e){return(n=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function r(){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(t){return!1}}function o(t,e,u){return(o=r()?Reflect.construct:function(t,e,r){var o=[null];o.push.apply(o,e);var u=new(Function.bind.apply(t,o));return r&&n(u,r.prototype),u}).apply(null,arguments)}function u(t){var r="function"==typeof Map?new Map:void 0;return(u=function(t){if(null===t||(u=t,-1===Function.toString.call(u).indexOf("[native code]")))return t;var u;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==r){if(r.has(t))return r.get(t);r.set(t,c)}function c(){return o(t,arguments,e(this).constructor)}return c.prototype=Object.create(t.prototype,{constructor:{value:c,enumerable:!1,writable:!0,configurable:!0}}),n(c,t)})(t)}var c=function(t){var e,n;function r(e,n){var r;return(r=t.call(this,"return arguments.callee.fetch.apply(arguments.callee, arguments)")||this).schema=null,r.getFetchKey=function(t){return r.key(t)},r.fetch=e,Object.assign(function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(r),n),r.type=r.sideEffect?"mutate":"read",r}n=t,(e=r).prototype=Object.create(n.prototype),e.prototype.constructor=e,e.__proto__=n;var o=r.prototype;return o.key=function(t){return this.fetch.name+" "+JSON.stringify(t)},o.extend=function(t){var e,n=Object.assign({},this,t);return new this.constructor(null!=(e=t.fetch)?e:this.fetch,n)},r}(u(Function)),i=function(){function t(t,e){this.schema=t,e&&(this.key=e)}return t.prototype.key=function(t){return JSON.stringify(t)},t}();t.Endpoint=c,t.Index=i,Object.defineProperty(t,"__esModule",{value:!0})})); | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t=t||self).restHookCore={})}(this,(function(t){"use strict";function e(t){return(e=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function n(t,e){return(n=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function o(){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(t){return!1}}function r(t,e,i){return(r=o()?Reflect.construct:function(t,e,o){var r=[null];r.push.apply(r,e);var i=new(Function.bind.apply(t,r));return o&&n(i,o.prototype),i}).apply(null,arguments)}function i(t){var o="function"==typeof Map?new Map:void 0;return(i=function(t){if(null===t||(i=t,-1===Function.toString.call(i).indexOf("[native code]")))return t;var i;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==o){if(o.has(t))return o.get(t);o.set(t,c)}function c(){return r(t,arguments,e(this).constructor)}return c.prototype=Object.create(t.prototype,{constructor:{value:c,enumerable:!1,writable:!0,configurable:!0}}),n(c,t)})(t)}var c=function(t){var e,n;function o(e,n){var o;return(o=t.call(this,"return arguments.callee.fetch.apply(arguments.callee, arguments)")||this).schema=null,o.getFetchKey=function(t){return o.key(t)},o.fetch=e,Object.assign(function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(o),n),o.type=o.sideEffect?"mutate":"read",o.options=Object.assign({},n),delete o.options.key,delete o.options.schema,delete o.options.sideEffect,0===Object.keys(o.options).length&&delete o.options,o}n=t,(e=o).prototype=Object.create(n.prototype),e.prototype.constructor=e,e.__proto__=n;var r=o.prototype;return r.key=function(t){return this.fetch.name+" "+JSON.stringify(t)},r.extend=function(t){var e,n=Object.assign({},t);delete n.key,delete n.schema,delete n.sideEffect;var o=Object.assign({},this,t,{options:Object.assign({},this.options,{optionsCopy:n})});return new this.constructor(null!=(e=t.fetch)?e:this.fetch,o)},o}(i(Function)),u=function(){function t(t,e){this.schema=t,e&&(this.key=e)}return t.prototype.key=function(t){return JSON.stringify(t)},t}();t.Endpoint=c,t.Index=u,Object.defineProperty(t,"__esModule",{value:!0})})); |
@@ -124,3 +124,4 @@ /* eslint-disable @typescript-eslint/ban-types */ | ||
readonly type: M extends undefined ? 'read' : 'mutate'; | ||
getFetchKey(...args: Parameters<F>): string; | ||
getFetchKey(params: Parameters<F>[0]): string; | ||
options?: EndpointExtraOptions; | ||
} | ||
@@ -127,0 +128,0 @@ |
@@ -15,2 +15,10 @@ export default class Endpoint extends Function { | ||
this.type = this.sideEffect ? 'mutate' : 'read'; | ||
this.options = Object.assign({}, options); | ||
delete this.options.key; | ||
delete this.options.schema; | ||
delete this.options.sideEffect; | ||
if (Object.keys(this.options).length === 0) { | ||
delete this.options; | ||
} | ||
} | ||
@@ -25,3 +33,13 @@ | ||
const optionsToPass = Object.assign({}, this, options); | ||
/** The following is for compatibility with FetchShape */ | ||
const optionsCopy = Object.assign({}, options); | ||
delete optionsCopy.key; | ||
delete optionsCopy.schema; | ||
delete optionsCopy.sideEffect; | ||
const optionsToPass = Object.assign({}, this, options, { | ||
/** The following is for compatibility with FetchShape */ | ||
options: Object.assign({}, this.options, { | ||
optionsCopy | ||
}) | ||
}); | ||
return new this.constructor((_options$fetch = options.fetch) != null ? _options$fetch : this.fetch, optionsToPass); | ||
@@ -33,2 +51,2 @@ } | ||
} | ||
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uL3NyYy9lbmRwb2ludC5qcyJdLCJuYW1lcyI6WyJFbmRwb2ludCIsIkZ1bmN0aW9uIiwiY29uc3RydWN0b3IiLCJmZXRjaEZ1bmN0aW9uIiwib3B0aW9ucyIsInNjaGVtYSIsImdldEZldGNoS2V5IiwicGFyYW1zIiwia2V5IiwiZmV0Y2giLCJPYmplY3QiLCJhc3NpZ24iLCJ0eXBlIiwic2lkZUVmZmVjdCIsIm5hbWUiLCJKU09OIiwic3RyaW5naWZ5IiwiZXh0ZW5kIiwib3B0aW9uc1RvUGFzcyJdLCJtYXBwaW5ncyI6IkFBQUEsZUFBZSxNQUFNQSxRQUFOLFNBQXVCQyxRQUF2QixDQUFnQztBQUM3Q0MsRUFBQUEsV0FBVyxDQUFDQyxhQUFELEVBQWdCQyxPQUFoQixFQUF5QjtBQUNs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XcgdGhpcy5jb25zdHJ1Y3RvcihvcHRpb25zLmZldGNoID8/IHRoaXMuZmV0Y2gsIG9wdGlvbnNUb1Bhc3MpO1xuICB9XG5cbiAgLyoqIFRoZSBmb2xsb3dpbmcgaXMgZm9yIGNvbXBhdGliaWxpdHkgd2l0aCBGZXRjaFNoYXBlICovXG4gIHNjaGVtYSA9IG51bGw7XG4gIGdldEZldGNoS2V5ID0gcGFyYW1zID0+IHtcbiAgICByZXR1cm4gdGhpcy5rZXkocGFyYW1zKTtcbiAgfTtcbn1cbiJdfQ== |
export type { EndpointInterface, ReadEndpoint, MutateEndpoint, IndexInterface, IndexParams, ArrayElement, } from './interface'; | ||
export type { EndpointOptions } from './endpoint'; | ||
export type { EndpointOptions, EndpointInstance, ExtendEndpoint, } from './endpoint'; | ||
export type { EndpointExtraOptions, FetchFunction, OptimisticUpdateParams, UpdateFunction, } from './types'; | ||
export type { ResolveType, InferReturn } from './utility'; | ||
export type { ResolveType, EndpointParam, InferReturn } from './utility'; | ||
export { default as Endpoint } from './endpoint'; | ||
export { default as Index } from './indexEndpoint'; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -1,8 +0,8 @@ | ||
import { Entity } from '@rest-hooks/normalizr'; | ||
import { Schema } from '@rest-hooks/normalizr'; | ||
import type { IndexInterface, IndexParams } from './interface'; | ||
export default class Index<E extends typeof Entity> implements IndexInterface<E> { | ||
schema: E; | ||
constructor(entity: E); | ||
key(params?: Readonly<IndexParams<E>>): string; | ||
export default class Index<S extends Schema, P = Readonly<IndexParams<S>>> implements IndexInterface<S, P> { | ||
schema: S; | ||
constructor(schema: S, key?: (params: P) => string); | ||
key(params?: P): string; | ||
} | ||
//# sourceMappingURL=indexEndpoint.d.ts.map |
@@ -1,6 +0,6 @@ | ||
import { Schema, Entity } from '@rest-hooks/normalizr'; | ||
import { Schema, AbstractInstanceType } from '@rest-hooks/normalizr'; | ||
import type { EndpointExtraOptions, FetchFunction } from './types'; | ||
import { InferReturn } from './utility'; | ||
/** Defines a networking endpoint */ | ||
export interface EndpointInterface<F extends (params?: any, body?: any) => Promise<any> = FetchFunction, S extends Schema | undefined = undefined, M extends true | undefined = undefined> extends EndpointExtraOptions { | ||
export interface EndpointInterface<F extends FetchFunction = FetchFunction, S extends Schema | undefined = Schema | undefined, M extends true | undefined = true | undefined> extends EndpointExtraOptions { | ||
(...args: Parameters<F>): InferReturn<F, S>; | ||
@@ -12,17 +12,17 @@ key(parmas?: Readonly<Parameters<F>[0]>): string; | ||
/** To change values on the server */ | ||
export interface MutateEndpoint<F extends (params?: any, body?: any) => Promise<any> = FetchFunction, S extends Schema | undefined = undefined> extends EndpointInterface<F, S, true> { | ||
fetch(params: Readonly<Parameters<F>[0]>, body: Readonly<Parameters<F>[1]>): ReturnType<F>; | ||
export interface MutateEndpoint<F extends (params?: any, body?: any) => Promise<any> = FetchFunction, S extends Schema | undefined = Schema | undefined> extends EndpointInterface<F, S, true> { | ||
sideEffect: true; | ||
} | ||
/** For retrieval requests */ | ||
export interface ReadEndpoint<F extends (params?: any) => Promise<any> = FetchFunction, S extends Schema | undefined = undefined> extends EndpointInterface<F, S> { | ||
fetch(params: Readonly<Parameters<F>[0]>): ReturnType<F>; | ||
} | ||
export declare type ReadEndpoint<F extends (params?: any) => Promise<any> = (params?: any) => Promise<any>, S extends Schema | undefined = Schema | undefined> = EndpointInterface<F, S, undefined>; | ||
export declare type ArrayElement<ArrayType extends unknown[] | readonly unknown[]> = ArrayType[number]; | ||
export declare type IndexParams<E extends typeof Entity> = { | ||
[K in Extract<ArrayElement<Exclude<E['indexes'], undefined>>, keyof E>]?: E[K]; | ||
}; | ||
export interface IndexInterface<S extends typeof Entity> { | ||
key(params?: Readonly<IndexParams<S>>): string; | ||
export declare type IndexParams<S extends Schema> = S extends { | ||
indexes: readonly string[]; | ||
} ? { | ||
[K in Extract<ArrayElement<S['indexes']>, keyof AbstractInstanceType<S>>]?: AbstractInstanceType<S>[K]; | ||
} : Readonly<object>; | ||
export interface IndexInterface<S extends Schema = Schema, P = object> { | ||
key(params?: P): string; | ||
readonly schema: S; | ||
} | ||
//# sourceMappingURL=interface.d.ts.map |
@@ -17,5 +17,5 @@ import { Schema, Normalize } from '@rest-hooks/normalizr'; | ||
} | ||
export declare type FetchFunction<P = any> = (params?: P, body?: any) => Promise<any>; | ||
export declare type FetchFunction<P = any, B = any, R = any> = (params?: P, body?: B) => Promise<R>; | ||
export declare type OptimisticUpdateParams<SourceSchema extends Schema, Dest extends EndpointInterface<FetchFunction, Schema, any>> = [Dest, Parameters<Dest>[0], UpdateFunction<SourceSchema, Exclude<Dest['schema'], undefined>>]; | ||
export declare type UpdateFunction<SourceSchema extends Schema, DestSchema extends Schema> = (sourceResults: Normalize<SourceSchema>, destResults: Normalize<DestSchema> | undefined) => Normalize<DestSchema>; | ||
//# sourceMappingURL=types.d.ts.map |
import { Denormalize, Schema } from '@rest-hooks/normalizr'; | ||
import { EndpointInterface } from './interface'; | ||
import { FetchFunction } from './types'; | ||
/** What the function's promise resolves to */ | ||
export declare type ResolveType<E extends EndpointInterface<any, any, any>> = ReturnType<E> extends Promise<infer R> ? R : never; | ||
export declare type ResolveType<E extends (...args: any) => any> = ReturnType<E> extends Promise<infer R> ? R : never; | ||
/** Fallback to schema if fetch function isn't defined */ | ||
export declare type InferReturn<F extends FetchFunction, S extends Schema | undefined> = S extends undefined ? ReturnType<F> : ReturnType<F> extends unknown ? Promise<Denormalize<S>> : ReturnType<F>; | ||
/** Get the Params type for a given Shape */ | ||
export declare type EndpointParam<E> = E extends (first: infer A, ...rest: any) => any ? A : E extends { | ||
key: (first: infer A, ...rest: any) => any; | ||
} ? A : never; | ||
//# sourceMappingURL=utility.d.ts.map |
{ | ||
"name": "@rest-hooks/endpoint", | ||
"version": "0.3.2", | ||
"version": "0.4.0", | ||
"description": "Declarative Network Interface Definitions", | ||
@@ -57,3 +57,3 @@ "sideEffects": false, | ||
}, | ||
"gitHead": "d0ab94539fe03f3366e2abf0cd206b19a2bee876" | ||
"gitHead": "6e9b8b0c92bb84fce92ec809bf0235053000ce1b" | ||
} |
@@ -124,3 +124,4 @@ /* eslint-disable @typescript-eslint/ban-types */ | ||
readonly type: M extends undefined ? 'read' : 'mutate'; | ||
getFetchKey(...args: Parameters<F>): string; | ||
getFetchKey(params: Parameters<F>[0]): string; | ||
options?: EndpointExtraOptions; | ||
} | ||
@@ -127,0 +128,0 @@ |
@@ -8,2 +8,9 @@ export default class Endpoint extends Function { | ||
this.type = this.sideEffect ? 'mutate' : 'read'; | ||
this.options = { ...options }; | ||
delete this.options.key; | ||
delete this.options.schema; | ||
delete this.options.sideEffect; | ||
if (Object.keys(this.options).length === 0) { | ||
delete this.options; | ||
} | ||
} | ||
@@ -16,5 +23,16 @@ | ||
extend(options) { | ||
/** The following is for compatibility with FetchShape */ | ||
const optionsCopy = { ...options }; | ||
delete optionsCopy.key; | ||
delete optionsCopy.schema; | ||
delete optionsCopy.sideEffect; | ||
const optionsToPass = { | ||
...this, | ||
...options, | ||
/** The following is for compatibility with FetchShape */ | ||
options: { | ||
...this.options, | ||
optionsCopy, | ||
}, | ||
}; | ||
@@ -21,0 +39,0 @@ return new this.constructor(options.fetch ?? this.fetch, optionsToPass); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
71398
1004