Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: improve exports organization and documentation #12

Merged
merged 2 commits into from
Feb 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,30 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [3.3.0] - 2025-02-16

### Improved

- Enhanced export organization:
- Better grouping of related exports
- Improved JSDoc documentation
- Clearer deprecation notices
- Separated v2 legacy exports into dedicated file

### Changed

- Moved v2 namespace to dedicated file for better maintainability
- Enhanced type exports organization
- Improved code organization and documentation
- Better separation of concerns between v2 and v3 exports

### Documentation

- Added comprehensive JSDoc documentation for all exports
- Improved type documentation and examples
- Enhanced deprecation notices with migration guidance
- Updated export structure documentation

## [3.2.0] - 2025-02-16

### Added
Expand Down
203 changes: 109 additions & 94 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,78 @@
# RuleKit
# RuleKit 🎯

A powerful and flexible toolkit for building rule-based matching and filtering systems with full TypeScript support.
A powerful and flexible toolkit for building intelligent filtering, matching, and rule-based systems. RuleKit combines high-performance rule evaluation with smart interface generation and data analysis.

[![npm version](https://badge.fury.io/js/@phr3nzy%2Frulekit.svg)](https://badge.fury.io/js/@phr3nzy%2Frulekit)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

## Features
## What is RuleKit?

RuleKit is a comprehensive toolkit that helps you build sophisticated filtering and matching systems. It's perfect for:

- 🛍️ **E-commerce Filtering**: Create smart product filters with automatic UI generation
- 🤝 **Entity Matching**: Match entities based on complex rule combinations
- 📊 **Data Analysis**: Automatically analyze data to suggest appropriate UI components
- 🎨 **Interface Generation**: Build dynamic interfaces based on data characteristics
- 🔍 **Smart Search**: Implement advanced search with type-safe rules
- 🎯 **Business Rules**: Define and evaluate complex business rules

## Core Features

- 🎯 **Type-Safe**: Full TypeScript support with generic type inference
- 🚀 **High Performance**: 47K+ ops/sec for real-world scenarios
- 🔍 **Flexible Matching**: Support for complex rule combinations
- 🔍 **Smart Analysis**: Automatic data analysis and component suggestion
- 🎨 **Interface Agnostic**: Flexible component system for any UI framework
- 📦 **Zero Dependencies**: Lightweight and efficient
- 🔒 **Validation**: Built-in schema validation
- 🔄 **Batch Processing**: Optimized for large datasets
- 📚 **Well Documented**: Clean, documented exports with proper versioning

## Key Components

### 1. Rule Engine

The core engine that evaluates rules against entities with high performance:

```typescript
const engine = new RuleEngine(schema);
const matches = engine.findMatchingFrom(entities, rules);
```

### 2. Data Analyzer

Automatically analyzes your data to suggest appropriate UI components:

```typescript
const analyzer = new DataAnalyzer();
const analysis = analyzer.analyze(data);
// Get insights like data types, statistics, and suggested components
```

### 3. Interface Components

Type-safe, framework-agnostic components that can be used with any UI:

```typescript
const component = {
type: ComponentType.RANGE,
identifier: 'price',
value: 500,
constraints: {
min: 0,
max: 1000,
step: 1,
},
};
```

### 4. Rule Converter

Convert UI components to rules and vice versa:

```typescript
const converter = new RuleConverter();
const rule = converter.convertComponentsToRule(components);
```

## Installation

Expand All @@ -27,72 +87,33 @@ yarn add @phr3nzy/rulekit
pnpm add @phr3nzy/rulekit
```

## Quick Start (v3)
## Exports Overview

RuleKit provides a well-organized export structure:

```typescript
import { AttributeType, RuleEngine } from '@phr3nzy/rulekit';
// Core functionality
import { RuleEngine, AttributeType } from '@phr3nzy/rulekit';
import type { Entity, Rule, RuleSet } from '@phr3nzy/rulekit';

// 1. Define your schema
type ProductSchema = {
category: {
type: typeof AttributeType.STRING;
validation: {
type: typeof AttributeType.STRING;
required: true;
enum: ['electronics', 'furniture'];
};
};
price: {
type: typeof AttributeType.NUMBER;
validation: {
type: typeof AttributeType.NUMBER;
required: true;
min: 0;
};
};
tags: {
type: typeof AttributeType.ARRAY;
validation: {
type: typeof AttributeType.ARRAY;
arrayType: typeof AttributeType.STRING;
required: false;
};
};
} & AttributeSchema;
// Interface-agnostic components
import { ComponentType, InterfaceOperators } from '@phr3nzy/rulekit';
import type { Component, ComponentConstraints } from '@phr3nzy/rulekit';

// 2. Create schema instance
const productSchema: ProductSchema = {
category: {
type: AttributeType.STRING,
validation: {
type: AttributeType.STRING,
required: true,
enum: ['electronics', 'furniture'],
},
},
price: {
type: AttributeType.NUMBER,
validation: {
type: AttributeType.NUMBER,
required: true,
min: 0,
},
},
tags: {
type: AttributeType.ARRAY,
validation: {
type: AttributeType.ARRAY,
arrayType: AttributeType.STRING,
required: false,
},
},
};
// Data analysis
import { Analyzer, type DataStatistics } from '@phr3nzy/rulekit';

// 3. Create engine
const engine = new RuleEngine(productSchema);
// Legacy v2 functionality (if needed)
import { v2 } from '@phr3nzy/rulekit';
```

## Quick Start

// 4. Define entities
const entities: Entity<ProductSchema>[] = [
```typescript
import { AttributeType, RuleEngine, DataAnalyzer, RuleConverter } from '@phr3nzy/rulekit';

// 1. Define your data
const products = [
{
id: '1',
name: 'Gaming Laptop',
Expand All @@ -103,42 +124,36 @@ const entities: Entity<ProductSchema>[] = [
__validated: true,
},
},
{
id: '2',
name: 'Office Chair',
attributes: {
category: 'furniture',
price: 299,
tags: ['office', 'ergonomic'],
__validated: true,
},
},
// ... more products
];

// 5. Define rules
const rules: Rule<ProductSchema>[] = [
{
and: [
{
attributes: {
category: { eq: 'electronics' },
price: { gte: 1000 },
},
},
{
attributes: {
tags: { in: ['premium'] },
},
},
],
// 2. Analyze data to get smart component suggestions
const analyzer = new DataAnalyzer();
const analysis = analyzer.analyze(products.map(p => p.attributes));

// 3. Create type-safe components based on analysis
const priceAnalysis = analysis.price;
const component = {
type: priceAnalysis.suggestedComponent.type, // RANGE
identifier: 'price',
value: 500,
constraints: {
min: priceAnalysis.statistics.numeric.min,
max: priceAnalysis.statistics.numeric.max,
},
];
};

// 6. Find matches
const matches = engine.findMatchingFrom(entities, rules);
console.log(matches); // [{ id: '1', name: 'Gaming Laptop', ... }]
// 4. Convert components to rules
const converter = new RuleConverter();
const rule = converter.convertComponentsToRule([{ field: 'price', component }]);

// 5. Find matches using the rule engine
const engine = new RuleEngine();
const matches = engine.findMatchingFrom(products, [rule]);
```

Check out our [examples](./examples) for more advanced usage!

## Features

### Type-Safe Schema Definition
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@phr3nzy/rulekit",
"version": "3.2.0",
"version": "3.3.0",
"description": "A powerful and flexible toolkit for building rule-based matching and filtering systems",
"main": "dist/index.js",
"module": "dist/index.mjs",
Expand Down
32 changes: 18 additions & 14 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
// Core exports
/**
* RuleKit - A type-safe rule engine for entity matching and filtering
* @packageDocumentation
*/

// Core type exports
export type {
Entity,
Rule,
Expand All @@ -8,12 +13,18 @@ export type {
RuleValue,
BaseFilter,
} from './core/models/types';

// Core functionality exports
export { ComparisonOperators } from './core/models/types';
export * from './core/models/validation';
export { RuleEngine } from './core/services/rule-engine';

// Attribute system exports
export * from './core/attributes/types';
export * from './core/attributes/registry';
export * from './core/attributes/validator';

// Rule evaluation exports
export * from './core/evaluators/types';
export * from './core/evaluators/base-rule-evaluator';

Expand All @@ -27,22 +38,15 @@ export * from './core/interface/converters/rule-converter';
export * from './core/analysis/types';
export * from './core/analysis/analyzer';

// Legacy UI exports (deprecated)
/** @deprecated Use interface-agnostic components instead */
/**
* @deprecated Use interface-agnostic components instead
* These exports will be removed in the next major version
*/
export * from './core/ui/types';
/** @deprecated Use interface-agnostic components instead */
export * from './core/ui/converter';

// V3 exports
// V3 exports (latest version)
export * from './v3';

// Legacy v2 namespace export
import * as validation from './core/models/validation';
import { RuleEngine as Engine } from './core/services/rule-engine';
import { ComparisonOperators as CoreOperators } from './core/models/types';

export const v2 = {
ruleEngine: Engine,
validation,
ComparisonOperators: CoreOperators,
};
export { v2 } from './v2';
15 changes: 15 additions & 0 deletions src/v2.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* Legacy v2 namespace exports
* @deprecated Use latest v3 exports instead
* @packageDocumentation
*/

import * as validation from './core/models/validation';
import { RuleEngine as Engine } from './core/services/rule-engine';
import { ComparisonOperators as CoreOperators } from './core/models/types';

export const v2 = {
ruleEngine: Engine,
validation,
ComparisonOperators: CoreOperators,
};
Loading