Schema value processors

These are categorized under schema managers as they oversee schema resources. Their main function is to process schema property values, searching for indicators suggesting that the processor must refine the value for use.

Take the variables manager as an example. When the parser encounters a root-level object named “variables” in the schema, it delegates its management to the variables manager. This manager is skilled in handling schema variables, ensuring that when these variables are employed in the schema’s property values, the variable’s value is utilized instead.

Furthermore, there are several conventions that the value processor must adhere to.

  1. The manager must possess a read-only “key” property, which identifies the root-level property that the object will manage.
  2. Additionally, it features a read-only “valueProcessor” property set to true. This property is crucial during the parser’s loading phase, where managers are registered. If this property is found to be true, an instance of this manager is added to the processor stack for use in value processing.
  3. The manager should include an “initialize” method, allowing the schema object to be passed to it for further management.
  4. It must also have a “reset” method, which is utilized to clear all internal data upon completion. This functionality also enables the manager to be reusable across different schemas.
  5. Lastly, it is essential to have a “process” method. This method, which takes a “value” parameter, is employed in the processing of schema value properties.
export default class VariablesManager extends BaseManager {
    get key() {
        return "variables"
    }

    get valueProcessor() {
        return true;
    }

    async reset() {
        delete this.variables;
    }

    async initialize(variables) {
        this.variables = variables;
    }

    async process(value) {
        // ... process the value and get the variable result
    }
}

Given this schema

{
    "variables" {
        "translations": {
            "submit": "SUBMIT"
        }
    }
}

When the parser checks if any managers have been registered for “variables” it will find the manager and call the initialize method passing the “variables” object to the instance.

Registering this manager with the parser is as simple as just calling the “register” method on the parser.

await parser.register(VariablesManager);