Plugin
ZenStack's "plugin" concept replaces PSL's "generator".
Plugin is a powerful mechanism that allows you to extend ZenStack at the schema, CLI, and runtime levels. This section only focuses on how to add plugins to your ZModel. Please refer to the Plugin Development guide for more details on how to develop plugins.
Adding plugins to ZModel​
Let's take a look at the following example:
plugin myPlugin {
provider = 'my-zenstack-plugin'
output = './generated'
}
In fact, the zen generate command is entirely implemented with plugins. The ZModel -> TypeScript generation is supported by the built-in @core/typescript plugin which runs automatically. You can explicitly declare it if you wish:
plugin typescript {
provider = '@core/typescript'
output = '../generated'
}
Please refer to the Plugin References for the full list of built-in plugins.
A plugin declaration involves three parts:
- A unique name
- A
providerfield that specifies where to load the plugin from. It can be a built-in plugin (like@core/prismahere), a local JS/TS module, or an NPM package name. - Plugin-specific configuration options, such as
outputin this case. Options are solely interpreted by the plugin implementation.
A plugin can have the following effects to ZModel:
- It can contribute custom attributes and functions that you can use to annotate models and fields.
- It can contribute code generation logic that's executed when you run the
zen generatecommand.
Plugins can also extend ZenStack's CLI and ORM runtime behavior. Please refer to the Plugin Development documentation for a comprehensive guide.