42 lines
1.2 KiB
TypeScript
42 lines
1.2 KiB
TypeScript
import { useMetadataStore } from '~/stores/metadata'
|
|
import { createTableDataStore } from '~/stores/tableDataFactory'
|
|
|
|
export default defineNuxtPlugin(async (nuxtApp) => {
|
|
// Wait for metadata to be available
|
|
const metadataStore = useMetadataStore()
|
|
|
|
// Initialize metadata first
|
|
await metadataStore.initialize()
|
|
|
|
// Create stores for all available tables
|
|
const tableStores = new Map<string, ReturnType<typeof createTableDataStore>>()
|
|
|
|
metadataStore.allTables.forEach((table) => {
|
|
const storeName = table.table
|
|
const storeFactory = createTableDataStore(storeName, 100)
|
|
|
|
// Register the store
|
|
tableStores.set(storeName, storeFactory)
|
|
|
|
// Optionally initialize stores in the background (lazy loading)
|
|
// You can uncomment this to preload all data
|
|
// const storeInstance = storeFactory()
|
|
// storeInstance.loadFromCache()
|
|
})
|
|
|
|
// Provide access to table stores
|
|
return {
|
|
provide: {
|
|
tableStores,
|
|
// Helper function to get a table store
|
|
getTableStore: (tableName: string) => {
|
|
const storeFactory = tableStores.get(tableName)
|
|
if (!storeFactory) {
|
|
console.warn(`Table store for "${tableName}" not found`)
|
|
return null
|
|
}
|
|
return storeFactory()
|
|
}
|
|
}
|
|
}
|
|
}) |