Skip to content

Commit

Permalink
chore: add examples for new JS config options, other minor cleanups
Browse files Browse the repository at this point in the history
This commit adds a "config-and-error-handling" page for the node.js
SDK, and in there we show some examples of how to use the succinct
version of the constructor without specifying an explicit config.
We also show an example of using the new `WithThrowOnErrors` configuration
option.

Also did a few other cleanups while I was in here, including:

* add missing example code for Lambda configuration on Configurations page.
* Remove all the "COMING SOON"s
* Fixed the order of the `TopicClient` example on the topics API reference page.
* Removed some redundant copies of stuff like 'observability' that was duplicated
  between "Topics" and "Cache" sections; but then gave up on this in favor of
  moving the "SDKs" stuff up to the top level in a subsequent PR after discussion
  with Allen.
  • Loading branch information
cprice404 committed Jan 17, 2024
1 parent ecf231b commit 8f62f1b
Show file tree
Hide file tree
Showing 38 changed files with 72 additions and 223 deletions.
2 changes: 1 addition & 1 deletion docs/cache/develop/basics/client-configuration-objects.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,4 @@ Here are some of the pre-built configurations that you might be interested in.

`Configurations.Lambda` is a configuration that is available in some SDKs, and is optimized for the AWS Lambda environment. It has configuration settings designed to pre-warm the client on Lambda function cold starts, and to ensure the connection is re-established proactively if a Lambda function remains idle long enough for the connection to time out.

