import { schema } from '@osd/config-schema' ; import { IRouter } from '../../http' ; export const registerCreateRoute = ( router ) => { router . post ( { path : '/{type}/{id?}' , validate : { params : schema . object ( { type : schema . string ( ) , id : schema . maybe ( schema . string ( ) ) , } ) , query : schema . object ( { overwrite : schema . boolean ( { defaultValue : false } ) , } ) , body : schema . object ( { attributes : schema . recordOf ( schema . string ( ) , schema . any ( ) ) , migrationVersion : schema . maybe ( schema . recordOf ( schema . string ( ) , schema . string ( ) ) ) , references : schema . maybe ( schema . arrayOf ( schema . object ( { name : schema . string ( ) , type : schema . string ( ) , id : schema . string ( ) , } ) ) ) , initialNamespaces : schema . maybe ( schema . arrayOf ( schema . string ( ) , { minSize : 1 } ) ) , } ) , } , } , router . handleLegacyErrors ( async ( context , req , res ) => { const { type , id } = req . params ; const { overwrite } = req . query ; const { attributes , migrationVersion , references , initialNamespaces } = req . body ; const options = { id , overwrite , migrationVersion , references , initialNamespaces } ; const result = await context . core . savedObjects . client . create ( type , attributes , options ) ; return res . ok ( { body : result } ) ; } ) ) ; } ;