UNPKG

@sheetxl/models

Version:

Models - A Headless javascript spreadsheet library.

142 lines 4.3 kB
export interface SharedResourceJSON { /** * A base64 encoded string of the data. */ base64: string; /** * A mimetype for the data */ type?: string; /** * The name of the resource. * This is optional but if provided then resource looks will use this as a cache key. */ name?: string; } export interface IPersistableAble<J> { toJSON: () => Promise<J>; } /** * A shared resource is a resource that can be shared between multiple objects. * This will track when a resource is no longer being used and can be removed. */ export interface ISharedResource extends IPersistableAble<SharedResourceJSON> { /** * Return the resource as a Promise to array buffer */ toBuffer(): Promise<ArrayBuffer>; /** * The mimetype of the resource */ getMimeType(): Promise<string>; /** * The options name of the resource */ readonly name: string | null; /** * For saving to json resources. */ toJSON(): Promise<SharedResourceJSON>; /** * Add a reference to the resource. * @param ref */ addReference(ref: any): void; /** * Delete a reference to the resource. * @param ref */ deleteReference(ref: any): void; /** * This is only called once. * @param listener */ addUnloadListener(listener: SharedResourceListener): void; /** * true if the resource if all references have been deleted. */ readonly isClosed: boolean; /** * For runtime introspection. */ readonly isISharedResource: true; } export interface ISharedPersister<J> { /** * For a sharedResource this will return a number that can be used to reference the resource in the persisted json. * @param sharedResource */ toResourceId(sharedResource: IPersistableAble<J>): number | null; /** * For a given resourceId this will return the sharedResource. * @param resourceId */ fromResourceId(resourceId: number): IPersistableAble<J> | null; /** * Called when done persisting. */ endPersist(): void; /** * Loads the json into the shared styles. * @param json */ fromJSON(json: J[]): void; /** * This can be called multiple times. * * @remarks * Only shared styles that have had the toResourceId called will * be shown in the persisted json. */ toJSON(): Promise<J[]>; } export interface FetchArgs { input: string | URL | Request; init?: RequestInit; } /** * When adding a shared source there are a number of ways to create it * Either from a base64 string, a buffer, a fetch, or a custom resolve function. */ export interface AddSharedResourceOptions { /** * An encoding for the resource. */ base64?: string | Promise<string>; fetch?: string | FetchArgs; buffer?: ArrayBuffer | Promise<ArrayBuffer> | (() => ArrayBuffer | Promise<ArrayBuffer>); file?: File | Promise<File>; /** * Mime type of the resource. * @defaultValue '*/ mimeType?: string; /** * The name of the resource. * This is optional and purely for human consumption and is not used by the system. */ name?: string; } export interface ISharedResourceCollection { /** * Add a resource to a collection with an initial reference. * Resources are not removed from the the collection. They are autoGCed when there are no references. * @param resource */ addResource(resource: string | ISharedResource | AddSharedResourceOptions): ISharedResource; /** * Used for saving resource this will return a visitor that will allow for a toJSON that * will only save the resource that were accessed within the persist scope. */ beginPersist(): ISharedPersister<SharedResourceJSON>; } interface SharedResourceListener { onUnload: (ref: ISharedResource) => void; } export declare class SharedResourceCollection implements ISharedResourceCollection { private _resources; private _persistOpen; constructor(); addResource(res: string | ISharedResource | AddSharedResourceOptions): ISharedResource; beginPersist(): ISharedPersister<SharedResourceJSON>; } export {}; //# sourceMappingURL=SharedResource.d.ts.map