UNPKG

@player-ui/player

Version:

86 lines 3.86 kB
import { SyncHook } from "tapable-ts"; import type { BindingLike, BindingFactory } from "../binding"; import { BindingInstance } from "../binding"; export declare const ROOT_BINDING: BindingInstance; export type BatchSetTransaction = [BindingInstance, any][]; export type Updates = Array<{ /** The updated binding */ binding: BindingInstance; /** The old value */ oldValue: any; /** The new value */ newValue: any; /** Force the Update to be included even if no data changed */ force?: boolean; }>; /** Options to use when getting or setting data */ export interface DataModelOptions { /** * The data (either to set or get) should represent a formatted value * For setting data, the data will be de-formatted before continuing in the pipeline * For getting data, the data will be formatted before returning */ formatted?: boolean; /** * By default, fetching data will ignore any invalid data. * You can choose to grab the queued invalid data if you'd like * This is usually the case for user-inputs */ includeInvalid?: boolean; /** * A flag to set to ignore any default value in the schema, and just use the raw value */ ignoreDefaultValue?: boolean; /** * A flag to indicate that this update should happen silently */ silent?: boolean; /** Other context associated with this request */ context?: { /** The data model to use when getting other data from the context of this request */ model: DataModelWithParser; }; } export interface DataModelWithParser<Options = DataModelOptions> { get(binding: BindingLike, options?: Options): any; set(transaction: [BindingLike, any][], options?: Options): Updates; delete(binding: BindingLike, options?: Options): void; } export interface DataModelImpl<Options = DataModelOptions> { get(binding: BindingInstance, options?: Options): any; set(transaction: BatchSetTransaction, options?: Options): Updates; delete(binding: BindingInstance, options?: Options): void; } export interface DataModelMiddleware { /** The name of the middleware */ name?: string; set(transaction: BatchSetTransaction, options?: DataModelOptions, next?: DataModelImpl): Updates; get(binding: BindingInstance, options?: DataModelOptions, next?: DataModelImpl): any; delete?(binding: BindingInstance, options?: DataModelOptions, next?: DataModelImpl): void; reset?(): void; } /** Wrap the inputs of the DataModel with calls to parse raw binding inputs */ export declare function withParser<Options = unknown>(model: DataModelImpl<Options>, parseBinding: BindingFactory): DataModelWithParser<Options>; /** Wrap a middleware instance in a DataModel compliant API */ export declare function toModel(middleware: DataModelMiddleware, defaultOptions?: DataModelOptions, next?: DataModelImpl): DataModelImpl; export type DataPipeline = Array<DataModelMiddleware | DataModelImpl>; /** * Given a set of steps in a pipeline, create the effective data-model */ export declare function constructModelForPipeline(pipeline: DataPipeline): DataModelImpl; /** A DataModel that manages middleware data handlers */ export declare class PipelinedDataModel implements DataModelImpl { private pipeline; private effectiveDataModel; readonly hooks: { onSet: SyncHook<[BatchSetTransaction], Record<string, any>>; }; constructor(pipeline?: DataPipeline); setMiddleware(handlers: DataPipeline): void; addMiddleware(handler: DataModelMiddleware): void; reset(model?: {}): void; set(transaction: BatchSetTransaction, options?: DataModelOptions): Updates; get(binding: BindingInstance, options?: DataModelOptions): any; delete(binding: BindingInstance, options?: DataModelOptions): void; } //# sourceMappingURL=model.d.ts.map