@@ -18,6 +18,7 @@ export class EnumFieldCondition<
18
18
constructor (
19
19
private readonly path : Path ,
20
20
private readonly allowed : ReadonlySet < ValueOfPath < TResourceStatic , Path > > ,
21
+ private readonly customId ?: string ,
21
22
) { }
22
23
23
24
isAllowed ( { object } : IsAllowedParams < TResourceStatic > ) {
@@ -51,6 +52,7 @@ export class EnumFieldCondition<
51
52
return new EnumFieldCondition (
52
53
conditionsForField [ 0 ] . path ,
53
54
new Set ( unioned ) ,
55
+ conditions . length === 1 ? conditions [ 0 ] . customId : undefined ,
54
56
) ;
55
57
} ) ;
56
58
}
@@ -63,11 +65,15 @@ export class EnumFieldCondition<
63
65
return new EnumFieldCondition (
64
66
conditionsForField [ 0 ] . path ,
65
67
new Set ( intersected ) ,
68
+ conditions . length === 1 ? conditions [ 0 ] . customId : undefined ,
66
69
) ;
67
70
} ) ;
68
71
}
69
72
70
73
[ inspect . custom ] ( _depth : number , _options : InspectOptionsStylized ) {
74
+ if ( this . customId ) {
75
+ return this . customId ;
76
+ }
71
77
return `${ startCase ( this . path ) } { ${ [ ...this . allowed ]
72
78
. map ( ( s ) => startCase ( s ) )
73
79
. join ( ', ' ) } }`;
@@ -83,17 +89,19 @@ export function field<
83
89
> (
84
90
path : Path ,
85
91
allowed : ManyIn < ValueOfPath < TResourceStatic , Path > > ,
86
- ... allowedMore : Array < ManyIn < ValueOfPath < TResourceStatic , Path > > >
92
+ customId ?: string ,
87
93
) {
88
94
const flattened = new Set (
89
- [ allowed , ...allowedMore ] . flatMap ( ( v ) =>
90
- // Assume values are strings to normalize cardinality.
91
- typeof v === 'string'
92
- ? [ v ]
93
- : [ ...( v as Array < ValueOfPath < TResourceStatic , Path > > ) ] ,
94
- ) ,
95
+ // Assume values are strings to normalize cardinality.
96
+ typeof allowed === 'string'
97
+ ? [ allowed ]
98
+ : [ ...( allowed as Array < ValueOfPath < TResourceStatic , Path > > ) ] ,
99
+ ) ;
100
+ return new EnumFieldCondition < TResourceStatic , Path > (
101
+ path ,
102
+ flattened ,
103
+ customId ,
95
104
) ;
96
- return new EnumFieldCondition < TResourceStatic , Path > ( path , flattened ) ;
97
105
}
98
106
99
107
type ManyIn < T extends string > = T | Iterable < T > ;
0 commit comments