17
17
18
18
import { FieldPath as PublicFieldPath } from '@firebase/firestore-types' ;
19
19
20
+ import { FieldPath as ExpFieldPath } from '../../lite/src/api/field_path' ;
20
21
import { FieldPath as InternalFieldPath } from '../model/path' ;
21
- import { Code , FirestoreError } from '../util/error ' ;
22
+ import { Compat } from '../compat/compat ' ;
22
23
23
24
// The objects that are a part of this API are exposed to third-parties as
24
25
// compiled javascript so we want to flag our private members with a leading
25
26
// underscore to discourage their use.
26
27
27
- /**
28
- * A field class base class that is shared by the lite, full and legacy SDK,
29
- * which supports shared code that deals with FieldPaths.
30
- */
31
- // Use underscore prefix to hide this class from our Public API.
32
- // eslint-disable-next-line @typescript-eslint/naming-convention
33
- export abstract class _BaseFieldPath {
34
- /** Internal representation of a Firestore field path. */
35
- readonly _internalPath : InternalFieldPath ;
36
-
37
- constructor ( fieldNames : string [ ] ) {
38
- for ( let i = 0 ; i < fieldNames . length ; ++ i ) {
39
- if ( fieldNames [ i ] . length === 0 ) {
40
- throw new FirestoreError (
41
- Code . INVALID_ARGUMENT ,
42
- `Invalid field name at argument $(i + 1). ` +
43
- 'Field names must not be empty.'
44
- ) ;
45
- }
46
- }
47
-
48
- this . _internalPath = new InternalFieldPath ( fieldNames ) ;
49
- }
50
- }
51
-
52
28
/**
53
29
* A `FieldPath` refers to a field in a document. The path may consist of a
54
30
* single field name (referring to a top-level field in the document), or a list
55
31
* of field names (referring to a nested field in the document).
56
32
*/
57
- export class FieldPath extends _BaseFieldPath implements PublicFieldPath {
33
+ export class FieldPath extends Compat < ExpFieldPath > implements PublicFieldPath {
58
34
/**
59
35
* Creates a FieldPath from the provided field names. If more than one field
60
36
* name is provided, the path will point to a nested field in a document.
61
37
*
62
38
* @param fieldNames A list of field names.
63
39
*/
64
40
constructor ( ...fieldNames : string [ ] ) {
65
- super ( fieldNames ) ;
41
+ super ( new ExpFieldPath ( ...fieldNames ) ) ;
42
+ }
43
+
44
+ get _internalPath ( ) : InternalFieldPath {
45
+ return this . _delegate . _internalPath ;
66
46
}
67
47
68
48
static documentId ( ) : FieldPath {
@@ -82,31 +62,3 @@ export class FieldPath extends _BaseFieldPath implements PublicFieldPath {
82
62
return this . _internalPath . isEqual ( other . _internalPath ) ;
83
63
}
84
64
}
85
-
86
- /**
87
- * Matches any characters in a field path string that are reserved.
88
- */
89
- const RESERVED = new RegExp ( '[~\\*/\\[\\]]' ) ;
90
-
91
- /**
92
- * Parses a field path string into a FieldPath, treating dots as separators.
93
- */
94
- export function fromDotSeparatedString ( path : string ) : FieldPath {
95
- const found = path . search ( RESERVED ) ;
96
- if ( found >= 0 ) {
97
- throw new FirestoreError (
98
- Code . INVALID_ARGUMENT ,
99
- `Invalid field path (${ path } ). Paths must not contain ` +
100
- `'~', '*', '/', '[', or ']'`
101
- ) ;
102
- }
103
- try {
104
- return new FieldPath ( ...path . split ( '.' ) ) ;
105
- } catch ( e ) {
106
- throw new FirestoreError (
107
- Code . INVALID_ARGUMENT ,
108
- `Invalid field path (${ path } ). Paths must not be empty, ` +
109
- `begin with '.', end with '.', or contain '..'`
110
- ) ;
111
- }
112
- }
0 commit comments