@@ -32,14 +32,16 @@ import { Server, createServer, registerFormat, IncomingMessage, OutgoingMessage
3232import slugify from "slugify" ;
3333import { Readable } from "stream" ;
3434import { MdnsIntroducer } from "./mdns-introducer" ;
35- import { PropertyElement , DataSchema } from "wot-thing-description-types" ;
35+ import { PropertyElement , DataSchema , ActionElement , EventElement } from "wot-thing-description-types" ;
3636import { CoapServerConfig } from "./coap" ;
3737import { DataSchemaValue } from "wot-typescript-definitions" ;
3838
3939const { debug, warn, info, error } = createLoggers ( "binding-coap" , "coap-server" ) ;
4040
4141type CoreLinkFormatParameters = Map < string , string [ ] | number [ ] > ;
4242
43+ type AffordanceElement = PropertyElement | ActionElement | EventElement ;
44+
4345// TODO: Move to core?
4446type AugmentedInteractionOptions = WoT . InteractionOptions & { formIndex : number } ;
4547
@@ -228,6 +230,15 @@ export default class CoapServer implements ProtocolServer {
228230 return opValues ;
229231 }
230232
233+ private addFormToAffordance ( form : TD . Form , affordance : AffordanceElement ) : void {
234+ const affordanceForms = affordance . forms ;
235+ if ( affordanceForms == null ) {
236+ affordance . forms ??= [ form ] ;
237+ } else {
238+ affordanceForms . push ( form ) ;
239+ }
240+ }
241+
231242 private fillInPropertyBindingData ( thing : ExposedThing , base : string , offeredMediaType : string ) {
232243 for ( const [ propertyName , property ] of Object . entries ( thing . properties ) ) {
233244 const opValues = ProtocolHelpers . getPropertyOpValues ( property ) ;
@@ -241,7 +252,7 @@ export default class CoapServer implements ProtocolServer {
241252 property . uriVariables
242253 ) ;
243254
244- property . forms . push ( form ) ;
255+ this . addFormToAffordance ( form , property ) ;
245256 this . logHrefAssignment ( form , "Property" , propertyName ) ;
246257 }
247258 }
@@ -258,7 +269,7 @@ export default class CoapServer implements ProtocolServer {
258269 action . uriVariables
259270 ) ;
260271
261- action . forms . push ( form ) ;
272+ this . addFormToAffordance ( form , action ) ;
262273 this . logHrefAssignment ( form , "Action" , actionName ) ;
263274 }
264275 }
@@ -275,7 +286,7 @@ export default class CoapServer implements ProtocolServer {
275286 event . uriVariables
276287 ) ;
277288
278- event . forms . push ( form ) ;
289+ this . addFormToAffordance ( form , event ) ;
279290 this . logHrefAssignment ( form , "Event" , eventName ) ;
280291 }
281292 }
0 commit comments