Skip to content

Commit

Permalink
feat(core): Code tidy
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewbrg committed Oct 3, 2024
1 parent ea66431 commit 8dcc56c
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 14 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<img src=".github/logo.png" width="190" alt="RulePilot" />

[![npm version](https://badge.fury.io/js/rulepilot.svg)](https://badge.fury.io/js/rulepilot?v1.2.1)
[![npm version](https://badge.fury.io/js/rulepilot.svg)](https://badge.fury.io/js/rulepilot?v1.3.0)

| Statements | Functions | Lines |
| --------------------------------------------------------------------------- | -------------------------------------------------------------------------- | ---------------------------------------------------------------------- |
Expand Down
2 changes: 1 addition & 1 deletion src/builder/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import {
Constraint,
ConditionType,
} from "../types/rule";
import { RuleError } from "../errors";
import { Validator } from "../services";
import { RuleError } from "../types/error";
import { SubRuleBuilder } from "./sub-rule-builder";

export class Builder {
Expand Down
2 changes: 2 additions & 0 deletions src/errors/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from "./rule.error";
export * from "./rule-type.error";
10 changes: 10 additions & 0 deletions src/errors/rule-type.error.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { RuleError } from "./rule.error";

export class RuleTypeError extends Error {
constructor(message: string) {
super(message ?? "The type of rule is not valid for this operation");
}

/** The name/type of the error. */
type: string = RuleError.name;
}
9 changes: 0 additions & 9 deletions src/types/error.ts → src/errors/rule.error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,3 @@ export class RuleError extends Error {
/** The element that caused the error. */
element: object;
}

export class RuleTypeError extends Error {
constructor(message: string) {
super(message ?? "The type of rule is not valid for this operation");
}

/** The name/type of the error. */
type: string = RuleError.name;
}
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export * from "./types/rule";
export * from "./types/error";
export * from "./errors";
export { RulePilot } from "./services/rule-pilot";
export { ValidationResult } from "./services/validator";
7 changes: 6 additions & 1 deletion src/services/introspector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
IntrospectionResult,
} from "../types/rule";
import { Logger } from "./logger";
import { RuleTypeError } from "../types/error";
import { RuleTypeError } from "../errors";
import { ObjectDiscovery } from "./object-discovery";

interface IntrospectionStep {
Expand All @@ -21,6 +21,11 @@ interface IntrospectionStep {
}[];
}

/**
* Introspection deals with the process of examining the constraints and conditions of a rule to determine all the
* possible range of input criteria which would satisfy the rule along with the result of the rule that would be
* produced by the criteria.
*/
export class Introspector {
#objectDiscovery: ObjectDiscovery = new ObjectDiscovery();
#steps: IntrospectionStep[];
Expand Down
2 changes: 1 addition & 1 deletion src/services/rule-pilot.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Mutator } from "./mutator";
import { Builder } from "../builder";
import { RuleError } from "../errors";
import { Evaluator } from "./evaluator";
import { RuleError } from "../types/error";
import { Introspector } from "./introspector";
import { Validator, ValidationResult } from "./validator";
import { Rule, IntrospectionResult } from "../types/rule";
Expand Down

0 comments on commit 8dcc56c

Please sign in to comment.