firebase / firebase-admin-node

Firebase Admin Node.js SDK

Home Page:https://firebase.google.com/docs/admin/setup

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Firestore] where issue should use a type safe approach

cedvdb opened this issue · comments

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;

I found a few problems with this issue:

  • I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.
  • This issue does not seem to follow the issue template. Make sure you provide all the required information.

Hey @cedvdb,

Cloud Firestore support is provided by the @google-cloud/firestore library. Therefore the easiest and most efficient way to get Firestore issues resolved is by directly reporting them at the nodejs-firestore GitHub repo.