declare global { interface Crypto { randomUUID ( ) : string ; } } export interface Post { id : string ; title : string ; body : string ; } export type Param = { title : string ; body : string ; } ; const posts = { } ; export const getPosts = ( ) : Post [ ] => { return Object . values ( posts ) ; } ; export const getPost = ( id ) : Post | undefined => { return posts [ id ] ; } ; export const createPost = ( param ) : Post | undefined => { if ( ! ( param . title && param . body ) ) return ; const id = crypto . randomUUID ( ) ; const newPost = { id : id , title : param . title , body : param . body } ; posts [ id ] = newPost ; return newPost ; } ; export const updatePost = ( id , param ) : boolean => { if ( ! ( param . title && param . body ) ) return false ; const post = posts [ id ] ; if ( post ) { post . title = param . title ; post . body = param . body ; return true ; } return false ; } ; export const deletePost = ( id ) : boolean => { if ( posts [ id ] ) { delete posts [ id ] ; return true ; } return false ; } ;