Skip to content

Commit fbe27c3

Browse files
committed
Moving path encoding code from the Datastore implementation to the Connection implementation, because the encoding is Connection specific.
1 parent cc839f4 commit fbe27c3

File tree

4 files changed

+13
-17
lines changed

4 files changed

+13
-17
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ export class GrpcConnection implements Connection {
114114

115115
invokeRPC<Req, Resp>(
116116
rpcName: string,
117-
path: string,
117+
path: string[],
118118
request: Req,
119119
authToken: Token | null,
120120
appCheckToken: Token | null
@@ -166,7 +166,7 @@ export class GrpcConnection implements Connection {
166166

167167
invokeStreamingRPC<Req, Resp>(
168168
rpcName: string,
169-
path: string,
169+
path: string[],
170170
request: Req,
171171
authToken: Token | null,
172172
appCheckToken: Token | null,

packages/firestore/src/remote/connection.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,15 @@ export interface Connection {
3838
* representing the JSON to send.
3939
*
4040
* @param rpcName - the name of the RPC to invoke
41-
* @param path - the path to invoke this RPC on
41+
* @param path - the path to invoke this RPC on. An array of path segments
42+
* that will be encoded and joined with path separators when required.
4243
* @param request - the Raw JSON object encoding of the request message
4344
* @param token - the Token to use for the RPC.
4445
* @returns a Promise containing the JSON object encoding of the response
4546
*/
4647
invokeRPC<Req, Resp>(
4748
rpcName: string,
48-
path: string,
49+
path: string[],
4950
request: Req,
5051
authToken: Token | null,
5152
appCheckToken: Token | null
@@ -57,15 +58,16 @@ export interface Connection {
5758
* completion and then returned as an array.
5859
*
5960
* @param rpcName - the name of the RPC to invoke
60-
* @param path - the path to invoke this RPC on
61+
* @param path - the path to invoke this RPC on. An array of path segments
62+
* that will be encoded and joined with path separators when required.
6163
* @param request - the Raw JSON object encoding of the request message
6264
* @param token - the Token to use for the RPC.
6365
* @returns a Promise containing an array with the JSON object encodings of the
6466
* responses
6567
*/
6668
invokeStreamingRPC<Req, Resp>(
6769
rpcName: string,
68-
path: string,
70+
path: string[],
6971
request: Req,
7072
authToken: Token | null,
7173
appCheckToken: Token | null,

packages/firestore/src/remote/datastore.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,7 @@ class DatastoreImpl extends Datastore {
106106
this.appCheckCredentials.getToken()
107107
])
108108
.then(([authToken, appCheckToken]) => {
109-
const path = toResourcePath(databaseId, resourcePath)
110-
.toArray()
111-
.map(encodeURIComponent)
112-
.join('/');
109+
const path = toResourcePath(databaseId, resourcePath).toArray();
113110
return this.connection.invokeRPC<Req, Resp>(
114111
rpcName,
115112
path,
@@ -145,10 +142,7 @@ class DatastoreImpl extends Datastore {
145142
this.appCheckCredentials.getToken()
146143
])
147144
.then(([authToken, appCheckToken]) => {
148-
const path = toResourcePath(databaseId, resourcePath)
149-
.toArray()
150-
.map(encodeURIComponent)
151-
.join('/');
145+
const path = toResourcePath(databaseId, resourcePath).toArray();
152146
return this.connection.invokeStreamingRPC<Req, Resp>(
153147
rpcName,
154148
path,

packages/firestore/src/remote/rest_connection.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,13 @@ export abstract class RestConnection implements Connection {
8282

8383
invokeRPC<Req, Resp>(
8484
rpcName: string,
85-
path: string,
85+
path: string[],
8686
req: Req,
8787
authToken: Token | null,
8888
appCheckToken: Token | null
8989
): Promise<Resp> {
9090
const streamId = generateUniqueDebugId();
91-
const url = this.makeUrl(rpcName, path);
91+
const url = this.makeUrl(rpcName, path.map(encodeURIComponent).join('/'));
9292
logDebug(LOG_TAG, `Sending RPC '${rpcName}' ${streamId}:`, url, req);
9393

9494
const headers: StringMap = {
@@ -119,7 +119,7 @@ export abstract class RestConnection implements Connection {
119119

120120
invokeStreamingRPC<Req, Resp>(
121121
rpcName: string,
122-
path: string,
122+
path: string[],
123123
request: Req,
124124
authToken: Token | null,
125125
appCheckToken: Token | null,

0 commit comments

Comments
 (0)