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] where should use a "type safe" approach #2020

Open
cedvdb opened this issue Mar 15, 2024 · 1 comment
Open

[Firestore] where should use a "type safe" approach #2020

cedvdb opened this issue Mar 15, 2024 · 1 comment
Assignees
Labels
api: firestore Issues related to the googleapis/nodejs-firestore API. priority: p2 Moderately-important priority. Fix may not be included in next release. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.

Comments

@cedvdb
Copy link

cedvdb commented Mar 15, 2024

You can currently use any string in the where clause of firestore. When using with converter the fieldPath should be "string safe"

Current implementation:

    where(
      fieldPath: string | FieldPath,
      opStr: WhereFilterOp,
      value: any
    ): Query<T>;

Proposed implementation (when using with converter) :

    where(
      fieldPath: Path<T>,
      opStr: WhereFilterOp,
      value: any
    ): Query<T>;

where Path:

// Allows dot separated properties of <T>
// for firebase updates
export type UpdatePath<T, K extends keyof T> =
  K extends string
  ? T[K] extends Record<string, any>
  ? T[K] extends ArrayLike<any>
  ? K | `${K}.${UpdatePath<T[K], Exclude<keyof T[K], keyof any[]>>}`
  : K | `${K}.${UpdatePath<T[K], keyof T[K]>}`
  : K
  : never;
export type Path<T> = UpdatePath<T, keyof T> | keyof T;
@cedvdb cedvdb added priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. labels Mar 15, 2024
@product-auto-label product-auto-label bot added the api: firestore Issues related to the googleapis/nodejs-firestore API. label Mar 15, 2024
@ehsannas ehsannas self-assigned this Mar 18, 2024
@ehsannas ehsannas added type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design. and removed type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. labels Mar 18, 2024
@ehsannas
Copy link
Contributor

Thanks for reporting @cedvdb . I'll bring up the proposed API with the team

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: firestore Issues related to the googleapis/nodejs-firestore API. priority: p2 Moderately-important priority. Fix may not be included in next release. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.
Projects
None yet
Development

No branches or pull requests

2 participants