import{logger as l}from"../../../../tools/notifiers/logger.js";import{entityDatabaseSchema as r}from"../../schemas/database-schemas.js";import{validateWithResult as s}from"../../utils/ajv-validator.js";const o=a=>"project_id"in a&&"organization_id"in a&&"created_at"in a;function d(a){if(o(a)){const e=s(r,a);if(!e.success)return l.warn(`Invalid database catalog entity for entity ${a.key}, error: ${e.error}`),null;const t=e.data||{};return{id:t.id,type:t.type,key:t.key||"",title:t.title||"",summary:t.summary||null,tags:t.tags?JSON.parse(t.tags):null,metadata:t.metadata?JSON.parse(t.metadata):null,git:t.git?JSON.parse(t.git):null,contact:t.contact?JSON.parse(t.contact):null,links:t.links?JSON.parse(t.links):null,source:t.source||"file",sourceFile:t.source_file||null,createdAt:t.created_at||null,updatedAt:t.updated_at||null,object:"catalogEntity"}}return{...a,tags:a.tags?JSON.parse(a.tags):null,metadata:a.metadata?JSON.parse(a.metadata):null,git:a.git?JSON.parse(a.git):null,contact:a.contact?JSON.parse(a.contact):null,links:a.links?JSON.parse(a.links):null,source:a.source||"file",object:"catalogEntity"}}export{d as createEntityReadModel};
