Skip to content
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
6 changes: 4 additions & 2 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 @@ -20,6 +20,7 @@
"integration-test-cache": "jest cache/ --maxWorkers 1 --testPathIgnorePatterns=\"abort-signal\" -- useConsistentReads",
"integration-test-control-cache-topics": "npm run integration-test-cache && npm run integration-test-topics",
"integration-test-leaderboard": "jest leaderboard/ --maxWorkers 1 -- useConsistentReads",
"integration-test-function": "jest function/ --maxWorkers 1",
"integration-test-topics": "jest topics/ --maxWorkers 1 -- useConsistentReads",
"integration-test-retry": "jest retry/ --maxWorkers 1 -- useConsistentReads",
"integration-test-consistent-reads": "jest integration --testPathIgnorePatterns=\"retry/\" --maxWorkers 1 -- useConsistentReads",
Expand Down Expand Up @@ -58,7 +59,7 @@
"uuid": "8.3.2"
},
"dependencies": {
"@gomomento/generated-types": "0.126.0",
"@gomomento/generated-types": "0.133.0",
"@gomomento/sdk-core": "file:../core",
"@grpc/grpc-js": "1.13.1",
"@types/google-protobuf": "3.15.10",
Expand Down
160 changes: 160 additions & 0 deletions packages/client-sdk-nodejs/src/config/function-configuration.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
import {MomentoLoggerFactory, TransportStrategy} from '../';
import {Middleware} from './middleware/middleware';

/**
* Configuration options for Momento FunctionClient
*
* @export
* @interface FunctionConfiguration
*/
export interface FunctionConfiguration {
/**
* @returns {MomentoLoggerFactory} the current configuration options for logging verbosity and format
*/
getLoggerFactory(): MomentoLoggerFactory;

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

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

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

/**
* @returns {boolean} Configures whether the client should return a Momento Error object or throw an exception when an
* error occurs. By default, this is set to false, and the client will return a Momento Error object on errors. Set it
* to true if you prefer for exceptions to be thrown.
*/
getThrowOnErrors(): boolean;

/**
* Copy constructor for configuring whether the client should return a Momento Error object or throw an exception when an
* error occurs. By default, this is set to false, and the client will return a Momento Error object on errors. Set it
* to true if you prefer for exceptions to be thrown.
* @param {boolean} throwOnErrors
* @returns {FunctionConfiguration} a new Configuration object with the specified throwOnErrors setting
*/
withThrowOnErrors(throwOnErrors: boolean): FunctionConfiguration;

/**
* @returns {Middleware[]} the middleware functions that will wrap each request
*/
getMiddlewares(): Middleware[];

/**
* Copy constructor for overriding Middlewares
* @param {Middleware[]} middlewares
* @returns {FunctionConfiguration} a new Configuration object with the specified Middlewares
*/
withMiddlewares(middlewares: Middleware[]): FunctionConfiguration;

/**
* Copy constructor that adds a single middleware to the existing middlewares
* @param {Middleware} middleware
* @returns {FunctionConfiguration} a new Configuration object with the specified Middleware prepended to the list of existing Middlewares
*/
addMiddleware(middleware: Middleware): FunctionConfiguration;
Comment thread
eaddingtonwhite marked this conversation as resolved.
}

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

/**
* Configures whether the client should return a Momento Error object or throw an exception when an error occurs.
*/
throwOnErrors: boolean;

/**
* Configures middleware functions that will wrap each request
*/
middlewares: Middleware[];
}

export class FunctionClientConfiguration implements FunctionConfiguration {
private readonly loggerFactory: MomentoLoggerFactory;
private readonly transportStrategy: TransportStrategy;
private readonly throwOnErrors: boolean;
private readonly middlewares: Middleware[];

constructor(props: FunctionConfigurationProps) {
this.loggerFactory = props.loggerFactory;
this.transportStrategy = props.transportStrategy;
this.throwOnErrors = props.throwOnErrors;
this.middlewares = props.middlewares;
}

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

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

withClientTimeoutMillis(clientTimeoutMillis: number): FunctionConfiguration {
return new FunctionClientConfiguration({
...this,
transportStrategy:
this.transportStrategy.withClientTimeoutMillis(clientTimeoutMillis),
});
}

withTransportStrategy(
transportStrategy: TransportStrategy
): FunctionConfiguration {
return new FunctionClientConfiguration({
...this,
transportStrategy,
});
}

getThrowOnErrors(): boolean {
return this.throwOnErrors;
}

withThrowOnErrors(throwOnErrors: boolean): FunctionConfiguration {
return new FunctionClientConfiguration({
...this,
throwOnErrors,
});
}

getMiddlewares(): Middleware[] {
return this.middlewares;
}

withMiddlewares(middlewares: Middleware[]): FunctionConfiguration {
return new FunctionClientConfiguration({
...this,
middlewares,
});
}

addMiddleware(middleware: Middleware): FunctionConfiguration {
return new FunctionClientConfiguration({
...this,
middlewares: [middleware, ...this.middlewares],
});
}
}
71 changes: 71 additions & 0 deletions packages/client-sdk-nodejs/src/config/function-configurations.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import {
FunctionClientConfiguration,
FunctionConfiguration,
} from './function-configuration';
import {MomentoLoggerFactory} from '@gomomento/sdk-core';

import {
GrpcConfiguration,
StaticGrpcConfiguration,
StaticTransportStrategy,
TransportStrategy,
} from '../';
import {DefaultMomentoLoggerFactory} from './logging/default-momento-logger';
import {Middleware} from './middleware/middleware';

