jaberbu / onfirework

Makes Firebase easy to use
Other
0 stars 0 forks source link

Type filter #2

Closed ezequieltejada closed 3 years ago

ezequieltejada commented 3 years ago

Working on #1 it came to my mind the issue with typing the query.

How should we type the querys?

I suggest something like this:

import { FieldPath } from "@google-cloud/firestore";

export interface Filter {
    fieldPath: string | FieldPath,
    operation: string,
    value: any
}

But in index.ts:141 (for example) it makes a check if it is a filter or array of filters, Would it be simpler if we provided Filter[] as a type for the parameter in Onfirework.listDocs method's parameter? but it's going to be a breaking change depending how it was implemented.

jaberbu commented 3 years ago

If this breaking change brings more stability to the project, we should allow a Filter[] as unique parameter type available. Keep in mind that this logic is used both in Onfirework.listDocs and in Onfirework.deleteDocs

ezequieltejada commented 3 years ago

The "operation" property should be taken from firebase.firestore.whereFilterOp

imagen

jaberbu commented 3 years ago

It would also be good, that the fieldPath was suggested based on the instance passed to the Onfirework class

jaberbu commented 3 years ago

I am working on this issue and I have seen that for it to work correctly, the input data type shouldn´t be a Filter[] instance but a typeof WhereFilter [] where WhereFilter is a tuple of type [FieldPath, WhereFilterOp, any]

e.g:

import {FieldPath, WhereFilterOp} from '@google-cloud/firestore';

let WhereFilter: [FieldPath, WhereFilterOp, any]

listDocs(filter: typeof WhereFilter[]): Promise<T[]> {
  filter.forEach((data: typeof WhereFilter) => (call = <any>call.where(...data)));
}
jaberbu commented 3 years ago

One of the solutions can be convert Interface <T> to type Model and pass results as definition of first element in filter tuple.

Captura de pantalla 2020-11-17 195335

[Model, WhereFilterOp, any]

Captura de pantalla 2020-11-17 195405

Similar as WhereFilterOp works

Captura de pantalla 2020-11-17 195817

jaberbu commented 3 years ago

Is fix on #12