SchemaKit
⚠️ BETA VERSION - This is a beta version and is not recommended for production use. Please use with caution and expect potential breaking changes.
🚧 ACTIVE DEVELOPMENT - This library is actively under development. Functionality may change and features are under testing. Expect bugs and incomplete features.
SchemaKit lets you create, validate, and manage entities and data at runtime, with built-in permissions and support for SQLite and PostgreSQL. Written in TypeScript.
Features
- Dynamic entities and fields (no migrations)
- Data validation
- Role-based permissions and RLS
- Multi-database: SQLite & Postgres
- TypeScript-first, zero dependencies
Install
- ✅ Built-in Validation - Comprehensive data validation with custom rules
- 🔐 Permission System - Role-based access control with row-level security
- 🔄 Workflow Engine - Automated actions on entity lifecycle events
- 🗃️ Multiple Databases - SQLite and PostgreSQL support
- 📱 Universal - Works in Node.js and browsers
- 🎯 TypeScript First - Full type safety and IntelliSense support
- 🧩 Modular Architecture - Use individual components as needed
📦 Installation
npm install @ahmedabdalla_85/schemakit
🚀 Quick Start
import { SchemaKit } from '@ahmedabdalla_85/schemakit';
const schemaKit = new SchemaKit({
adapter: {
type: 'sqlite',
config: { filename: 'database.db' }
}
});
await schemaKit.initialize();
const user = await schemaKit.entity('users','system');
await user.create({
name: 'John Doe',
email: 'john@example.com'
});
const updatedUser = await user.update(1,{
name: 'John Smith'
});
const Entities = await user.read();
const fieldRecord = await user.read({user_name:"John Doe"});
await user.delete(1);
Built-in Validation
Automatic validation based on field types and custom rules:
const user = await schemaKit.create('user', {
name: 'John',
age: 25,
isActive: true,
createdAt: new Date(),
tags: ['admin', 'user'],
metadata: { role: 'admin' }
});
Permission System
Role-based access control with fine-grained permissions:
const context = {
user: {
id: 'user123',
roles: ['admin']
}
};
const canCreate = await schemaKit.checkPermission('user', 'create', context);
const permissions = await schemaKit.getEntityPermissions('user', context);
SQL Schema Files
sql/schema.sql
- Defines system tables structure
sql/seed.sql
- Initial data and default entities
- Version tracking - Automatic version management
- Migration support - Ready for future schema updates
🗄️ Database Tables
When SchemaKit is installed, it creates the following system tables in your database:
Core System Tables
system_entities | Entity Definitions | Stores metadata for all dynamic entities including name, table name, and configuration |
system_fields | Field Definitions | Defines fields for each entity with validation rules, types, and constraints |
system_permissions | Access Control | Role-based permissions for entities and field-level access control |
system_views | Query Views | Predefined query configurations for entities with sorting and filtering |
system_workflows | Automation | Workflow definitions for automated actions on entity lifecycle events |
system_rls | Row-Level Security | Security rules that control which records users can access |
system_installation | Version Management | Tracks SchemaKit installation version and metadata |
🔌 Database Adapters
SQLite (Default)
const schemaKit = new SchemaKit({
adapter: {
type: 'sqlite',
config: {
filename: 'database.db'
}
}
});
Note: SQLite adapter requires better-sqlite3
to be installed separately:
npm install better-sqlite3
PostgreSQL
const schemaKit = new SchemaKit({
adapter: {
type: 'postgres',
config: {
host: 'localhost',
port: 5432,
database: 'mydb',
user: 'username',
password: 'password'
}
}
});
🔧 Configuration
SchemaKit Options
const schemaKit = new SchemaKit({
adapter: {
type: 'sqlite',
config: { filename: 'database.db' }
},
cache: {
enabled: true,
ttl: 3600000
}
});
Field Types
Supported field types:
string
- Text data
number
- Numeric data
boolean
- True/false values
date
- Date/time values
array
- Array data
json
- JSON objects
reference
- References to other entities
Validation Rules
{
type: 'string',
validation_rules: {
minLength: 2,
maxLength: 50,
pattern: '^[a-zA-Z]+$'
}
}
{
type: 'number',
validation_rules: {
min: 0,
max: 120
}
}
{
type: 'array',
validation_rules: {
minItems: 1,
maxItems: 10
}
}
🧪 Testing
npm test
npm run test:coverage
npm run test:watch
🏗️ Building
npm run build:all
npm run build
npm run build:esm
npm run build:umd
📄 License
MIT © Ahmed Abdalla
🤝 Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
📞 Support
🗺️ Roadmap
Made with ❤️ by Ahmed Abdalla