Open wovalle opened 5 years ago
Hi @wovalle - we're running into this issue in validating complex data types using nested classes with fireorm. Is there an update on this issue? Is there anything that we can help with?
Hey @ericliu121187, somehow I missed this notification.
Sadly there are no updates, I haven't had time to tackle this issue. What are you trying to accomplish?
Hi @wovalle , no worries. Let’s say we are creating a Post document via fireorm.
await getRepository(Post).create(
Post.create({
// ...data
}),
);
@Collection(‘posts’)
export class Post {
@Expose()
@IsString()
public readonly id!: string;
/**
* Metadata
*/
@Expose()
@IsObject()
public readonly metadata!: Readonly<{
author: Readonly<{
name: string;
}>;
data: Readonly<{
entities: Readonly<{
hashtags?: readonly unknown[];
urls?: readonly unknown[];
tags?: readonly unknown[];
}>;
description: string;
}>;
}>;
static create(
data: Partial<Post>,
): Post {
return plainToClass(Post, data);
}
}
Am I correct in saying that the nested values in metadata
would not be validated?
If not, do you have any suggestions in how we could validate it? Writing a custom validator isn't ideal here bc we want to work with classes to add custom methods to values + ideally, the validation would be recursive out-of-the-box.
What are your thoughts here?
Not an expert with validation but I think they won't be validated. In my case I'd try to flatten more the structure to have simple fields that can be easily validated.
Hello guys. Is there any progress with this one?
@hondem Not on my end. We decided to punt on validating nested data. My instinct is that there could be 2 approaches.
A. Fireorm can validate recursively B. Writing a custom validator
Any update on this?
In https://github.com/wovalle/fireorm/pull/56 we started re-exporting [class-transformer's @Type Decorator]() to be able to cast Firestore GeoPoint fields. That solution is far from final and was only meant as a temporary workaround.
The way Typescript works, types are not available at runtime. If you want to cast Firestore's complex types into your custom classes, you need to tell Typescript the class it should cast it to... via a Decorator.
This issue is more of an exploration in this topic. More information is needed to fully implement a flexible solution.
Acceptance criteria:
latitude
andlongitude
fields