@@ -21,6 +21,12 @@ import {customObjectMessage, invalidArgumentMessage, validateMinNumberOfArgument
2121
2222import api = google . firestore . v1 ;
2323
24+ /*!
25+ * The default database ID for this Firestore client. We do not yet expose the
26+ * ability to use different databases.
27+ */
28+ export const DEFAULT_DATABASE_ID = '(default)' ;
29+
2430/*!
2531 * A regular expression to verify an absolute Resource Path in Firestore. It
2632 * extracts the project ID, the database name and the relative resource path
@@ -49,12 +55,6 @@ const UNESCAPED_FIELD_NAME_RE = /^[_a-zA-Z][_a-zA-Z0-9]*$/;
4955 */
5056const FIELD_PATH_RE = / ^ [ ^ * ~ / [ \] ] + $ / ;
5157
52- /*!
53- * The default database ID for this Firestore client. We do not yet expose the
54- * ability to use different databases.
55- */
56- export const DATABASE_ID = '(default)' ;
57-
5858/**
5959 * An abstract class representing a Firestore path.
6060 *
@@ -190,12 +190,12 @@ abstract class Path<T> {
190190 *
191191 * @private
192192 */
193- export class RelativePath extends Path < RelativePath > {
193+ export class ResourcePath extends Path < ResourcePath > {
194194 /** A default instance pointing to the root collection. */
195- static EMPTY = new RelativePath ( ) ;
195+ static EMPTY = new ResourcePath ( ) ;
196196
197197 /**
198- * Constructs a RelativePath .
198+ * Constructs a ResourcePath .
199199 *
200200 * @param segments Sequence of names of the parts of the path.
201201 */
@@ -238,11 +238,11 @@ export class RelativePath extends Path<RelativePath> {
238238 /**
239239 * Constructs a new instance of RelativePath.
240240 *
241- * @param segments Sequence of names of the parts of the path.
241+ * @param segments Sequence of ResourcePath of the parts of the path.
242242 * @returns The newly created RelativePath.
243243 */
244- construct ( segments : string [ ] ) : RelativePath {
245- return new RelativePath ( ...segments ) ;
244+ construct ( segments : string [ ] ) : ResourcePath {
245+ return new ResourcePath ( ...segments ) ;
246246 }
247247
248248 /**
@@ -263,18 +263,19 @@ export class RelativePath extends Path<RelativePath> {
263263 * @param databaseId The database ID of the new path.
264264 * @return A fully-qualified resource path pointing to the same element.
265265 */
266- toResourcePath ( projectId : string ) : ResourcePath {
267- return new ResourcePath ( projectId , DATABASE_ID , ...this . segments ) ;
266+ toQualifiedResourcePath ( projectId : string ) : QualifiedResourcePath {
267+ return new QualifiedResourcePath (
268+ projectId , DEFAULT_DATABASE_ID , ...this . segments ) ;
268269 }
269270}
270271
271272/**
272- * A slash-separated path for navigating resources (documents and collections)
273- * within any Firestore project.
273+ * A slash-separated path that includes a project and database ID for referring
274+ * to resources in any Firestore project.
274275 *
275276 * @private
276277 */
277- export class ResourcePath extends RelativePath {
278+ export class QualifiedResourcePath extends ResourcePath {
278279 /**
279280 * The project ID of this path.
280281 */
@@ -312,14 +313,14 @@ export class ResourcePath extends RelativePath {
312313 * @param absolutePath A string representation of a Resource Path.
313314 * @returns The new ResourcePath.
314315 */
315- static fromSlashSeparatedString ( absolutePath : string ) : ResourcePath {
316+ static fromSlashSeparatedString ( absolutePath : string ) : QualifiedResourcePath {
316317 const elements = RESOURCE_PATH_RE . exec ( absolutePath ) ;
317318
318319 if ( elements ) {
319320 const project = elements [ 1 ] ;
320321 const database = elements [ 2 ] ;
321322 const path = elements [ 3 ] ;
322- return new ResourcePath ( project , database ) . append ( path ) ;
323+ return new QualifiedResourcePath ( project , database ) . append ( path ) ;
323324 }
324325
325326 throw new Error ( `Resource name '${ absolutePath } ' is not valid.` ) ;
@@ -331,8 +332,8 @@ export class ResourcePath extends RelativePath {
331332 * @param relativePath Relative path to append to the current path.
332333 * @returns The new path.
333334 */
334- append ( relativePath : RelativePath | string ) : ResourcePath {
335- return super . append ( relativePath ) as ResourcePath ;
335+ append ( relativePath : ResourcePath | string ) : QualifiedResourcePath {
336+ return super . append ( relativePath ) as QualifiedResourcePath ;
336337 }
337338
338339
@@ -341,8 +342,8 @@ export class ResourcePath extends RelativePath {
341342 *
342343 * @returns The new path.
343344 */
344- parent ( ) : ResourcePath | null {
345- return super . parent ( ) as ResourcePath | null ;
345+ parent ( ) : QualifiedResourcePath | null {
346+ return super . parent ( ) as QualifiedResourcePath | null ;
346347 }
347348
348349 /**
@@ -364,17 +365,18 @@ export class ResourcePath extends RelativePath {
364365 * methods.
365366 *
366367 * @param segments Sequence of names of the parts of the path.
367- * @returns { ResourcePath } The newly created ResourcePath .
368+ * @returns The newly created QualifiedResourcePath .
368369 */
369- construct ( segments : string [ ] ) : ResourcePath {
370- return new ResourcePath ( this . projectId , this . databaseId , ...segments ) ;
370+ construct ( segments : string [ ] ) : QualifiedResourcePath {
371+ return new QualifiedResourcePath (
372+ this . projectId , this . databaseId , ...segments ) ;
371373 }
372374
373375 /**
374- * Convenience method to match the RelativePath API. This method always
376+ * Convenience method to match the ResourcePath API. This method always
375377 * returns the current instance. The arguments is ignored.
376378 */
377- toResourcePath ( projectId : string ) : ResourcePath {
379+ toQualifiedResourcePath ( projectId : string ) : QualifiedResourcePath {
378380 return this ;
379381 }
380382
@@ -384,8 +386,8 @@ export class ResourcePath extends RelativePath {
384386 * @param other The path to compare to.
385387 * @returns -1 if current < other, 1 if current > other, 0 if equal
386388 */
387- compareTo ( other : RelativePath ) : number {
388- if ( other instanceof ResourcePath ) {
389+ compareTo ( other : ResourcePath ) : number {
390+ if ( other instanceof QualifiedResourcePath ) {
389391 if ( this . projectId < other . projectId ) {
390392 return - 1 ;
391393 }
@@ -557,8 +559,8 @@ export class FieldPath extends Path<FieldPath> {
557559 *
558560 * @private
559561 * @override
560- * @param { Array.<string> } segments Sequence of field names.
561- * @returns { ResourcePath } The newly created FieldPath.
562+ * @param segments Sequence of field names.
563+ * @returns The newly created FieldPath.
562564 */
563565 construct ( segments : string [ ] ) {
564566 return new FieldPath ( ...segments ) ;
0 commit comments