@rest-api/react-models
Version:
[](https://www.npmjs.com/package/@rest-api/react-models) [](https://codecov.io/gh/hector7/rest-
57 lines (56 loc) • 1.89 kB
TypeScript
import { Schema } from '../Schema';
import Model from '../Model';
import { ModelState } from '../State';
export declare type RouteOpts = {
trailingSlash?: boolean;
headers?: {
[key: string]: string;
};
};
export declare type UrlCallbackParam<Opts> = (opts: Opts) => string;
declare class ReducerImplementation extends Object {
constructor(modelName: string);
protected addBasicIdReducer<IdKey extends string>(idKey: IdKey): void;
}
export declare class RestModel<Opts = any, S extends Schema<any, any, any> = any, IdKey extends string = any, GetItem = any, MetaData = any> extends ReducerImplementation {
readonly state: ModelState<RestModel<Opts, S, IdKey, GetItem, MetaData>>;
readonly model: Model<S>;
readonly _id: IdKey;
readonly getUrl: (opts: Opts) => string;
readonly itemStructure?: Schema<GetItem>;
constructor(model: Model<S>, id: IdKey, url: UrlCallbackParam<Opts>, opts?: {
itemStructure?: Schema<GetItem, any, any>;
getItems?: (el: GetItem) => S['RealType'][];
getMetaData?: (el: GetItem) => MetaData;
} & RouteOpts);
get validateItem(): (el: any) => el is S['RealType'];
get validateFetch(): (el: any) => el is GetItem;
}
export declare type GetMethods<T extends {
[key: string]: any;
}> = {
[k in keyof T]: T[k];
};
/**
* This method will extract all methods from parameters binded from each parameter.
*
* ```typescript
* const methodsClass1Binded = joinClassMethods(class1)
* const methodsClass1AndClass2Binded = joinClassMethods(class1, class2)
* ```
*/
export declare function joinClassMethods<A extends {
[key: string]: any;
}>(a: A): {
[k in keyof A]: A[k];
};
export declare function joinClassMethods<A extends {
[key: string]: any;
}, B extends {
[key: string]: any;
}>(a: A, b: B): {
[k in keyof A]: A[k];
} & {
[k in keyof B]: B[k];
};
export {};