Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: copy constructors should use spread operator #1494

Merged
merged 1 commit into from
Jan 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 13 additions & 53 deletions packages/client-sdk-nodejs/src/config/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,13 +183,8 @@ export class CacheConfiguration implements Configuration {

withRetryStrategy(retryStrategy: RetryStrategy): Configuration {
return new CacheConfiguration({
loggerFactory: this.loggerFactory,
retryStrategy: retryStrategy,
transportStrategy: this.transportStrategy,
middlewares: this.middlewares,
throwOnErrors: this.throwOnErrors,
readConcern: this.readConcern,
compression: this.compression,
...this,
retryStrategy,
});
}

Expand All @@ -199,13 +194,8 @@ export class CacheConfiguration implements Configuration {

withTransportStrategy(transportStrategy: TransportStrategy): Configuration {
return new CacheConfiguration({
loggerFactory: this.loggerFactory,
retryStrategy: this.retryStrategy,
transportStrategy: transportStrategy,
middlewares: this.middlewares,
throwOnErrors: this.throwOnErrors,
readConcern: this.readConcern,
compression: this.compression,
...this,
transportStrategy,
});
}

Expand All @@ -225,38 +215,23 @@ export class CacheConfiguration implements Configuration {

withMiddlewares(middlewares: Middleware[]): Configuration {
return new CacheConfiguration({
loggerFactory: this.loggerFactory,
retryStrategy: this.retryStrategy,
transportStrategy: this.transportStrategy,
middlewares: middlewares,
throwOnErrors: this.throwOnErrors,
readConcern: this.readConcern,
compression: this.compression,
...this,
middlewares,
});
}

addMiddleware(middleware: Middleware): Configuration {
return new CacheConfiguration({
loggerFactory: this.loggerFactory,
retryStrategy: this.retryStrategy,
transportStrategy: this.transportStrategy,
...this,
middlewares: [middleware, ...this.middlewares],
throwOnErrors: this.throwOnErrors,
readConcern: this.readConcern,
compression: this.compression,
});
}

withClientTimeoutMillis(clientTimeout: number): Configuration {
return new CacheConfiguration({
loggerFactory: this.loggerFactory,
retryStrategy: this.retryStrategy,
...this,
transportStrategy:
this.transportStrategy.withClientTimeoutMillis(clientTimeout),
middlewares: this.middlewares,
throwOnErrors: this.throwOnErrors,
readConcern: this.readConcern,
compression: this.compression,
});
}

Expand All @@ -266,13 +241,8 @@ export class CacheConfiguration implements Configuration {

withThrowOnErrors(throwOnErrors: boolean): Configuration {
return new CacheConfiguration({
loggerFactory: this.loggerFactory,
retryStrategy: this.retryStrategy,
transportStrategy: this.transportStrategy,
middlewares: this.middlewares,
throwOnErrors: throwOnErrors,
readConcern: this.readConcern,
compression: this.compression,
...this,
throwOnErrors,
});
}

Expand All @@ -282,13 +252,8 @@ export class CacheConfiguration implements Configuration {

withReadConcern(readConcern: ReadConcern): Configuration {
return new CacheConfiguration({
loggerFactory: this.loggerFactory,
retryStrategy: this.retryStrategy,
transportStrategy: this.transportStrategy,
middlewares: this.middlewares,
throwOnErrors: this.throwOnErrors,
readConcern: readConcern,
compression: this.compression,
...this,
readConcern,
});
}

Expand All @@ -300,12 +265,7 @@ export class CacheConfiguration implements Configuration {
compressionStrategy: CompressionStrategy
): Configuration {
return new CacheConfiguration({
loggerFactory: this.loggerFactory,
retryStrategy: this.retryStrategy,
transportStrategy: this.transportStrategy,
middlewares: this.middlewares,
throwOnErrors: this.throwOnErrors,
readConcern: this.readConcern,
...this,
compression: compressionStrategy,
});
}
Expand Down
26 changes: 8 additions & 18 deletions packages/client-sdk-nodejs/src/config/leaderboard-configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,22 +120,18 @@ export class LeaderboardClientConfiguration
clientTimeoutMillis: number
): LeaderboardConfiguration {
return new LeaderboardClientConfiguration({
loggerFactory: this.loggerFactory,
...this,
transportStrategy:
this.transportStrategy.withClientTimeoutMillis(clientTimeoutMillis),
throwOnErrors: this.throwOnErrors,
middlewares: this.middlewares,
});
}

withTransportStrategy(
transportStrategy: TransportStrategy
): LeaderboardConfiguration {
return new LeaderboardClientConfiguration({
loggerFactory: this.loggerFactory,
transportStrategy: transportStrategy,
throwOnErrors: this.throwOnErrors,
middlewares: this.middlewares,
...this,
transportStrategy,
});
}

Expand All @@ -145,10 +141,8 @@ export class LeaderboardClientConfiguration

withThrowOnErrors(throwOnErrors: boolean): LeaderboardConfiguration {
return new LeaderboardClientConfiguration({
loggerFactory: this.loggerFactory,
transportStrategy: this.transportStrategy,
throwOnErrors: throwOnErrors,
middlewares: this.middlewares,
...this,
throwOnErrors,
});
}

Expand All @@ -158,19 +152,15 @@ export class LeaderboardClientConfiguration

withMiddlewares(middlewares: Middleware[]): LeaderboardConfiguration {
return new LeaderboardClientConfiguration({
loggerFactory: this.loggerFactory,
transportStrategy: this.transportStrategy,
middlewares: middlewares,
throwOnErrors: this.throwOnErrors,
...this,
middlewares,
});
}

addMiddleware(middleware: Middleware): LeaderboardConfiguration {
return new LeaderboardClientConfiguration({
loggerFactory: this.loggerFactory,
transportStrategy: this.transportStrategy,
...this,
middlewares: [middleware, ...this.middlewares],
throwOnErrors: this.throwOnErrors,
});
}
}
13 changes: 5 additions & 8 deletions packages/client-sdk-nodejs/src/config/storage-configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,28 +87,25 @@ export class StorageClientConfiguration implements StorageConfiguration {

withClientTimeoutMillis(clientTimeoutMillis: number): StorageConfiguration {
return new StorageClientConfiguration({
loggerFactory: this.loggerFactory,
...this,
transportStrategy:
this.transportStrategy.withClientTimeoutMillis(clientTimeoutMillis),
retryStrategy: this.retryStrategy,
});
}

withTransportStrategy(
transportStrategy: StorageTransportStrategy
): StorageConfiguration {
return new StorageClientConfiguration({
loggerFactory: this.loggerFactory,
transportStrategy: transportStrategy,
retryStrategy: this.retryStrategy,
...this,
transportStrategy,
});
}

withRetryStrategy(retryStrategy: RetryStrategy): StorageConfiguration {
return new StorageClientConfiguration({
loggerFactory: this.loggerFactory,
transportStrategy: this.transportStrategy,
retryStrategy: retryStrategy,
...this,
retryStrategy,
});
}
}
10 changes: 4 additions & 6 deletions packages/client-sdk-nodejs/src/config/topic-configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,8 @@ export class TopicClientConfiguration implements TopicConfiguration {
transportStrategy: TopicTransportStrategy
): TopicConfiguration {
return new TopicClientConfiguration({
loggerFactory: this.loggerFactory,
transportStrategy: transportStrategy,
throwOnErrors: this.throwOnErrors,
...this,
transportStrategy,
});
}

Expand All @@ -108,9 +107,8 @@ export class TopicClientConfiguration implements TopicConfiguration {

withThrowOnErrors(throwOnErrors: boolean): TopicConfiguration {
return new TopicClientConfiguration({
loggerFactory: this.loggerFactory,
transportStrategy: this.transportStrategy,
throwOnErrors: throwOnErrors,
...this,
throwOnErrors,
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -137,17 +137,15 @@ export class StaticGrpcConfiguration implements GrpcConfiguration {

withDeadlineMillis(deadlineMillis: number): StaticGrpcConfiguration {
return new StaticGrpcConfiguration({
deadlineMillis: deadlineMillis,
maxSessionMemoryMb: this.maxSessionMemoryMb,
numClients: this.numClients,
...this,
deadlineMillis,
});
}

withMaxSessionMemoryMb(maxSessionMemoryMb: number): StaticGrpcConfiguration {
return new StaticGrpcConfiguration({
deadlineMillis: this.deadlineMillis,
maxSessionMemoryMb: maxSessionMemoryMb,
numClients: this.numClients,
...this,
maxSessionMemoryMb,
});
}

Expand All @@ -165,9 +163,8 @@ export class StaticGrpcConfiguration implements GrpcConfiguration {

withNumClients(numClients: number): GrpcConfiguration {
return new StaticGrpcConfiguration({
deadlineMillis: this.deadlineMillis,
maxSessionMemoryMb: this.maxSessionMemoryMb,
numClients: numClients,
...this,
numClients,
});
}

Expand All @@ -177,38 +174,37 @@ export class StaticGrpcConfiguration implements GrpcConfiguration {

withMaxConcurrentRequests(maxConcurrentRequests: number): GrpcConfiguration {
return new StaticGrpcConfiguration({
deadlineMillis: this.deadlineMillis,
maxSessionMemoryMb: this.maxSessionMemoryMb,
numClients: this.numClients,
maxConcurrentRequests: maxConcurrentRequests,
...this,
maxConcurrentRequests,
});
}
}

export class StaticTransportStrategy implements TransportStrategy {
private readonly grpcConfig: GrpcConfiguration;
private readonly grpcConfiguration: GrpcConfiguration;
private readonly maxIdleMillis: number;
private readonly maxClientAgeMillis?: number;

constructor(props: TransportStrategyProps) {
this.grpcConfig = props.grpcConfiguration;
this.grpcConfiguration = props.grpcConfiguration;
this.maxIdleMillis = props.maxIdleMillis;
this.maxClientAgeMillis = props.maxClientAgeMillis;
}

getGrpcConfig(): GrpcConfiguration {
return this.grpcConfig;
return this.grpcConfiguration;
}

getMaxClientAgeMillis(): number | undefined {
return this.maxClientAgeMillis;
}

withGrpcConfig(grpcConfig: GrpcConfiguration): StaticTransportStrategy {
withGrpcConfig(
grpcConfiguration: GrpcConfiguration
): StaticTransportStrategy {
return new StaticTransportStrategy({
grpcConfiguration: grpcConfig,
maxIdleMillis: this.maxIdleMillis,
maxClientAgeMillis: this.maxClientAgeMillis,
...this,
grpcConfiguration,
});
}

Expand All @@ -218,39 +214,38 @@ export class StaticTransportStrategy implements TransportStrategy {

withMaxIdleMillis(maxIdleMillis: number): TransportStrategy {
return new StaticTransportStrategy({
grpcConfiguration: this.grpcConfig,
maxIdleMillis: maxIdleMillis,
maxClientAgeMillis: this.maxClientAgeMillis,
...this,
maxIdleMillis,
});
}

withMaxClientAgeMillis(maxClientAgeMillis: number): TransportStrategy {
return new StaticTransportStrategy({
grpcConfiguration: this.grpcConfig,
maxIdleMillis: this.maxIdleMillis,
maxClientAgeMillis: maxClientAgeMillis,
...this,
maxClientAgeMillis,
});
}

withClientTimeoutMillis(clientTimeout: number): StaticTransportStrategy {
return new StaticTransportStrategy({
grpcConfiguration: this.grpcConfig.withDeadlineMillis(clientTimeout),
maxIdleMillis: this.maxIdleMillis,
...this,
grpcConfiguration:
this.grpcConfiguration.withDeadlineMillis(clientTimeout),
});
}

getMaxConcurrentRequests(): number | undefined {
return this.grpcConfig.getMaxConcurrentRequests();
return this.grpcConfiguration.getMaxConcurrentRequests();
}

withMaxConcurrentRequests(
maxConcurrentRequests: number
): StaticTransportStrategy {
return new StaticTransportStrategy({
grpcConfiguration: this.grpcConfig.withMaxConcurrentRequests(
...this,
grpcConfiguration: this.grpcConfiguration.withMaxConcurrentRequests(
maxConcurrentRequests
),
maxIdleMillis: this.maxIdleMillis,
});
}
}
Loading
Loading