Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
throw new ValidationError(`Failed to deserialize union. Errors: \n ${errors.map(e => e.message).join('\n ')}`);
}
const enm = deconstructEnum(stack, typeRef, key, value);
if (enm) {
return enm;
}
// if this is an interface, deserialize each property
const ifc = deconstructInterface(stack, typeRef, key, value);
if (ifc) {
return ifc;
}
// if this is an enum type, use the name to dereference
if (typeRef.type instanceof reflect.EnumType) {
const enumType = resolveType(typeRef.type.fqn);
return enumType[value];
}
if (typeRef.primitive) {
return value;
}
const enumLike = deconstructEnumLike(stack, typeRef, value);
if (enumLike) {
return enumLike;
}
const asType = deconstructType(stack, typeRef, value);
if (asType) {
return asType;
method(m: reflect.Method): T;
init(m: reflect.Initializer): T;
property(m: reflect.Property): T;
enumMember(m: reflect.EnumMember): T;
enumType(m: reflect.EnumType): T;
klass(m: reflect.ClassType): T;
iface(m: reflect.InterfaceType): T;
}) {
if (apiElement instanceof reflect.Method) { return fns.method(apiElement); }
if (apiElement instanceof reflect.Property) { return fns.property(apiElement); }
if (apiElement instanceof reflect.EnumMember) { return fns.enumMember(apiElement); }
if (apiElement instanceof reflect.ClassType) { return fns.klass(apiElement); }
if (apiElement instanceof reflect.InterfaceType) { return fns.iface(apiElement); }
if (apiElement instanceof reflect.Initializer) { return fns.init(apiElement); }
if (apiElement instanceof reflect.EnumType) { return fns.enumType(apiElement); }
throw new Error(`Unrecognized violator: ${apiElement}`);
}
function schemaForEnum(type: jsiiReflect.Type | undefined) {
if (!type || !(type instanceof jsiiReflect.EnumType)) {
return undefined;
}
return {
enum: type.members.map(m => m.name)
};
}