From 81fde2ebd3d5389328b5de87a863136fb7241bb4 Mon Sep 17 00:00:00 2001 From: Joakim Carlstein Date: Wed, 15 Nov 2023 16:00:21 +0100 Subject: [PATCH] feat(plugin-tools): add types for "loader" plugins --- .changeset/spicy-seahorses-listen.md | 5 +++++ packages/plugin-tools/src/types.ts | 28 ++++++++++++++++++++++++++-- 2 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 .changeset/spicy-seahorses-listen.md 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;