https://github.com/worotyns/atoms
Simple complex object aka atoms storage via persist, restore in fs
https://github.com/worotyns/atoms
deno framework pure-object storage
Last synced: 2 months ago
JSON representation
Simple complex object aka atoms storage via persist, restore in fs
- Host: GitHub
- URL: https://github.com/worotyns/atoms
- Owner: worotyns
- License: mit
- Created: 2023-11-23T08:08:00.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-01-12T15:51:04.000Z (over 2 years ago)
- Last Synced: 2025-12-25T11:50:14.229Z (4 months ago)
- Topics: deno, framework, pure-object, storage
- Language: TypeScript
- Homepage:
- Size: 30.3 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Atoms
## Overview
Atoms is a simple and lightweight micro "framework" designed for easy
prototyping and interaction with objects. It consists of just two methods,
_restore_ and _persist_, and an interface to implement _IAtom_.
## Features
- **Simplicity:** Define your classes with just two methods, making it easy to
create small programs without unnecessary complexity.
- **Persistence:** Easily persist and restore the state of your objects without
the need for databases. Use the file system to preview data and query with
tools like `jq` or similar.
- **Extensibility:** Implement the _IAtom_ interface by extending the _Atom_
class to enable seamless serialization and deserialization.
- **Drivers:** Includes drivers for memory, file system, object storage (in
progress), and Deno KV storage (in progress).
- **Serializers:** Currently supports JSON serialization.
## Example Codes (see /examples directory)
### Simple Structure (One File)
```typescript
import { Atom, createFs } from 'https://deno.land/x/atoms/mod.ts';
const { persist, restore } = createFs('./tmp');
class Simple extends Atom {
public readonly name: string = 'example';
public readonly age: number = 33;
sayNameAndAge() {
return `${this.name} is ${this.age} yo`;
}
static deserialize(value: PropertiesOnly): Simple {
return Object.assign(
new Simple(),
Atom.parse(value),
);
}
}
const simple = new Simple();
await persist(simple);
const restored = await restore(simple.identity, Simple);
```
## Nested structure (multiple files on save)
```ts
import { Atom, createFs } from 'https://deno.land/x/atoms/mod.ts';
const { persist, restore } = createFs('./tmp');
class MySample extends Atom {
public readonly name: string = 'example';
public readonly age: number = 33;
public nested: MySecondClass = new MySecondClass();
static deserialize(value: PropertiesOnly): MySample {
const temporary = Atom.parse(value);
const newSample = new MySample();
Object.assign(newSample, temporary, {
nested: MySecondClass.deserialize(temporary.nested),
});
return newSample;
}
}
class MySecondClass extends Atom {
public collection: Array = [1, 2, 3, 4];
static deserialize(value: PropertiesOnly): MySecondClass {
const temporary = Atom.parse(value);
const newSample = new MySecondClass();
Object.assign(newSample, temporary);
return newSample;
}
}
const mySample = new MySample();
await persist(mySample);
const restored = await restore(mySample.identity, MySample);
```