Skip to content

Commit 608ff83

Browse files
committed
Code cleanup: string[] replaced with ResourcePath.
1 parent ca6a28c commit 608ff83

File tree

5 files changed

+20
-7
lines changed

5 files changed

+20
-7
lines changed

packages/firestore/src/model/path.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,15 @@ export class ResourcePath extends BasePath<ResourcePath> {
215215
return this.canonicalString();
216216
}
217217

218+
/**
219+
* Returns a string representation of this path
220+
* where each path segment has been encoded with
221+
* `encodeURIComponent`.
222+
*/
223+
toUriEncodedString(): string {
224+
return this.toArray().map(encodeURIComponent).join('/');
225+
}
226+
218227
/**
219228
* Creates a resource path from the given slash-delimited string. If multiple
220229
* arguments are provided, all components are combined. Leading and trailing

packages/firestore/src/platform/node/grpc_connection.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import * as grpc from '@grpc/grpc-js';
2222
import { Token } from '../../api/credentials';
2323
import { DatabaseInfo } from '../../core/database_info';
2424
import { SDK_VERSION } from '../../core/version';
25+
import { ResourcePath } from '../../model/path';
2526
import { Connection, Stream } from '../../remote/connection';
2627
import { mapCodeFromRpcCode } from '../../remote/rpc_error';
2728
import { StreamBridge } from '../../remote/stream_bridge';
@@ -114,7 +115,7 @@ export class GrpcConnection implements Connection {
114115

115116
invokeRPC<Req, Resp>(
116117
rpcName: string,
117-
path: string[],
118+
path: ResourcePath,
118119
request: Req,
119120
authToken: Token | null,
120121
appCheckToken: Token | null
@@ -166,7 +167,7 @@ export class GrpcConnection implements Connection {
166167

167168
invokeStreamingRPC<Req, Resp>(
168169
rpcName: string,
169-
path: string[],
170+
path: ResourcePath,
170171
request: Req,
171172
authToken: Token | null,
172173
appCheckToken: Token | null,

packages/firestore/src/remote/connection.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
*/
1717

1818
import { Token } from '../api/credentials';
19+
import { ResourcePath } from '../model/path';
1920
import { FirestoreError } from '../util/error';
2021

2122
/**
@@ -46,7 +47,7 @@ export interface Connection {
4647
*/
4748
invokeRPC<Req, Resp>(
4849
rpcName: string,
49-
path: string[],
50+
path: ResourcePath,
5051
request: Req,
5152
authToken: Token | null,
5253
appCheckToken: Token | null
@@ -67,7 +68,7 @@ export interface Connection {
6768
*/
6869
invokeStreamingRPC<Req, Resp>(
6970
rpcName: string,
70-
path: string[],
71+
path: ResourcePath,
7172
request: Req,
7273
authToken: Token | null,
7374
appCheckToken: Token | null,

packages/firestore/src/remote/rest_connection.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import {
2222
DatabaseInfo,
2323
DEFAULT_DATABASE_NAME
2424
} from '../core/database_info';
25+
import { ResourcePath } from '../model/path';
2526
import { debugAssert } from '../util/assert';
2627
import { generateUniqueDebugId } from '../util/debug_uid';
2728
import { FirestoreError } from '../util/error';
@@ -82,7 +83,7 @@ export abstract class RestConnection implements Connection {
8283

8384
invokeRPC<Req, Resp>(
8485
rpcName: string,
85-
path: string[],
86+
path: ResourcePath,
8687
req: Req,
8788
authToken: Token | null,
8889
appCheckToken: Token | null

packages/firestore/test/unit/remote/datastore.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import {
2424
Token
2525
} from '../../../src/api/credentials';
2626
import { DatabaseId } from '../../../src/core/database_info';
27+
import { ResourcePath } from '../../../src/model/path';
2728
import { Connection, Stream } from '../../../src/remote/connection';
2829
import {
2930
Datastore,
@@ -49,7 +50,7 @@ describe('Datastore', () => {
4950

5051
invokeRPC<Req, Resp>(
5152
rpcName: string,
52-
path: string[],
53+
path: ResourcePath,
5354
request: Req,
5455
token: Token | null
5556
): Promise<Resp> {
@@ -58,7 +59,7 @@ describe('Datastore', () => {
5859

5960
invokeStreamingRPC<Req, Resp>(
6061
rpcName: string,
61-
path: string[],
62+
path: ResourcePath,
6263
request: Req,
6364
token: Token | null
6465
): Promise<Resp[]> {

0 commit comments

Comments
 (0)