@tatva-framework/core
v0.0.1
Published
<!-- packages/core/README.md --> # Core (packages/core)
Readme
Core (packages/core)
Lightweight building blocks used across this monorepo: small model base classes, adapters, filters and decorators for declaring entity metadata.
Key pieces
- Decorators:
Entity,Ignore,Key(seesrc/decorators/*). - Models & types:
BaseModel,BaseAdapter,BaseFilters,SaveInstruction(seesrc/models/*). - Entry point:
src/index.tsexports the package public API.
The package aims to be minimal and framework-agnostic — provide simple contracts and helpers so other packages in the workspace can implement adapters and models consistently.
Quick Example
Below is a small example showing how to define a model with the decorators and a tiny in-memory adapter that implements the BaseAdapter contract. This demonstrates basic save/find behavior.
// Example: define a model and an in-memory adapter
import { Entity } from './decorators/entity_decorator';
import { Key } from './decorators/key_decorator';
import { Ignore } from './decorators/ignore_decorator';
import { BaseModel } from './models/base_model';
import { BaseAdapter } from './models/base_adapter';
import { SaveInstruction } from './models/SaveInstruction';
import { BaseFilters } from './models/base_filters';
@Entity('users')
class User extends BaseModel {
@Key()
id!: string;
name!: string;
@Ignore()
transientToken?: string;
}
class InMemoryAdapter extends BaseAdapter {
private store = new Map<string, any>();
async save<T extends BaseModel>(instruction: SaveInstruction<T>) {
const model = instruction.model as unknown as any;
if (!model.id) model.id = String(Date.now());
this.store.set(model.id, { ...model });
return model;
}
async find<T extends BaseModel>(_filters?: BaseFilters) {
return Array.from(this.store.values());
}
}
// usage
async function runExample() {
const adapter = new InMemoryAdapter();
const user = new User();
user.name = 'Alice';
await adapter.save({ model: user });
const all = await adapter.find();
console.log('stored users', all);
}
runExample().catch(console.error);Notes
- Inspect the concrete implementations in
src/modelsandsrc/decoratorsfor exact method signatures and additional helpers. - To build the package from the workspace root (using pnpm):
pnpm --filter core run buildIf you'd like, I can also add a small test or example runner file under packages/core/examples/ that demonstrates this code running within the repo.
