query-partition.d.ts 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. import * as firestore from '@google-cloud/firestore';
  2. import * as protos from '../protos/firestore_v1_proto_api';
  3. import { Query } from './reference/query';
  4. import { Firestore } from './index';
  5. import api = protos.google.firestore.v1;
  6. /**
  7. * A split point that can be used in a query as a starting and/or end point for
  8. * the query results. The cursors returned by {@link #startAt} and {@link
  9. * #endBefore} can only be used in a query that matches the constraint of query
  10. * that produced this partition.
  11. *
  12. * @class QueryPartition
  13. */
  14. export declare class QueryPartition<AppModelType = firestore.DocumentData, DbModelType extends firestore.DocumentData = firestore.DocumentData> implements firestore.QueryPartition<AppModelType, DbModelType> {
  15. private readonly _firestore;
  16. private readonly _collectionId;
  17. private readonly _converter;
  18. private readonly _startAt;
  19. private readonly _endBefore;
  20. private readonly _serializer;
  21. private _memoizedStartAt;
  22. private _memoizedEndBefore;
  23. /** @private */
  24. constructor(_firestore: Firestore, _collectionId: string, _converter: firestore.FirestoreDataConverter<AppModelType, DbModelType>, _startAt: api.IValue[] | undefined, _endBefore: api.IValue[] | undefined);
  25. /**
  26. * The cursor that defines the first result for this partition or `undefined`
  27. * if this is the first partition. The cursor value must be
  28. * destructured when passed to `startAt()` (for example with
  29. * `query.startAt(...queryPartition.startAt)`).
  30. *
  31. * @example
  32. * ```
  33. * const query = firestore.collectionGroup('collectionId');
  34. * for await (const partition of query.getPartitions(42)) {
  35. * let partitionedQuery = query.orderBy(FieldPath.documentId());
  36. * if (partition.startAt) {
  37. * partitionedQuery = partitionedQuery.startAt(...partition.startAt);
  38. * }
  39. * if (partition.endBefore) {
  40. * partitionedQuery = partitionedQuery.endBefore(...partition.endBefore);
  41. * }
  42. * const querySnapshot = await partitionedQuery.get();
  43. * console.log(`Partition contained ${querySnapshot.length} documents`);
  44. * }
  45. *
  46. * ```
  47. * @type {Array<*>}
  48. * @return {Array<*>} A cursor value that can be used with {@link
  49. * Query#startAt} or `undefined` if this is the first partition.
  50. */
  51. get startAt(): unknown[] | undefined;
  52. /**
  53. * The cursor that defines the first result after this partition or
  54. * `undefined` if this is the last partition. The cursor value must be
  55. * destructured when passed to `endBefore()` (for example with
  56. * `query.endBefore(...queryPartition.endBefore)`).
  57. *
  58. * @example
  59. * ```
  60. * const query = firestore.collectionGroup('collectionId');
  61. * for await (const partition of query.getPartitions(42)) {
  62. * let partitionedQuery = query.orderBy(FieldPath.documentId());
  63. * if (partition.startAt) {
  64. * partitionedQuery = partitionedQuery.startAt(...partition.startAt);
  65. * }
  66. * if (partition.endBefore) {
  67. * partitionedQuery = partitionedQuery.endBefore(...partition.endBefore);
  68. * }
  69. * const querySnapshot = await partitionedQuery.get();
  70. * console.log(`Partition contained ${querySnapshot.length} documents`);
  71. * }
  72. *
  73. * ```
  74. * @type {Array<*>}
  75. * @return {Array<*>} A cursor value that can be used with {@link
  76. * Query#endBefore} or `undefined` if this is the last partition.
  77. */
  78. get endBefore(): unknown[] | undefined;
  79. /**
  80. * Returns a query that only encapsulates the documents for this partition.
  81. *
  82. * @example
  83. * ```
  84. * const query = firestore.collectionGroup('collectionId');
  85. * for await (const partition of query.getPartitions(42)) {
  86. * const partitionedQuery = partition.toQuery();
  87. * const querySnapshot = await partitionedQuery.get();
  88. * console.log(`Partition contained ${querySnapshot.length} documents`);
  89. * }
  90. *
  91. * ```
  92. * @return {Query<T>} A query partitioned by a {@link Query#startAt} and
  93. * {@link Query#endBefore} cursor.
  94. */
  95. toQuery(): Query<AppModelType, DbModelType>;
  96. }