packageDocumentation module import { RegisteredRuleset , Ruleset } from "@itwin/presentation-common" ; import { NativePlatformDefinition } from "./NativePlatform" ; public export interface RulesetManager { /**
     * Get a ruleset with the specified id.
     */ get ( id ) : RegisteredRuleset | undefined ; /**
     * Register the supplied ruleset
     */ add ( ruleset ) : RegisteredRuleset ; /**
     * Unregister the supplied ruleset
     */ remove ( ruleset ) : boolean ; /**
     * Remove all rulesets registered in this session.
     */ clear ( ) : void ; } internal export class RulesetManagerImpl implements RulesetManager { private _getNativePlatform : ( ) => NativePlatformDefinition ; private _registeredRulesets = new Map < string , RegisteredRuleset > ( ) ; constructor ( getNativePlatform ) { this . _getNativePlatform = getNativePlatform ; } /**
     * Get a ruleset with the specified id.
     */ public get ( id ) { const foundRuleset = this . _registeredRulesets . get ( id ) ; if ( foundRuleset ) return foundRuleset ; const serializedRulesetsArray = this . _getNativePlatform ( ) . getRulesets ( id ) . result ; const rulesetsArray = JSON . parse ( serializedRulesetsArray ) ; if ( 0 === rulesetsArray . length ) return undefined ; return this . saveRuleset ( rulesetsArray [ 0 ] . ruleset , rulesetsArray [ 0 ] . hash , ( ruleset ) => this . remove ( ruleset ) ) ; } /**
     * Register the supplied ruleset
     */ public add ( ruleset ) { const foundRuleset = this . _registeredRulesets . get ( ruleset . id ) ; if ( foundRuleset ) return foundRuleset ; const hash = this . _getNativePlatform ( ) . addRuleset ( JSON . stringify ( ruleset ) ) . result ; return this . saveRuleset ( ruleset , hash , ( r ) => this . remove ( r ) ) ; } /**
     * Unregister the supplied ruleset
     */ public remove ( ruleset ) { let rulesetId , rulesetIdentifier ; if ( Array . isArray ( ruleset ) ) { rulesetId = ruleset [ 0 ] ; rulesetIdentifier = ruleset [ 1 ] ; } else { rulesetId = ruleset . id ; rulesetIdentifier = ruleset . uniqueIdentifier ; } this . _registeredRulesets . delete ( rulesetId ) ; return this . _getNativePlatform ( ) . removeRuleset ( rulesetId , rulesetIdentifier ) . result ; } /**
     * Remove all rulesets registered in this session.
     */ public clear ( ) { this . _getNativePlatform ( ) . clearRulesets ( ) ; this . _registeredRulesets . clear ( ) ; } private saveRuleset ( ruleset , hash , disposeFunc ) { const newRuleset = new RegisteredRuleset ( ruleset , hash , disposeFunc ) ; this . _registeredRulesets . set ( newRuleset . id , newRuleset ) ; return newRuleset ; } } interface RulesetResponseJson { ruleset : Ruleset ; hash : string ; }