entity.ts 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import ContentDirectoryCommandBase from '../../base/ContentDirectoryCommandBase'
  2. import chalk from 'chalk'
  3. import { displayCollapsedRow, displayHeader } from '../../helpers/display'
  4. import _ from 'lodash'
  5. export default class EntityCommand extends ContentDirectoryCommandBase {
  6. static description = 'Show Entity details by id.'
  7. static args = [
  8. {
  9. name: 'id',
  10. required: true,
  11. description: 'ID of the Entity',
  12. },
  13. ]
  14. async run() {
  15. const { id } = this.parse(EntityCommand).args
  16. const entity = await this.getEntity(id, undefined, undefined, false)
  17. const { controller, frozen, referenceable } = entity.entity_permissions
  18. const [classId, entityClass] = await this.classEntryByNameOrId(entity.class_id.toString())
  19. const propertyValues = this.parseEntityPropertyValues(entity, entityClass)
  20. displayCollapsedRow({
  21. 'ID': id,
  22. 'Class name': entityClass.name.toString(),
  23. 'Class ID': classId.toNumber(),
  24. 'Supported schemas': JSON.stringify(entity.supported_schemas.toJSON()),
  25. 'Controller': controller.type + (controller.isOfType('Member') ? `(${controller.asType('Member')})` : ''),
  26. 'Frozen': frozen.toString(),
  27. 'Refrecencable': referenceable.toString(),
  28. 'Same owner references': entity.reference_counter.same_owner.toNumber(),
  29. 'Total references': entity.reference_counter.total.toNumber(),
  30. })
  31. displayHeader('Property values')
  32. displayCollapsedRow(
  33. _.mapValues(
  34. propertyValues,
  35. (v) =>
  36. (v.value === null ? chalk.grey('[not set]') : v.value.toString()) +
  37. ` ${chalk.green(`${v.type}<${v.subtype}>`)}`
  38. )
  39. )
  40. }
  41. }