Linked map support (#801)

* able to get head

* head actually working

* Correctly get linkage

* I think it is working

* Results now return both keys and values
This commit is contained in:
Jaco Greeff
2019-03-27 15:34:11 +01:00
committed by GitHub
parent d4646f99c6
commit cda0ef3486
10 changed files with 284 additions and 70 deletions
+27 -17
View File
@@ -194,9 +194,14 @@ export default class Rpc implements RpcInterface {
const Clazz = createClass(type);
const meta = key.meta || { default: undefined, modifier: { isOptional: true } };
return meta.modifier.isOptional
? new Option(Clazz, isNull(result) ? null : new Clazz(base))
: new Clazz(base);
if (key.meta && key.meta.type.isMap && key.meta.type.asMap.isLinked) {
// linked map
return new Clazz(base);
} else {
return meta.modifier.isOptional
? new Option(Clazz, isNull(result) ? null : new Clazz(base))
: new Clazz(base);
}
} else if (method.type === 'StorageChangeSet') {
// multiple return values (via state.storage subscription), decode the values
// one at a time, all based on the query types. Three values can be returned -
@@ -215,21 +220,26 @@ export default class Rpc implements RpcInterface {
) || { value: null };
const meta = key.meta || { default: undefined, modifier: { isOptional: true } };
// if we don't have a value, do not fill in the entry, it will be up to the
if (!value) {
// if we don't have a value, do not fill in the entry, it will be up to the
// caller to sort this out, either ignoring or having a cache for older values
result.push(
!value
? undefined
: (
meta.modifier.isOptional
// create option either with the existing value, or empty when
// there is no value returned
? new Option(Clazz, value.isNone ? null : new Clazz(value.unwrap()))
// for `null` we fallback to the default value, or create an empty type,
// otherwise we return the actual value as retrieved
: new Clazz(value.unwrapOr(meta.default))
)
);
result.push(undefined);
} else {
if (key.meta && key.meta.type.isMap && key.meta.type.asMap.isLinked) {
// linked map
result.push(new Clazz(value.unwrapOr(null)));
} else {
if (meta.modifier.isOptional) {
// create option either with the existing value, or empty when
// there is no value returned
result.push(new Option(Clazz, value.isNone ? null : new Clazz(value.unwrap())));
} else {
// for `null` we fallback to the default value, or create an empty type,
// otherwise we return the actual value as retrieved
result.push(new Clazz(value.unwrapOr(meta.default)));
}
}
}
return result;
}, [] as Array<Codec | null | undefined>);