TypeScript Lookup Cache Loaders
Generator
The following table of contents provides an outline of the documentation for this generator.
1. Overview
Generates XomegaJS based classes for contextual loading of
lookup tables from a database using a service operation. The lookup cache is then used to populate selection lists and to
decode values, if the list is relatively static. The service operations for contextual cache loaders take input parameters, so
the generated cache loaders classes should be used as base classes for custom cache loaders, which will provide the input parameters
from the context that they are used in.
To generate cache loaders, the generator uses contextual "readlist" REST operations in the model that have rest:method
and xfk:enum-cache elements nested inside their config element. The xfk:enum-cache element must have
a skip-registration attribute set to "true", as well as the attribute enum-name with the name that is unique
across all enumerations defined in the model.
It should also specify id-param and desc-param attributes that indicate which output parameters of the
"read list" operation return the ID and Description of the record respectively. The ID is what is stored internally in the
system when you select an item from that list, and also what you typically look up the record by. The Description is what
is displayed to the user on the screen instead of (or in combination with) the ID. Any other output parameters will be stored
as additional named attributes of the cached record.
Contextual Loaders. The "readlist" operation of the contextual cache loaders take input parameters, so
you will need to subclass the generated class, and override the loadRequest method to supply their values for the current
context. The generated cache loaders cannot be used to load the cache by themslves, and therefore should not be registered with the framework.
To indicate that, you need to set the skip-registration attribute on the
xfk:enum-cache element to "true". The following example shows a "business entity address" cache loader,
which loads all addresses for a specific business entity.
Static Loaders. For "readlist" operations that have no input parameters, and return static data that can
be loaded into the lookup cache globally, the cache loaders are generated in C# by a separate generator for Xomega Framework
to load them into the lookup cache on the server side. The lookup tables are then exposed via a standard REST endpoint,
which XomegaJS framework uses to load the static data to the client. Therefore, there is no need to generate static TypeScript
cache loaders for such operations.
1.2 Generator outputs
This generator creates TypeScript classes for XomegaJS-based cache loaders that call the specified operation and
construct lookup tables from the results, with ID and description of each record according to the configuration,
and all other result parameters stored in additional attributes. For any operation input parameters,
the default (null) values will be passed for the service method call, which should be overridden in a subclass
as appropriate.
The generator also adds the generated classes to the specified project as needed.
2. Configuration
The following sections describe configuration parameters used by the generator.
2.1 Generator parameters
The following table lists configuration parameters that are set as the generator’s properties.
Parameter |
Value Example |
Description |
Generator Name |
TypeScript Lookup Cache Loaders
|
The name of the current configuration of the generator that will appear in the model project and the build output. |
Folder |
Presentation Layer\SPA
|
Folder path to the generator inside the Model project. The folders are separated by a backslash (\). |
Include In Build |
True
|
A flag indicating whether or not running this generator should be included in building of the model project. |
Output |
Output Path |
../MySolution.Services.Spa /CacheLoaders/{File}.ts |
Relative path where to output files with generated Lookup Cache Loaders. The path may contain {Module/} and {File} placeholders
to output files by module and data object respectively.
|
Add To Project |
../MySolution.Services.Spa /MySolution.Services.Spa.csproj |
Relative path to the project file to add the generated files to. The project will be reloaded every time you run the generator.
Leave it blank if you don't want generated files to be added to your project automatically.
|
2.2 Model configuration
Parameters specified in the model configuration that are used by this generator consist of the output path for the TypeScript
service contracts. This is specified in the wcf:services-config element under the top level config model
element, which is conventionally placed in the global_config.xom file, as follows.
2.3 Common configurations
There expected to be just one configuration of this generator in the model, with the parameter values as illustrated above.
3. How to use the generator
The sections below provide some details on how to work with the generator.
3.1 Running the generator
You can run this generator either for the entire model, or for individual files by selecting them in the model project,
and running the generator from the context menu.
You can rerun the generator when you add or change the contextual xfk:enum-cache configuration of "readlist" operations,
or if you change any parameters on those operations. Normally, the latter will require re-running other generators
that depend on the same model elements, such as generators of UI views, data objects, service and data contracts or
the service implementations. Therefore, this generator should be included in the build of the model project in the configuration,
in order to allow to easily regenerate all cache loaders along with other artifacts.
3.2 Customizing the output
You should never edit generated cache loaders directly. This allows re-running the generator at any time without losing
your customizations.
To add your customizations, you should create a subclass of the generated cache loader class, and use the subclass in your code.
3.3 Cleaning generator’s output
This generator supports cleaning either all generated cache loaders, or only the ones from the selected model files using
the Clean context menu for that generator. Normally, cleaning the generated files makes sense if you are planning to change
the output path for the generator. Also, it can be used as part of Regenerate action, which runs the Clean and then Generate
actions, when you have removed some of the data objects from the model, and want the generated classes deleted and removed
from the target project.