Skip to content

Commit b1c42cb

Browse files
authored
docs: Update Contributor Guide (#261)
1 parent b788992 commit b1c42cb

File tree

2 files changed

+77
-2
lines changed

2 files changed

+77
-2
lines changed

CONTRIBUTING.md

Lines changed: 76 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ Thank you so much for your interest in contributing to Substation! This document
1313

1414
[Development](#development)
1515
+ [Development Environment](#development-environment)
16+
+ [Conditions](#conditions)
17+
+ [Transforms](#transforms)
1618
+ [Testing](#testing)
19+
+ [Config Unit Tests](#config-unit-tests)
1720

1821
[Style Guides](#style-guides)
1922
+ [Design Patterns](#design-patterns)
@@ -45,10 +48,82 @@ Enhancements should be submitted as issues using the issue template.
4548

4649
The project supports development through the use of [Visual Studio Code configurations](https://code.visualstudio.com/docs/remote/containers). The VS Code [development container](.devcontainer/Dockerfile) contains all packages required to develop and test changes locally before submitting pull requests.
4750

51+
### [Conditions](condition/)
52+
53+
Each condition should be functional and solve a single problem, and each one is nested under a "family" of conditions. (We may ask that you split complex condition logic into multiple conditions.) For example, there is a family for string comparisons:
54+
- Equal To (`cnd.string.equal_to`, `cnd.str.eq`)
55+
- Starts With (`cnd.string.starts_with`, `cnd.str.prefix`)
56+
- Ends With (`cnd.string.ends_with`, `cnd.str.suffix`)
57+
- Contains (`cnd.string.contains`, `cnd.str.has`)
58+
- Match (regular expression) (`cnd.string.match`)
59+
- Greater Than (`cnd.string.greater_than`, `cnd.str.gt`)
60+
- Less Than (`cnd.string.less_than`, `cnd.str.lt`)
61+
62+
Conditions may require changes to the [configuration library](substation.libsonnet) (usually when adding features or making breaking changes). For new conditions, we typically ask that you add a new [example](examples/) that uses a config unit test.
63+
64+
Conditions may reuse these field structures:
65+
- `object`: For reading from JSON objects.
66+
67+
In some cases, we may ask you to rename fields for consistency.
68+
69+
### [Transforms](transform/)
70+
71+
Each transform should be functional and solve a single problem, and each one is nested under a "family" of transforms. (We may ask that you split complex transform logic into multiple transforms.) For example, there is a family for JSON object operations:
72+
- Copy (`tf.object.copy`, `tf.obj.cp`)
73+
- Delete (`tf.object.delete`, `tf.obj.del`)
74+
- Insert (`tf.object.insert`)
75+
- To Boolean (`tf.object.to.boolean`, `tf.obj.to.bool`)
76+
- To String (`tf.object.to.string`, `tf.obj.to.str`)
77+
- To Float (`tf.object.to.float`)
78+
- To Integer (`tf.object.to.integer`, `tf.obj.to.int`)
79+
- To Unsigned Integer (`tf.object.to.unsigned_integer`, `tf.obj.to.uint`)
80+
81+
Transforms may require changes to the [configuration library](substation.libsonnet) (usually when adding features or making breaking changes). For new transforms, we typically ask that you add a new [example](examples/) that uses a config unit test.
82+
83+
Transforms may reuse these field structures:
84+
- `id`: For uniquely identifying a transform. (If not configured, then this is automatically generated when a configuration is compiled by Jsonnet.)
85+
- `object`: For reading from and writing to JSON objects.
86+
- `batch`: For stateful collection of multiple messages in a transform.
87+
- `transforms`: For chaining multiple transforms together. (Used in `meta` transforms.)
88+
- `aux_transforms`: For chaining multiple transforms together, _after_ the primary transform has executed. (Used in `send` transforms.)
89+
90+
In some cases, we may ask you to rename fields for consistency.
91+
4892
### Testing
4993

5094
We rely on contributors to test changes before they are submitted as pull requests. Any components added or changed should be tested and public packages should be supported by unit tests.
5195

96+
#### Config Unit Tests
97+
98+
Configuration examples should use config unit tests to demo new concepts or features, like this:
99+
100+
```jsonnet
101+
{
102+
tests: [
103+
{
104+
// Every test should have a unique name.
105+
name: 'my-passing-test',
106+
// Generates the test message '{"a": true}' which
107+
// is run through the configured transforms and
108+
// then checked against the condition.
109+
transforms: [
110+
sub.tf.test.message({ value: {a: true} }),
111+
],
112+
// Checks if key 'x' == 'true'.
113+
condition: sub.cnd.all([
114+
sub.cnd.str.eq({ object: {source_key: 'x'}, value: 'true' }),
115+
])
116+
},
117+
],
118+
// These transforms process the test message and the result
119+
// is checked against the condition.
120+
transforms: [
121+
// Copies the value of key 'a' to key 'x'.
122+
sub.tf.obj.cp({ object: { source_key: 'a', target_key: 'x' } }),
123+
],
124+
}
125+
```
126+
52127
## Style Guides
53128

54129
### Design Patterns
@@ -125,7 +200,7 @@ Sources that [add metadata during message creation](/message/) should use lowerC
125200

126201
#### Package Configurations
127202

128-
Configurations for packages (for example, [condition](/condition/README.md) and [transform](/transform/README.md)) should always use lower_snake_case in their JSON keys. This helps maintain readability when reviewing large configuration files.
203+
Configurations for packages (for example, conditions and transforms) should always use lower_snake_case in their JSON keys. This helps maintain readability when reviewing large configuration files.
129204

130205
We strongly urge everyone to use Jsonnet for managing configurations.
131206

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ ok examples/transform/time/str_conversion/config.jsonnet 133µs
474474

475475
[VS Code](https://code.visualstudio.com/docs/devcontainers/containers) is the recommended development environment for Substation. The project includes a [development container](.devcontainer/Dockerfile) that should be used to develop and test the system. Refer to the [development guide](CONTRIBUTING.md) for more information.
476476

477-
If don't use VS Code, then you should run the development container from the command line:
477+
If you don't use VS Code, then you should run the development container from the command line:
478478

479479
```sh
480480
git clone https://github.com/brexhq/substation.git && cd substation && \

0 commit comments

Comments
 (0)