Skip to content

ChainGraph API Documentation / @badaitech/chaingraph-types / PortEnumFromObject

Function: PortEnumFromObject()

PortEnumFromObject<T>(options, config?): PropertyDecorator

Defined in: packages/chaingraph-types/src/decorator/enum.decorator.ts:128

PortEnumFromObject decorator creates an enum port based on an object mapping.

The keys of the provided object are used as option identifiers and titles, while their corresponding values become the option's defaultValue. The option type is automatically inferred as follows:

  • strings become type 'string'
  • numbers become type 'number'
  • booleans become type 'boolean'
  • objects (non-null) become type 'object'

The default selected option (if not explicitly provided in config) is the first key from the mapping.

Example usage:

const userStatusOptions = { active: new UserStatus('Active'), inactive: new UserStatus('Inactive'), pending: new UserStatus('Pending'), } // Here default will be "active" (first key) @PortEnumFromObject(userStatusOptions, { defaultValue: 'active' }) public statusEnum: keyof typeof userStatusOptions;

Type Parameters

T

T extends Record<string, any>

Parameters

options

T

An object mapping keys to option values.

config?

Omit<EnumPortConfig, "options" | "type">

Optional configuration for the enum port (excluding the "type" property).

Returns

PropertyDecorator

Licensed under BUSL-1.1