diff --git a/.changeset/angry-houses-chew.md b/.changeset/angry-houses-chew.md new file mode 100644 index 0000000..d335e53 --- /dev/null +++ b/.changeset/angry-houses-chew.md @@ -0,0 +1,5 @@ +--- +'@emigrate/plugin-tools': patch +--- + +Add missing types and utility methods related to the new "loader" plugins diff --git a/packages/plugin-tools/src/index.ts b/packages/plugin-tools/src/index.ts index caae636..f448629 100644 --- a/packages/plugin-tools/src/index.ts +++ b/packages/plugin-tools/src/index.ts @@ -5,6 +5,7 @@ import { type GeneratorPlugin, type StoragePlugin, type Plugin, + type LoaderPlugin, } from './types.js'; export const isGeneratorPlugin = (plugin: any): plugin is GeneratorPlugin => { @@ -23,6 +24,14 @@ export const isStoragePlugin = (plugin: any): plugin is StoragePlugin => { return typeof plugin.initializeStorage === 'function'; }; +export const isLoaderPlugin = (plugin: any): plugin is LoaderPlugin => { + if (!plugin || typeof plugin !== 'object') { + return false; + } + + return typeof plugin.loadMigration === 'function' && Array.isArray(plugin.loadableExtensions); +}; + export const isPluginOfType = (type: T, plugin: any): plugin is PluginFromType => { if (type === 'generator') { return isGeneratorPlugin(plugin); @@ -32,6 +41,10 @@ export const isPluginOfType = (type: T, plugin: any): plug return isStoragePlugin(plugin); } + if (type === 'loader') { + return isLoaderPlugin(plugin); + } + throw new Error(`Unknown plugin type: ${type}`); }; diff --git a/packages/plugin-tools/src/types.ts b/packages/plugin-tools/src/types.ts index 90bb5f7..873fe86 100644 --- a/packages/plugin-tools/src/types.ts +++ b/packages/plugin-tools/src/types.ts @@ -109,7 +109,7 @@ export type LoaderPlugin = { loadMigration(migration: MigrationMetadata): Promise; }; -export type Plugin = StoragePlugin | GeneratorPlugin; +export type Plugin = StoragePlugin | GeneratorPlugin | LoaderPlugin; export type PluginType = 'storage' | 'generator' | 'loader';