diff --git a/.changeset/spicy-seahorses-listen.md b/.changeset/spicy-seahorses-listen.md new file mode 100644 index 0000000..4979c11 --- /dev/null +++ b/.changeset/spicy-seahorses-listen.md @@ -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. diff --git a/packages/plugin-tools/src/types.ts b/packages/plugin-tools/src/types.ts index a35e013..90bb5f7 100644 --- a/packages/plugin-tools/src/types.ts +++ b/packages/plugin-tools/src/types.ts @@ -87,12 +87,36 @@ export type GeneratorPlugin = { export type GenerateMigrationFunction = GeneratorPlugin['generateMigration']; +export type MigrationFunction = () => Promise; + +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; +}; + export type Plugin = StoragePlugin | GeneratorPlugin; -export type PluginType = 'storage' | 'generator'; +export type PluginType = 'storage' | 'generator' | 'loader'; export type PluginFromType = T extends 'storage' ? StoragePlugin : T extends 'generator' ? GeneratorPlugin - : never; + : T extends 'loader' + ? LoaderPlugin + : never;