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
18 changes: 16 additions & 2 deletions docs/server/features/projections/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,22 @@ meet the criteria. The output of all queries is a stream, you can listen to this
There are two types of projections in KurrentDB:

- [Built in (system) projections](system.md)
- [User-defined JavaScript projections](custom.md) which you create via the API or the admin
UI
- [User-defined JavaScript projections](custom.md), which you write yourself and create through the
API, a client library, or the embedded UI

## Tooling

Kurrent maintains tooling for developing user-defined projections:

- **[gaffer](https://gaffer.kurrent.io)**, a command-line tool, runs a projection on your machine against
a file of sample events or subscribed to one of your databases. It deploys the projection to a server
when you are ready, and can run it with a debugger attached so you can step through a handler and watch
the state change. See [Your first projection](https://gaffer.kurrent.io/getting-started/first-projection/).
- **[The VS Code extension](https://gaffer.kurrent.io/extension/vs-code/)** drives the same runs and
breakpoints from the editor, and shows which of your projections are deployed where. Other DAP-aware
editors can attach to the debugger too.
- **[The testing library](https://gaffer.kurrent.io/testing/nodejs/)** feeds events to a projection from
a JavaScript test suite and hands back the state at each step for your tests to assert on.

## Performance impact

Expand Down
38 changes: 13 additions & 25 deletions docs/server/features/projections/custom.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ fromStream('account-1')
.outputState()
```

::: tip
Kurrent's [gaffer](https://gaffer.kurrent.io) tooling runs projections like this one on your machine and
deploys them to a server.
:::

## Projections API

Below, you can find the JavaScript API for user defined projections.
Expand Down Expand Up @@ -110,9 +115,8 @@ handler. The event provided through the handler contains the following propertie

## Debugging

User projections have a bonus that debugging is easier
via any browser that ships with debugging capabilities. The screenshots in this document show the use of
Chrome, but we have tested debugging with all major browsers including Firefox, Edge and Safari.
A projection can log from inside a handler, and you can step through one before it goes anywhere near a
server. Both are covered below.

### Logging from a projection

Expand Down Expand Up @@ -160,29 +164,13 @@ curl -i -d@stats-counter.json \
-u admin:changeit
```

### Debugging your first projection

Once the projection is running, open your browser and enable the developer tools. Once you have the developer
tools open, visit your projection URL and you should see a button labelled _Debug_.

![Projections Debugging Part 1](images/projections_debugging_part_1.png)

After clicking the projection "Debug" button, you see the debugging interface with the definition of the
projection and information about the events the projection is processing on the right-hand side.

At the top there are a couple of buttons to take note of, specifically the _Run Step_ and _Update_ buttons.
You use _Run Step_ to step through the event waiting in the queue, placing you in projection debugging mode.
The _Update_ button provides you with a way to update the projection definition without having to go back to
the projection itself and leave the context of the debugger.

![Projections Debugging Part 2](images/projections_debugging_part_2.png)

If the _Run Step_ button is not greyed out, and you click it, the browser has hit a breakpoint.

![Projections Debugging Part 3](images/projections_debugging_part_3.png)
### Stepping through a projection

You are now able to step through the projection, the important method to step into is
the `handler(state, eventEnvelope)` method.
The [gaffer](https://gaffer.kurrent.io) command line runs a projection on your machine with a debugger
attached, against a file of sample events or against one of your databases, so you can set breakpoints,
step through a handler and inspect the state as it changes without deploying anything. The
[VS Code extension](https://gaffer.kurrent.io/extension/vs-code/) drives it from the editor, and any
DAP-aware editor can attach to it.

## Configuring projections

Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading
Loading