@bernierllc/nevar-types
v0.1.0
Published
Shared type definitions, interfaces, error classes, and type guards for the Nevar rules engine suite
Readme
@bernierllc/nevar-types
Shared type definitions, interfaces, error classes, and type guards for the Nevar rules engine suite.
Overview
This package provides the foundational types that all Nevar packages depend on. It has zero runtime dependencies — it exports only TypeScript types, interfaces, error classes, and type guard functions.
Installation
npm install @bernierllc/nevar-typesUsage
import type {
Rule,
ConditionGroup,
ActionDefinition,
NevarConfig,
EvaluationResult,
NevarStorageAdapter,
} from '@bernierllc/nevar-types';
import {
isConditionGroup,
isCondition,
NevarError,
NevarEvaluationError,
} from '@bernierllc/nevar-types';
// Type guard usage
const node: ConditionGroup | Condition = getNode();
if (isConditionGroup(node)) {
console.log(node.operator, node.conditions);
} else if (isCondition(node)) {
console.log(node.field, node.op, node.value);
}
// Error handling with cause chain
try {
evaluateRule(rule, context);
} catch (error) {
if (error instanceof NevarEvaluationError) {
console.log(error.code, error.context, error.cause);
}
}API
Types and Interfaces
Rule- Complete rule definition with trigger type, condition tree, actions, and execution settingsRuleGroup- Named collection of rulesConditionGroup- Tree node withoperator(AND/OR/NOT) and nestedconditionsCondition- Leaf node withfield,op, andvalueActionDefinition- Action type, config, retry settings, and execution orderActionIntent- Resolved action ready for execution, tied to a specific ruleActionResult- Outcome of executing an action intentTriggerDefinition- Trigger type definition with payload schemaOperatorDefinition- Operator with evaluate function, label, category, and field typesNevarStorageAdapter- Storage interface for rules, groups, and execution logsNevarConfig- Full engine configuration including circuit breaker, loop, and audit settingsEvaluationResult- Match result with evaluation traceLoopHandle- Runtime loop state with heartbeat tracking
Error Classes
All errors extend NevarError and support ES2022 Error.cause chaining via NevarErrorOptions:
NevarError- Base error withcode: stringandcontext?: Record<string, unknown>NevarTriggerError- Trigger validation and dispatch failuresNevarEvaluationError- Condition evaluation failures (unknown operators, provider errors)NevarActionError- Action execution failuresNevarCircuitBreakerError- Circuit breaker limit violationsNevarLoopError- Loop detection and control failuresNevarStorageError- Storage adapter failuresNevarValidationError- Schema and configuration validation failures
Type Guards
isConditionGroup(value)- Returnstrueif value hasoperatorandconditionsfieldsisCondition(value)- Returnstrueif value hasfield,op, andvaluefields
Exports
Types & Interfaces
- Models:
Rule,RuleGroup,LogLevel,EvaluationTrace - Conditions:
ConditionGroup,Condition - Actions:
ActionDefinition,ActionRetryConfig,ActionIntent,ActionResult,MatchedRule,DeferredTrigger,ActionFailureMode - Triggers:
TriggerDefinition - Context:
ContextProviderDefinition - Operators:
OperatorDefinition,OperatorInfo - Storage:
NevarStorageAdapter,GroupFilters,RuleFilters,LogFilters,PaginatedResult,ExecutionLogEntry - Config:
NevarConfig,CircuitBreakerConfig,LoopConfig,AuditLoggerConfig,SeedStrategy - Results:
EmitResult,PreviewResult,EvaluationResult,LoopHandle,LoopAnalysis,DetectedLoop
Error Classes
All errors extend NevarError and follow the ES2022 Error.cause pattern:
NevarError(base)NevarTriggerErrorNevarEvaluationErrorNevarActionErrorNevarCircuitBreakerErrorNevarLoopErrorNevarStorageErrorNevarValidationError
Type Guards
isConditionGroup(value)— checks foroperatorandconditionsfieldsisCondition(value)— checks forfield,op,valuefields
Integration Documentation
Logger Integration
This package does not integrate with @bernierllc/logger. As a core package, logger integration is optional and not included by default. Consumers should handle logging at the service layer.
NeverHub Integration
This package does not integrate with @bernierllc/neverhub-adapter. As a core package, NeverHub integration is not applicable. NeverHub registration should be handled by service-layer packages that compose this package.
License
Copyright (c) 2025 Bernier LLC. All rights reserved.
