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

feat: add new storage clients to nodejs/web sdks #1318

Merged
merged 15 commits into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
Changes from 14 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
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const deleteCacheIfExists = async (
) => {
const deleteResponse = await momento.deleteCache(cacheName);
if (deleteResponse instanceof DeleteCache.Error) {
if (deleteResponse.errorCode() !== MomentoErrorCode.NOT_FOUND_ERROR) {
if (deleteResponse.errorCode() !== MomentoErrorCode.CACHE_NOT_FOUND_ERROR) {
throw deleteResponse.innerException();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const deleteCacheIfExists = async (
) => {
const deleteResponse = await momento.deleteCache(cacheName);
if (deleteResponse instanceof DeleteCache.Error) {
if (deleteResponse.errorCode() !== MomentoErrorCode.NOT_FOUND_ERROR) {
if (deleteResponse.errorCode() !== MomentoErrorCode.CACHE_NOT_FOUND_ERROR) {
throw deleteResponse.innerException();
}
}
Expand Down
58 changes: 38 additions & 20 deletions packages/client-sdk-nodejs/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion packages/client-sdk-nodejs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"prebuild": "eslint . --ext .ts",
"test": "jest --testPathIgnorePatterns auth-client.test.ts --maxWorkers 1",
"integration-test-auth": "jest auth-client.test.ts --maxWorkers 1",
"integration-test-store": "jest storage.test.ts --maxWorkers 1",
"unit-test": "jest unit",
"integration-test-leaderboard": "jest leaderboard --maxWorkers 1",
"integration-test": "jest integration --testPathIgnorePatterns \"auth-client.test.ts|leaderboard.test.ts\" --maxWorkers 1",
Expand Down Expand Up @@ -52,7 +53,7 @@
"uuid": "8.3.2"
},
"dependencies": {
"@gomomento/generated-types": "0.112.1",
"@gomomento/generated-types": "0.113.0",
"@gomomento/sdk-core": "file:../core",
"@grpc/grpc-js": "1.10.9",
"@types/google-protobuf": "3.15.10",
Expand Down
82 changes: 82 additions & 0 deletions packages/client-sdk-nodejs/src/config/storage-configuration.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import {MomentoLoggerFactory} from '../';
import {StorageTransportStrategy} from './transport/storage';

/**
* Configuration options for Momento StorageClient
*
* @export
* @interface StorageConfiguration
*/
export interface StorageConfiguration {
rishtigupta marked this conversation as resolved.
Show resolved Hide resolved
/**
* @returns {MomentoLoggerFactory} the current configuration options for logging verbosity and format
*/
getLoggerFactory(): MomentoLoggerFactory;

/**
* @returns {StorageTransportStrategy} the current configuration options for wire interactions with the Momento service
*/
getTransportStrategy(): StorageTransportStrategy;

/**
* Convenience copy constructor that updates the client-side timeout setting in the TransportStrategy
* @param {number} clientTimeoutMillis
* @returns {StorageConfiguration} a new Configuration object with its TransportStrategy updated to use the specified client timeout
*/
withClientTimeoutMillis(clientTimeoutMillis: number): StorageConfiguration;

/**
* Copy constructor for overriding TransportStrategy
* @param {StorageTransportStrategy} transportStrategy
* @returns {Configuration} a new Configuration object with the specified TransportStrategy
*/
withTransportStrategy(
transportStrategy: StorageTransportStrategy
): StorageConfiguration;
}

export interface StorageConfigurationProps {
/**
* Configures logging verbosity and format
*/
loggerFactory: MomentoLoggerFactory;
/**
* Configures low-level options for network interactions with the Momento service
*/
transportStrategy: StorageTransportStrategy;
}

export class StorageClientConfiguration implements StorageConfiguration {
private readonly loggerFactory: MomentoLoggerFactory;
private readonly transportStrategy: StorageTransportStrategy;

constructor(props: StorageConfigurationProps) {
this.loggerFactory = props.loggerFactory;
this.transportStrategy = props.transportStrategy;
}

getLoggerFactory(): MomentoLoggerFactory {
return this.loggerFactory;
}

getTransportStrategy(): StorageTransportStrategy {
return this.transportStrategy;
}

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

withTransportStrategy(
transportStrategy: StorageTransportStrategy
): StorageConfiguration {
return new StorageClientConfiguration({
loggerFactory: this.loggerFactory,
transportStrategy: transportStrategy,
});
}
}
39 changes: 39 additions & 0 deletions packages/client-sdk-nodejs/src/config/storage-configurations.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import {MomentoLoggerFactory} from '@gomomento/sdk-core';
import {DefaultMomentoLoggerFactory} from './logging/default-momento-logger';
import {
StorageClientConfiguration,
StorageConfiguration,
} from './storage-configuration';
import {
StaticStorageGrpcConfiguration,
StaticStorageTransportStrategy,
} from './transport/storage';

const defaultLoggerFactory: MomentoLoggerFactory =
new DefaultMomentoLoggerFactory();

/**
* Laptop config provides defaults suitable for a medium-to-high-latency dev environment.
* @export
* @class Laptop
*/
export class Laptop extends StorageClientConfiguration {
/**
* Provides the latest recommended configuration for a laptop development environment. NOTE: this configuration may
* change in future releases to take advantage of improvements we identify for default configurations.
* @param {MomentoLoggerFactory} [loggerFactory=defaultLoggerFactory]
* @returns {StorageConfiguration}
*/
static latest(
loggerFactory: MomentoLoggerFactory = defaultLoggerFactory
): StorageConfiguration {
return new StorageClientConfiguration({
loggerFactory: loggerFactory,
transportStrategy: new StaticStorageTransportStrategy({
grpcConfiguration: new StaticStorageGrpcConfiguration({
deadlineMillis: 5000,
}),
}),
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
export interface StorageGrpcConfigurationProps {
/**
* number of milliseconds the client is willing to wait for an RPC to complete before it is terminated
* with a DeadlineExceeded error.
*/
deadlineMillis: number;
}

/**
* Encapsulates gRPC configuration tunables.
* @export
* @interface StorageGrpcConfiguration
*/
export interface StorageGrpcConfiguration {
/**
* @returns {number} number of milliseconds the client is willing to wait for an RPC to complete before it is terminated
* with a DeadlineExceeded error.
*/
getDeadlineMillis(): number;

/**
* Copy constructor for overriding the client-side deadline
* @param {number} deadlineMillis
* @returns {StorageGrpcConfiguration} a new StorageGrpcConfiguration with the specified client-side deadline
*/
withDeadlineMillis(deadlineMillis: number): StorageGrpcConfiguration;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './grpc-configuration';
export * from './transport-strategy';
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import {
StorageGrpcConfiguration,
StorageGrpcConfigurationProps,
} from './grpc-configuration';

export interface StorageTransportStrategy {
/**
* Configures the low-level gRPC settings for the Momento client's communication
* with the Momento server.
* @returns {StorageGrpcConfiguration}
*/
getGrpcConfig(): StorageGrpcConfiguration;

/**
* Copy constructor for overriding the gRPC configuration
* @param {TopicGrpcConfiguration} grpcConfig
* @returns {TopicTransportStrategy} a new StorageTransportStrategy with the specified gRPC config.
*/
withGrpcConfig(
grpcConfig: StorageGrpcConfiguration
): StorageTransportStrategy;

/**
* Copy constructor to update the client-side timeout
* @param {number} clientTimeoutMillis
* @returns {StorageTransportStrategy} a new StorageTransportStrategy with the specified client timeout
*/
withClientTimeoutMillis(
clientTimeoutMillis: number
): StorageTransportStrategy;
}

export interface StorageTransportStrategyProps {
/**
* low-level gRPC settings for communication with the Momento server
*/
grpcConfiguration: StorageGrpcConfiguration;
}

export class StaticStorageGrpcConfiguration
implements StorageGrpcConfiguration
{
private readonly deadlineMillis: number;

constructor(props: StorageGrpcConfigurationProps) {
this.deadlineMillis = props.deadlineMillis;
}

getDeadlineMillis(): number {
return this.deadlineMillis;
}

withDeadlineMillis(deadlineMillis: number): StorageGrpcConfiguration {
return new StaticStorageGrpcConfiguration({
deadlineMillis: deadlineMillis,
});
}
}

export class StaticStorageTransportStrategy
implements StorageTransportStrategy
{
private readonly grpcConfig: StorageGrpcConfiguration;

constructor(props: StorageTransportStrategyProps) {
this.grpcConfig = props.grpcConfiguration;
}

getGrpcConfig(): StorageGrpcConfiguration {
return this.grpcConfig;
}

withGrpcConfig(
grpcConfig: StorageGrpcConfiguration
): StorageTransportStrategy {
return new StaticStorageTransportStrategy({
grpcConfiguration: grpcConfig,
});
}

withClientTimeoutMillis(
clientTimeoutMillis: number
): StorageTransportStrategy {
return new StaticStorageTransportStrategy({
grpcConfiguration:
this.grpcConfig.withDeadlineMillis(clientTimeoutMillis),
});
}
}
Loading
Loading