// // Copyright 2025 DXOS.org // import type { InspectOptionsStylized, inspect as inspectFn } from 'node:util'; import { type CustomInspectFunction, inspectCustom } from '@dxos/debug'; import { getTypeURI } from '../Annotation'; import { ATTR_TYPE, type AnyEntity } from '../common/types'; import { ATTR_META } from '../common/types/meta'; import { MetaId } from '../common/types/model-symbols'; /* * @internal */ export const attachedTypedObjectInspector = (obj: any) => { const descriptor = Object.getOwnPropertyDescriptor(obj, inspectCustom); if (descriptor) { return; } Object.defineProperty(obj, inspectCustom, { value: typedObjectInspectFunction, writable: false, enumerable: false, configurable: true, }); }; // NOTE: KEEP as function. const typedObjectInspectFunction: CustomInspectFunction = function ( this: AnyEntity, depth: number, options: InspectOptionsStylized, inspect: typeof inspectFn, ) { const { id, ...props } = this; return inspect( { id, [ATTR_TYPE]: getTypeURI(this), ...props, [ATTR_META]: (this as any)[MetaId], // TODO(dmaretskyi): Couldn't use getMeta since that throw's if the object has no meta. }, options, ); };