UNPKG

@apistudio/apim-cli

Version:

CLI for API Management Products

63 lines (44 loc) 1.83 kB
# Variable Context Manager ### How to use it First create context by importing VCM which will be default context ```ts VCM.createContext("test"); ``` To create a new context manager instance, instead of using default one. Create instance for context manager and create context. ```ts const ctx = new ContextManager(); ``` ### How to set variables in store. We have two stores. - Global store - which is unique for entire context. i.e for "VCM" it will be one global store. On createContext, two other stores will be created for each context. - Environment store - which will have least priority in the context - Variable store - which will have highest priority in the context To set variables on global context ```ts VCM.getGlobalContext().setVariable("env", "prod"); ``` To set variables on variable context. Both `set` and `setVariable` can be used. ```ts VCM.createContext("contextA").setVariable("user", "Alice"); VCM.createContext("contextA").set("user", "Alice"); VCM.getContext("contextA")?.setVariable("userJson", { name: "Alice", address: { city: "London", country: "UK" }, }); ``` To get variable ```ts VCM.createContext("contextA").setVariable("user", "Alice"); VCM.getContext("contextA").getValue("content-type") -> which return value VCM.getContext("contextA").get("content-type") -> which return object, which have value and isSecret key. ``` To resolve variable. which will check variable store, environment store then global store. ```ts VCM.resolve("testContext", input); ``` To get context ```ts VCM.getContext("test")?.getAll(); -> Get all stores within the context, which will not give global variable VCM.getContext("test")?.getEnvStore(); Get environment stores within the mentioned context VCM.getContext("test")?.getVarStore(); Get Variable store within the mentioned context ```