@firebase/firestore 3.8.3-canary.d5d78cbcf → 3.8.3-canary.e2bf2eca2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -33,7 +33,7 @@ var grpc__namespace = /*#__PURE__*/_interopNamespace(grpc);
33
33
  var protoLoader__namespace = /*#__PURE__*/_interopNamespace(protoLoader);
34
34
 
35
35
  const name = "@firebase/firestore";
36
- const version$1 = "3.8.3-canary.d5d78cbcf";
36
+ const version$1 = "3.8.3-canary.e2bf2eca2";
37
37
 
38
38
  /**
39
39
  * @license
@@ -86,7 +86,7 @@ User.GOOGLE_CREDENTIALS = new User('google-credentials-uid');
86
86
  User.FIRST_PARTY = new User('first-party-uid');
87
87
  User.MOCK_USER = new User('mock-user');
88
88
 
89
- const version = "9.17.1-canary.d5d78cbcf";
89
+ const version = "9.17.1-canary.e2bf2eca2";
90
90
 
91
91
  /**
92
92
  * @license
@@ -17937,6 +17937,66 @@ class StreamBridge {
17937
17937
  }
17938
17938
  }
17939
17939
 
17940
+ /**
17941
+ * @license
17942
+ * Copyright 2023 Google LLC
17943
+ *
17944
+ * Licensed under the Apache License, Version 2.0 (the "License");
17945
+ * you may not use this file except in compliance with the License.
17946
+ * You may obtain a copy of the License at
17947
+ *
17948
+ * http://www.apache.org/licenses/LICENSE-2.0
17949
+ *
17950
+ * Unless required by applicable law or agreed to in writing, software
17951
+ * distributed under the License is distributed on an "AS IS" BASIS,
17952
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17953
+ * See the License for the specific language governing permissions and
17954
+ * limitations under the License.
17955
+ */
17956
+ /**
17957
+ * The value returned from the most recent invocation of
17958
+ * `generateUniqueDebugId()`, or null if it has never been invoked.
17959
+ */
17960
+ let lastUniqueDebugId = null;
17961
+ /**
17962
+ * Generates and returns an initial value for `lastUniqueDebugId`.
17963
+ *
17964
+ * The returned value is randomly selected from a range of integers that are
17965
+ * represented as 8 hexadecimal digits. This means that (within reason) any
17966
+ * numbers generated by incrementing the returned number by 1 will also be
17967
+ * represented by 8 hexadecimal digits. This leads to all "IDs" having the same
17968
+ * length when converted to a hexadecimal string, making reading logs containing
17969
+ * these IDs easier to follow. And since the return value is randomly selected
17970
+ * it will help to differentiate between logs from different executions.
17971
+ */
17972
+ function generateInitialUniqueDebugId() {
17973
+ const minResult = 0x10000000;
17974
+ const maxResult = 0x90000000;
17975
+ const resultRange = maxResult - minResult;
17976
+ const resultOffset = Math.round(resultRange * Math.random());
17977
+ return minResult + resultOffset;
17978
+ }
17979
+ /**
17980
+ * Generates and returns a unique ID as a hexadecimal string.
17981
+ *
17982
+ * The returned ID is intended to be used in debug logging messages to help
17983
+ * correlate log messages that may be spatially separated in the logs, but
17984
+ * logically related. For example, a network connection could include the same
17985
+ * "debug ID" string in all of its log messages to help trace a specific
17986
+ * connection over time.
17987
+ *
17988
+ * @return the 10-character generated ID (e.g. "0xa1b2c3d4").
17989
+ */
17990
+ function generateUniqueDebugId() {
17991
+ if (lastUniqueDebugId === null) {
17992
+ lastUniqueDebugId = generateInitialUniqueDebugId();
17993
+ }
17994
+ else {
17995
+ lastUniqueDebugId++;
17996
+ }
17997
+ return '0x' + lastUniqueDebugId.toString(16);
17998
+ }
17999
+
17940
18000
  /**
17941
18001
  * @license
17942
18002
  * Copyright 2017 Google LLC
@@ -18023,7 +18083,7 @@ function nodePromise(action) {
18023
18083
  // TODO: Fetch runtime version from grpc-js/package.json instead
18024
18084
  // when there's a cleaner way to dynamic require JSON in both Node ESM and CJS
18025
18085
  const grpcVersion = '1.7.3';
18026
- const LOG_TAG$9 = 'Connection';
18086
+ const LOG_TAG$9 = 'GrpcConnection';
18027
18087
  const X_GOOG_API_CLIENT_VALUE = `gl-node/${process.versions.node} fire/${SDK_VERSION} grpc/${grpcVersion}`;
18028
18088
  function createMetadata(databasePath, authToken, appCheckToken, appId) {
18029
18089
  hardAssert(authToken === null || authToken.type === 'OAuth');
@@ -18075,34 +18135,36 @@ class GrpcConnection {
18075
18135
  return this.cachedStub;
18076
18136
  }
18077
18137
  invokeRPC(rpcName, path, request, authToken, appCheckToken) {
18138
+ const streamId = generateUniqueDebugId();
18078
18139
  const stub = this.ensureActiveStub();
18079
18140
  const metadata = createMetadata(this.databasePath, authToken, appCheckToken, this.databaseInfo.appId);
18080
18141
  const jsonRequest = Object.assign({ database: this.databasePath }, request);
18081
18142
  return nodePromise((callback) => {
18082
- logDebug(LOG_TAG$9, `RPC '${rpcName}' invoked with request:`, request);
18143
+ logDebug(LOG_TAG$9, `RPC '${rpcName}' ${streamId} invoked with request:`, request);
18083
18144
  return stub[rpcName](jsonRequest, metadata, (grpcError, value) => {
18084
18145
  if (grpcError) {
18085
- logDebug(LOG_TAG$9, `RPC '${rpcName}' failed with error:`, grpcError);
18146
+ logDebug(LOG_TAG$9, `RPC '${rpcName}' ${streamId} failed with error:`, grpcError);
18086
18147
  callback(new FirestoreError(mapCodeFromRpcCode(grpcError.code), grpcError.message));
18087
18148
  }
18088
18149
  else {
18089
- logDebug(LOG_TAG$9, `RPC '${rpcName}' completed with response:`, value);
18150
+ logDebug(LOG_TAG$9, `RPC '${rpcName}' ${streamId} completed with response:`, value);
18090
18151
  callback(undefined, value);
18091
18152
  }
18092
18153
  });
18093
18154
  });
18094
18155
  }
18095
18156
  invokeStreamingRPC(rpcName, path, request, authToken, appCheckToken, expectedResponseCount) {
18157
+ const streamId = generateUniqueDebugId();
18096
18158
  const results = [];
18097
18159
  const responseDeferred = new Deferred();
18098
- logDebug(LOG_TAG$9, `RPC '${rpcName}' invoked (streaming) with request:`, request);
18160
+ logDebug(LOG_TAG$9, `RPC '${rpcName}' ${streamId} invoked (streaming) with request:`, request);
18099
18161
  const stub = this.ensureActiveStub();
18100
18162
  const metadata = createMetadata(this.databasePath, authToken, appCheckToken, this.databaseInfo.appId);
18101
18163
  const jsonRequest = Object.assign(Object.assign({}, request), { database: this.databasePath });
18102
18164
  const stream = stub[rpcName](jsonRequest, metadata);
18103
18165
  let callbackFired = false;
18104
18166
  stream.on('data', (response) => {
18105
- logDebug(LOG_TAG$9, `RPC ${rpcName} received result:`, response);
18167
+ logDebug(LOG_TAG$9, `RPC ${rpcName} ${streamId} received result:`, response);
18106
18168
  results.push(response);
18107
18169
  if (expectedResponseCount !== undefined &&
18108
18170
  results.length === expectedResponseCount) {
@@ -18111,14 +18173,14 @@ class GrpcConnection {
18111
18173
  }
18112
18174
  });
18113
18175
  stream.on('end', () => {
18114
- logDebug(LOG_TAG$9, `RPC '${rpcName}' completed.`);
18176
+ logDebug(LOG_TAG$9, `RPC '${rpcName}' ${streamId} completed.`);
18115
18177
  if (!callbackFired) {
18116
18178
  callbackFired = true;
18117
18179
  responseDeferred.resolve(results);
18118
18180
  }
18119
18181
  });
18120
18182
  stream.on('error', (grpcError) => {
18121
- logDebug(LOG_TAG$9, `RPC '${rpcName}' failed with error:`, grpcError);
18183
+ logDebug(LOG_TAG$9, `RPC '${rpcName}' ${streamId} failed with error:`, grpcError);
18122
18184
  const code = mapCodeFromRpcCode(grpcError.code);
18123
18185
  responseDeferred.reject(new FirestoreError(code, grpcError.message));
18124
18186
  });
@@ -18126,6 +18188,7 @@ class GrpcConnection {
18126
18188
  }
18127
18189
  // TODO(mikelehen): This "method" is a monster. Should be refactored.
18128
18190
  openStream(rpcName, authToken, appCheckToken) {
18191
+ const streamId = generateUniqueDebugId();
18129
18192
  const stub = this.ensureActiveStub();
18130
18193
  const metadata = createMetadata(this.databasePath, authToken, appCheckToken, this.databaseInfo.appId);
18131
18194
  const grpcStream = stub[rpcName](metadata);
@@ -18140,7 +18203,7 @@ class GrpcConnection {
18140
18203
  const stream = new StreamBridge({
18141
18204
  sendFn: (msg) => {
18142
18205
  if (!closed) {
18143
- logDebug(LOG_TAG$9, 'GRPC stream sending:', msg);
18206
+ logDebug(LOG_TAG$9, `RPC '${rpcName}' stream ${streamId} sending:`, msg);
18144
18207
  try {
18145
18208
  grpcStream.write(msg);
18146
18209
  }
@@ -18153,32 +18216,34 @@ class GrpcConnection {
18153
18216
  }
18154
18217
  }
18155
18218
  else {
18156
- logDebug(LOG_TAG$9, 'Not sending because gRPC stream is closed:', msg);
18219
+ logDebug(LOG_TAG$9, `RPC '${rpcName}' stream ${streamId} ` +
18220
+ 'not sending because gRPC stream is closed:', msg);
18157
18221
  }
18158
18222
  },
18159
18223
  closeFn: () => {
18160
- logDebug(LOG_TAG$9, 'GRPC stream closed locally via close().');
18224
+ logDebug(LOG_TAG$9, `RPC '${rpcName}' stream ${streamId} closed locally via close().`);
18161
18225
  close();
18162
18226
  }
18163
18227
  });
18164
18228
  grpcStream.on('data', (msg) => {
18165
18229
  if (!closed) {
18166
- logDebug(LOG_TAG$9, 'GRPC stream received:', msg);
18230
+ logDebug(LOG_TAG$9, `RPC '${rpcName}' stream ${streamId} received:`, msg);
18167
18231
  stream.callOnMessage(msg);
18168
18232
  }
18169
18233
  });
18170
18234
  grpcStream.on('end', () => {
18171
- logDebug(LOG_TAG$9, 'GRPC stream ended.');
18235
+ logDebug(LOG_TAG$9, `RPC '${rpcName}' stream ${streamId} ended.`);
18172
18236
  close();
18173
18237
  });
18174
18238
  grpcStream.on('error', (grpcError) => {
18175
18239
  if (!closed) {
18176
- logWarn(LOG_TAG$9, 'GRPC stream error. Code:', grpcError.code, 'Message:', grpcError.message);
18240
+ logWarn(LOG_TAG$9, `RPC '${rpcName}' stream ${streamId} error. Code:`, grpcError.code, 'Message:', grpcError.message);
18177
18241
  const code = mapCodeFromRpcCode(grpcError.code);
18178
18242
  close(new FirestoreError(code, grpcError.message));
18179
18243
  }
18180
18244
  });
18181
- logDebug(LOG_TAG$9, 'Opening GRPC stream');
18245
+ logDebug(LOG_TAG$9, `Opening RPC '${rpcName}' stream ${streamId} ` +
18246
+ `to ${this.databaseInfo.host}`);
18182
18247
  // TODO(dimond): Since grpc has no explicit open status (or does it?) we
18183
18248
  // simulate an onOpen in the next loop after the stream had it's listeners
18184
18249
  // registered