Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('should determine if the value is a timestamp', () => {
assert.deepStrictEqual(codec.getType(new PreciseDate()), {
type: 'timestamp',
});
});
it('should convert `readTimestamp` Date to proto', () => {
const fakeTimestamp = new PreciseDate();
sandbox.stub(fakeTimestamp, 'toStruct').returns(PROTO_TIMESTAMP);
const options = Snapshot.encodeTimestampBounds({
readTimestamp: fakeTimestamp,
});
assert.strictEqual(options.readTimestamp, PROTO_TIMESTAMP);
});
it('should localize `readTimestamp` if present', done => {
const expectedTimestamp = new PreciseDate(0);
const readTimestamp = {seconds: 0, nanos: 0};
const response = Object.assign({readTimestamp}, BEGIN_RESPONSE);
REQUEST.callsFake((_, callback) => callback(null, response));
snapshot.begin(err => {
assert.ifError(err);
assert.deepStrictEqual(snapshot.readTimestamp, expectedTimestamp);
assert.strictEqual(snapshot.readTimestampProto, readTimestamp);
done();
});
});
it('should decode TIMESTAMP', () => {
const value = new Date();
const expected = new PreciseDate(value.getTime());
const decoded = codec.decode(value.toJSON(), {
code: s.TypeCode.TIMESTAMP,
});
assert.deepStrictEqual(decoded, expected);
});
it('should encode TIMESTAMP', () => {
const value = new PreciseDate();
const encoded = codec.encode(value);
assert.strictEqual(encoded, value.toJSON());
});
it('should convert `minReadTimestamp` Date to proto', () => {
const fakeTimestamp = new PreciseDate();
sandbox.stub(fakeTimestamp, 'toStruct').returns(PROTO_TIMESTAMP);
const options = Snapshot.encodeTimestampBounds({
minReadTimestamp: fakeTimestamp,
});
assert.strictEqual(options.minReadTimestamp, PROTO_TIMESTAMP);
});
*
* **EXPERIMENTAL:** This feature is part of a closed alpha release. This
* API might be changed in backward-incompatible ways and is not recommended
* for production use. It is not subject to any SLA or deprecation policy.
*
* @name Message#orderingKey
* @type {string}
*/
this.orderingKey = message!.orderingKey!;
/**
* The time at which the message was published.
*
* @name Message#publishTime
* @type {external:PreciseDate}
*/
this.publishTime = new PreciseDate(message!.publishTime as DateStruct);
/**
* The time at which the message was recieved by the subscription.
*
* @name Message#received
* @type {number}
*/
this.received = Date.now();
this._handled = false;
this._length = this.data.length;
this._subscriber = sub;
}
/**
callback(err, null, resp);
return;
}
const partitions = resp.partitions.map(partition => {
return extend({}, query, partition);
});
if (resp.transaction) {
const {id, readTimestamp} = resp.transaction;
this.id = id;
if (readTimestamp) {
this.readTimestampProto = readTimestamp;
this.readTimestamp = new PreciseDate(readTimestamp);
}
}
callback(null, partitions, resp);
});
}