s7webserverapi
Version:
Unofficial Simatic-S7-Webserver JSON-RPC-API Client for S7-1200/1500 PLCs
113 lines (112 loc) • 4.33 kB
TypeScript
import { FlattenKeys } from "../util/types";
/**
* Helper class that holds the cache-structure for the PLC-Connector.
* Its used to easily access and write values in the cache given a flattened key that fits to the template T
*
* @export
* @class CacheStructure
* @typedef {CacheStructure}
* @template T - The type of the cacheObject that is used to store the values
*/
export declare class CacheStructure<T> {
/**
* Holds the actual values of the cache
*
* @public
* @type {{}}
*/
cacheObject: {};
/**
* Parses a flattened key into an array of key-elements. A number is later interpreted as an array-index. A string is interpreted as an object-key
*
* @public
* @param {(FlattenKeys<T> | string)} flattenedKey
* @returns {(string | number)[]}
*/
parseFlattenedKey(flattenedKey: FlattenKeys<T> | string): (string | number)[];
constructor(initObject?: any);
/**
* Static helper function that gets the next reference from a given reference and a new key.
*
* @public
* @static
* @param {*} ref
* @param {string} newKey
* @returns {any}
*/
static getNextReference(ref: any, newKey: string): any;
/**
* Checks if an entry with the given flattened key exists in the cache
*
* @public
* @param {FlattenKeys<T>} flattenedKey
* @returns {boolean}
*/
entryExists(flattenedKey: FlattenKeys<T>): boolean;
/**
* Gets a copy of a value in the cache. Useful if the value is an object and we need to change the value somewhere else without chaning the original value in the cache
*
* @public
* @param {FlattenKeys<T>} flattenedKey
* @returns {*}
*/
getCopy(flattenedKey: FlattenKeys<T>): any;
/**
* Recursive function to deeply clone an object. Since we only have a simple structure that is deeply nested this function should be enough.
* @param obj Object to clone
* @returns
*/
private deepClone;
/**
* Gets a reference to a value in the cache. Useful if the value is an object and we need to change the value somewhere else and want to change the original value in the cache
*
* @public
* @param {FlattenKeys<T>} flattenedKey
* @returns {any}
*/
getReference(flattenedKey: FlattenKeys<T>): any;
/**
* Writes a value to the cache given a flattened key. It also builds up the structure if it does not exist yet.
* E.g. if the cache is completley empty {} and we call this function with ("test.someArray", [0,1,2]) the resulting cache looks liek this at the end:
* {
* test: {
* someArray: [0,1,2]
* }
* }
*
* @public
* @param {FlattenKeys<T>} flattenedKey
* @param {*} value
*/
writeEntry(flattenedKey: FlattenKeys<T>, value: any): void;
/**
* Checks if the key is correct and fills up the cache structure up to the second last key. this is used before we write a value to the cache.
* @param flattenedKey
* @returns the reference to the second last key in the cache structure
*/
private checkAndFillCacheStructure;
/**
*
* @param current Reference to the current level in the cache structure
* @param key The key that should be checked, relative to the current level
* @param nextKey The next key that should be checked. Given this key we can determine if we need to insert an array or an object
* @returns the reference to the next level in the cache structure, given the key.
*/
private ensureKeyExists;
/**
*
* @param current Reference to the current level in the cache structure
* @param key The key that should be initialized
* @param nextKey The next key that should be initialized. Given this next key, we can determine if we need to insert an array or an object
* @returns the initialized next level in the cache structure
*/
private initializeNextLevel;
/**
* Determines if the next level in the cache structure should be an array or an object
* Placeholder if in the future we want to use a different structure for the cache
* @param nextKey
* @returns
*/
private determineNewLevelType;
hmiKeyLoaded(key: FlattenKeys<T> | FlattenKeys<T>[]): boolean;
}