import { EntityConfig , EntityModel , JoinProperty } from '@commun/core' ; import { request , requestUntilSuccess } from '../utils/apiUtils' ; import { JSONSchema7 } from 'json-schema' ; export const EntityService = { async getEntities ( ) { return request ( 'GET' , '/admin/entities' ) ; } , async getEntity ( entityName ) { return request ( 'GET' , `/admin/entities/${ entityName }` ) ; } , async createEntity ( data ) { return request ( 'POST' , `/admin/entities` , data ) ; } , async updateEntity < T extends EntityModel > ( entityName , data ) { return request ( 'PUT' , `/admin/entities/${ entityName }` , data ) ; } , async deleteEntity < T extends EntityModel > ( entityName ) { return request ( 'DELETE' , `/admin/entities/${ entityName }` ) ; } , async updateEntityProperty ( entityName , propertyKey , property , required ? ) { return request ( 'PUT' , `/admin/entities/${ entityName }/properties/${ propertyKey }` , { ... property , required , } ) ; } , async deleteEntityProperty ( entityName , propertyKey ) { return request ( 'DELETE' , `/admin/entities/${ entityName }/properties/${ propertyKey }` ) ; } , async updateEntityJoinProperty ( entityName , propertyKey , joinProperty ) { return request ( 'PUT' , `/admin/entities/${ entityName }/joinProperties/${ propertyKey }` , joinProperty ) ; } , async deleteEntityJoinProperty ( entityName , attributeKey ) { return request ( 'DELETE' , `/admin/entities/${ entityName }/joinProperties/${ attributeKey }` ) ; } , async waitUntilEntityExist ( entityName ) { return requestUntilSuccess ( { waitBetweenRetries : 500 , maxRetries : 20 } , 'GET' , `/admin/entities/${ entityName }` ) ; } } ;