@@ -194,46 +194,56 @@ func (vm *jsinterpreter) registerStack(stack *schema.Stack) func(string, map[str
194194 }
195195}
196196
197- func (vm * jsinterpreter ) registerMetadata (stack * schema.Stack ) func (map [ string ] interface {} ) {
198- return func (meta map [ string ] interface {} ) {
197+ func (vm * jsinterpreter ) registerMetadata (stack * schema.Stack ) func (goja. Value ) {
198+ return func (metaValue goja. Value ) {
199199 log .Debug ("register metadata" , "stack" , stack .Name )
200200
201201 metadata := & schema.Metadata {}
202202
203- if desc , ok := meta ["description" ].(string ); ok {
204- metadata .Description = desc
203+ // Get the metadata object
204+ metaObj := metaValue .ToObject (vm .rt )
205+ if metaObj == nil {
206+ return
205207 }
206208
207- if owner , ok := meta ["owner" ].(string ); ok {
208- metadata .Owner = owner
209+ // Extract description
210+ if descVal := metaObj .Get ("description" ); descVal != nil && ! goja .IsUndefined (descVal ) {
211+ if desc , ok := descVal .Export ().(string ); ok {
212+ metadata .Description = desc
213+ }
209214 }
210215
211- if tags , ok := meta ["tags" ].([]interface {}); ok {
212- metadata .Tags = make ([]string , 0 , len (tags ))
213- for _ , tag := range tags {
214- if tagStr , ok := tag .(string ); ok {
215- metadata .Tags = append (metadata .Tags , tagStr )
216- }
216+ // Extract owner
217+ if ownerVal := metaObj .Get ("owner" ); ownerVal != nil && ! goja .IsUndefined (ownerVal ) {
218+ if owner , ok := ownerVal .Export ().(string ); ok {
219+ metadata .Owner = owner
217220 }
218221 }
219222
220- // Store custom fields preserving order
221- if customObj , ok := meta ["custom" ].(map [string ]interface {}); ok {
222- // Use goja to get object keys in order
223- if vm .rt != nil {
224- customValue := vm .rt .ToValue (meta ["custom" ])
225- if obj := customValue .ToObject (vm .rt ); obj != nil {
226- keys := obj .Keys ()
227- orderedCustom := make ([]interface {}, 0 , len (keys )* 2 )
228- for _ , key := range keys {
229- val := obj .Get (key )
230- orderedCustom = append (orderedCustom , key , val .Export ())
223+ // Extract tags
224+ if tagsVal := metaObj .Get ("tags" ); tagsVal != nil && ! goja .IsUndefined (tagsVal ) {
225+ if tagsExport := tagsVal .Export (); tagsExport != nil {
226+ if tags , ok := tagsExport .([]interface {}); ok {
227+ metadata .Tags = make ([]string , 0 , len (tags ))
228+ for _ , tag := range tags {
229+ if tagStr , ok := tag .(string ); ok {
230+ metadata .Tags = append (metadata .Tags , tagStr )
231+ }
231232 }
232- metadata .Custom = orderedCustom
233233 }
234- } else {
235- // Fallback to map
236- metadata .Custom = customObj
234+ }
235+ }
236+
237+ // Extract custom fields preserving order
238+ if customVal := metaObj .Get ("custom" ); customVal != nil && ! goja .IsUndefined (customVal ) {
239+ if customObj := customVal .ToObject (vm .rt ); customObj != nil {
240+ keys := customObj .Keys ()
241+ orderedCustom := make ([]interface {}, 0 , len (keys )* 2 )
242+ for _ , key := range keys {
243+ val := customObj .Get (key )
244+ orderedCustom = append (orderedCustom , key , val .Export ())
245+ }
246+ metadata .Custom = orderedCustom
237247 }
238248 }
239249
0 commit comments