@diskcare/rules-engine
v1.0.4
Published
DiskCare rules engine (risk + safeAfterDays decisions).
Readme
@diskcare/rules-engine
English
Rule engine for DiskCare. It decides risk and eligibility based on rule config.
What it provides
RulesEngineto evaluate rules by target idRulesConfigLoaderto load and validate rule files- Types for rule configs and decisions
Usage
import { RulesEngine } from "@diskcare/rules-engine";
const engine = new RulesEngine({
rules: [
{ id: "npm-cache", risk: "safe", safeAfterDays: 14, description: "npm cache is reproducible" },
],
defaults: { risk: "caution", safeAfterDays: 30 },
});
const decision = engine.decide("npm-cache");Notes
- Validation errors throw
RulesConfigErrorwith filePath and cause. - When no rule matches, defaults are used.
- Rules may include optional
pathsfor custom target discovery (handled by the CLI).
Standalone usage
You can embed the rules engine in another tool by providing a RuleConfig object and calling decide(targetId) for each target you discover.
Türkçe
DiskCare için kural motoru. Risk ve uygunluk kararlarını kural yapılandırmasına göre verir.
Sağladıkları
- Hedef id'ye göre kuralları değerlendiren
RulesEngine - Kural dosyalarını yükleyen ve doğrulayan
RulesConfigLoader - Kural yapılandırmaları ve kararlar için tipler
Kullanım
import { RulesEngine } from "@diskcare/rules-engine";
const engine = new RulesEngine({
rules: [
{ id: "npm-cache", risk: "safe", safeAfterDays: 14, description: "npm cache is reproducible" },
],
defaults: { risk: "caution", safeAfterDays: 30 },
});
const decision = engine.decide("npm-cache");Notlar
- Doğrulama hataları, filePath ve sebep ile
RulesConfigErrorfırlatır. - Hiçbir kural eşleşmezse, varsayılanlar kullanılır.
- Kurallar, özel hedef keşfi için isteğe bağlı
pathsiçerebilir (CLI tarafından işlenir).
Bağımsız kullanım
Kurallar motorunu başka bir araca gömerek bir RuleConfig nesnesi sağlayabilir ve keşfettiğiniz her hedef için decide(targetId) çağırabilirsiniz.
