convector
convector copied to clipboard
Objects retrieved from Fabric should be mapped to ConvectorModels in terms of their keys
The problem
Functions on retrieved instances derived from a ConvectorModel like history and query promise to return an instance of a defined ConvectorModel. For example history(): Promise<History<T>[]>; The Template T is as I understand it a model extending ConvectorModel. Instead of returning an object of type T it returns an object where every key has the prefix '_' to the keys defined in T.
Current Behavior
history(): Promise<History<T>[]> does not return Promise<History<T>[]> but Promise<History<T2>[]> where T2 has '_' as the prefix to every key defined in T.
Expected Behavior
history(): Promise<History<T>[]> should actually return Promise<History<T>[]>
I think this is because those functions call the chaincode and just return the object returned from hyperledger fabric (I therefore suspect that all values are strings too). My expectation would be that the returned object would be cast to the specified ConvectorModel.
This is a problem in the way that Fabric is returning the response to client. A fix for this is in the way, expected to be merged and released in the next week.
In the meantime you can overcome this by doing (await myModel.history()) .map(item => ({...item, value: item.value.toJSON()}));
, not a sexy fix, but can get you out of the problem right now.