From 8944650a1ffbf7ac22ba5fb1f22d1826adec1749 Mon Sep 17 00:00:00 2001 From: Nate Anderson Date: Fri, 19 May 2023 16:06:44 -0700 Subject: [PATCH] Update configurations Remove the in-region and low-latency configurations and replace them with a browser configuration. Split the deadline and metadata creation into separate functions. --- .../src/config/configurations.ts | 80 ++---------- .../src/internal/data-client.ts | 114 ++++++++++++------ .../src/internal/pubsub-client.ts | 9 +- .../src/utils/web-client-utils.ts | 11 +- 4 files changed, 102 insertions(+), 112 deletions(-) diff --git a/packages/client-sdk-web/src/config/configurations.ts b/packages/client-sdk-web/src/config/configurations.ts index 09a8f76e7..7af5fd786 100644 --- a/packages/client-sdk-web/src/config/configurations.ts +++ b/packages/client-sdk-web/src/config/configurations.ts @@ -14,8 +14,7 @@ const defaultLoggerFactory: MomentoLoggerFactory = new DefaultMomentoLoggerFactory(); /** - * Laptop config provides defaults suitable for a medium-to-high-latency dev environment. Permissive timeouts, retries, and - * relaxed latency and throughput targets. + * Laptop config provides defaults suitable for a medium-to-high-latency dev environment. * @export * @class Laptop */ @@ -55,9 +54,14 @@ export class Laptop extends CacheConfiguration { } } -class InRegionDefault extends CacheConfiguration { +/** + * Browser config provides defaults suitable for use in a web browser. + * @export + * @class Browser + */ +export class Browser extends CacheConfiguration { /** - * Provides the latest recommended configuration for a typical in-region environment. NOTE: this configuration may + * Provides the latest recommended configuration for an in-browser environment. NOTE: this configuration may * change in future releases to take advantage of improvements we identify for default configurations. * @param {MomentoLoggerFactory} [loggerFactory=defaultLoggerFactory] * @returns {CacheConfiguration} @@ -65,11 +69,11 @@ class InRegionDefault extends CacheConfiguration { static latest( loggerFactory: MomentoLoggerFactory = defaultLoggerFactory ): CacheConfiguration { - return InRegionDefault.v1(loggerFactory); + return Browser.v1(loggerFactory); } /** - * Provides v1 recommended configuration for a typical in-region environment. This configuration is guaranteed not + * Provides v1 recommended configuration for an in-browser environment. This configuration is guaranteed not * to change in future releases of the Momento node.js SDK. * @param {MomentoLoggerFactory} [loggerFactory=defaultLoggerFactory] * @returns {CacheConfiguration} @@ -77,76 +81,16 @@ class InRegionDefault extends CacheConfiguration { static v1( loggerFactory: MomentoLoggerFactory = defaultLoggerFactory ): CacheConfiguration { - const deadlineMillis = 1100; - const grpcConfig: GrpcConfiguration = new StaticGrpcConfiguration({ - deadlineMillis: deadlineMillis, - }); - const transportStrategy: TransportStrategy = new StaticTransportStrategy({ - grpcConfiguration: grpcConfig, - }); - return new InRegionDefault({ - loggerFactory: loggerFactory, - transportStrategy: transportStrategy, - }); - } -} - -class InRegionLowLatency extends CacheConfiguration { - /** - * Provides the latest recommended configuration for an in-region environment with aggressive low-latency requirements. - * NOTE: this configuration may change in future releases to take advantage of improvements we identify for default - * configurations. - * @param {MomentoLoggerFactory} [loggerFactory=defaultLoggerFactory] - * @returns {CacheConfiguration} - */ - static latest( - loggerFactory: MomentoLoggerFactory = defaultLoggerFactory - ): CacheConfiguration { - return InRegionLowLatency.v1(loggerFactory); - } - - /** - * Provides v1 recommended configuration for an in-region environment with aggressive low-latency requirements. - * This configuration is guaranteed not to change in future releases of the Momento node.js SDK. - * @param {MomentoLoggerFactory} [loggerFactory=defaultLoggerFactory] - * @returns {CacheConfiguration} - */ - static v1( - loggerFactory: MomentoLoggerFactory = defaultLoggerFactory - ): CacheConfiguration { - const deadlineMillis = 500; + const deadlineMillis = 5000; const grpcConfig: GrpcConfiguration = new StaticGrpcConfiguration({ deadlineMillis: deadlineMillis, }); const transportStrategy: TransportStrategy = new StaticTransportStrategy({ grpcConfiguration: grpcConfig, }); - return new InRegionDefault({ + return new Browser({ loggerFactory: loggerFactory, transportStrategy: transportStrategy, }); } } - -/** - * InRegion provides defaults suitable for an environment where your client is running in the same region as the Momento - * service. It has more aggressive timeouts and retry behavior than the Laptop config. - * @export - * @class InRegion - */ -export class InRegion { - /** - * This config prioritizes throughput and client resource utilization. It has a slightly relaxed client-side timeout - * setting to maximize throughput. - * @type {InRegionDefault} - */ - static Default = InRegionDefault; - /** - * This config prioritizes keeping p99.9 latencies as low as possible, potentially sacrificing - * some throughput to achieve this. It has a very aggressive client-side timeout. Use this - * configuration if the most important factor is to ensure that cache unavailability doesn't force - * unacceptably high latencies for your own application. - * @type {InRegionLowLatency} - */ - static LowLatency = InRegionLowLatency; -} diff --git a/packages/client-sdk-web/src/internal/data-client.ts b/packages/client-sdk-web/src/internal/data-client.ts index c128e660f..6380a86aa 100644 --- a/packages/client-sdk-web/src/internal/data-client.ts +++ b/packages/client-sdk-web/src/internal/data-client.ts @@ -109,7 +109,11 @@ import { validateSortedSetScores, } from '@gomomento/sdk-core/dist/src/internal/utils'; import {normalizeSdkError} from '@gomomento/sdk-core/dist/src/errors'; -import {convertToB64String, createMetadata} from '../utils/web-client-utils'; +import { + convertToB64String, + createDeadline, + createMetadata, +} from '../utils/web-client-utils'; export interface DataClientProps { configuration: Configuration; @@ -185,7 +189,7 @@ export class DataClient< ): Promise { const request = new _GetRequest(); request.setCacheKey(key); - const metadata = createMetadata(cacheName, this.deadlineMillis); + const metadata = createMetadata(cacheName); return await new Promise(resolve => { this.clientWrapper.get( @@ -193,6 +197,7 @@ export class DataClient< { ...this.authHeaders, ...metadata, + ...createDeadline(this.deadlineMillis), }, (err, resp) => { if (resp) { @@ -268,13 +273,14 @@ export class DataClient< request.setCacheKey(key); request.setCacheBody(value); request.setTtlMilliseconds(this.convertSecondsToMilliseconds(ttlSeconds)); - const metadata = createMetadata(cacheName, this.deadlineMillis); + const metadata = createMetadata(cacheName); return await new Promise(resolve => { this.clientWrapper.set( request, { ...this.authHeaders, ...metadata, + ...createDeadline(this.deadlineMillis), }, (err, resp) => { if (resp) { @@ -329,7 +335,7 @@ export class DataClient< request.setCacheKey(key); request.setCacheBody(field); request.setTtlMilliseconds(ttlMilliseconds); - const metadata = createMetadata(cacheName, this.deadlineMillis); + const metadata = createMetadata(cacheName); return await new Promise(resolve => { this.clientWrapper.setIfNotExists( @@ -337,6 +343,7 @@ export class DataClient< { ...this.authHeaders, ...metadata, + ...createDeadline(this.deadlineMillis), }, (err, resp) => { if (resp) { @@ -386,13 +393,14 @@ export class DataClient< ): Promise { const request = new _DeleteRequest(); request.setCacheKey(key); - const metadata = createMetadata(cacheName, this.deadlineMillis); + const metadata = createMetadata(cacheName); return await new Promise(resolve => { this.clientWrapper.delete( request, { ...this.authHeaders, ...metadata, + ...createDeadline(this.deadlineMillis), }, (err, resp) => { if (resp) { @@ -442,7 +450,7 @@ export class DataClient< request.setCacheKey(field); request.setAmount(amount); request.setTtlMilliseconds(ttlMilliseconds); - const metadata = createMetadata(cacheName, this.deadlineMillis); + const metadata = createMetadata(cacheName); return await new Promise(resolve => { this.clientWrapper.increment( @@ -450,6 +458,7 @@ export class DataClient< { ...this.authHeaders, ...metadata, + ...createDeadline(this.deadlineMillis), }, (err, resp) => { if (resp) { @@ -485,13 +494,14 @@ export class DataClient< ): Promise { const request = new _SetFetchRequest(); request.setSetName(setName); - const metadata = createMetadata(cacheName, this.deadlineMillis); + const metadata = createMetadata(cacheName); return await new Promise(resolve => { this.clientWrapper.setFetch( request, { ...this.authHeaders, ...metadata, + ...createDeadline(this.deadlineMillis), }, (err, resp) => { const theSet = resp.getFound(); @@ -541,13 +551,14 @@ export class DataClient< request.setElementsList(elements); request.setTtlMilliseconds(ttlMilliseconds); request.setRefreshTtl(refreshTtl); - const metadata = createMetadata(cacheName, this.deadlineMillis); + const metadata = createMetadata(cacheName); return await new Promise(resolve => { this.clientWrapper.setUnion( request, { ...this.authHeaders, ...metadata, + ...createDeadline(this.deadlineMillis), }, err => { if (err) { @@ -593,13 +604,14 @@ export class DataClient< request.setSetName(setName); request.setSubtrahend(subtrahend); - const metadata = createMetadata(cacheName, this.deadlineMillis); + const metadata = createMetadata(cacheName); return await new Promise(resolve => { this.clientWrapper.setDifference( request, { ...this.authHeaders, ...metadata, + ...createDeadline(this.deadlineMillis), }, err => { if (err) { @@ -667,13 +679,14 @@ export class DataClient< request.setRefreshTtl(refreshTtl); request.setTruncateFrontToSize(truncateFrontToSize || 0); - const metadata = createMetadata(cacheName, this.deadlineMillis); + const metadata = createMetadata(cacheName); return await new Promise(resolve => { this.clientWrapper.listConcatenateBack( request, { ...this.authHeaders, ...metadata, + ...createDeadline(this.deadlineMillis), }, (err, resp) => { if (resp) { @@ -741,13 +754,14 @@ export class DataClient< request.setRefreshTtl(refreshTtl); request.setTruncateBackToSize(truncateBackToSize || 0); - const metadata = createMetadata(cacheName, this.deadlineMillis); + const metadata = createMetadata(cacheName); return await new Promise(resolve => { this.clientWrapper.listConcatenateFront( request, { ...this.authHeaders, ...metadata, + ...createDeadline(this.deadlineMillis), }, (err, resp) => { if (resp) { @@ -811,7 +825,7 @@ export class DataClient< } else { request.setUnboundedEnd(new _Unbounded()); } - const metadata = createMetadata(cacheName, this.deadlineMillis); + const metadata = createMetadata(cacheName); return await new Promise(resolve => { this.clientWrapper.listFetch( @@ -819,6 +833,7 @@ export class DataClient< { ...this.authHeaders, ...metadata, + ...createDeadline(this.deadlineMillis), }, (err, resp) => { if (resp?.getMissing()) { @@ -898,7 +913,7 @@ export class DataClient< } else { request.setUnboundedEnd(new _Unbounded()); } - const metadata = createMetadata(cacheName, this.deadlineMillis); + const metadata = createMetadata(cacheName); return await new Promise(resolve => { this.clientWrapper.listRetain( @@ -906,6 +921,7 @@ export class DataClient< { ...this.authHeaders, ...metadata, + ...createDeadline(this.deadlineMillis), }, (err, resp) => { if (resp) { @@ -943,7 +959,7 @@ export class DataClient< ): Promise { const request = new _ListLengthRequest(); request.setListName(listName); - const metadata = createMetadata(cacheName, this.deadlineMillis); + const metadata = createMetadata(cacheName); return await new Promise(resolve => { this.clientWrapper.listLength( @@ -951,6 +967,7 @@ export class DataClient< { ...this.authHeaders, ...metadata, + ...createDeadline(this.deadlineMillis), }, (err, resp) => { if (resp?.getMissing()) { @@ -998,7 +1015,7 @@ export class DataClient< ): Promise { const request = new _ListPopBackRequest(); request.setListName(listName); - const metadata = createMetadata(cacheName, this.deadlineMillis); + const metadata = createMetadata(cacheName); return await new Promise(resolve => { this.clientWrapper.listPopBack( @@ -1006,6 +1023,7 @@ export class DataClient< { ...this.authHeaders, ...metadata, + ...createDeadline(this.deadlineMillis), }, (err, resp) => { if (resp?.getMissing()) { @@ -1051,7 +1069,7 @@ export class DataClient< ): Promise { const request = new _ListPopFrontRequest(); request.setListName(listName); - const metadata = createMetadata(cacheName, this.deadlineMillis); + const metadata = createMetadata(cacheName); return await new Promise(resolve => { this.clientWrapper.listPopFront( @@ -1059,6 +1077,7 @@ export class DataClient< { ...this.authHeaders, ...metadata, + ...createDeadline(this.deadlineMillis), }, (err, resp) => { if (resp?.getMissing()) { @@ -1126,13 +1145,14 @@ export class DataClient< request.setTtlMilliseconds(ttlMilliseconds); request.setRefreshTtl(refreshTtl); request.setTruncateFrontToSize(truncateFrontToSize || 0); - const metadata = createMetadata(cacheName, this.deadlineMillis); + const metadata = createMetadata(cacheName); return await new Promise(resolve => { this.clientWrapper.listPushBack( request, { ...this.authHeaders, ...metadata, + ...createDeadline(this.deadlineMillis), }, (err, resp) => { if (resp) { @@ -1193,13 +1213,14 @@ export class DataClient< request.setTtlMilliseconds(ttlMilliseconds); request.setRefreshTtl(refreshTtl); request.setTruncateBackToSize(truncateBackToSize || 0); - const metadata = createMetadata(cacheName, this.deadlineMillis); + const metadata = createMetadata(cacheName); return await new Promise(resolve => { this.clientWrapper.listPushFront( request, { ...this.authHeaders, ...metadata, + ...createDeadline(this.deadlineMillis), }, (err, resp) => { if (resp) { @@ -1245,13 +1266,14 @@ export class DataClient< const request = new _ListRemoveRequest(); request.setListName(listName); request.setAllElementsWithValue(value); - const metadata = createMetadata(cacheName, this.deadlineMillis); + const metadata = createMetadata(cacheName); return await new Promise(resolve => { this.clientWrapper.listRemove( request, { ...this.authHeaders, ...metadata, + ...createDeadline(this.deadlineMillis), }, (err, resp) => { if (resp) { @@ -1314,13 +1336,14 @@ export class DataClient< request.setItemsList([item]); request.setTtlMilliseconds(ttlMilliseconds); request.setRefreshTtl(refreshTtl); - const metadata = createMetadata(cacheName, this.deadlineMillis); + const metadata = createMetadata(cacheName); return await new Promise(resolve => { this.clientWrapper.dictionarySet( request, { ...this.authHeaders, ...metadata, + ...createDeadline(this.deadlineMillis), }, (err, resp) => { if (resp) { @@ -1384,13 +1407,14 @@ export class DataClient< request.setItemsList(elements); request.setTtlMilliseconds(ttlMilliseconds); request.setRefreshTtl(refreshTtl); - const metadata = createMetadata(cacheName, this.deadlineMillis); + const metadata = createMetadata(cacheName); return await new Promise(resolve => { this.clientWrapper.dictionarySet( request, { ...this.authHeaders, ...metadata, + ...createDeadline(this.deadlineMillis), }, (err, resp) => { if (resp) { @@ -1441,7 +1465,7 @@ export class DataClient< const request = new _DictionaryGetRequest(); request.setDictionaryName(dictionaryName); request.setFieldsList([field]); - const metadata = createMetadata(cacheName, this.deadlineMillis); + const metadata = createMetadata(cacheName); return await new Promise(resolve => { this.clientWrapper.dictionaryGet( @@ -1449,6 +1473,7 @@ export class DataClient< { ...this.authHeaders, ...metadata, + ...createDeadline(this.deadlineMillis), }, (err, resp) => { if (resp?.getMissing()) { @@ -1531,7 +1556,7 @@ export class DataClient< const request = new _DictionaryGetRequest(); request.setDictionaryName(dictionaryName); request.setFieldsList(this.convertArrayToB64Strings(fields)); - const metadata = createMetadata(cacheName, this.deadlineMillis); + const metadata = createMetadata(cacheName); return await new Promise(resolve => { this.clientWrapper.dictionaryGet( @@ -1539,6 +1564,7 @@ export class DataClient< { ...this.authHeaders, ...metadata, + ...createDeadline(this.deadlineMillis), }, (err, resp) => { const found = resp?.getFound(); @@ -1595,13 +1621,14 @@ export class DataClient< ): Promise { const request = new _DictionaryFetchRequest(); request.setDictionaryName(dictionaryName); - const metadata = createMetadata(cacheName, this.deadlineMillis); + const metadata = createMetadata(cacheName); return await new Promise(resolve => { this.clientWrapper.dictionaryFetch( request, { ...this.authHeaders, ...metadata, + ...createDeadline(this.deadlineMillis), }, (err, resp) => { const theDict = resp?.getFound(); @@ -1677,13 +1704,14 @@ export class DataClient< request.setAmount(amount); request.setTtlMilliseconds(ttlMilliseconds); request.setRefreshTtl(refreshTtl); - const metadata = createMetadata(cacheName, this.deadlineMillis); + const metadata = createMetadata(cacheName); return await new Promise(resolve => { this.clientWrapper.dictionaryIncrement( request, { ...this.authHeaders, ...metadata, + ...createDeadline(this.deadlineMillis), }, (err, resp) => { if (resp) { @@ -1737,13 +1765,14 @@ export class DataClient< const request = new _DictionaryDeleteRequest(); request.setDictionaryName(dictionaryName); request.setSome(new _DictionaryDeleteRequest.Some().addFields(field)); - const metadata = createMetadata(cacheName, this.deadlineMillis); + const metadata = createMetadata(cacheName); return await new Promise(resolve => { this.clientWrapper.dictionaryDelete( request, { ...this.authHeaders, ...metadata, + ...createDeadline(this.deadlineMillis), }, (err, resp) => { if (resp) { @@ -1793,7 +1822,7 @@ export class DataClient< const request = new _DictionaryDeleteRequest(); request.setDictionaryName(dictionaryName); request.setSome(new _DictionaryDeleteRequest.Some().setFieldsList(fields)); - const metadata = createMetadata(cacheName, this.deadlineMillis); + const metadata = createMetadata(cacheName); return await new Promise(resolve => { this.clientWrapper.dictionaryDelete( @@ -1801,6 +1830,7 @@ export class DataClient< { ...this.authHeaders, ...metadata, + ...createDeadline(this.deadlineMillis), }, (err, resp) => { if (resp) { @@ -1883,13 +1913,14 @@ export class DataClient< request.setWithScores(true); request.setByIndex(by_index); - const metadata = createMetadata(cacheName, this.deadlineMillis); + const metadata = createMetadata(cacheName); return await new Promise(resolve => { this.clientWrapper.sortedSetFetch( request, { ...this.authHeaders, ...metadata, + ...createDeadline(this.deadlineMillis), }, (err, resp) => { if (resp && resp.getFound()) { @@ -2017,13 +2048,14 @@ export class DataClient< request.setWithScores(true); request.setByScore(by_score); - const metadata = createMetadata(cacheName, this.deadlineMillis); + const metadata = createMetadata(cacheName); return await new Promise(resolve => { this.clientWrapper.sortedSetFetch( request, { ...this.authHeaders, ...metadata, + ...createDeadline(this.deadlineMillis), }, (err, resp) => { if (resp) { @@ -2121,13 +2153,14 @@ export class DataClient< request.setElementsList([elem]); request.setTtlMilliseconds(ttlMilliseconds); request.setRefreshTtl(refreshTtl); - const metadata = createMetadata(cacheName, this.deadlineMillis); + const metadata = createMetadata(cacheName); return await new Promise(resolve => { this.clientWrapper.sortedSetPut( request, { ...this.authHeaders, ...metadata, + ...createDeadline(this.deadlineMillis), }, (err, resp) => { if (resp) { @@ -2190,13 +2223,14 @@ export class DataClient< request.setElementsList(elements); request.setTtlMilliseconds(ttlMilliseconds); request.setRefreshTtl(refreshTtl); - const metadata = createMetadata(cacheName, this.deadlineMillis); + const metadata = createMetadata(cacheName); return await new Promise(resolve => { this.clientWrapper.sortedSetPut( request, { ...this.authHeaders, ...metadata, + ...createDeadline(this.deadlineMillis), }, (err, resp) => { if (resp) { @@ -2274,13 +2308,14 @@ export class DataClient< const request = new _SortedSetGetScoreRequest(); request.setSetName(sortedSetName); request.setValuesList(values); - const metadata = createMetadata(cacheName, this.deadlineMillis); + const metadata = createMetadata(cacheName); return await new Promise(resolve => { this.clientWrapper.sortedSetGetScore( request, { ...this.authHeaders, ...metadata, + ...createDeadline(this.deadlineMillis), }, (err, resp) => { if (resp?.getMissing()) { @@ -2358,13 +2393,14 @@ export class DataClient< const request = new _SortedSetGetRankRequest(); request.setSetName(sortedSetName); request.setValue(value); - const metadata = createMetadata(cacheName, this.deadlineMillis); + const metadata = createMetadata(cacheName); return await new Promise(resolve => { this.clientWrapper.sortedSetGetRank( request, { ...this.authHeaders, ...metadata, + ...createDeadline(this.deadlineMillis), }, (err, resp) => { if ( @@ -2438,13 +2474,14 @@ export class DataClient< request.setAmount(amount); request.setTtlMilliseconds(ttlMilliseconds); request.setRefreshTtl(refreshTtl); - const metadata = createMetadata(cacheName, this.deadlineMillis); + const metadata = createMetadata(cacheName); return await new Promise(resolve => { this.clientWrapper.sortedSetIncrement( request, { ...this.authHeaders, ...metadata, + ...createDeadline(this.deadlineMillis), }, (err, resp) => { if (resp) { @@ -2500,13 +2537,14 @@ export class DataClient< const request = new _SortedSetRemoveRequest(); request.setSetName(sortedSetName); request.setSome(new _SortedSetRemoveRequest._Some().setValuesList([value])); - const metadata = createMetadata(cacheName, this.deadlineMillis); + const metadata = createMetadata(cacheName); return await new Promise(resolve => { this.clientWrapper.sortedSetRemove( request, { ...this.authHeaders, ...metadata, + ...createDeadline(this.deadlineMillis), }, err => { if (err) { @@ -2558,13 +2596,14 @@ export class DataClient< const request = new _SortedSetRemoveRequest(); request.setSetName(sortedSetName); request.setSome(new _SortedSetRemoveRequest._Some().setValuesList(values)); - const metadata = createMetadata(cacheName, this.deadlineMillis); + const metadata = createMetadata(cacheName); return await new Promise(resolve => { this.clientWrapper.sortedSetRemove( request, { ...this.authHeaders, ...metadata, + ...createDeadline(this.deadlineMillis), }, err => { if (err) { @@ -2599,13 +2638,14 @@ export class DataClient< ): Promise { const request = new _ItemGetTypeRequest(); request.setCacheKey(key); - const metadata = createMetadata(cacheName, this.deadlineMillis); + const metadata = createMetadata(cacheName); return await new Promise(resolve => { this.clientWrapper.itemGetType( request, { ...this.authHeaders, ...metadata, + ...createDeadline(this.deadlineMillis), }, (err, resp) => { const theType = resp.getFound(); diff --git a/packages/client-sdk-web/src/internal/pubsub-client.ts b/packages/client-sdk-web/src/internal/pubsub-client.ts index b3da0d13d..221bdea5d 100644 --- a/packages/client-sdk-web/src/internal/pubsub-client.ts +++ b/packages/client-sdk-web/src/internal/pubsub-client.ts @@ -27,7 +27,11 @@ import { SendSubscribeOptions, PrepareSubscribeCallbackOptions, } from '@gomomento/sdk-core/dist/src/internal/clients/pubsub/AbstractPubsubClient'; -import {convertToB64String, createMetadata} from '../utils/web-client-utils'; +import { + convertToB64String, + createDeadline, + createMetadata, +} from '../utils/web-client-utils'; export class PubsubClient< REQ extends Request, @@ -108,7 +112,7 @@ export class PubsubClient< request.setCacheName(cacheName); request.setTopic(topicName); request.setValue(topicValue); - const metadata = createMetadata(cacheName, this.requestTimeoutMs); + const metadata = createMetadata(cacheName); return await new Promise(resolve => { this.client.publish( @@ -116,6 +120,7 @@ export class PubsubClient< { ...this.authHeaders, ...metadata, + ...createDeadline(this.requestTimeoutMs), }, (err, resp) => { if (resp) { diff --git a/packages/client-sdk-web/src/utils/web-client-utils.ts b/packages/client-sdk-web/src/utils/web-client-utils.ts index b31642d5f..9306d2f74 100644 --- a/packages/client-sdk-web/src/utils/web-client-utils.ts +++ b/packages/client-sdk-web/src/utils/web-client-utils.ts @@ -7,10 +7,11 @@ export function convertToB64String(v: string | Uint8Array): string { return btoa(String.fromCharCode.apply(null, v)); } -export function createMetadata( - cacheName: string, - timeoutMillis: number -): {cache: string; deadline: string} { +export function createMetadata(cacheName: string): {cache: string} { + return {cache: cacheName}; +} + +export function createDeadline(timeoutMillis: number): {deadline: string} { const deadline = Date.now() + timeoutMillis; - return {cache: cacheName, deadline: deadline.toString()}; + return {deadline: deadline.toString()}; }