import { _CfgProductInternal } from "../CfgProduct.js"; import { _CfgOptionInternal } from "../productConfiguration/CfgOption.js"; import { ProductLoader } from "../productLoader.js"; import { SyncGroupsApplyMode } from "./SyncGroupsApplyMode.js"; import { CfgPath } from "./SyncGroupsPathHelper.js"; import { SyncGroupsState } from "./SyncGroupsState.js"; /** * The Transaction is a transient object used to track all the changes made to the supplied * SyncGroupState as a result of a (normally) single initial event, like when opening a product * or the user selecting an option on an already open product. * * All state changes are made on an internal copy of the original SyncGroupState (called target) * so they can later be used (i.e. committed) at once to the visible product, or safely discarded * without affecting anything. * * The Transaction keeps track of which Features and SyncGroups have been affected so far, to * eliminate the risk of infinite loops. * * Terminology * =========== * * You APPLY things onto the transaction in order to update the sync state inside the transaction. * The transaction can then UPDATE other things in order to apply it's sync state onto them. * * Transaction.applyThing() ...onto the transaction * Transaction.updateThing() ...with the transaction * * @see SyncGroupHandler.ts for more information, including the general resolution algorithm. */ export declare class SyncGroupsTransaction { /** * A clone of the original syncState. * Replaces the original syncState if nothing fails and the transaction doesn't get cancelled. */ private readonly syncState; /** * A clone of the original product used to apply the configuration changes to. */ private readonly target; /** * A clone of the original product used to track what the original state was. As a safe measure * we do not use originalProduct for this, as it might be changed by someone else. */ private readonly initial; /** * The original sync state instance that this transaction will be applied on, provided nothing * fails and the transaction doesn't get cancelled. */ private readonly originalSyncState; /** * The original product instance that this transaction will be applied on, provided nothing * fails and the transaction doesn't get cancelled. */ private readonly originalProduct; private readonly updateMode; private readonly productLoader; static make(syncState: SyncGroupsState, updateMode: SyncGroupsApplyMode, product: _CfgProductInternal, productLoader: ProductLoader, assumeNoStartState: boolean): Promise; private constructor(); private _closed; private affectedSelectOneFeatures; private affectedSelectManyOptions; private affectedSelectOneSyncGroups; private affectedSelectManySyncGroupsAndOptions; /************************************************************************ * Public API (intentionally limited) ************************************************************************/ get isClosed(): boolean; close(): void; /** * This is (among other) the entry point when loading a new product. * * @returns true if at least one Feature changed it state. This is a bit counter intuitive, * but as this method will hand over to applyProduct if it updates the SyncState it can cause * the Features to change. And we need to pass that information back to know when to stop. */ applyRootProduct(): Promise; /** * This is the entry point for an active (often user) selection of an option. */ selectOption(optionPath: CfgPath, on: boolean): Promise; /** * Overwrites the original Product and SyncGroupState (supplied when creating the Transaction) * with the internal versions inside this Transaction. * * @throws error if the transaction has already been closed. */ commit(): Promise; /************************************************************************ * Updating things with the Transaction's SyncState ************************************************************************/ /** * Apply current sync groups on those who wants to listen until there is no more to settle. * @returns true if at least one Feature changed selected Option */ updateRootProduct(productToValidate: _CfgProductInternal | undefined): Promise; /** * Applies the SyncState to the Product and it's AdditionalProducts (sub-products). * @param productsToValidate To this all products that will need validation are added. */ private updateProduct; /** * Applies the SyncState to an array of Features. * @param productsToValidate To this all products that will need validation are added. */ private updateFeatures; /** * Applies the SyncState to an array of Options. * @param productsToValidate To this all products that will need validation are added. */ private updateOptions; /** * Applies the SyncState to a Feature * @param productsToValidate To this all products that will need validation are added * @returns Whether we shall stop recursing down (because we are in a state which we * expect to be resolved later), we shall continue recursing down. */ private updateFeature; /** * Decides if the SyncState can be applied to the SelectOne Feature, and then changes * the state of the Feature if so. * @param syncCode What SyncGroup the Feature belongs to * @param productsToValidate To this all products that will need validation are added * @returns Whether we shall stop recursing down (because we are in a state which we * expect to be resolved later), we shall continue recursing down. */ private updateSelectOneFeature; /** * Decides if the SyncState can be applied to Options in the SelectMany Feature, and * then changes the state of the Options if so. * @param syncCode What SyncGroup the Feature belongs to * @param productsToValidate To this all products that will need validation are added * @returns Always "stop" as recursion is handled internally. Return for consistency. */ private updateSelectManyFeature; /** * Decides if the SyncState can be applied to the SelectMany Option, and then changes * the state of the Option if so. * @param syncCode What SyncGroup the Feature belongs to * @param productsToValidate To this all products that will need validation are added * @returns Whether we shall stop recursing down (because we are in a state which we * expect to be resolved later), we shall continue recursing down. */ private updateSelectManyOption; /************************************************************************ * Applying things to the Transaction's SyncState ************************************************************************/ private applyProduct; private applyFeatures; private applyOptions; private applySelectOneFeature; private applySelectManyFeature; private applySelectManyOption; /** * Applies the given diff to the transaction's sync state. */ applyFromDiff(diffs: _CfgOptionInternal[]): void; /** * Applies the new state for the given option to the transaction's sync state. */ private applyNewStateFor; private addSyncGroupAffectedForSelectMany; private hasSyncGroupAffectedForSelectMany; } /************************************************************************ * Product diffing ************************************************************************/ /** * Finds all options that have changed in the new product compared to the original product. * * This is used to determine which options need to be updated in the sync state. */ export declare function generateSelectionDiff(originalProduct: _CfgProductInternal, newProduct: _CfgProductInternal): _CfgOptionInternal[] | null; //# sourceMappingURL=SyncGroupsTransaction.d.ts.map