-
Notifications
You must be signed in to change notification settings - Fork 23
feat: add Function (FunctionRegistry) client #1618
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
2b439c7
feat: add Function (FunctionRegistry) client
eaddingtonwhite 40c5471
fix: validate function name/id + wasm, fail on malformed version rows
eaddingtonwhite 3e407cb
fix: import public sdk-core types + correct addMiddleware doc
eaddingtonwhite 4ba118d
feat: surface current_version + last_updated_at; return full Function…
eaddingtonwhite dc17806
fix: move IFunctionClient to public clients dir + correct config JSDoc
eaddingtonwhite 5af56e5
feat: surface FunctionNotFoundError for missing functions
eaddingtonwhite 0aca283
docs: FunctionInfo is returned by putFunction too
eaddingtonwhite File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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
160 changes: 160 additions & 0 deletions
160
packages/client-sdk-nodejs/src/config/function-configuration.ts
This file contains hidden or 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,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; | ||
| } | ||
|
|
||
| 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
71
packages/client-sdk-nodejs/src/config/function-configurations.ts
This file contains hidden or 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,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
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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, | ||
| }); | ||
| } | ||
| } | ||
This file contains hidden or 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,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; | ||
| } |
This file contains hidden or 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
8 changes: 8 additions & 0 deletions
8
packages/client-sdk-nodejs/src/internal/function-client-all-props.ts
This file contains hidden or 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,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; | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.