Skip to content

Commit

Permalink
Add info about TypeScript support (#2247)
Browse files Browse the repository at this point in the history
  • Loading branch information
EugeniyBurmistrov authored Apr 4, 2022
1 parent 8ea99ce commit 66493d5
Show file tree
Hide file tree
Showing 20 changed files with 434 additions and 48 deletions.
11 changes: 10 additions & 1 deletion docs/api/aggregate/command-handler.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@ id: command-handler
title: Command Handler
---

:::info TypeScript Support

Command handlers are grouped into an Aggregate container object that has an associated TypeScript type:

- Type Name - `Aggregate`
- Package - `@resolve-js/core`

:::

A command handler function has the following structure:

```js
Expand Down Expand Up @@ -30,7 +39,7 @@ The `context` argument is an object with the following fields:
| Field Name | Description |
| ---------------- | ---------------------------------------------------------------------------------------------------------- |
| jwt | The JSON Web Token attached to the request. |
| aggregateVersion | The aggregate version that is a number incremented for each consequent event with the current aggregateId. |
| aggregateVersion | The aggregate version that is a number incremented for each subsequent event with the current aggregateId. |
| encrypt | The user-defined [encrypt](../../encryption.md) function. |
| decrypt | The user-defined [decrypt](../../encryption.md) function. |

Expand Down
9 changes: 9 additions & 0 deletions docs/api/aggregate/projection.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@ id: projection
title: Projection
---

:::info TypeScript Support

An aggregate projection object has an associated TypeScript type:

- Type Name - `AggregateProjection`
- Package - `@resolve-js/core`

:::

An aggregate projection is an object of the following structure:

```js
Expand Down
18 changes: 18 additions & 0 deletions docs/api/api-handler/api-handler.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ The handler receives a request and response objects. See the sections below for

### Request

:::info TypeScript Support

A request object has an associated TypeScript type:

- Type Name - `ResolveRequest`
- Package - `@resolve-js/runtime-base`

:::

The request object exposes the following fields:

| Field | Description |
Expand All @@ -30,6 +39,15 @@ The request object exposes the following fields:

### Response

:::info TypeScript Support

A response object has an associated TypeScript type:

- Type Name - `ResolveResponse`
- Package - `@resolve-js/runtime-base`

:::

The request object exposes the following functions:

| Function | Description |
Expand Down
9 changes: 9 additions & 0 deletions docs/api/api-handler/resolve-context.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@ title: ReSolve Context
description: The 'resolve' context object is available to an API handler function through its request (req) argument. This object implements a communication layer between an API handler and the reSolve framework.
---

:::info TypeScript Support

A reSolve context object has an associated TypeScript type:

- Type Name - `UserBackendResolve`
- Package - `@resolve-js/runtime-base`

:::

The `resolve` context object is available to an [API handler](api-handler.md) function through its [request (`req`)](api-handler.md#request) argument. This object implements a communication layer between an API handler and the reSolve framework.

The `resolve` context object exposes the following API:
Expand Down
18 changes: 18 additions & 0 deletions docs/api/command.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@ title: Command

## Command Object

:::info TypeScript Support

A command object has an associated TypeScript type:

- Type Name - `Command`
- Package - `@resolve-js/core`

:::

A command is an object of the following structure:

<!-- prettier-ignore-start -->
Expand All @@ -23,6 +32,15 @@ A command is an object of the following structure:

## Command Result Object

:::info TypeScript Support

A command result object has an associated TypeScript type:

- Type Name - `CommandResult`
- Package - `@resolve-js/core`

:::

A command result object has the following structure:

<!-- prettier-ignore-start -->
Expand Down
13 changes: 11 additions & 2 deletions docs/api/event.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@ id: event
title: Event
---

:::info TypeScript Support

An event object has an associated TypeScript type:

- Type Name - `Event`
- Package - `@resolve-js/core`

:::

An event is an object of the following structure:

<!-- prettier-ignore-start -->
Expand All @@ -12,8 +21,8 @@ An event is an object of the following structure:
type, // A string that contains the command type name.
timestamp, // A number type field that stores the point in time when the event was produced.
aggregateId, // A string that uniquely identifies an aggregate instance.
aggregateVersion, // A number that is incremented for each consequent event with the current aggregateId.
payload // An object of arbitrary structure that contains data attached to the event. (optional)
aggregateVersion, // A number that is incremented for each subsequent event with the current aggregateId.
payload // Optional. An object of arbitrary structure that contains data attached to the event.
}
```

Expand Down
27 changes: 27 additions & 0 deletions docs/api/middleware.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@ description: This document describes API used by Aggregate and Read Model middle

## Command Middleware

:::info TypeScript Support

A command middleware function has an associated TypeScript type:

- Type Name - `CommandMiddleware`
- Package - `@resolve-js/core`

:::

A command middleware function has the following structure:

```js
Expand Down Expand Up @@ -43,6 +52,15 @@ Both `req` and `res` fields are included only if the client sends the command. I

## Read Model Projection Middleware

:::info TypeScript Support

A read model projection middleware function has an associated TypeScript type:

- Type Name - `ReadModelProjectionMiddleware`
- Package - `@resolve-js/core`

:::

A read model projection middleware function has the following structure:

```js
Expand Down Expand Up @@ -78,6 +96,15 @@ A projection middleware handler's `middlewareContext` argument is an object with

## Read Model Resolver Middleware

:::info TypeScript Support

A read model resolver middleware function has an associated TypeScript type:

- Type Name - `ReadModelResolverMiddleware`
- Package - `@resolve-js/core`

:::

A read model resolver middleware function has the following structure:

```js
Expand Down
18 changes: 18 additions & 0 deletions docs/api/monitoring/metric.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@ title: Monitoring Metric

## Metric Object

:::info TypeScript Support

A monitoring metric object has an associated TypeScript type:

- Type Name - `MonitoringMetric`
- Package - `@resolve-js/core`

:::

A monitoring metric object contains information about a particular metric collected during application execution. Metrics are stored and processed internally by monitoring adapters and can be accessed through a monitoring object's [`getMetrics`](monitoring.md#getmetrics) method:

```js
Expand All @@ -26,6 +35,15 @@ A metric object has the following structure:

## Custom Metric Object

:::info TypeScript Support

A custom metric object has an associated TypeScript type:

- Type Name - `MonitoringCustomMetric`
- Package - `@resolve-js/core`

:::

A custom metric object is used to pass metric data to the `metrics.custom()` method. This object has the following structure:

```js
Expand Down
35 changes: 22 additions & 13 deletions docs/api/monitoring/monitoring-adapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@ description: This document describes the interface that a monitoring adapter sho

## Monitoring Adapter API

:::info TypeScript Support

A monitoring adapter object has an associated TypeScript type:

- Type Name - `MonitoringAdapter`
- Package - `@resolve-js/core`

:::

A monitoring adapter implementation should expose the following interface:

| Member Name | Description |
Expand All @@ -18,9 +27,9 @@ A monitoring adapter implementation should expose the following interface:
| [`custom`](#custom) | Registers a custom metric. |
| [`publish`](#publish) | Defined by an implementation, publishes the collected metrics to the intended destination. |
| [`rate`](#rate) | Registers operation execution rate during the specified time interval in seconds. |
| [`group`](#group) | Create a monitoring group. |
| [`getMetrics`](#getmetrics) | Get a list of collected metrics. |
| [`clearMetrics`](#clearmetrics) | Clear the list of collected metrics. |
| [`group`](#group) | Creates a monitoring group. |
| [`getMetrics`](#getmetrics) | Gets a list of collected metrics. |
| [`clearMetrics`](#clearmetrics) | Clears the list of collected metrics. |

All of the listed functions except for `publish` have a default implementation in the base package.

Expand All @@ -30,7 +39,7 @@ Registers an occurred error. The default implementation increments the count of

#### Arguments

| Argument Name | Type | Descriptions |
| Argument Name | Type | Description |
| ------------- | ------------------ | -------------------------------------- |
| `error` | An `error` object. | An error to add to monitoring metrics. |

Expand All @@ -40,7 +49,7 @@ Registers an operation's execution. The default implementation increments the co

#### Arguments

| Argument Name | Type | Descriptions |
| Argument Name | Type | Description |
| ------------- | --------------------------- | -------------------------------------- |
| `error?` | An `error` object or `null` | An error to add to monitoring metrics. |

Expand All @@ -50,7 +59,7 @@ Registers the duration of an operation. The default implementation adds the spec

#### Arguments

| Argument Name | Type | Descriptions |
| Argument Name | Type | Description |
| ------------- | -------- | ------------------------------------------------------- |
| `label` | `string` | A text label to add to the 'Label' dimension. |
| `duration` | `number` | An operation duration in milliseconds. |
Expand All @@ -62,7 +71,7 @@ Starts a timer to measure execution time.

#### Arguments

| Argument Name | Type | Descriptions |
| Argument Name | Type | Description |
| ------------- | -------- | ------------------------------------------------------------------------ |
| `name` | `string` | The ID of the started timer. |
| `timestamp?` | `number` | A moment in time from which to start counting. Defaults to `Date.now()`. |
Expand All @@ -73,7 +82,7 @@ Ends time measurement and registers the resulting duration. The default implemen

#### Arguments

| Argument Name | Type | Descriptions |
| Argument Name | Type | Description |
| ------------- | -------- | --------------------------------------------------------------------- |
| `name` | `string` | The ID of the timer to stop. |
| `timestamp?` | `number` | A moment in time at which to stop counting. Defaults to `Date.now()`. |
Expand All @@ -84,7 +93,7 @@ Registers the specified custom metric. If the metric object's `value` and/or `co

#### Arguments

| Argument Name | Type | Descriptions |
| Argument Name | Type | Description |
| ------------- | --------------------------------------------------------- | --------------------------------- |
| `metricData` | A [custom metric object](metric.md#custom-metric-object). | Specifies a custom metric's data. |

Expand All @@ -94,7 +103,7 @@ Defined by an implementation, publishes the collected metrics to the intended de

#### Arguments

| Argument Name | Type | Descriptions |
| Argument Name | Type | Description |
| ------------- | -------- | ------------------------------------------------------- |
| `options?` | `object` | Specifies additional options for the publish operation. |

Expand All @@ -115,7 +124,7 @@ Registers operation execution rate during the specified time interval in seconds

#### Arguments

| Argument Name | Type | Descriptions |
| Argument Name | Type | Description |
| ------------- | -------- | ------------------------------------------------------------------- |
| `metricName` | `string` | The name of the metric to add. |
| `count` | `number` | A number to add to the metric's count. |
Expand All @@ -127,7 +136,7 @@ Creates a monitoring group and returns a monitoring adapter instance for this gr

#### Arguments

| Argument Name | Type | Descriptions |
| Argument Name | Type | Description |
| ------------- | -------------------------- | ------------------------------------------- |
| `config` | A key-value pair `object`. | A key-value pair that identifies the group. |

Expand All @@ -149,7 +158,7 @@ Clear the list of collected metrics.

## Custom Monitoring Adapter Example

The code below demonstrates how to implement a monitoring that uses [Prometheus](https://prometheus.io/) to publish metrics.
The code below demonstrates how to implement a monitoring adapter that uses [Prometheus](https://prometheus.io/) to publish metrics.

The adapter implementation redefines the base adapter's `publish` function and reuses the default implementation for other API functions.

Expand Down
Loading

0 comments on commit 66493d5

Please sign in to comment.