mirror of
https://github.com/flarum/core.git
synced 2025-08-08 09:26:34 +02:00
Bundled output for commit 187b5c6f0b
Includes transpiled JS/TS, and Typescript declaration files (typings). [skip ci]
This commit is contained in:
134
js/dist-typings/common/Store.d.ts
vendored
134
js/dist-typings/common/Store.d.ts
vendored
@@ -1,97 +1,127 @@
|
||||
import { FlarumRequestOptions } from './Application';
|
||||
import Model, { ModelData, SavedModelData } from './Model';
|
||||
export interface MetaInformation {
|
||||
[key: string]: any;
|
||||
}
|
||||
export interface ApiQueryParamsSingle {
|
||||
fields?: string[];
|
||||
include?: string;
|
||||
bySlug?: boolean;
|
||||
meta?: MetaInformation;
|
||||
}
|
||||
export interface ApiQueryParamsPlural {
|
||||
fields?: string[];
|
||||
include?: string;
|
||||
filter?: {
|
||||
q: string;
|
||||
[key: string]: string;
|
||||
};
|
||||
page?: {
|
||||
offset?: number;
|
||||
number?: number;
|
||||
limit?: number;
|
||||
size?: number;
|
||||
};
|
||||
sort?: string;
|
||||
meta?: MetaInformation;
|
||||
}
|
||||
export declare type ApiQueryParams = ApiQueryParamsPlural | ApiQueryParamsSingle;
|
||||
export interface ApiPayloadSingle {
|
||||
data: SavedModelData;
|
||||
included?: SavedModelData[];
|
||||
meta?: MetaInformation;
|
||||
}
|
||||
export interface ApiPayloadPlural {
|
||||
data: SavedModelData[];
|
||||
included?: SavedModelData[];
|
||||
links?: {
|
||||
first: string;
|
||||
next?: string;
|
||||
prev?: string;
|
||||
};
|
||||
meta?: MetaInformation;
|
||||
}
|
||||
export declare type ApiPayload = ApiPayloadSingle | ApiPayloadPlural;
|
||||
export declare type ApiResponseSingle<M extends Model> = M & {
|
||||
payload: ApiPayloadSingle;
|
||||
};
|
||||
export declare type ApiResponsePlural<M extends Model> = M[] & {
|
||||
payload: ApiPayloadPlural;
|
||||
};
|
||||
export declare type ApiResponse<M extends Model> = ApiResponseSingle<M> | ApiResponsePlural<M>;
|
||||
interface ApiQueryRequestOptions<ResponseType> extends Omit<FlarumRequestOptions<ResponseType>, 'url'> {
|
||||
}
|
||||
interface StoreData {
|
||||
[type: string]: Partial<Record<string, Model>>;
|
||||
}
|
||||
export declare function payloadIsPlural(payload: ApiPayload): payload is ApiPayloadPlural;
|
||||
/**
|
||||
* The `Store` class defines a local data store, and provides methods to
|
||||
* retrieve data from the API.
|
||||
*/
|
||||
export default class Store {
|
||||
constructor(models: any);
|
||||
/**
|
||||
* The local data store. A tree of resource types to IDs, such that
|
||||
* accessing data[type][id] will return the model for that type/ID.
|
||||
*
|
||||
* @type {Object}
|
||||
* @protected
|
||||
*/
|
||||
protected data: Object;
|
||||
protected data: StoreData;
|
||||
/**
|
||||
* The model registry. A map of resource types to the model class that
|
||||
* should be used to represent resources of that type.
|
||||
*
|
||||
* @type {Object}
|
||||
* @public
|
||||
*/
|
||||
public models: Object;
|
||||
models: Record<string, typeof Model>;
|
||||
constructor(models: Record<string, typeof Model>);
|
||||
/**
|
||||
* Push resources contained within an API payload into the store.
|
||||
*
|
||||
* @param {Object} payload
|
||||
* @return {Model|Model[]} The model(s) representing the resource(s) contained
|
||||
* @return The model(s) representing the resource(s) contained
|
||||
* within the 'data' key of the payload.
|
||||
* @public
|
||||
*/
|
||||
public pushPayload(payload: Object): any | any[];
|
||||
pushPayload<M extends Model>(payload: ApiPayloadSingle): ApiResponseSingle<M>;
|
||||
pushPayload<Ms extends Model[]>(payload: ApiPayloadPlural): ApiResponseSingle<Ms[number]>;
|
||||
/**
|
||||
* Create a model to represent a resource object (or update an existing one),
|
||||
* and push it into the store.
|
||||
*
|
||||
* @param {Object} data The resource object
|
||||
* @return {Model|null} The model, or null if no model class has been
|
||||
* @param data The resource object
|
||||
* @return The model, or null if no model class has been
|
||||
* registered for this resource type.
|
||||
* @public
|
||||
*/
|
||||
public pushObject(data: Object): any | null;
|
||||
pushObject<M extends Model>(data: SavedModelData): M | null;
|
||||
pushObject<M extends Model>(data: SavedModelData, allowUnregistered: false): M;
|
||||
/**
|
||||
* Make a request to the API to find record(s) of a specific type.
|
||||
*
|
||||
* @param {String} type The resource type.
|
||||
* @param {Integer|Integer[]|Object} [id] The ID(s) of the model(s) to retrieve.
|
||||
* Alternatively, if an object is passed, it will be handled as the
|
||||
* `query` parameter.
|
||||
* @param {Object} [query]
|
||||
* @param {Object} [options]
|
||||
* @return {Promise}
|
||||
* @public
|
||||
*/
|
||||
public find(type: string, id?: any | any[] | Object, query?: Object | undefined, options?: Object | undefined): Promise<any>;
|
||||
find<M extends Model>(type: string, params: ApiQueryParamsSingle): Promise<ApiResponseSingle<M>>;
|
||||
find<Ms extends Model[]>(type: string, params: ApiQueryParamsPlural): Promise<ApiResponsePlural<Ms[number]>>;
|
||||
find<M extends Model>(type: string, id: string, params?: ApiQueryParamsSingle, options?: ApiQueryRequestOptions<ApiPayloadSingle>): Promise<ApiResponseSingle<M>>;
|
||||
find<Ms extends Model[]>(type: string, ids: string[], params?: ApiQueryParamsPlural, options?: ApiQueryRequestOptions<ApiPayloadPlural>): Promise<ApiResponsePlural<Ms[number]>>;
|
||||
/**
|
||||
* Get a record from the store by ID.
|
||||
*
|
||||
* @param {String} type The resource type.
|
||||
* @param {Integer} id The resource ID.
|
||||
* @return {Model}
|
||||
* @public
|
||||
*/
|
||||
public getById(type: string, id: any): any;
|
||||
getById<M extends Model>(type: string, id: string): M | undefined;
|
||||
/**
|
||||
* Get a record from the store by the value of a model attribute.
|
||||
*
|
||||
* @param {String} type The resource type.
|
||||
* @param {String} key The name of the method on the model.
|
||||
* @param {*} value The value of the model attribute.
|
||||
* @return {Model}
|
||||
* @public
|
||||
* @param type The resource type.
|
||||
* @param key The name of the method on the model.
|
||||
* @param value The value of the model attribute.
|
||||
*/
|
||||
public getBy(type: string, key: string, value: any): any;
|
||||
getBy<M extends Model, T = unknown>(type: string, key: keyof M, value: T): M | undefined;
|
||||
/**
|
||||
* Get all loaded records of a specific type.
|
||||
*
|
||||
* @param {String} type
|
||||
* @return {Model[]}
|
||||
* @public
|
||||
*/
|
||||
public all(type: string): any[];
|
||||
all<M extends Model>(type: string): M[];
|
||||
/**
|
||||
* Remove the given model from the store.
|
||||
*
|
||||
* @param {Model} model
|
||||
*/
|
||||
remove(model: any): void;
|
||||
remove(model: Model): void;
|
||||
/**
|
||||
* Create a new record of the given type.
|
||||
*
|
||||
* @param {String} type The resource type
|
||||
* @param {Object} [data] Any data to initialize the model with
|
||||
* @return {Model}
|
||||
* @public
|
||||
* @param type The resource type
|
||||
* @param data Any data to initialize the model with
|
||||
*/
|
||||
public createRecord(type: string, data?: Object | undefined): any;
|
||||
createRecord<M extends Model>(type: string, data?: ModelData): M;
|
||||
}
|
||||
export {};
|
||||
|
Reference in New Issue
Block a user