import { InjectionToken } from '@angular/core'; import { MergeValueOptions, Schema, TypeValidationOptions } from '@lightweightform/storage'; import { LfSerializer } from '../abstract/value-serializer'; import { FileSystemService } from './file-system.service'; import { LfStorage } from './storage.service'; import * as i0 from "@angular/core"; /** * Interface of a class that can be used to intercept the loading of a file into * the storage. */ export interface LfFileStorageLoadInterceptor { /** * When an interceptor is provided, this method is called after the content of * a file has been deserialised but before the value is typechecked or * inserted into the storage. * * Among other uses, it can be used to check that the value to be loaded isn't * "too big" (since inserting a value into the storage may cause JavaScript's * heap size to explode due to it being converted into a MobX value), for * instance, in which case a warning or error may be raised. * * If a value other than `undefined` is returned, the returned value is the * one that will be typechecked and inserted into the storage. * @param deserializedValue File content after being deserialised and before * being inserted into the storage. * @param schema Schema of the deserialised value. * @param path Path of the deserialised value. * @returns The value with which to proceed the loading or `undefined` to * proceed with `deserializedValue`. */ beforeLoad(deserializedValue: any, schema: Schema, path: string): any; } /** * Injection token used to add a "load interceptor" that runs before a value is * loaded. */ export declare const LF_FILE_STORAGE_LOAD_INTERCEPTOR: InjectionToken; /** * Service used to save/load storage values to/from files in the user's file * system. Using this service requires providing an LF serialiser. */ export declare class LfFileStorage { protected lfStorage: LfStorage; protected fileSystemService: FileSystemService; protected lfSerializer: LfSerializer; protected loadInterceptor: LfFileStorageLoadInterceptor; /** * Whether a load operation is currently happening. */ private _isLoading; constructor(lfStorage: LfStorage, fileSystemService: FileSystemService, lfSerializer: LfSerializer, loadInterceptor: LfFileStorageLoadInterceptor); /** * Whether the current browser supports loading from a file. */ get loadIsSupported(): boolean; /** * Whether a load operation is currently happening. */ get isLoading(): boolean; /** * Saves the value at the given path to a file in the user's file system given * the name of the file to save (minus extension). * @param path Storage path of the value to save. Defaults to `'/'`. * @param fileName Name of file to save (minus extension, which is dictated by * the serialiser). Defaults to `'app'` when saving the root value or `path` * (with `'/'` replaced by `'_'`) when saving another value. * @returns A promise which resolves once the file has been saved. */ saveToFile(path?: string, fileName?: string): Promise; /** * Loads a value from a file in the user's file system and sets it as the * value in the provided path. * @param path Storage path on which to set the value from the file. Defaults * to `'/'`. * @param mergeValueOptions Options used for setting the value in the storage. * @param typeValidationOptions Options used when validating the type of the * value. * @returns A promise which resolves with whether a value was loaded (`false` * when the user cancels the action). */ loadFromFile(path?: string, mergeValueOptions?: MergeValueOptions, typeValidationOptions?: TypeValidationOptions): Promise; static ɵfac: i0.ɵɵFactoryDeclaration; static ɵprov: i0.ɵɵInjectableDeclaration; }