// 4 minutes. We want to remain comfortably underneath the idle timeout for AWS NLB, which is 350s.
const defaultMaxIdleMillis = 4 * 60 * 1_000;
const defaultMaxSessionMemoryMb = 256;
const defaultLoggerFactory: MomentoLoggerFactory =
new DefaultMomentoLoggerFactory();
const defaultMiddlewares: Middleware[] = [];

/**
* Laptop config provides defaults suitable for a medium-to-high-latency dev environment.
* @export
* @class Laptop
*/
export class Laptop extends FunctionClientConfiguration {
/**
* 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 {FunctionConfiguration}
*/
static latest(
loggerFactory: MomentoLoggerFactory = defaultLoggerFactory
): FunctionConfiguration {
return Laptop.v1(loggerFactory);
}

/**
* Provides v1 recommended configuration for a laptop development environment. This configuration is guaranteed not
* to change in future releases of the Momento SDK.
* @param {MomentoLoggerFactory} [loggerFactory=defaultLoggerFactory]
* @returns {FunctionConfiguration}
*/
static v1(
loggerFactory: MomentoLoggerFactory = defaultLoggerFactory
): FunctionConfiguration {
// Deploying a function uploads the wasm artifact inline, so the deadline is more generous than the
// cache-data defaults.
Comment on lines +50 to +51

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

const deadlineMillis = 60000;
const grpcConfig: GrpcConfiguration = new StaticGrpcConfiguration({
deadlineMillis: deadlineMillis,
maxSessionMemoryMb: defaultMaxSessionMemoryMb,
keepAlivePermitWithoutCalls: 1,
keepAliveTimeMs: 5000,
keepAliveTimeoutMs: 1000,
});
const transportStrategy: TransportStrategy = new StaticTransportStrategy({
grpcConfiguration: grpcConfig,
maxIdleMillis: defaultMaxIdleMillis,
});
return new Laptop({
loggerFactory: loggerFactory,
transportStrategy: transportStrategy,
throwOnErrors: false,
middlewares: defaultMiddlewares,
});
}
}
13 changes: 13 additions & 0 deletions packages/client-sdk-nodejs/src/function-client-props.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import {CredentialProvider} from '@gomomento/sdk-core';
import {FunctionConfiguration} from './config/function-configuration';

export interface FunctionClientProps {
/**
* Configuration settings for the function client
*/
configuration?: FunctionConfiguration;
/**
* controls how the client will get authentication information for connecting to the Momento service
*/
credentialProvider?: CredentialProvider;
}
27 changes: 27 additions & 0 deletions packages/client-sdk-nodejs/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import * as Configurations from './config/configurations';
import * as AuthClientConfigurations from './config/auth-client-configurations';
import * as TopicConfigurations from './config/topic-configurations';
import * as LeaderboardConfigurations from './config/leaderboard-configurations';
import * as FunctionConfigurations from './config/function-configurations';
import * as BatchUtils from './batchutils/batch-functions';

import {TopicClientProps} from './topic-client-props';
Expand Down Expand Up @@ -96,6 +97,10 @@ import * as GenerateDisposableToken from '@gomomento/sdk-core/dist/src/messages/
export {leaderboard} from '@gomomento/sdk-core';
export * from '@gomomento/sdk-core/dist/src/messages/responses/leaderboard';

// FunctionClient Response Types
export {functions} from '@gomomento/sdk-core';
export * from '@gomomento/sdk-core/dist/src/messages/responses/function';

// Enums representing the different types available for each response
export * from '@gomomento/sdk-core/dist/src/messages/responses/enums';

Expand All @@ -116,6 +121,10 @@ import {
SetIfAbsentOrHashEqualOptions,
SetIfAbsentOrHashNotEqualOptions,
CacheInfo,
FunctionInfo,
FunctionVersionInfo,
IFunctionClient,
PutFunctionOptions,
CollectionTtl,
ItemType,
SortedSetOrder,
Expand All @@ -138,6 +147,7 @@ import {
BadRequestError,
PermissionError,
CacheNotFoundError,
FunctionNotFoundError,
UnknownError,
MomentoLogger,
MomentoLoggerFactory,
Expand Down Expand Up @@ -204,6 +214,12 @@ import {
LeaderboardClientConfiguration,
} from './config/leaderboard-configuration';
import {PreviewLeaderboardClient} from './preview-leaderboard-client';
import {
FunctionConfiguration,
FunctionClientConfiguration,
} from './config/function-configuration';
import {PreviewFunctionClient} from './preview-function-client';
import {FunctionClientProps} from './function-client-props';

export {
DefaultMomentoLoggerFactory,
Expand Down Expand Up @@ -462,6 +478,16 @@ export {
PreviewLeaderboardClient,
LeaderboardOrder,
ILeaderboard,
// FunctionClient
FunctionConfigurations,
FunctionConfiguration,
FunctionClientConfiguration,
PreviewFunctionClient,
FunctionClientProps,
IFunctionClient,
PutFunctionOptions,
FunctionInfo,
FunctionVersionInfo,
// Errors
MomentoErrorCode,
SdkError,
Expand All @@ -478,6 +504,7 @@ export {
BadRequestError,
PermissionError,
CacheNotFoundError,
FunctionNotFoundError,
UnknownError,
// Logging
MomentoLogger,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import {FunctionClientProps} from '../function-client-props';
import {FunctionConfiguration} from '../config/function-configuration';
import {CredentialProvider} from '@gomomento/sdk-core';

export interface FunctionClientAllProps extends FunctionClientProps {
configuration: FunctionConfiguration;
credentialProvider: CredentialProvider;
}
Loading
Loading