update tsconfig
This commit is contained in:
parent
15c865c141
commit
5c1beec833
@ -5,17 +5,25 @@
|
||||
"githost": "code.foss.global",
|
||||
"gitscope": "push.rocks",
|
||||
"gitrepo": "smartrule",
|
||||
"description": "a smart rule library for handling decision trees.",
|
||||
"description": "A library for creating and managing decision trees with smart rules.",
|
||||
"npmPackagename": "@push.rocks/smartrule",
|
||||
"license": "MIT",
|
||||
"projectDomain": "push.rocks"
|
||||
"projectDomain": "push.rocks",
|
||||
"keywords": [
|
||||
"decision tree",
|
||||
"rules engine",
|
||||
"smart rules",
|
||||
"typescript",
|
||||
"nodejs",
|
||||
"library"
|
||||
]
|
||||
}
|
||||
},
|
||||
"npmci": {
|
||||
"npmGlobalTools": [],
|
||||
"npmAccessLevel": "public"
|
||||
},
|
||||
"tsdocs": {
|
||||
"tsdoc": {
|
||||
"legal": "\n## License and Legal Information\n\nThis repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository. \n\n**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.\n\n### Trademarks\n\nThis project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.\n\n### Company Information\n\nTask Venture Capital GmbH \nRegistered at District court Bremen HRB 35230 HB, Germany\n\nFor any legal inquiries or if you require further information, please contact us via email at hello@task.vc.\n\nBy using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.\n"
|
||||
}
|
||||
}
|
10
package.json
10
package.json
@ -2,7 +2,7 @@
|
||||
"name": "@push.rocks/smartrule",
|
||||
"version": "2.0.1",
|
||||
"private": false,
|
||||
"description": "a smart rule library for handling decision trees.",
|
||||
"description": "A library for creating and managing decision trees with smart rules.",
|
||||
"main": "dist_ts/index.js",
|
||||
"typings": "dist_ts/index.d.ts",
|
||||
"type": "module",
|
||||
@ -34,5 +34,13 @@
|
||||
],
|
||||
"browserslist": [
|
||||
"last 1 chrome versions"
|
||||
],
|
||||
"keywords": [
|
||||
"decision tree",
|
||||
"rules engine",
|
||||
"smart rules",
|
||||
"typescript",
|
||||
"nodejs",
|
||||
"library"
|
||||
]
|
||||
}
|
1
readme.hints.md
Normal file
1
readme.hints.md
Normal file
@ -0,0 +1 @@
|
||||
|
150
readme.md
150
readme.md
@ -1,39 +1,135 @@
|
||||
# @pushrocks/smartrule
|
||||
# @push.rocks/smartrule
|
||||
|
||||
a smart rule library for handling decision trees.
|
||||
|
||||
## Availabililty and Links
|
||||
* [npmjs.org (npm package)](https://www.npmjs.com/package/@pushrocks/smartrule)
|
||||
* [gitlab.com (source)](https://gitlab.com/pushrocks/smartrule)
|
||||
* [github.com (source mirror)](https://github.com/pushrocks/smartrule)
|
||||
* [docs (typedoc)](https://pushrocks.gitlab.io/smartrule/)
|
||||
## Install
|
||||
|
||||
## Status for master
|
||||
To install `@push.rocks/smartrule`, use the following command with npm:
|
||||
|
||||
Status Category | Status Badge
|
||||
-- | --
|
||||
GitLab Pipelines | [![pipeline status](https://gitlab.com/pushrocks/smartrule/badges/master/pipeline.svg)](https://lossless.cloud)
|
||||
GitLab Pipline Test Coverage | [![coverage report](https://gitlab.com/pushrocks/smartrule/badges/master/coverage.svg)](https://lossless.cloud)
|
||||
npm | [![npm downloads per month](https://badgen.net/npm/dy/@pushrocks/smartrule)](https://lossless.cloud)
|
||||
Snyk | [![Known Vulnerabilities](https://badgen.net/snyk/pushrocks/smartrule)](https://lossless.cloud)
|
||||
TypeScript Support | [![TypeScript](https://badgen.net/badge/TypeScript/>=%203.x/blue?icon=typescript)](https://lossless.cloud)
|
||||
node Support | [![node](https://img.shields.io/badge/node->=%2010.x.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
||||
Code Style | [![Code Style](https://badgen.net/badge/style/prettier/purple)](https://lossless.cloud)
|
||||
PackagePhobia (total standalone install weight) | [![PackagePhobia](https://badgen.net/packagephobia/install/@pushrocks/smartrule)](https://lossless.cloud)
|
||||
PackagePhobia (package size on registry) | [![PackagePhobia](https://badgen.net/packagephobia/publish/@pushrocks/smartrule)](https://lossless.cloud)
|
||||
BundlePhobia (total size when bundled) | [![BundlePhobia](https://badgen.net/bundlephobia/minzip/@pushrocks/smartrule)](https://lossless.cloud)
|
||||
Platform support | [![Supports Windows 10](https://badgen.net/badge/supports%20Windows%2010/yes/green?icon=windows)](https://lossless.cloud) [![Supports Mac OS X](https://badgen.net/badge/supports%20Mac%20OS%20X/yes/green?icon=apple)](https://lossless.cloud)
|
||||
```bash
|
||||
npm install @push.rocks/smartrule --save
|
||||
```
|
||||
|
||||
Or if you prefer using Yarn:
|
||||
|
||||
```bash
|
||||
yarn add @push.rocks/smartrule
|
||||
```
|
||||
|
||||
Ensure you have TypeScript and necessary typings installed in your project. If you haven't, you can add TypeScript and the types for Node.js by running:
|
||||
|
||||
```bash
|
||||
npm install typescript @types/node --save-dev
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
Use TypeScript for best in class intellisense.
|
||||
`@push.rocks/smartrule` is designed to simplify handling decision trees in your application, allowing you to manage complex business logic based on a set of predefined rules. Below we will walk through using this library to create and manage a simple set of decision rules programmatically.
|
||||
|
||||
## Contribution
|
||||
### Getting Started
|
||||
|
||||
We are always happy for code contributions. If you are not the code contributing type that is ok. Still, maintaining Open Source repositories takes considerable time and thought. If you like the quality of what we do and our modules are useful to you we would appreciate a little monthly contribution: You can [contribute one time](https://lossless.link/contribute-onetime) or [contribute monthly](https://lossless.link/contribute). :)
|
||||
First, ensure that you import `SmartRule` & define interfaces or types that you plan to use with it if necessary:
|
||||
|
||||
For further information read the linked docs at the top of this readme.
|
||||
```typescript
|
||||
import { SmartRule } from '@push.rocks/smartrule';
|
||||
|
||||
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
||||
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
|
||||
interface IMessage {
|
||||
id: string;
|
||||
content: string;
|
||||
userType: 'admin' | 'user';
|
||||
}
|
||||
```
|
||||
|
||||
[![repo-footer](https://lossless.gitlab.io/publicrelations/repofooter.svg)](https://maintainedby.lossless.com)
|
||||
### Creating a Decision Rule Instance
|
||||
|
||||
To start using smart rules, instantiate `SmartRule` with your data type:
|
||||
|
||||
```typescript
|
||||
const messageRule = new SmartRule<IMessage>();
|
||||
```
|
||||
|
||||
### Adding Rules
|
||||
|
||||
Rules are added by specifying a priority, a check function, and an action function. The check function decides whether the action function should be executed based on the input object. Let's define rules for our `IMessage` objects:
|
||||
|
||||
```typescript
|
||||
// Rule 1: Greet Admins
|
||||
messageRule.createRule(
|
||||
1, // priority
|
||||
async (message: IMessage) => {
|
||||
if (message.userType === 'admin') {
|
||||
return 'apply-continue'; // Apply action and continue evaluating
|
||||
}
|
||||
return 'continue'; // Continue without applying
|
||||
},
|
||||
async (message: IMessage) => {
|
||||
console.log(`Welcome, admin with ID: ${message.id}`);
|
||||
}
|
||||
);
|
||||
|
||||
// Rule 2: Delete messages containing forbidden words
|
||||
messageRule.createRule(
|
||||
2, // priority is higher, so this rule gets evaluated first
|
||||
async (message: IMessage) => {
|
||||
const forbiddenWords = ['forbidden', 'unallowed'];
|
||||
const containsForbiddenWord = forbiddenWords.some((word) =>
|
||||
message.content.includes(word)
|
||||
);
|
||||
return containsForbiddenWord ? 'apply-stop' : 'continue'; // Stops evaluating if forbidden word found
|
||||
},
|
||||
async (message: IMessage) => {
|
||||
console.log(`Message with ID: ${message.id} contained a forbidden word and was deleted.`);
|
||||
// Logic to delete the message would go here
|
||||
}
|
||||
);
|
||||
```
|
||||
|
||||
### Making Decisions
|
||||
|
||||
To evaluate an object against the defined rules, use the `makeDecision` method:
|
||||
|
||||
```typescript
|
||||
const testMessage: IMessage = {
|
||||
id: '001',
|
||||
content: 'This is a welcome message for an admin containing a forbidden word',
|
||||
userType: 'admin'
|
||||
};
|
||||
|
||||
messageRule.makeDecision(testMessage).then(() => {
|
||||
console.log('Decision making process completed.');
|
||||
// Implement further logic as needed
|
||||
});
|
||||
```
|
||||
|
||||
### Advanced Usage
|
||||
|
||||
- **Rule Prioritization**: You can manage the order in which rules are evaluated based on their priority. Rules with lower numbers are evaluated first.
|
||||
- **Decision Flow Control**: Through your check function return value (`apply-continue`, `apply-stop`, `continue`, or `stop`), you can precisely control how the decision-making process progresses after evaluating each rule.
|
||||
- **Asynchronous Support**: Both check and action functions support asynchronous operations, making it easy to integrate with APIs, databases, or other asynchronous data sources in your rules.
|
||||
|
||||
#### Handling Complex Scenarios
|
||||
|
||||
`@push.rocks/smartrule` is especially useful when you have complex decision-making processes in your application. By segmenting the logic into individual rules, you make your code more organized, maintainable, and scalable. You can easily add new rules or modify existing ones without affecting other parts of your decision tree.
|
||||
|
||||
---
|
||||
|
||||
By following this guide, you should now have a basic understanding of how to use `@push.rocks/smartrule` for managing decision trees in TypeScript using ESM syntax. This library provides a powerful yet simple abstraction for creating and managing complex decision-making logic, allowing you to focus on implementing the business rules specific to your application.
|
||||
|
||||
## License and Legal Information
|
||||
|
||||
This repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository.
|
||||
|
||||
**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.
|
||||
|
||||
### Trademarks
|
||||
|
||||
This project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.
|
||||
|
||||
### Company Information
|
||||
|
||||
Task Venture Capital GmbH
|
||||
Registered at District court Bremen HRB 35230 HB, Germany
|
||||
|
||||
For any legal inquiries or if you require further information, please contact us via email at hello@task.vc.
|
||||
|
||||
By using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.
|
||||
|
Loading…
Reference in New Issue
Block a user