Documentation ¶
Overview ¶
Package typeregistry offers features useful to manage the registration and operation of types in the context of the jsii runtime. These are used to support type conversion for values exchanged between the child node process and the go application.
Index ¶
- type TypeRegistry
- func (t *TypeRegistry) DiscoverImplementation(vt reflect.Type) (interfaces []api.FQN, overrides []api.Override)
- func (t *TypeRegistry) EnumMemberForEnumRef(ref api.EnumRef) (interface{}, error)
- func (t *TypeRegistry) FindType(fqn api.FQN) (typ reflect.Type, ok bool)
- func (t *TypeRegistry) GetOverride(fqn api.FQN, n string) (api.Override, bool)
- func (t *TypeRegistry) InitJsiiProxy(val reflect.Value, valType reflect.Type) error
- func (t *TypeRegistry) InterfaceFQN(typ reflect.Type) (fqn api.FQN, found bool)
- func (t *TypeRegistry) IsAnonymousProxy(v interface{}) bool
- func (t *TypeRegistry) RegisterClass(fqn api.FQN, class reflect.Type, overrides []api.Override, ...) error
- func (t *TypeRegistry) RegisterEnum(fqn api.FQN, enm reflect.Type, members map[string]interface{}) error
- func (t *TypeRegistry) RegisterInterface(fqn api.FQN, iface reflect.Type, overrides []api.Override, ...) error
- func (t *TypeRegistry) RegisterStruct(fqn api.FQN, strct reflect.Type) error
- func (t *TypeRegistry) RegisterStructValidator(strct reflect.Type, validator func(interface{}, func() string) error) error
- func (t *TypeRegistry) StructFields(typ reflect.Type) (fields []reflect.StructField, fqn api.FQN, ok bool)
- func (t *TypeRegistry) TryRenderEnumRef(value reflect.Value) (ref *api.EnumRef, isEnumRef bool)
- func (t *TypeRegistry) ValidateStruct(v interface{}, d func() string) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type TypeRegistry ¶
type TypeRegistry struct {
// contains filtered or unexported fields
}
TypeRegistry is used to record runtime type information about the loaded modules, which is later used to correctly convert objects received from the JavaScript process into native go values.
func (*TypeRegistry) DiscoverImplementation ¶
func (t *TypeRegistry) DiscoverImplementation(vt reflect.Type) (interfaces []api.FQN, overrides []api.Override)
DiscoverImplementation determines the list of registered interfaces that are implemented by the provided type, and returns the list of their FQNs and overrides for all their combined methods and properties.
func (*TypeRegistry) EnumMemberForEnumRef ¶
func (t *TypeRegistry) EnumMemberForEnumRef(ref api.EnumRef) (interface{}, error)
EnumMemberForEnumRef returns the go enum member corresponding to a jsii fully qualified enum member name (e.g: "jsii-calc.StringEnum/A"). If no enum member was registered (via registerEnum) for the provided enumref, an error is returned.
func (*TypeRegistry) FindType ¶ added in v1.26.0
FindType returns the registered type corresponding to the provided jsii FQN.
func (*TypeRegistry) GetOverride ¶ added in v1.26.0
func (*TypeRegistry) InitJsiiProxy ¶
InitJsiiProxy initializes a jsii proxy value at the provided pointer. It returns an error if the pointer does not have a value of a registered proxyable type (that is, a class or interface type).
func (*TypeRegistry) InterfaceFQN ¶ added in v1.53.0
func (*TypeRegistry) IsAnonymousProxy ¶ added in v1.66.0
func (t *TypeRegistry) IsAnonymousProxy(v interface{}) bool
IsAnonymousProxy tells whether the value v is an anonymous object proxy, or a pointer to one.
func (*TypeRegistry) RegisterClass ¶
func (t *TypeRegistry) RegisterClass(fqn api.FQN, class reflect.Type, overrides []api.Override, maker func() interface{}) error
RegisterClass maps the given FQN to the provided class interface, list of overrides, and proxy maker function. This returns an error if the class type is not a go interface.
func (*TypeRegistry) RegisterEnum ¶
func (t *TypeRegistry) RegisterEnum(fqn api.FQN, enm reflect.Type, members map[string]interface{}) error
RegisterEnum maps the given FQN to the provided enum type, and records the provided members map (jsii member name => go value). This returns an error if the provided enum is not a string derivative, or of any of the provided member values has a type other than enm.
func (*TypeRegistry) RegisterInterface ¶
func (t *TypeRegistry) RegisterInterface(fqn api.FQN, iface reflect.Type, overrides []api.Override, maker func() interface{}) error
RegisterInterface maps the given FQN to the provided interface type, list of overrides, and proxy maker function. Returns an error if the provided interface is not a go interface.
func (*TypeRegistry) RegisterStruct ¶
RegisterStruct maps the given FQN to the provided struct type, and struct interface. Returns an error if the provided struct type is not a go struct, or the provided iface not a go interface.
func (*TypeRegistry) RegisterStructValidator ¶ added in v1.66.0
func (t *TypeRegistry) RegisterStructValidator(strct reflect.Type, validator func(interface{}, func() string) error) error
RegisterStructValidator adds a validator function to an already registered struct type. This is separate call largely to maintain backwards compatibility with existing code.
func (*TypeRegistry) StructFields ¶
func (t *TypeRegistry) StructFields(typ reflect.Type) (fields []reflect.StructField, fqn api.FQN, ok bool)
StructFields returns the list of fields associated with a jsii struct type, the jsii fully qualified type name, and a boolean telling whether the provided type was a registered jsii struct type.
func (*TypeRegistry) TryRenderEnumRef ¶
TryRenderEnumRef returns an enumref if the provided value corresponds to a registered enum type. The returned enumref is nil if the provided enum value is a zero-value (i.e: "").
func (*TypeRegistry) ValidateStruct ¶ added in v1.66.0
func (t *TypeRegistry) ValidateStruct(v interface{}, d func() string) error
ValidateStruct runs validations on the supplied struct to determine whether it is valid. In particular, it checks union-typed properties to ensure the provided value is of one of the allowed types.
May panic if v is not a pointer to a struct value.