MCPcopy
hub / github.com/vercel/hyper / decorateEntity

Function decorateEntity

app/plugins.ts:359–379  ·  view source on GitHub ↗
(base: any, key: string, type: 'object' | 'function')

Source from the content-addressed store, hash-verified

357// decorates the base entity by calling plugin[key]
358// for all the available plugins
359function decorateEntity(base: any, key: string, type: 'object' | 'function') {
360 let decorated = base;
361 modules.forEach((plugin) => {
362 if (plugin[key]) {
363 let res;
364 try {
365 res = plugin[key](decorated);
366 } catch (e) {
367 notify('Plugin error!', `"${plugin._name}" when decorating ${key}`, {error: e});
368 return;
369 }
370 if (res && (!type || typeof res === type)) {
371 decorated = res;
372 } else {
373 notify('Plugin error!', `"${plugin._name}": invalid return type for \`${key}\``);
374 }
375 }
376 });
377
378 return decorated;
379}
380
381function decorateObject<T>(base: T, key: string): T {
382 return decorateEntity(base, key, 'object');

Callers 2

decorateObjectFunction · 0.85
decorateClassFunction · 0.85

Calls 2

notifyFunction · 0.70
forEachMethod · 0.45

Tested by

no test coverage detected