Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Firestore Complex Types handling #58

Open
5 tasks
wovalle opened this issue Jun 26, 2019 · 7 comments
Open
5 tasks

Firestore Complex Types handling #58

wovalle opened this issue Jun 26, 2019 · 7 comments
Labels
enhancement New feature or request planning
Milestone

Comments

@wovalle
Copy link
Owner

wovalle commented Jun 26, 2019

In #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:

  • Explore each of the Firestore Data Types, create unit tests for complex types.
  • Get rid of class transformers @type
  • Create a new Decorator (@Transform?) to store field's type-casting information and (probably) some constraints.
  • The new decorator MUST provide a way to call custom constructors and let the owner of the class "construct" its object. This is to get rid of the current limitation in which in order to parse a GeoPoint, you must provide a class with public latitude and longitude fields
  • The new Decorator MUST enforce the user to provide a way to serialize and deserialize data. How we will be able to store an object with a custom GeoPoint class if we don't now how to serialize it back?
@wovalle wovalle changed the title Firestore Types handling Firestore Complex Types handling Jun 26, 2019
@wovalle wovalle added this to the v1 milestone Jun 26, 2019
@wovalle wovalle added enhancement New feature or request planning labels Jun 26, 2019
@wovalle wovalle removed this from the v1 milestone Sep 4, 2019
@wovalle wovalle added this to the next-major milestone Sep 30, 2019
@eric-ships
Copy link

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?

@wovalle
Copy link
Owner Author

wovalle commented Feb 1, 2021

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?

@eric-ships
Copy link

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?

@wovalle
Copy link
Owner Author

wovalle commented Feb 13, 2021

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.

@hondem
Copy link

hondem commented Mar 20, 2021

Hello guys. Is there any progress with this one?

@eric-ships
Copy link

@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

@Yunus1903
Copy link

Any update on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request planning
Projects
None yet
Development

No branches or pull requests

4 participants