-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add web sdk configurations (#518)
* feat: Add web sdk configurations Move transport-strategy and grpc-configuration out of core since it contains options that are only useful for the node sdk. Create web versions of transport strategy and grpc configuration. Create web version of configurations. Plumb deadline millis into the web sdk.
- Loading branch information
Showing
20 changed files
with
537 additions
and
261 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from '@gomomento/sdk-core/dist/src/config/transport'; | ||
export * from './grpc-configuration'; | ||
export * from './transport-strategy'; |
130 changes: 129 additions & 1 deletion
130
packages/client-sdk-nodejs/src/config/transport/transport-strategy.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,129 @@ | ||
export * from '@gomomento/sdk-core/dist/src/config/transport/transport-strategy'; | ||
import {GrpcConfiguration, GrpcConfigurationProps} from './grpc-configuration'; | ||
|
||
export interface TransportStrategy { | ||
/** | ||
* Configures the low-level gRPC settings for the Momento client's communication | ||
* with the Momento server. | ||
* @returns {GrpcConfiguration} | ||
*/ | ||
getGrpcConfig(): GrpcConfiguration; | ||
|
||
/** | ||
* Copy constructor for overriding the gRPC configuration | ||
* @param {GrpcConfiguration} grpcConfig | ||
* @returns {TransportStrategy} a new TransportStrategy with the specified gRPC config. | ||
*/ | ||
withGrpcConfig(grpcConfig: GrpcConfiguration): TransportStrategy; | ||
|
||
/** | ||
* Copy constructor to update the client-side timeout | ||
* @param {number} clientTimeoutMillis | ||
* @returns {TransportStrategy} a new TransportStrategy with the specified client timeout | ||
*/ | ||
withClientTimeoutMillis(clientTimeoutMillis: number): TransportStrategy; | ||
|
||
/** | ||
* The maximum duration for which a connection may remain idle before being replaced. This | ||
* setting can be used to force re-connection of a client if it has been idle for too long. | ||
* In environments such as AWS lambda, if the lambda is suspended for too long the connection | ||
* may be closed by the load balancer, resulting in an error on the subsequent request. If | ||
* this setting is set to a duration less than the load balancer timeout, we can ensure that | ||
* the connection will be refreshed to avoid errors. | ||
* @returns {number} | ||
*/ | ||
getMaxIdleMillis(): number; | ||
|
||
/** | ||
* Copy constructor to update the max idle connection timeout. (See {getMaxIdleMillis}.) | ||
* @param {number} maxIdleMillis | ||
* @returns {TransportStrategy} a new TransportStrategy with the specified max idle connection timeout. | ||
*/ | ||
withMaxIdleMillis(maxIdleMillis: number): TransportStrategy; | ||
} | ||
|
||
export interface TransportStrategyProps { | ||
/** | ||
* low-level gRPC settings for communication with the Momento server | ||
*/ | ||
grpcConfiguration: GrpcConfiguration; | ||
/** | ||
* The maximum duration for which a connection may remain idle before being replaced. This | ||
* setting can be used to force re-connection of a client if it has been idle for too long. | ||
* In environments such as AWS lambda, if the lambda is suspended for too long the connection | ||
* may be closed by the load balancer, resulting in an error on the subsequent request. If | ||
* this setting is set to a duration less than the load balancer timeout, we can ensure that | ||
* the connection will be refreshed to avoid errors. | ||
* @returns {number} | ||
*/ | ||
maxIdleMillis: number; | ||
} | ||
|
||
export class StaticGrpcConfiguration implements GrpcConfiguration { | ||
private readonly deadlineMillis: number; | ||
private readonly maxSessionMemoryMb: number; | ||
constructor(props: GrpcConfigurationProps) { | ||
this.deadlineMillis = props.deadlineMillis; | ||
this.maxSessionMemoryMb = props.maxSessionMemoryMb; | ||
} | ||
|
||
getDeadlineMillis(): number { | ||
return this.deadlineMillis; | ||
} | ||
|
||
getMaxSessionMemoryMb(): number { | ||
return this.maxSessionMemoryMb; | ||
} | ||
|
||
withDeadlineMillis(deadlineMillis: number): StaticGrpcConfiguration { | ||
return new StaticGrpcConfiguration({ | ||
deadlineMillis: deadlineMillis, | ||
maxSessionMemoryMb: this.maxSessionMemoryMb, | ||
}); | ||
} | ||
|
||
withMaxSessionMemoryMb(maxSessionMemoryMb: number): StaticGrpcConfiguration { | ||
return new StaticGrpcConfiguration({ | ||
deadlineMillis: this.deadlineMillis, | ||
maxSessionMemoryMb: maxSessionMemoryMb, | ||
}); | ||
} | ||
} | ||
|
||
export class StaticTransportStrategy implements TransportStrategy { | ||
private readonly grpcConfig: GrpcConfiguration; | ||
private readonly maxIdleMillis: number; | ||
|
||
constructor(props: TransportStrategyProps) { | ||
this.grpcConfig = props.grpcConfiguration; | ||
this.maxIdleMillis = props.maxIdleMillis; | ||
} | ||
|
||
getGrpcConfig(): GrpcConfiguration { | ||
return this.grpcConfig; | ||
} | ||
|
||
withGrpcConfig(grpcConfig: GrpcConfiguration): StaticTransportStrategy { | ||
return new StaticTransportStrategy({ | ||
grpcConfiguration: grpcConfig, | ||
maxIdleMillis: this.maxIdleMillis, | ||
}); | ||
} | ||
|
||
getMaxIdleMillis(): number { | ||
return this.maxIdleMillis; | ||
} | ||
|
||
withMaxIdleMillis(maxIdleMillis: number): TransportStrategy { | ||
return new StaticTransportStrategy({ | ||
grpcConfiguration: this.grpcConfig, | ||
maxIdleMillis: maxIdleMillis, | ||
}); | ||
} | ||
|
||
withClientTimeoutMillis(clientTimeout: number): StaticTransportStrategy { | ||
return new StaticTransportStrategy({ | ||
grpcConfiguration: this.grpcConfig.withDeadlineMillis(clientTimeout), | ||
maxIdleMillis: this.maxIdleMillis, | ||
}); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...nfig/transport/transport-strategy.test.ts → ...nfig/transport/transport-strategy.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import {CredentialProvider} from '.'; | ||
import {Configuration} from './config/configuration'; | ||
|
||
export interface CacheClientProps { | ||
/** | ||
* Configuration settings for the cache client | ||
*/ | ||
configuration: Configuration; | ||
/** | ||
* controls how the client will get authentication information for connecting to the Momento service | ||
*/ | ||
credentialProvider: CredentialProvider; | ||
/** | ||
* the default time to live of object inside of cache, in seconds | ||
*/ | ||
defaultTtlSeconds: number; | ||
} | ||
|
||
/** | ||
* @deprecated use {CacheClientProps} instead | ||
*/ | ||
export type SimpleCacheClientProps = CacheClientProps; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.