Skip to content

Commit 0083fc7

Browse files
authored
Add another fallback for snpashot not including a read time (#923)
* Add another fallback for snpashot not including a read time * run formtter/linter
1 parent 3609804 commit 0083fc7

File tree

4 files changed

+12
-4
lines changed

4 files changed

+12
-4
lines changed

src/logger/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ function removeCircular(obj: any, refs: any[] = []): any {
3636
return obj;
3737
}
3838
// If the object defines its own toJSON, prefer that.
39-
if (obj['toJSON']) {
39+
if (obj.toJSON) {
4040
return obj.toJSON();
4141
}
4242
if (refs.includes(obj)) {

src/v1/providers/firestore.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@
2222

2323
import * as firebase from 'firebase-admin';
2424
import * as _ from 'lodash';
25+
2526
import { posix } from 'path';
27+
import * as logger from '../../logger';
2628
import { apps } from '../apps';
2729
import {
2830
Change,
@@ -155,9 +157,15 @@ export function snapshotConstructor(event: Event): DocumentSnapshot {
155157
event.context.resource.name,
156158
'value'
157159
);
158-
const timeString =
160+
let timeString =
159161
_.get(event, 'data.value.readTime') ??
160162
_.get(event, 'data.value.updateTime');
163+
164+
if (!timeString) {
165+
logger.warn('Snapshot has no readTime. Using now()');
166+
timeString = new Date().toISOString();
167+
}
168+
161169
const readTime = dateToTimestampProto(timeString);
162170
return firestoreInstance.snapshot_(valueProto, readTime, 'json');
163171
}

src/v2/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2121
// SOFTWARE.
2222

23-
import * as https from './providers/https';
2423
import * as logger from '../logger';
24+
import * as https from './providers/https';
2525

2626
export { https, logger };
2727

src/v2/options.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ import {
2424
durationFromSeconds,
2525
serviceAccountFromShorthand,
2626
} from '../common/encoding';
27+
import { convertIfPresent, copyIfPresent } from '../common/encoding';
2728
import * as logger from '../logger';
2829
import { TriggerAnnotation } from './base';
29-
import { copyIfPresent, convertIfPresent } from '../common/encoding';
3030

3131
/**
3232
* List of all regions supported by Cloud Functions v2

0 commit comments

Comments
 (0)