<SdkExampleTabs snippetId={'API_ConfigurationLambda'} />
<SdkExampleTabs snippetId={'API_ConfigurationLambdaLatest'} />
6 changes: 0 additions & 6 deletions docs/cache/develop/sdks/dart/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,3 @@ The Momento Dart SDK and source code are available via GitHub: [momentohq/client

- [Dart SDK cheat sheet](./cheat-sheet.mdx)
- [Dart SDK examples](https://github.com/momentohq/client-sdk-dart/tree/main/example): working example projects that illustrate how to use the Dart SDK
- COMING SOON: Observability: Logging and client-side metrics with the Dart SDK
- COMING SOON: Taking your code to prod: configuration and error handling in the Dart SDK

## Integrations

COMING SOON
1 change: 0 additions & 1 deletion docs/cache/develop/sdks/dotnet/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ The source code can be found on GitHub: [momentohq/client-sdk-dotnet](https://gi
- [.NET SDK Cheat Sheet](./cheat-sheet.mdx)
- [.NET SDK Examples](https://github.com/momentohq/client-sdk-dotnet/blob/main/examples/README.md): working example projects that illustrate how to use the .NET SDK
- [.NET SDK Observability](./observability.mdx): Logging and Client-side Metrics with the .NET SDK
- COMING SOON: Taking your code to prod: Configuration and Error handling in the .NET SDK

## Integrations

Expand Down
6 changes: 0 additions & 6 deletions docs/cache/develop/sdks/elixir/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,3 @@ The source code can be found on GitHub: [momentohq/client-sdk-elixir](https://gi

- [Elixir SDK cheat sheet](./cheat-sheet.mdx)
- [Elixir SDK examples](https://github.com/momentohq/client-sdk-elixir/blob/main/examples/README.md): working example projects that illustrate how to use the Elixir SDK
- COMING SOON: Observability: Logging and client-side metrics with the Elixir SDK
- COMING SOON: Taking your code to prod: configuration and error handling in the Elixir SDK

## Integrations

COMING SOON
2 changes: 0 additions & 2 deletions docs/cache/develop/sdks/go/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ The source code can be found on GitHub: [momentohq/client-sdk-go](https://github

- [Go SDK Cheat Sheet](./cheat-sheet.mdx)
- [Go SDK Examples](https://github.com/momentohq/client-sdk-go/blob/main/examples/README.md): working example projects that illustrate how to use the Go SDK
- COMING SOON: Observability: Logging and Client-side Metrics with the Go SDK
- COMING SOON: Taking your code to prod: Configuration and Error handling in the Go SDK

## Integrations

Expand Down
6 changes: 0 additions & 6 deletions docs/cache/develop/sdks/java/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,3 @@ The source code can be found on GitHub: [momentohq/client-sdk-java](https://gith

- [Java SDK Cheat Sheet](./cheat-sheet.mdx)
- [Java SDK Examples](https://github.com/momentohq/client-sdk-java/blob/main/examples/README.md): working example projects that illustrate how to use the Java SDK
- COMING SOON: Observability: Logging and Client-side Metrics with the Java SDK
- COMING SOON: Taking your code to prod: Configuration and Error handling in the Java SDK

## Integrations

COMING SOON
6 changes: 0 additions & 6 deletions docs/cache/develop/sdks/kotlin/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,3 @@ The source code can be found on GitHub: [momentohq/client-sdk-kotlin](https://gi

- [Kotlin SDK Cheat Sheet](./cheat-sheet.mdx)
- [Kotlin SDK Examples](https://github.com/momentohq/client-sdk-kotlin/blob/main/examples/README.md): working example projects that illustrate how to use the Kotlin SDK
- COMING SOON: Observability: Logging and Client-side Metrics with the Kotlin SDK
- COMING SOON: Taking your code to prod: Configuration and Error handling in the Kotlin SDK

## Integrations

COMING SOON
53 changes: 53 additions & 0 deletions docs/cache/develop/sdks/nodejs/config-and-error-handling.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
---
sidebar_position: 2
sidebar_label: Config and Error Handling
title: Observability for TypeScript and Node.js
description: Instrument your Momento-enabled Node.js code with Logs, Metrics, and Traces
---

import { SdkExampleCodeBlock } from "@site/src/components/SdkExampleCodeBlock";
// This import is necessary even though it looks like it's un-used; The inject-example-code-snippet
// plugin will transform instances of SdkExampleCodeBlock to SdkExampleCodeBlockImpl
import { SdkExampleCodeBlockImpl } from "@site/src/components/SdkExampleCodeBlockImpl";

# Configuration and Error Handling in the Momento node.js SDK

## Configuration

The code below illustrates the simplest way to construct a `CacheClient`:

<SdkExampleCodeBlock language={'javascript'} snippetId={'configuration_ConstructWithNoConfig'} />

However, you may pass in a `Configuration` object to customize the behavior.

Momento provides several pre-built configurations in the `Configurations` module, such as `InRegion` (which is configured
with timeouts and connection counts that are appropriate for server-side connectivity from within the same AWS region),
and `Lambda` (which is tuned for use in AWS Lambda environments). Here is how you can specify the `Lambda` configuration:

<SdkExampleCodeBlock language={'javascript'} snippetId={'configuration_ConstructWithLambdaConfig'} />

If you omit the configuration, Momento will use the `Laptop` configuration by default. This configuration has relaxed
timeouts, suitable for development or in high-latency environments. (It is not recommended for production, server-side use.)

For more information about `Configuration` objects see [SDK Configuration Objects](/cache/develop/basics/client-configuration-objects.md).

## Error Handling

By default, `CacheClient` errors are surfaced to developers as part of the return values of the calls, as opposed to throwing
exceptions. This makes errors more visible when you're writing your code, and allows your IDE to be more helpful in ensuring
you've handled the errors you care about.

Here's an example of how to check for errors on a `get` call:

<SdkExampleCodeBlock language={'javascript'} snippetId={'configuration_ErrorHandlingHitMiss'} />

However, if you prefer for exceptions to be thrown, you can configure the `CacheClient` to do so:

<SdkExampleCodeBlock language={'javascript'} snippetId={'configuration_ConstructWithThrowOnErrorsConfig'} />

With this configuration setting, any errors that occur will result in an instance of `SdkError` being thrown. You may
catch it and use its `.errorCode()` method to determine the specific error that occurred:

<SdkExampleCodeBlock language={'javascript'} snippetId={'configuration_ErrorHandlingExceptionErrorCode'} />

For more information about error handling in Momento see [SDK Error Handling](/cache/develop/basics/error-handling-production-readiness.md).
6 changes: 3 additions & 3 deletions docs/cache/develop/sdks/nodejs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ sidebar_label: Node.js
description: Information about the Momento Node.js SDK
---

# Momento Node.js SDK
# Momento Node.js SDK - Cache Client

The Momento Node.js SDK is available via the npm package [`@gomomento/sdk`](https://www.npmjs.com/package/@gomomento/sdk).

Expand All @@ -21,11 +21,11 @@ The source code can be found on GitHub: [momentohq/client-sdk-javascript](https:

- [Node.js SDK Cache Cheat Sheet](./cheat-sheet.mdx)
- [Node.js SDK Examples](https://github.com/momentohq/client-sdk-javascript/blob/main/examples/nodejs/README.md): working example projects that illustrate how to use the Node.js SDK
- [Node.js Token Vending Machine](https://github.com/momentohq/client-sdk-javascript/tree/main/examples/nodejs/token-vending-machine): provides temporary, restricted scope Momento Auth tokens that can be used by browsers running apps written against the [Momento Web SDK](https://github.com/momentohq/client-sdk-javascript/tree/main/packages/client-sdk-web).
- [Node.js SDK Configuration and Error Handling](./config-and-error-handling.mdx): Taking your code to production
- [Node.js SDK Observability](./observability.mdx): Logging and Client-side Metrics with the Node.js SDK
- COMING SOON: Taking your code to prod: Configuration and Error handling in the Node.js SDK

## Integrations

- [Node.js Token Vending Machine](https://github.com/momentohq/client-sdk-javascript/tree/main/examples/nodejs/token-vending-machine): provides temporary, restricted scope Momento Auth tokens that can be used by browsers running apps written against the [Momento Web SDK](https://github.com/momentohq/client-sdk-javascript/tree/main/packages/client-sdk-web).
- [Redis Compatibility Client for `@redis/client`](https://github.com/momentohq/momento-node-redis-client) - a drop-in replacement that allows you to use Momento Cache with your existing `@redis/client` code! See also our [Redis Client Compatibility](./../../integrations/redis-client-compatibility.md) page.
- [Redis Compatibility Client for `ioredis`](https://github.com/momentohq/momento-node-ioredis-client) - a drop-in replacement that allows you to use Momento Cache with your existing `ioredis` code! See also our [Redis Client Compatibility](./../../integrations/redis-client-compatibility.md) page.
3 changes: 1 addition & 2 deletions docs/cache/develop/sdks/php/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,10 @@ The source code can be found on GitHub: [momentohq/client-sdk-php](https://githu

- [PHP SDK cheat sheet](./cheat-sheet.md)
- [PHP SDK examples](https://github.com/momentohq/client-sdk-php/blob/main/examples/README.md): working example projects that illustrate how to use the PHP SDK
- COMING SOON: Observability: logging and client-side metrics with the PHP SDK
- COMING SOON: Taking your code to prod: configuration and error handling in the PHP SDK

## Integrations

- [Drupal Cache Backend](../../integrations/drupal-integration.md)
- [Laravel Cache](https://github.com/momentohq/laravel-cache) - a drop-in replacement that allows you to use Momento Cache with your existing Laravel application! See also our [Laravel Integration](./../../integrations/momento-cache-laravel-php.md) page.
- [Laravel Example App](https://github.com/momentohq/laravel-example) - a fully operational Laravel example application that uses the Momento Laravel cache integration.
- [PSR-16 Cache API](https://github.com/momentohq/client-sdk-php/blob/main/README-PSR16.md) - an implementation of the PHP PSR-16 cache specification backed by Momento Cache.
2 changes: 0 additions & 2 deletions docs/cache/develop/sdks/python/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ The source code can be found on GitHub: [momentohq/client-sdk-python](https://gi

- [Python SDK Cheat Sheet](./cheat-sheet.md)
- [Python SDK Examples](https://github.com/momentohq/client-sdk-python/blob/main/examples/README.md): working example projects that illustrate how to use the Python SDK
- COMING SOON: Observability: Logging and Client-side Metrics with the Python SDK
- COMING SOON: Taking your code to prod: Configuration and Error handling in the Python SDK

## Integrations

Expand Down
7 changes: 0 additions & 7 deletions docs/cache/develop/sdks/ruby/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,4 @@ The source code can be found on GitHub: [momentohq/client-sdk-ruby](https://gith

## Resources

- COMING SOON: Ruby SDK Cheat Sheet
- [Ruby SDK Examples](https://github.com/momentohq/client-sdk-ruby/blob/main/examples/README.md): working example projects that illustrate how to use the Ruby SDK
- COMING SOON: Observability: Logging and Client-side Metrics with the Ruby SDK
- COMING SOON: Taking your code to prod: Configuration and Error handling in the Ruby SDK

## Integrations

COMING SOON
7 changes: 0 additions & 7 deletions docs/cache/develop/sdks/rust/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,4 @@ The source code can be found on github: [momentohq/client-sdk-rust](https://gith

## Resources

- COMING SOON: Rust SDK Cheat Sheet
- [Rust SDK Examples](https://github.com/momentohq/client-sdk-rust/blob/main/example/README.md): working example projects that illustrate how to use the Rust SDK
- COMING SOON: Observability: Logging and Client-side Metrics with the Rust SDK
- COMING SOON: Taking your code to prod: Configuration and Error handling in the Rust SDK

## Integrations

COMING SOON
6 changes: 0 additions & 6 deletions docs/cache/develop/sdks/swift/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,3 @@ The Momento Swift SDK and source code are available via GitHub: [momentohq/clien

- [Swift SDK cheat sheet](./cheat-sheet.mdx)
- [Swift SDK examples](https://github.com/momentohq/client-sdk-swift/tree/main/Examples): working example projects that illustrate how to use the Swift SDK
- COMING SOON: Observability: Logging and client-side metrics with the Swift SDK
- COMING SOON: Taking your code to prod: configuration and error handling in the Swift SDK

## Integrations

COMING SOON
1 change: 0 additions & 1 deletion docs/cache/develop/sdks/web/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ The source code can be found on GitHub: [momentohq/client-sdk-javascript](https:
- [Chat app: Next.js](https://github.com/momentohq/client-sdk-javascript/tree/main/examples/web/nextjs-chat): a dynamic app that allows users to chat in their browser by entering a cache and topic name. The application vends low scope, short-lived auth tokens to the browser which uses them to subscribe to the topic.
- [Chat app: Vite](https://github.com/momentohq/client-sdk-javascript/tree/main/examples/web/vite-chat-app): a static version of the chat app that requires a separate API (such as our [Node.js token vending machine](https://github.com/momentohq/client-sdk-javascript/tree/main/examples/nodejs/token-vending-machine)) to provide auth tokens to browsers.
- [Web SDK Examples](https://github.com/momentohq/client-sdk-javascript/blob/main/examples/web/README.md): working example projects that illustrate how to use the web SDK
- COMING SOON: Taking your code to prod: configuration and error handling in the web SDK

## Momento web SDK and Momento Topics

Expand Down
21 changes: 6 additions & 15 deletions docs/topics/develop/api-reference/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ import { SdkExampleTabsImpl } from "@site/src/components/SdkExampleTabsImpl";
# Using the Momento Topics API
Momento Topics is a messaging pattern enabling real-time communication between parts of a distributed application. It enables you to publish (produce) values to a topic and subscribe (consume) from a topic. This page details the Momento API methods for interacting with Momento Topics.

## TopicClient

Momento Topics API calls are made using a `TopicClient` object.

<SdkExampleTabs snippetId={'API_InstantiateTopicClient'} />

## Topics methods

### Subscribe
Expand Down Expand Up @@ -47,15 +53,6 @@ Publishes a message to a topic.
| topicName | String | Name of the topic to publish the value to. |
| value | String / bytes | Value to publish to the topic. |

<Tabs>
<TabItem value="golang" label="Go" default>
This is <a href="https://github.com/momentohq/client-sdk-go/blob/main/examples/pubsub-example/main.go#L95">example code</a>.
</TabItem>
<TabItem value="nodejs" label="Node.js" default>
Coming soon.
</TabItem>
</Tabs>

<details>
<summary>Method response object</summary>

Expand All @@ -68,12 +65,6 @@ See [response objects](./response-objects.md) for specific information.

<SdkExampleTabs snippetId={'API_TopicPublish'} />

## TopicClient

Instead of the CacheClient, as used in most Momento Cache API calls, for Topics you use a TopicClient object.

<SdkExampleTabs snippetId={'API_InstantiateTopicClient'} />

## Example apps using Momento Topics APIs

A growing list of example apps using the Momento Topics.
Expand Down
6 changes: 0 additions & 6 deletions docs/topics/develop/sdks/dart/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,3 @@ The Momento Dart SDK and source code are available via GitHub: [momentohq/client

- [Dart SDK cheat sheet](./cheat-sheet.mdx)
- [Dart SDK examples](https://github.com/momentohq/client-sdk-dart/tree/main/example): working example projects that illustrate how to use the Dart SDK
- COMING SOON: Observability: Logging and client-side metrics with the Dart SDK
- COMING SOON: Taking your code to prod: configuration and error handling in the Dart SDK

## Integrations

COMING SOON
3 changes: 0 additions & 3 deletions docs/topics/develop/sdks/dotnet/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@ The source code can be found on GitHub: [momentohq/client-sdk-dotnet](https://gi

## Resources

- COMING SOON: .NET SDK Cheat Sheet
- [.NET SDK Examples](https://github.com/momentohq/client-sdk-dotnet/blob/main/examples/README.md): working example projects that illustrate how to use the .NET SDK
- COMING SOON: Observability: Logging and Client-side Metrics with the .NET SDK
- COMING SOON: Taking your code to prod: Configuration and Error handling in the .NET SDK

## Integrations

Expand Down
6 changes: 0 additions & 6 deletions docs/topics/develop/sdks/elixir/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,3 @@ The source code can be found on GitHub: [momentohq/client-sdk-elixir](https://gi
## Resources

- [Elixir SDK examples](https://github.com/momentohq/client-sdk-elixir/blob/main/examples/README.md): working example projects that illustrate how to use the Elixir SDK
- COMING SOON: Observability: Logging and client-side metrics with the Elixir SDK
- COMING SOON: Taking your code to prod: configuration and error handling in the Elixir SDK

## Integrations

COMING SOON
2 changes: 0 additions & 2 deletions docs/topics/develop/sdks/go/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,3 @@ The source code can be found on GitHub: [momentohq/client-sdk-go](https://github
## Resources

- [Go SDK Examples](https://github.com/momentohq/client-sdk-go/blob/main/examples/README.md): working example projects that illustrate how to use the Go SDK
- COMING SOON: Observability: Logging and Client-side Metrics with the Go SDK
- COMING SOON: Taking your code to prod: Configuration and Error handling in the Go SDK
6 changes: 0 additions & 6 deletions docs/topics/develop/sdks/java/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,3 @@ The source code can be found on GitHub: [momentohq/client-sdk-java](https://gith
## Resources

- [Java SDK Examples](https://github.com/momentohq/client-sdk-java/blob/main/examples/README.md): working example projects that illustrate how to use the Java SDK
- COMING SOON: Observability: Logging and Client-side Metrics with the Java SDK
- COMING SOON: Taking your code to prod: Configuration and Error handling in the Java SDK

## Integrations

COMING SOON
6 changes: 0 additions & 6 deletions docs/topics/develop/sdks/kotlin/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,3 @@ The source code can be found on GitHub: [momentohq/client-sdk-kotlin](https://gi
## Resources

- [Kotlin SDK Examples](https://github.com/momentohq/client-sdk-kotlin/blob/main/examples/README.md): working example projects that illustrate how to use the Kotlin SDK
- COMING SOON: Observability: Logging and Client-side Metrics with the Kotlin SDK
- COMING SOON: Taking your code to prod: Configuration and Error handling in the Kotlin SDK

## Integrations

COMING SOON
Binary file not shown.
Binary file not shown.
Binary file not shown.
13 changes: 7 additions & 6 deletions docs/topics/develop/sdks/nodejs/index.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
---
sidebar_position: 1
title: Momento Topics Node.js SDK
title: Momento Node.js SDK
pagination_prev: null
sidebar_label: Node.js
description: Information about the Momento Node.js SDK
---

# Momento Topics Node.js SDK
# Momento Node.js SDK - Topic Client

The Momento Node.js SDK is available via the npm package [`@gomomento/sdk`](https://www.npmjs.com/package/@gomomento/sdk).

Expand All @@ -15,12 +15,13 @@ The source code can be found on GitHub: [momentohq/client-sdk-javascript](https:
## Requirements

- Node version [14 or higher](https://nodejs.org/en/download/) is required.
- A Momento API key is required; you can get one from the [Momento Web Console](https://console.gomomento.com/).
- A Momento API Key is required; you can get one from the [Momento Web Console](https://console.gomomento.com/).

## Resources

- [Node.js SDK cheat sheet](./cheat-sheet.mdx)
- [Node.js SDK Topics Cheat Sheet](./cheat-sheet.mdx)
- [Node.js SDK Examples](https://github.com/momentohq/client-sdk-javascript/blob/main/examples/nodejs/README.md): working example projects that illustrate how to use the Node.js SDK

## Integrations

- [Node.js Token Vending Machine](https://github.com/momentohq/client-sdk-javascript/tree/main/examples/nodejs/token-vending-machine): provides temporary, restricted scope Momento Auth tokens that can be used by browsers running apps written against the [Momento Web SDK](https://github.com/momentohq/client-sdk-javascript/tree/main/packages/client-sdk-web).
- [Node.js SDK Observability](./observability.mdx): Logging and Client-side Metrics with the Node.js SDK
- COMING SOON: Taking your code to prod: Configuration and Error handling in the Node.js SDK
Loading

0 comments on commit 8f62f1b

Please sign in to comment.