function importedBlocksIterate ( importedBlocks , action ) { importedBlocks . forEach ( ( importedModule ) => { Object . keys ( importedModule ) . filter ( ( item ) => ! item . includes ( "_init_blocks" ) ) . forEach ( ( k ) => { action ( k , importedModule ) ; } ) ; } ) ; } export const addImportedBlocks = ( importedBlocks ) => importedBlocksIterate ( importedBlocks , ( k , importedModule ) => { globalThis [ k ] = importedModule [ k ] ; } ) ; export const removeImportedBlocks = ( importedBlocks ) => importedBlocksIterate ( importedBlocks , ( k ) => { delete globalThis [ k ] ; } ) ; export interface RunError { exception : Error ; blockId : string ; } export type Function = ( ... args : any [ ] ) => any ; export type AsyncFunction = ( ... args : any [ ] ) => Promise < any > ; export const makeAsyncFn = Object . getPrototypeOf ( async function ( ) { } ) . constructor ; export const makeHighlightBlock = ( highlighter , globalThisIdKey ) => async function ( id , f ) { const prevId = globalThis [ globalThisIdKey ] ; highlighter ( id ) ; const ret = await f ( ) ; highlighter ( prevId ) ; return ret ; } ; export const addGlobals = ( globals ) => Object . entries ( globals ) . forEach ( ( [ k , v ] ) => { globalThis [ k ] = v ; } ) ; export const removeGlobals = ( globals ) => Object . keys ( globals ) . forEach ( ( k ) => { delete globalThis [ k ] ; } ) ; export const serializeError = < T extends Error > ( error ) => Object . fromEntries ( Array . from ( new Set ( [ ... Object . getOwnPropertyNames ( Object . getPrototypeOf ( error ) ) , ... Object . getOwnPropertyNames ( error ) ] ) ) . filter ( ( k ) => typeof error [ k ] !== "function" ) . map ( ( k ) => [ k , error [ k ] ] ) ) as T ;