New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@rest-hooks/endpoint

Package Overview
Dependencies
Maintainers
1
Versions
120
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@rest-hooks/endpoint - npm Package Compare versions

Comparing version 0.3.0 to 0.3.1

10

CHANGELOG.md

@@ -6,2 +6,12 @@ # Change Log

## <small>0.3.1 (2020-07-13)</small>
* docs: Add Endpoint to API section ([73428b0](https://github.com/coinbase/rest-hooks/commit/73428b0))
* enhance: Improve endpoint (#364) ([503dd29](https://github.com/coinbase/rest-hooks/commit/503dd29)), closes [#364](https://github.com/coinbase/rest-hooks/issues/364)
* enhance: Make Endpoint compatible with FetchShape ([caa967c](https://github.com/coinbase/rest-hooks/commit/caa967c))
## 0.3.0 (2020-07-13)

@@ -8,0 +18,0 @@

18

dist/index.cjs.js

@@ -110,4 +110,13 @@ 'use strict';

_this = _Function.call(this, 'return arguments.callee.fetch.apply(arguments.callee, arguments)') || this;
_this.schema = null;
_this.getFetchKey = function (params) {
return _this.key(params);
};
_this.fetch = fetchFunction;
Object.assign(_assertThisInitialized(_this), options);
/** The following is for compatibility with FetchShape */
_this.type = _this.sideEffect ? 'mutate' : 'read';
return _this;

@@ -127,3 +136,5 @@ }

return new this.constructor((_options$fetch = options.fetch) != null ? _options$fetch : this.fetch, optionsToPass);
};
}
/** The following is for compatibility with FetchShape */
;

@@ -134,4 +145,5 @@ return Endpoint;

var Index = /*#__PURE__*/function () {
function Index(entity) {
this.schema = entity;
function Index(schema, key) {
this.schema = schema;
if (key) this.key = key;
}

@@ -138,0 +150,0 @@

2

dist/index.umd.min.js

@@ -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).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}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){this.schema=t}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 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})}));
export default class Endpoint extends Function {
constructor(fetchFunction, options) {
super('return arguments.callee.fetch.apply(arguments.callee, arguments)');
this.schema = null;
this.getFetchKey = params => {
return this.key(params);
};
this.fetch = fetchFunction;
Object.assign(this, options);
/** The following is for compatibility with FetchShape */
this.type = this.sideEffect ? 'mutate' : 'read';
}

@@ -18,4 +27,6 @@

}
/** The following is for compatibility with FetchShape */
}
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uL3NyYy9lbmRwb2ludC5qcyJdLCJuYW1lcyI6WyJFbmRwb2ludCIsIkZ1bmN0aW9uIiwiY29uc3RydWN0b3IiLCJmZXRjaEZ1bmN0aW9uIiwib3B0aW9ucyIsImZldGNoIiwiT2JqZWN0IiwiYXNzaWduIiwia2V5IiwicGFyYW1zIiwibmFtZSIsIkpTT04iLCJzdHJpbmdpZnkiLCJleHRlbmQiLCJvcHRpb25zVG9QYXNzIl0sIm1hcHBpbmdzIjoiQUFBQSxlQUFlLE1BQU1BLFFBQU4sU0FBdUJDLFFBQXZCLENBQWdDO0FBQzdDQyxFQUFBQSxXQUFXLENBQUNDLGFBQUQsRUFBZ0JDLE9BQWhCLEVBQXlCO0FBQ2xDLFVBQU0sa0VBQU47QUFDQSxTQUFLQyxLQUFMLEdBQWFGLGFBQWI7QUFDQUcsSUFBQUEsTUFBTSxDQUFDQyxNQUFQLENBQWMsSUFBZCxFQUFvQkgsT0FBcEI7QUFDRDs7QUFFREksRUFBQUEsR0FBRyxDQUFDQyxNQUFELEVBQVM7QUFDVixXQUFRLEdBQUUsS0FBS0osS0FBTCxDQUFXSyxJQUFLLElBQUdDLElBQUksQ0FBQ0MsU0FBTCxDQUFlSCxNQUFmLENBQXVCLEVBQXBEO0FBQ0Q7O0FBRURJLEVBQUFBLE1BQU0sQ0FBQ1QsT0FBRCxFQUFVO0FBQUE7O0FBQ2QsVUFBTVUsYUFBYSxxQkFDZCxJQURjLEVBRWRWLE9BRmMsQ0FBbkI7QUFJQSxXQUFPLElBQUksS0FBS0YsV0FBVCxtQkFBcUJFLE9BQU8sQ0FBQ0MsS0FBN0IsNkJBQXNDLEtBQUtBLEtBQTNDLEVBQWtEUyxhQUFsRCxDQUFQO0FBQ0Q7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uICBjb25zdHJ1Y3RvcihmZXRjaEZ1bmN0aW9uLCBvcHRpb25zKSB7XG4gICAgc3VwZXIoJ3JldHVybiBhcmd1bWVudHMuY2FsbGVlLmZldGNoLmFwcGx5KGFyZ3VtZW50cy5jYWxsZWUsIGFyZ3VtZW50cyknKTtcbiAgICB0aGlzLmZldGNoID0gZmV0Y2hGdW5jdGlvbjtcbiAgICBPYmplY3QuYXNzaWduKHRoaXMsIG9wdGlvbnMpO1xuICAgIC8qKiBUaGUgZm9sbG93aW5nIGlzIGZvciBjb21wYXRpYmlsaXR5IHdpdGggRmV0Y2hTaGFwZSAqL1xuICAgIHRoaXMudHlwZSA9IHRoaXMuc2lkZUVmZmVjdCA/ICdtdXRhdGUnIDogJ3JlYWQnO1xuICB9XG5cbiAga2V5KHBhcmFtcykge1xuICAgIHJldHVybiBgJHt0aGlzLmZldGNoLm5hbWV9ICR7SlNPTi5zdHJpbmdpZnkocGFyYW1zKX1gO1xuICB9XG5cbiAgZXh0ZW5kKG9wdGlvbnMpIHtcbiAgICBjb25zdCBvcHRpb25zVG9QYXNzID0ge1xuICAgICAgLi4udGhpcyxcbiAgICAgIC4uLm9wdGlvbnMsXG4gICAgfTtcbiAgICByZXR1cm4gbmV3IHRoaXMuY29uc3RydWN0b3Iob3B0aW9ucy5mZXRjaCA/PyB0aGlzLmZldGNoLCBvcHRpb25zVG9QYXNzKTtcbiAgfVxuXG4gIC8qKiBUaGUgZm9sbG93aW5nIGlzIGZvciBjb21wYXRpYmlsaXR5IHdpdGggRmV0Y2hTaGFwZSAqL1xuICBzY2hlbWEgPSBudWxsO1xuICBnZXRGZXRjaEtleSA9IHBhcmFtcyA9PiB7XG4gICAgcmV0dXJuIHRoaXMua2V5KHBhcmFtcyk7XG4gIH07XG59XG4iXX0=
export { default as Endpoint } from './endpoint';
export { default as Index } from './indexEndpoint';
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uL3NyY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BSUMsUUFBcEIsUUFBb0MsWUFBcEM7QUFDQSxTQUFTRCxPQUFPLElBQUlFLEtBQXBCLFFBQWlDLGlCQUFqQyIsInNvdXJjZXNDb250ZW50IjpbImV4cG9ydCB0eXBlIHtcbiAgRW5kcG9pbnRJbnRlcmZhY2UsXG4gIFJlYWRFbmRwb2ludCxcbiAgTXV0YXRlRW5kcG9pbnQsXG4gIEluZGV4SW50ZXJmYWNlLFxuICBJbmRleFBhcmFtcyxcbiAgQXJyYXlFbGVtZW50LFxufSBmcm9tICcuL2ludGVyZmFjZSc7XG5leHBvcnQgdHlwZSB7XG4gIEVuZHBvaW50T3B0aW9ucyxcbiAgRW5kcG9pbnRJbnN0YW5jZSxcbiAgRXh0ZW5kRW5kcG9pbnQsXG59IGZyb20gJy4vZW5kcG9pbnQnO1xuZXhwb3J0IHR5cGUge1xuICBFbmRwb2ludEV4dHJhT3B0aW9ucyxcbiAgRmV0Y2hGdW5jdGlvbixcbiAgT3B0aW1pc3RpY1VwZGF0ZVBhcmFtcyxcbiAgVXBkYXRlRnVuY3Rpb24sXG59IGZyb20gJy4vdHlwZXMnO1xuZXhwb3J0IHR5cGUgeyBSZXNvbHZlVHlwZSwgRW5kcG9pbnRQYXJhbSwgSW5mZXJSZXR1cm4gfSBmcm9tICcuL3V0aWxpdHknO1xuXG5leHBvcnQgeyBkZWZhdWx0IGFzIEVuZHBvaW50IH0gZnJvbSAnLi9lbmRwb2ludCc7XG5leHBvcnQgeyBkZWZhdWx0IGFzIEluZGV4IH0gZnJvbSAnLi9pbmRleEVuZHBvaW50JztcbiJdfQ==
export default class Index {
constructor(entity) {
this.schema = entity;
constructor(schema, key) {
this.schema = schema;
if (key) this.key = key;
}

@@ -11,2 +12,2 @@

}
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uL3NyYy9pbmRleEVuZHBvaW50LnRzIl0sIm5hbWVzIjpbIkluZGV4IiwiY29uc3RydWN0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5Il0sIm1hcHBpbmdzIjoiQUFJQSxlQUFlLE1BQU1BLEtBQU4sQ0FDbUI7QUFFaENDLEVBQUFBLFdBQVcsQ0FBQ0MsTUFBRCxFQUFZQyxHQUFaLEVBQXlDO0FBQ2xELFNBQUtELE1BQUwsR0FBY0EsTUFBZDtBQUNBLFFBQUlDLEdBQUosRUFBUyxLQUFLQSxHQUFMLEdBQVdBLEdBQVg7QUFDVjs7QUFFREEsRUFBQUEsR0FBRyxDQUFDQyxNQUFELEVBQWE7QUFDZCxXQUFPQyxJQUFJLENBQUNDLFNBQUwsQ0FBZUYsTUFBZixDQUFQO0FBQ0Q7O0FBVCtCIiwic291cmNlc0NvbnRlbnQiOlsiaW1wb3J0IHsgU2NoZW1hIH0gZnJvbSAnQHJlc3QtaG9va3Mvbm9ybWFsaXpyJztcblxuaW1wb3J0IHR5cGUgeyBJbmRleEludGVyZmFjZSwgSW5kZXhQYXJhbXMgfSBmcm9tICcuL2ludGVyZmFjZSc7XG5cbmV4cG9ydCBkZWZhdWx0IGNsYXNzIEluZGV4PFMgZXh0ZW5kcyBTY2hlbWEsIFAgPSBSZWFkb25seTxJbmRleFBhcmFtczxTPj4+XG4gIGltcGxlbWVudHMgSW5kZXhJbnRlcmZhY2U8UywgUD4ge1xuICBkZWNsYXJlIHNjaGVtYTogUztcbiAgY29uc3RydWN0b3Ioc2NoZW1hOiBTLCBrZXk/OiAocGFyYW1zOiBQKSA9PiBzdHJpbmcpIHtcbiAgICB0aGlzLnNjaGVtYSA9IHNjaGVtYTtcbiAgICBpZiAoa2V5KSB0aGlzLmtleSA9IGtleTtcbiAgfVxuXG4gIGtleShwYXJhbXM/OiBQKSB7XG4gICAgcmV0dXJuIEpTT04uc3RyaW5naWZ5KHBhcmFtcyk7XG4gIH1cbn1cbiJdfQ==
{
"name": "@rest-hooks/endpoint",
"version": "0.3.0",
"version": "0.3.1",
"description": "Declarative Network Interface Definitions",

@@ -44,3 +44,3 @@ "sideEffects": false,

"license": "Apache-2.0",
"homepage": "https://resthooks.io",
"homepage": "https://resthooks.io/docs/next/api/Endpoint",
"repository": {

@@ -58,3 +58,3 @@ "type": "git",

},
"gitHead": "c0fb0d84e41cf81ee78840532645b3b6f17753e0"
"gitHead": "3b786d17b9ee4f9e4b8cd86fd6cca383c777b6f8"
}

@@ -13,3 +13,3 @@ # TypeScript Standard Endpoints

**[📖Read The Docs](https://resthooks.io)**
**[📖Read The Docs](https://resthooks.io/docs/next/api/Endpoint)**

@@ -23,3 +23,3 @@ </div>

const UserDetail = new Endpoint(({ id }) ⇒ fetch(`/users/${id}`));
const UserDetail = new Endpoint(({ id }) ⇒ fetch(`/users/${id}`).then(res => res.json()));
```

@@ -26,0 +26,0 @@

@@ -70,3 +70,3 @@ import nock from 'nock';

expect(UserDetail.sideEffect).toBe(undefined);
expect(UserDetail.schema).toBeUndefined();
//expect(UserDetail.schema).toBeUndefined(); TODO: re-enable once we don't care about FetchShape compatibility
expect(UserDetail.key({ id: payload.id })).toMatchInlineSnapshot(

@@ -73,0 +73,0 @@ `"fetchUsers {\\"id\\":\\"5\\"}"`,

@@ -5,3 +5,4 @@ /* eslint-disable @typescript-eslint/ban-types */

import type { EndpointInterface } from './interface';
import type { EndpointExtraOptions } from './types';
import type { EndpointExtraOptions, FetchFunction } from './types';
import type { ResolveType } from './utility';

@@ -34,8 +35,20 @@ export interface EndpointOptions<

type Overwrite<T, U> = Pick<T, Exclude<keyof T, keyof U>> & U;
export type FetchFunction<P = any> = (params?: P, body?: any) => Promise<any>;
export type ExtendEndpoint<
E extends EndpointInstance<any, any, any>,
O extends EndpointExtendOptions<K, any, any>
> = EndpointInstance<
'fetch' extends keyof typeof options ? typeof options['fetch'] : E['fetch'],
'schema' extends keyof typeof options
? typeof options['schema']
: E['_schema'],
'sideEffect' extends keyof typeof options
? typeof options['sideEffect']
: E['sideEffect']
>;
/**
* Creates a new function.
*/
interface EndpointInstance<
export interface EndpointInstance<
F extends FetchFunction,

@@ -45,2 +58,4 @@ S extends Schema | undefined = undefined,

> extends EndpointInterface<F, S, M> {
constructor: EndpointConstructor;
/**

@@ -82,3 +97,4 @@ * Calls the function, substituting the specified object for the this value of the function, and the specified array for the arguments of the function.

readonly schema?: S;
readonly schema: S extends undefined ? ResolveType<F> : S;
private _schema: S; // TODO: remove once we don't care about FetchShape compatibility

@@ -88,3 +104,3 @@ fetch: F;

extend<
E extends EndpointInstance<any, any, any>,
E extends EndpointInstance<any, S, any>,
O extends EndpointExtendOptions<K, any, any>,

@@ -96,3 +112,4 @@ K extends (

params: ParamFromFetch<'fetch' extends keyof O ? O['fetch'] : E['fetch']>,
) => string
) => string,
S
>(

@@ -105,3 +122,3 @@ this: E,

? typeof options['schema']
: E['schema'],
: E['_schema'],
'sideEffect' extends keyof typeof options

@@ -111,2 +128,6 @@ ? typeof options['sideEffect']

>;
/** The following is for compatibility with FetchShape */
readonly type: M extends undefined ? 'read' : 'mutate';
getFetchKey(...args: Parameters<F>): string;
}

@@ -113,0 +134,0 @@

@@ -6,2 +6,4 @@ export default class Endpoint extends Function {

Object.assign(this, options);
/** The following is for compatibility with FetchShape */
this.type = this.sideEffect ? 'mutate' : 'read';
}

@@ -20,2 +22,8 @@

}
/** The following is for compatibility with FetchShape */
schema = null;
getFetchKey = params => {
return this.key(params);
};
}

@@ -9,4 +9,8 @@ export type {

} from './interface';
export type { EndpointOptions } from './endpoint';
export type {
EndpointOptions,
EndpointInstance,
ExtendEndpoint,
} from './endpoint';
export type {
EndpointExtraOptions,

@@ -17,5 +21,5 @@ FetchFunction,

} 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';

@@ -1,15 +0,16 @@

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> {
declare schema: E;
constructor(entity: E) {
this.schema = entity;
export default class Index<S extends Schema, P = Readonly<IndexParams<S>>>
implements IndexInterface<S, P> {
declare schema: S;
constructor(schema: S, key?: (params: P) => string) {
this.schema = schema;
if (key) this.key = key;
}
key(params?: Readonly<IndexParams<E>>) {
key(params?: P) {
return JSON.stringify(params);
}
}

@@ -1,2 +0,2 @@

import { Schema, Entity } from '@rest-hooks/normalizr';
import { Schema, AbstractInstanceType } from '@rest-hooks/normalizr';

@@ -8,5 +8,5 @@ import type { EndpointExtraOptions, FetchFunction } from './types';

export interface EndpointInterface<
F extends (params?: any, body?: any) => Promise<any> = FetchFunction,
S extends Schema | undefined = undefined,
M extends true | undefined = undefined
F extends FetchFunction = FetchFunction,
S extends Schema | undefined = Schema | undefined,
M extends true | undefined = true | undefined
> extends EndpointExtraOptions {

@@ -22,17 +22,12 @@ (...args: Parameters<F>): InferReturn<F, S>;

F extends (params?: any, body?: any) => Promise<any> = FetchFunction,
S extends Schema | undefined = undefined
S extends Schema | undefined = Schema | undefined
> extends EndpointInterface<F, S, true> {
fetch(
params: Readonly<Parameters<F>[0]>,
body: Readonly<Parameters<F>[1]>,
): ReturnType<F>;
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 type ReadEndpoint<
F extends (params?: any) => Promise<any> = (params?: any) => Promise<any>,
S extends Schema | undefined = Schema | undefined
> = EndpointInterface<F, S, undefined>;

@@ -43,12 +38,16 @@ export type ArrayElement<

export type IndexParams<E extends typeof Entity> = {
[K in Extract<
ArrayElement<Exclude<E['indexes'], undefined>>,
keyof E
>]?: E[K];
};
export 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 typeof Entity> {
key(params?: Readonly<IndexParams<S>>): string;
export interface IndexInterface<S extends Schema = Schema, P = object> {
key(params?: P): string;
readonly schema: S;
}

@@ -22,3 +22,6 @@ import { Schema, Normalize } from '@rest-hooks/normalizr';

}
export type FetchFunction<P = any> = (params?: P, body?: any) => Promise<any>;
export type FetchFunction<P = any, B = any, R = any> = (
params?: P,
body?: B,
) => Promise<R>;

@@ -25,0 +28,0 @@ export type OptimisticUpdateParams<

import { Denormalize, Schema } from '@rest-hooks/normalizr';
import { EndpointInterface } from './interface';
import { FetchFunction } from './types';
/** What the function's promise resolves to */
export type ResolveType<
E extends EndpointInterface<any, any, any>
> = ReturnType<E> extends Promise<infer R> ? R : never;
export type ResolveType<E extends (...args: any) => any> = ReturnType<
E
> extends Promise<infer R>
? R
: never;

@@ -20,1 +21,8 @@ /** Fallback to schema if fetch function isn't defined */

: ReturnType<F>;
/** Get the Params type for a given Shape */
export type EndpointParam<E> = E extends (first: infer A, ...rest: any) => any
? A
: E extends { key: (first: infer A, ...rest: any) => any }
? A
: never;
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc