add example of custom operator

Signed-off-by: goenning <me@goenning.net>
This commit is contained in:
goenning
2021-12-27 12:08:42 +00:00
parent 273c9aa1ca
commit e3b49153b7
2 changed files with 30 additions and 1 deletions
+1 -1
View File
@@ -1,5 +1,5 @@
---
'@backstage/plugin-tech-insights-backend-module-jsonfc': minor
'@backstage/plugin-tech-insights-backend-module-jsonfc': patch
---
ability to add custom operators
@@ -85,3 +85,32 @@ export const exampleCheck: TechInsightJsonRuleCheck = {
},
};
```
# Custom operators
json-rules-engine supports a limited [number of built-in operators](https://github.com/CacheControl/json-rules-engine/blob/master/docs/rules.md#operators) that can be used in conditions. You can add your own operators by adding them to the `operators` array in the `JsonRulesEngineFactCheckerFactory` constructor. For example:
```diff
const myFactCheckerFactory = new JsonRulesEngineFactCheckerFactory({
checks: [],
logger,
+ operators: [ new Operator("startsWith", (a, b) => a.startsWith(b) ]
})
```
And you can then use it in your checks like this:
```js
...
rule: {
conditions: {
any: [
{
fact: 'version',
operator: 'startsWith',
value: '12',
},
],
},
}
```