Spaces:
Sleeping
Sleeping
File size: 18,149 Bytes
de5ba48 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 | /*!
* Copyright 2019 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import * as firestore from '@google-cloud/firestore';
import { google } from '../protos/firestore_v1_proto_api';
import { FieldTransform } from './field-value';
import { FieldPath } from './path';
import { DocumentReference } from './reference';
import { Serializer } from './serializer';
import { Timestamp } from './timestamp';
import { ApiMapValue, UpdateMap } from './types';
import api = google.firestore.v1;
/**
* Returns a builder for DocumentSnapshot and QueryDocumentSnapshot instances.
* Invoke `.build()' to assemble the final snapshot.
*
* @private
* @internal
*/
export declare class DocumentSnapshotBuilder<T = firestore.DocumentData> {
readonly ref: DocumentReference<T>;
/** The fields of the Firestore `Document` Protobuf backing this document. */
fieldsProto?: ApiMapValue;
/** The time when this document was read. */
readTime?: Timestamp;
/** The time when this document was created. */
createTime?: Timestamp;
/** The time when this document was last updated. */
updateTime?: Timestamp;
constructor(ref: DocumentReference<T>);
/**
* Builds the DocumentSnapshot.
*
* @private
* @internal
* @returns Returns either a QueryDocumentSnapshot (if `fieldsProto` was
* provided) or a DocumentSnapshot.
*/
build(): QueryDocumentSnapshot<T> | DocumentSnapshot<T>;
}
/**
* A DocumentSnapshot is an immutable representation for a document in a
* Firestore database. The data can be extracted with
* [data()]{@link DocumentSnapshot#data} or
* [get(fieldPath)]{@link DocumentSnapshot#get} to get a
* specific field.
*
* <p>For a DocumentSnapshot that points to a non-existing document, any data
* access will return 'undefined'. You can use the
* [exists]{@link DocumentSnapshot#exists} property to explicitly verify a
* document's existence.
*
* @class DocumentSnapshot
*/
export declare class DocumentSnapshot<T = firestore.DocumentData> implements firestore.DocumentSnapshot<T> {
/** @private */
readonly _fieldsProto?: ApiMapValue | undefined;
private _ref;
private _serializer;
private _readTime;
private _createTime;
private _updateTime;
/**
* @private
*
* @param ref The reference to the document.
* @param _fieldsProto The fields of the Firestore `Document` Protobuf backing
* this document (or undefined if the document does not exist).
* @param readTime The time when this snapshot was read (or undefined if
* the document exists only locally).
* @param createTime The time when the document was created (or undefined if
* the document does not exist).
* @param updateTime The time when the document was last updated (or undefined
* if the document does not exist).
*/
constructor(ref: DocumentReference<T>,
/** @private */
_fieldsProto?: ApiMapValue | undefined, readTime?: Timestamp, createTime?: Timestamp, updateTime?: Timestamp);
/**
* Creates a DocumentSnapshot from an object.
*
* @private
* @internal
* @param ref The reference to the document.
* @param obj The object to store in the DocumentSnapshot.
* @return The created DocumentSnapshot.
*/
static fromObject<U>(ref: firestore.DocumentReference<U>, obj: firestore.DocumentData): DocumentSnapshot<U>;
/**
* Creates a DocumentSnapshot from an UpdateMap.
*
* This methods expands the top-level field paths in a JavaScript map and
* turns { foo.bar : foobar } into { foo { bar : foobar }}
*
* @private
* @internal
* @param ref The reference to the document.
* @param data The field/value map to expand.
* @return The created DocumentSnapshot.
*/
static fromUpdateMap<U>(ref: firestore.DocumentReference<U>, data: UpdateMap): DocumentSnapshot<U>;
/**
* True if the document exists.
*
* @type {boolean}
* @name DocumentSnapshot#exists
* @readonly
*
* @example
* ```
* let documentRef = firestore.doc('col/doc');
*
* documentRef.get().then((documentSnapshot) => {
* if (documentSnapshot.exists) {
* console.log(`Data: ${JSON.stringify(documentSnapshot.data())}`);
* }
* });
* ```
*/
get exists(): boolean;
/**
* A [DocumentReference]{@link DocumentReference} for the document
* stored in this snapshot.
*
* @type {DocumentReference}
* @name DocumentSnapshot#ref
* @readonly
*
* @example
* ```
* let documentRef = firestore.doc('col/doc');
*
* documentRef.get().then((documentSnapshot) => {
* if (documentSnapshot.exists) {
* console.log(`Found document at '${documentSnapshot.ref.path}'`);
* }
* });
* ```
*/
get ref(): DocumentReference<T>;
/**
* The ID of the document for which this DocumentSnapshot contains data.
*
* @type {string}
* @name DocumentSnapshot#id
* @readonly
*
* @example
* ```
* let documentRef = firestore.doc('col/doc');
*
* documentRef.get().then((documentSnapshot) => {
* if (documentSnapshot.exists) {
* console.log(`Document found with name '${documentSnapshot.id}'`);
* }
* });
* ```
*/
get id(): string;
/**
* The time the document was created. Undefined for documents that don't
* exist.
*
* @type {Timestamp|undefined}
* @name DocumentSnapshot#createTime
* @readonly
*
* @example
* ```
* let documentRef = firestore.doc('col/doc');
*
* documentRef.get().then(documentSnapshot => {
* if (documentSnapshot.exists) {
* let createTime = documentSnapshot.createTime;
* console.log(`Document created at '${createTime.toDate()}'`);
* }
* });
* ```
*/
get createTime(): Timestamp | undefined;
/**
* The time the document was last updated (at the time the snapshot was
* generated). Undefined for documents that don't exist.
*
* @type {Timestamp|undefined}
* @name DocumentSnapshot#updateTime
* @readonly
*
* @example
* ```
* let documentRef = firestore.doc('col/doc');
*
* documentRef.get().then(documentSnapshot => {
* if (documentSnapshot.exists) {
* let updateTime = documentSnapshot.updateTime;
* console.log(`Document updated at '${updateTime.toDate()}'`);
* }
* });
* ```
*/
get updateTime(): Timestamp | undefined;
/**
* The time this snapshot was read.
*
* @type {Timestamp}
* @name DocumentSnapshot#readTime
* @readonly
*
* @example
* ```
* let documentRef = firestore.doc('col/doc');
*
* documentRef.get().then(documentSnapshot => {
* let readTime = documentSnapshot.readTime;
* console.log(`Document read at '${readTime.toDate()}'`);
* });
* ```
*/
get readTime(): Timestamp;
/**
* Retrieves all fields in the document as an object. Returns 'undefined' if
* the document doesn't exist.
*
* @returns {T|undefined} An object containing all fields in the document or
* 'undefined' if the document doesn't exist.
*
* @example
* ```
* let documentRef = firestore.doc('col/doc');
*
* documentRef.get().then(documentSnapshot => {
* let data = documentSnapshot.data();
* console.log(`Retrieved data: ${JSON.stringify(data)}`);
* });
* ```
*/
data(): T | undefined;
/**
* Retrieves the field specified by `field`.
*
* @param {string|FieldPath} field The field path
* (e.g. 'foo' or 'foo.bar') to a specific field.
* @returns {*} The data at the specified field location or undefined if no
* such field exists.
*
* @example
* ```
* let documentRef = firestore.doc('col/doc');
*
* documentRef.set({ a: { b: 'c' }}).then(() => {
* return documentRef.get();
* }).then(documentSnapshot => {
* let field = documentSnapshot.get('a.b');
* console.log(`Retrieved field value: ${field}`);
* });
* ```
*/
get(field: string | FieldPath): any;
/**
* Retrieves the field specified by 'fieldPath' in its Protobuf JS
* representation.
*
* @private
* @internal
* @param field The path (e.g. 'foo' or 'foo.bar') to a specific field.
* @returns The Protobuf-encoded data at the specified field location or
* undefined if no such field exists.
*/
protoField(field: string | FieldPath): api.IValue | undefined;
/**
* Convert a document snapshot to the Firestore 'Write' proto.
*
* @private
* @internal
*/
toWriteProto(): api.IWrite;
/**
* Convert a document snapshot to the Firestore 'Document' proto.
*
* @private
* @internal
*/
toDocumentProto(): api.IDocument;
/**
* Returns true if the document's data and path in this `DocumentSnapshot` is
* equal to the provided value.
*
* @param {*} other The value to compare against.
* @return {boolean} true if this `DocumentSnapshot` is equal to the provided
* value.
*/
isEqual(other: firestore.DocumentSnapshot<T>): boolean;
}
/**
* A QueryDocumentSnapshot contains data read from a document in your
* Firestore database as part of a query. The document is guaranteed to exist
* and its data can be extracted with [data()]{@link QueryDocumentSnapshot#data}
* or [get()]{@link DocumentSnapshot#get} to get a specific field.
*
* A QueryDocumentSnapshot offers the same API surface as a
* {@link DocumentSnapshot}. Since query results contain only existing
* documents, the [exists]{@link DocumentSnapshot#exists} property will
* always be true and [data()]{@link QueryDocumentSnapshot#data} will never
* return 'undefined'.
*
* @class QueryDocumentSnapshot
* @extends DocumentSnapshot
*/
export declare class QueryDocumentSnapshot<T = firestore.DocumentData> extends DocumentSnapshot<T> implements firestore.QueryDocumentSnapshot<T> {
/**
* The time the document was created.
*
* @type {Timestamp}
* @name QueryDocumentSnapshot#createTime
* @readonly
* @override
*
* @example
* ```
* let query = firestore.collection('col');
*
* query.get().forEach(snapshot => {
* console.log(`Document created at '${snapshot.createTime.toDate()}'`);
* });
* ```
*/
get createTime(): Timestamp;
/**
* The time the document was last updated (at the time the snapshot was
* generated).
*
* @type {Timestamp}
* @name QueryDocumentSnapshot#updateTime
* @readonly
* @override
*
* @example
* ```
* let query = firestore.collection('col');
*
* query.get().forEach(snapshot => {
* console.log(`Document updated at '${snapshot.updateTime.toDate()}'`);
* });
* ```
*/
get updateTime(): Timestamp;
/**
* Retrieves all fields in the document as an object.
*
* @override
*
* @returns {T} An object containing all fields in the document.
*
* @example
* ```
* let query = firestore.collection('col');
*
* query.get().forEach(documentSnapshot => {
* let data = documentSnapshot.data();
* console.log(`Retrieved data: ${JSON.stringify(data)}`);
* });
* ```
*/
data(): T;
}
/**
* A Firestore Document Mask contains the field paths affected by an update.
*
* @class
* @private
* @internal
*/
export declare class DocumentMask {
private _sortedPaths;
/**
* @private
* @internal
* @private
*
* @param fieldPaths The field paths in this mask.
*/
constructor(fieldPaths: FieldPath[]);
/**
* Creates a document mask with the field paths of a document.
*
* @private
* @internal
* @param data A map with fields to modify. Only the keys are used to extract
* the document mask.
*/
static fromUpdateMap(data: UpdateMap): DocumentMask;
/**
* Creates a document mask from an array of field paths.
*
* @private
* @internal
* @param fieldMask A list of field paths.
*/
static fromFieldMask(fieldMask: Array<string | firestore.FieldPath>): DocumentMask;
/**
* Creates a document mask with the field names of a document.
*
* @private
* @internal
* @param data An object with fields to modify. Only the keys are used to
* extract the document mask.
*/
static fromObject(data: firestore.DocumentData): DocumentMask;
/**
* Returns true if this document mask contains no fields.
*
* @private
* @internal
* @return {boolean} Whether this document mask is empty.
*/
get isEmpty(): boolean;
/**
* Removes the specified values from a sorted field path array.
*
* @private
* @internal
* @param input A sorted array of FieldPaths.
* @param values An array of FieldPaths to remove.
*/
private static removeFromSortedArray;
/**
* Removes the field path specified in 'fieldPaths' from this document mask.
*
* @private
* @internal
* @param fieldPaths An array of FieldPaths.
*/
removeFields(fieldPaths: FieldPath[]): void;
/**
* Returns whether this document mask contains 'fieldPath'.
*
* @private
* @internal
* @param fieldPath The field path to test.
* @return Whether this document mask contains 'fieldPath'.
*/
contains(fieldPath: FieldPath): boolean;
/**
* Removes all properties from 'data' that are not contained in this document
* mask.
*
* @private
* @internal
* @param data An object to filter.
* @return A shallow copy of the object filtered by this document mask.
*/
applyTo(data: firestore.DocumentData): firestore.DocumentData;
/**
* Converts a document mask to the Firestore 'DocumentMask' Proto.
*
* @private
* @internal
* @returns A Firestore 'DocumentMask' Proto.
*/
toProto(): api.IDocumentMask;
}
/**
* A Firestore Document Transform.
*
* A DocumentTransform contains pending server-side transforms and their
* corresponding field paths.
*
* @private
* @internal
* @class
*/
export declare class DocumentTransform<T = firestore.DocumentData> {
private readonly ref;
private readonly transforms;
/**
* @private
* @internal
* @private
*
* @param ref The DocumentReference for this transform.
* @param transforms A Map of FieldPaths to FieldTransforms.
*/
constructor(ref: DocumentReference<T>, transforms: Map<FieldPath, FieldTransform>);
/**
* Generates a DocumentTransform from a JavaScript object.
*
* @private
* @internal
* @param ref The `DocumentReference` to use for the DocumentTransform.
* @param obj The object to extract the transformations from.
* @returns The Document Transform.
*/
static fromObject<T>(ref: firestore.DocumentReference<T>, obj: firestore.DocumentData): DocumentTransform<T>;
/**
* Generates a DocumentTransform from an Update Map.
*
* @private
* @internal
* @param ref The `DocumentReference` to use for the DocumentTransform.
* @param data The update data to extract the transformations from.
* @returns The Document Transform.
*/
static fromUpdateMap<T>(ref: firestore.DocumentReference<T>, data: UpdateMap): DocumentTransform<T>;
/**
* Whether this DocumentTransform contains any actionable transformations.
*
* @private
* @internal
*/
get isEmpty(): boolean;
/**
* Returns the array of fields in this DocumentTransform.
*
* @private
* @internal
*/
get fields(): FieldPath[];
/**
* Validates the user provided field values in this document transform.
* @private
* @internal
*/
validate(): void;
/**
* Converts a document transform to the Firestore 'FieldTransform' Proto.
*
* @private
* @internal
* @param serializer The Firestore serializer
* @returns A list of Firestore 'FieldTransform' Protos
*/
toProto(serializer: Serializer): api.DocumentTransform.IFieldTransform[];
}
/**
* A Firestore Precondition encapsulates options for database writes.
*
* @private
* @internal
* @class
*/
export declare class Precondition {
private _exists?;
private _lastUpdateTime?;
/**
* @private
* @internal
* @private
*
* @param options.exists - Whether the referenced document should exist in
* Firestore,
* @param options.lastUpdateTime - The last update time of the referenced
* document in Firestore.
* @param options
*/
constructor(options?: {
exists?: boolean;
lastUpdateTime?: firestore.Timestamp;
});
/**
* Generates the Protobuf `Preconditon` object for this precondition.
*
* @private
* @internal
* @returns The `Preconditon` Protobuf object or 'null' if there are no
* preconditions.
*/
toProto(): api.IPrecondition | null;
/**
* Whether this DocumentTransform contains any enforcement.
*
* @private
* @internal
*/
get isEmpty(): boolean;
}
|