mage-module-staticdata
Static data module (TypeScript), including a Google Spreadsheet add-on to manage exports and imports.
Installation
npm install --save mage-module-staticdata
If you wish to validate your schema upon import, you will
also want to install class-validator
npm install --save class-validator
Finally, if you plan to use the
MAGE Static Data Manager Add-on for Google Spreadsheets,
you will also want to install mage-https-devel
. This is needed
to allow seamless communication over HTTPS between the Google Spreadsheet
Add-on and your MAGE local server during development.
npm install --save mage-https-devel
Usage
Creating a module instance
lib/modules/staticData/index.ts
// Load the staticdata external module /** * Static Data module class * * We create an instance of this module, which will * be used to import, export, and provide static data. * * @class StaticDataModule * @extends */
Creating user commands
For instance if you wish to use this module with the
MAGE Static Data Manager Add-on for Google Spreadsheets,
you will need to create at least an import
and export
user command.
lib/modules/staticData/usercommands/export.ts
/** * * @module staticData */ // mage // validation tools // User command
Creating your static data structure
lib/modules/staticData/types/StaticData.ts
/** * The StaticData class is the root] * class for static data; all static data * items must be added here. * * @export * @class * @extends */
The @StaticData()
decorator takes the following parameters:
- name: Human-readable name; can be used by content management tools for display
- options:
- If the attribute is an array or an object, you will need to put the class for this attribute
- Otherwise, it can be used to transmit metadata information usable by content management tools
lib/modules/staticData/types/StaticData.ts
/** * Sample card class * * @export * @class * @extends */
Here we see that we can both add meta-data to our entry and validation decorators.
MAGE Static Data Manager Add-on for Google Spreadsheets
Coming soon (with link updates).
Storage & access to the static data
Location
By default, your static data will be stored into a static.dat
file
at the top level of your project. This behaviours is of course
configurable:
config/default.yaml
static: location: 'lib/modules/staticData/dump.dat'
Remote storage
Additionally, you can alter your module class
by creating your own load
and store
methods;
this will allow you to distribute the update process
when pushing static data to a full-blown MAGE cluster.
lib/modules/staticData/index.ts
This static data module instance will automatically make sure to broadcast the static data update to all MAGE nodes in the cluster.
Clustering
Unless you define a load
and a store
method override, data will automatically
be propagated throughout your cluster. If you wish to keep this behavior, simply
make sure to add the notify
method call in your store
override:
lib/modules/staticData/index.ts
However, doing this will likely pose scalability issues, since now you
will be sending static data from a single MAGE node to all other nodes.
What you will likely want to do, instead, is add an update
method override
which will take care of loading the data from the right location.
lib/modules/staticData/index.ts
License
MIT.