useEntityManager.ts 589 B

12345678910111213141516
  1. import EntityManager from "~/services/data/entityManager";
  2. import {useAp2iRequestService} from "~/composables/data/useAp2iRequestService";
  3. import ApiResource from "~/models/ApiResource";
  4. import {useRepo} from "pinia-orm";
  5. let entityManager: EntityManager | null = null
  6. export const useEntityManager = () => {
  7. if (entityManager === null) {
  8. const { apiRequestService } = useAp2iRequestService()
  9. const getRepo = (model: typeof ApiResource) => useRepo(model)
  10. entityManager = new EntityManager(apiRequestService, getRepo)
  11. }
  12. return { em: entityManager }
  13. }