@@ -10,7 +10,7 @@ import type {
10
10
ControllerStateChangeEvent ,
11
11
} from '@metamask/base-controller' ;
12
12
import { BaseController } from '@metamask/base-controller' ;
13
- import type { PublicInterface } from '@metamask/utils' ;
13
+ import type { Json , PublicInterface } from '@metamask/utils' ;
14
14
import type { Patch } from 'immer' ;
15
15
16
16
export const controllerName = 'ComposableController' ;
@@ -39,6 +39,23 @@ type BaseControllerV1Instance = PublicInterface<
39
39
BaseControllerV1 < ConfigConstraintV1 , StateConstraintV1 >
40
40
> ;
41
41
42
+ /**
43
+ * A universal supertype of functions that accept a piece of controller state and return some derivation of that state.
44
+ */
45
+ type StateDeriverConstraint = ( value : never ) => Json ;
46
+
47
+ /**
48
+ * A universal supertype of metadata objects for individual state properties.
49
+ */
50
+ type StatePropertyMetadataConstraint = {
51
+ [ P in 'anonymous' | 'persist' ] : boolean | StateDeriverConstraint ;
52
+ } ;
53
+
54
+ /**
55
+ * A universal supertype of state metadata objects.
56
+ */
57
+ type StateMetadataConstraint = Record < string , StatePropertyMetadataConstraint > ;
58
+
42
59
/**
43
60
* A universal subtype of all controller instances that extend from `BaseController` (formerly `BaseControllerV2`).
44
61
* Any `BaseController` instance can be assigned to this type.
@@ -57,7 +74,9 @@ type BaseControllerInstance = Omit<
57
74
>
58
75
> ,
59
76
'metadata'
60
- > & { metadata : Record < string , unknown > } ;
77
+ > & {
78
+ metadata : StateMetadataConstraint ;
79
+ } ;
61
80
62
81
/**
63
82
* A universal subtype of all controller instances that extend from `BaseController` (formerly `BaseControllerV2`) or `BaseControllerV1`.
0 commit comments