feat(plugin-tools): add types for "loader" plugins
This commit is contained in:
parent
70d2140dde
commit
81fde2ebd3
2 changed files with 31 additions and 2 deletions
5
.changeset/spicy-seahorses-listen.md
Normal file
5
.changeset/spicy-seahorses-listen.md
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
'@emigrate/plugin-tools': minor
|
||||||
|
---
|
||||||
|
|
||||||
|
Prepare for supporting "loader" plugins. A loader plugin is used to transform a migration file of a given type (file extension) to a function that will execute the actual migration.
|
||||||
|
|
@ -87,12 +87,36 @@ export type GeneratorPlugin = {
|
||||||
|
|
||||||
export type GenerateMigrationFunction = GeneratorPlugin['generateMigration'];
|
export type GenerateMigrationFunction = GeneratorPlugin['generateMigration'];
|
||||||
|
|
||||||
|
export type MigrationFunction = () => Promise<void>;
|
||||||
|
|
||||||
|
export type MigrationMetadata = {
|
||||||
|
name: string;
|
||||||
|
filename: string;
|
||||||
|
extension: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type LoaderPlugin = {
|
||||||
|
/**
|
||||||
|
* The file extensions that this plugin can load.
|
||||||
|
*/
|
||||||
|
loadableExtensions: string[];
|
||||||
|
/**
|
||||||
|
* Used to load a migration file, i.e. transform it into a function that can be executed.
|
||||||
|
*
|
||||||
|
* @param migration Some metadata about the migration file that should be loaded.
|
||||||
|
* @returns A function that will execute the migration.
|
||||||
|
*/
|
||||||
|
loadMigration(migration: MigrationMetadata): Promise<MigrationFunction>;
|
||||||
|
};
|
||||||
|
|
||||||
export type Plugin = StoragePlugin | GeneratorPlugin;
|
export type Plugin = StoragePlugin | GeneratorPlugin;
|
||||||
|
|
||||||
export type PluginType = 'storage' | 'generator';
|
export type PluginType = 'storage' | 'generator' | 'loader';
|
||||||
|
|
||||||
export type PluginFromType<T extends PluginType> = T extends 'storage'
|
export type PluginFromType<T extends PluginType> = T extends 'storage'
|
||||||
? StoragePlugin
|
? StoragePlugin
|
||||||
: T extends 'generator'
|
: T extends 'generator'
|
||||||
? GeneratorPlugin
|
? GeneratorPlugin
|
||||||
|
: T extends 'loader'
|
||||||
|
? LoaderPlugin
|
||||||
: never;
|
: never;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue