@samatawy/objects
v0.1.0
Published
TypeScript object state, cache, and typed store utilities for small application runtime layers.
Maintainers
Readme
@samatawy/objects
TypeScript object-state, cache, and typed store utilities.
Typed Stores And Caching
The package also includes a small typed runtime layer for applications that want validated objects to move through simple store and cache abstractions.
That layer includes:
TypeCacheandObjectCachefor in-memory cachingTypeStoreandObjectStorefor per-type CRUD orchestrationCachedObjectStorefor read-through and write-through cachingInMemoryTypeStorefor tests, demos, and other local in-process implementations
These helpers are intentionally lightweight. They are meant to sit next to your DTOs, validation rules, and object factories, not replace a full ORM or distributed cache.
Documentation
The local docs source lives under help/ and can be turned into the generated site under docs/ with:
npm run docsSee Object Caching, Cache API, and the Examples section for the current patterns.
Installation
npm install @samatawy/objectsQuick Start
import { CachedObjectStore, InMemoryTypeStore, StateStore } from '@samatawy/objects';
class PersonDto {
constructor(
public readonly id: string,
public readonly name: string,
) { }
}
const people = new InMemoryTypeStore<PersonDto>({
keyOf(person) {
return person.id;
},
});
const store = new CachedObjectStore().registerTypeStore(PersonDto, people);
const state = new StateStore();
state.define<number>('count', { initialValue: 1 });
await store.create(PersonDto, new PersonDto('1', 'Ada'));Development
npm install
npm run lint
npm test
npm run build