Skip to content

Commit 13d9f99

Browse files
committed
docs: add readme
1 parent 4abf8bc commit 13d9f99

File tree

5 files changed

+318
-28
lines changed

5 files changed

+318
-28
lines changed

README.md

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# stenodb [![](https://img.shields.io/npm/v/stenodb)](https://www.npmjs.org/package/stenodb)
22

3-
> ✍ Easy to use local JSON database. Ready to use with [LocalStorage](https://developer.mozilla.org/ru/docs/Web/API/Window/localStorage), [SessionStorage](https://developer.mozilla.org/ru/docs/Web/API/Window/sessionStorage) and Node.js.
3+
> ✍ Easy to use local JSON database. Ready to use with [LocalStorage](https://developer.mozilla.org/ru/docs/Web/API/Window/localStorage), [SessionStorage](https://developer.mozilla.org/ru/docs/Web/API/Window/sessionStorage) and [Node.js](https://nodejs.org).
44
55
## Install
66

@@ -16,14 +16,20 @@ yarn add stenodb
1616
pnpm add stenodb
1717
```
1818

19+
| Package | Version | Platform |
20+
| ------- | ------ | ----------- |
21+
| [stenodb](./packages/stenodb) | [![](https://img.shields.io/npm/v/stenodb)](https://npm.im/stenodb) | Reexports packages |
22+
| [@stenodb/node](./packages/node) | [![](https://img.shields.io/npm/v/@stenodb/node)](https://npm.im/@stenodb/node) | Node.js |
23+
| [@stenodb/browser](./packages/browser) | [![](https://img.shields.io/npm/v/@stenodb/browser)](https://npm.im/@stenodb/browser) | Browser |
24+
1925
## Usage
2026

2127
> **Warning**\
2228
> stenodb is a pure ESM package. If you're having trouble using it in your project, please [read this](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c).
2329
24-
25-
### Entity
30+
### Database entities
2631
```typescript
32+
// entities.ts
2733
import { Type } from 'class-transformer'
2834

2935
export class Users {
@@ -60,55 +66,48 @@ export class Post {
6066
}
6167
```
6268

63-
### Node.js
69+
### `@stenodb/node`
6470

6571
```typescript
6672
import 'reflect-metadata'
67-
import { join } from 'node:path'
68-
import { NodeProvider } from 'stenodb/node'
73+
import { dirname, resolve } from 'node:path'
74+
import { fileURLToPath } from 'node:url'
75+
import { AsyncWriter, NodeDatabase } from '@stenodb/node'
6976
import { Users, User, Post } from './entities.js'
7077

7178
const path = resolve(dirname(fileURLToPath(import.meta.url)), '..', 'database')
79+
const adapter = new AsyncWriter('users', Users)
80+
const initialData = new Users(new User('John Doe'))
81+
const database = new NodeDatabase(path)
82+
const databaseUsers = database.create(adapter, initialData)
7283

73-
const databaseProvider = new NodeProvider({
74-
path,
75-
logger: { enabled: true }
76-
})
77-
78-
const databaseUsers = databaseProvider.createDatabase({
79-
name: 'users',
80-
entity: Users,
81-
initialData: new Users(new User('John Doe'))
82-
})
83-
84+
await databaseUsers.read()
8485
databaseUsers.data?.users[0]?.addPost(new Post('Lorem ipsum'))
85-
databaseUsers.write()
86+
await databaseUsers.write()
8687
```
8788

88-
### Browser
89+
### `@stenodb/browser`
8990
```typescript
9091
import 'reflect-metadata'
91-
import { BrowserProvider, LocalStorage } from 'stenodb/browser'
92+
import { LocalStorage, BrowserDatabase } from '@stenodb/browser'
9293
import { Users, User, Post } from './entities.js'
9394

94-
const adapter = new LocalStorage<Users>('users')
95-
96-
const databaseUsers = new BrowserProvider({
97-
adapter,
98-
entity: Users,
99-
initialData: new Users(new User('John Doe'))
100-
})
95+
const adapter = new LocalStorage('users', Users)
96+
const initialData = new Users(new User('John Doe'))
97+
const databaseUsers = new BrowserDatabase(adapter, initialData)
10198

99+
databaseUsers.read()
102100
databaseUsers.data?.users[0]?.addPost(new Post('Lorem ipsum'))
103101
databaseUsers.write()
104102
```
105103

106-
## Related
104+
## Credits
107105

108106
- [steno](https://github.com/typicode/steno) - Specialized fast async file writer.
109107
- [class-transformer](https://github.com/typestack/class-transformer) - Decorator-based transformation, serialization, and deserialization between objects and classes.
110108
- [class-validator](https://github.com/typestack/class-validator) - Decorator-based property validation for classes.
111109
- [json-difference](https://github.com/lukascivil/json-difference) - A simple way to find the difference between two objects or json diff.
110+
- [tslog](https://github.com/fullstack-build/tslog) - Universal Logger for TypeScript and JavaScript.
112111

113112
## License
114113

packages/browser/README.md

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
# @stenodb/browser [![](https://img.shields.io/npm/v/@stenodb/browser)](https://www.npmjs.org/package/@stenodb/browser)
2+
3+
> ✍ Easy to use local JSON database for [LocalStorage](https://developer.mozilla.org/ru/docs/Web/API/Window/localStorage) and [SessionStorage](https://developer.mozilla.org/ru/docs/Web/API/Window/sessionStorage).
4+
5+
## Install
6+
7+
```sh
8+
npm install @stenodb/browser
9+
```
10+
11+
```sh
12+
yarn add @stenodb/browser
13+
```
14+
15+
```sh
16+
pnpm add @stenodb/browser
17+
```
18+
19+
## Usage
20+
21+
> **Warning**\
22+
> stenodb is a pure ESM package. If you're having trouble using it in your project, please [read this](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c).
23+
24+
```typescript
25+
// entities.ts
26+
import { Type } from 'class-transformer'
27+
28+
export class Users {
29+
@Type(() => User)
30+
users: User[]
31+
32+
constructor(...users: User[]) {
33+
this.users = users
34+
}
35+
}
36+
37+
export class User {
38+
username: string
39+
40+
@Type(() => Post)
41+
posts: Post[]
42+
43+
constructor(username: string, ...posts: Post[]) {
44+
this.username = username
45+
this.posts = posts
46+
}
47+
48+
addPost(post: Post) {
49+
this.posts.push(post)
50+
}
51+
}
52+
53+
export class Post {
54+
title: string
55+
56+
constructor(text: string) {
57+
this.title = title
58+
}
59+
}
60+
```
61+
62+
```typescript
63+
// index.ts
64+
import 'reflect-metadata'
65+
import { LocalStorage, BrowserDatabase } from '@stenodb/browser'
66+
import { Users, User, Post } from './entities.js'
67+
68+
const adapter = new LocalStorage('users', Users)
69+
const initialData = new Users(new User('John Doe'))
70+
const databaseUsers = new BrowserDatabase(adapter, initialData)
71+
72+
databaseUsers.read()
73+
databaseUsers.data?.users[0]?.addPost(new Post('Lorem ipsum'))
74+
databaseUsers.write()
75+
```
76+
77+
## Credits
78+
79+
- [steno](https://github.com/typicode/steno) - Specialized fast async file writer.
80+
- [class-transformer](https://github.com/typestack/class-transformer) - Decorator-based transformation, serialization, and deserialization between objects and classes.
81+
- [class-validator](https://github.com/typestack/class-validator) - Decorator-based property validation for classes.
82+
- [json-difference](https://github.com/lukascivil/json-difference) - A simple way to find the difference between two objects or json diff.
83+
- [tslog](https://github.com/fullstack-build/tslog) - Universal Logger for TypeScript and JavaScript.
84+
85+
## License
86+
87+
MIT - [crashmax](https://github.com/crashmax-dev)

packages/node/README.md

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
# @stenodb/node [![](https://img.shields.io/npm/v/@stenodb/node)](https://www.npmjs.org/package/@stenodb/node)
2+
3+
> ✍ Easy to use local JSON database for [Node.js](https://nodejs.org).
4+
5+
## Install
6+
7+
```sh
8+
npm install @stenodb/node
9+
```
10+
11+
```sh
12+
yarn add @stenodb/node
13+
```
14+
15+
```sh
16+
pnpm add @stenodb/node
17+
```
18+
19+
## Usage
20+
21+
> **Warning**\
22+
> stenodb is a pure ESM package. If you're having trouble using it in your project, please [read this](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c).
23+
24+
```typescript
25+
// entities.ts
26+
import { Type } from 'class-transformer'
27+
28+
export class Users {
29+
@Type(() => User)
30+
users: User[]
31+
32+
constructor(...users: User[]) {
33+
this.users = users
34+
}
35+
}
36+
37+
export class User {
38+
username: string
39+
40+
@Type(() => Post)
41+
posts: Post[]
42+
43+
constructor(username: string, ...posts: Post[]) {
44+
this.username = username
45+
this.posts = posts
46+
}
47+
48+
addPost(post: Post) {
49+
this.posts.push(post)
50+
}
51+
}
52+
53+
export class Post {
54+
title: string
55+
56+
constructor(text: string) {
57+
this.title = title
58+
}
59+
}
60+
```
61+
62+
```typescript
63+
// index.ts
64+
import 'reflect-metadata'
65+
import { dirname, resolve } from 'node:path'
66+
import { fileURLToPath } from 'node:url'
67+
import { AsyncWriter, NodeDatabase } from '@stenodb/node'
68+
import { Users, User, Post } from './entities.js'
69+
70+
const path = resolve(dirname(fileURLToPath(import.meta.url)), '..', 'database')
71+
const adapter = new AsyncWriter('users', Users)
72+
const initialData = new Users(new User('John Doe'))
73+
const database = new NodeDatabase(path)
74+
const databaseUsers = database.create(adapter, initialData)
75+
76+
await databaseUsers.read()
77+
databaseUsers.data?.users[0]?.addPost(new Post('Lorem ipsum'))
78+
await databaseUsers.write()
79+
```
80+
81+
## Credits
82+
83+
- [steno](https://github.com/typicode/steno) - Specialized fast async file writer.
84+
- [class-transformer](https://github.com/typestack/class-transformer) - Decorator-based transformation, serialization, and deserialization between objects and classes.
85+
- [class-validator](https://github.com/typestack/class-validator) - Decorator-based property validation for classes.
86+
- [json-difference](https://github.com/lukascivil/json-difference) - A simple way to find the difference between two objects or json diff.
87+
- [tslog](https://github.com/fullstack-build/tslog) - Universal Logger for TypeScript and JavaScript.
88+
89+
## License
90+
91+
MIT - [crashmax](https://github.com/crashmax-dev)

packages/stenodb/README.md

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
# stenodb [![](https://img.shields.io/npm/v/stenodb)](https://www.npmjs.org/package/stenodb)
2+
3+
> ✍ Easy to use local JSON database. Ready to use with [LocalStorage](https://developer.mozilla.org/ru/docs/Web/API/Window/localStorage), [SessionStorage](https://developer.mozilla.org/ru/docs/Web/API/Window/sessionStorage) and Node.js.
4+
5+
## Install
6+
7+
```sh
8+
npm install stenodb
9+
```
10+
11+
```sh
12+
yarn add stenodb
13+
```
14+
15+
```sh
16+
pnpm add stenodb
17+
```
18+
19+
| Package | Version | Description |
20+
| ------- | ------ | ----------- |
21+
| [stenodb](./packages/stenodb) | [![](https://img.shields.io/npm/v/stenodb)](https://npm.im/stenodb) | Meta package |
22+
| [@stenodb/node](./packages/node) | [![](https://img.shields.io/npm/v/@stenodb/node)](https://npm.im/@stenodb/node) | ... |
23+
| [@stenodb/browser](./packages/browser) | [![](https://img.shields.io/npm/v/@stenodb/browser)](https://npm.im/@stenodb/browser) | ... |
24+
25+
## Usage
26+
27+
> **Warning**\
28+
> stenodb is a pure ESM package. If you're having trouble using it in your project, please [read this](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c).
29+
30+
31+
### Database entities
32+
```typescript
33+
import { Type } from 'class-transformer'
34+
35+
export class Users {
36+
@Type(() => User)
37+
users: User[]
38+
39+
constructor(...users: User[]) {
40+
this.users = users
41+
}
42+
}
43+
44+
export class User {
45+
username: string
46+
47+
@Type(() => Post)
48+
posts: Post[]
49+
50+
constructor(username: string, ...posts: Post[]) {
51+
this.username = username
52+
this.posts = posts
53+
}
54+
55+
addPost(post: Post) {
56+
this.posts.push(post)
57+
}
58+
}
59+
60+
export class Post {
61+
title: string
62+
63+
constructor(text: string) {
64+
this.title = title
65+
}
66+
}
67+
```
68+
69+
### `@stenodb/node`
70+
71+
```typescript
72+
import 'reflect-metadata'
73+
import { join } from 'node:path'
74+
import { AsyncWriter, NodeDatabase } from '@stenodb/node'
75+
import { Users, User, Post } from './entities.js'
76+
77+
const path = resolve(dirname(fileURLToPath(import.meta.url)), '..', 'database')
78+
const adapter = new AsyncWriter('users', Users)
79+
const initialData = new Users(new User('John Doe'))
80+
const database = new NodeDatabase(path)
81+
const databaseUsers = database.create(adapter, initialData)
82+
83+
await databaseUsers.read()
84+
databaseUsers.data?.users[0]?.addPost(new Post('Lorem ipsum'))
85+
await databaseUsers.write()
86+
```
87+
88+
### `@stenodb/browser`
89+
```typescript
90+
import 'reflect-metadata'
91+
import { LocalStorage, BrowserDatabase } from '@stenodb/browser'
92+
import { Users, User, Post } from './entities.js'
93+
94+
const adapter = new LocalStorage('users', Users)
95+
const initialData = new Users(new User('John Doe'))
96+
const databaseUsers = new BrowserDatabase(adapter, initialData)
97+
98+
databaseUsers.read()
99+
databaseUsers.data?.users[0]?.addPost(new Post('Lorem ipsum'))
100+
databaseUsers.write()
101+
```
102+
103+
## Related
104+
105+
- [steno](https://github.com/typicode/steno) - Specialized fast async file writer.
106+
- [class-transformer](https://github.com/typestack/class-transformer) - Decorator-based transformation, serialization, and deserialization between objects and classes.
107+
- [class-validator](https://github.com/typestack/class-validator) - Decorator-based property validation for classes.
108+
- [json-difference](https://github.com/lukascivil/json-difference) - A simple way to find the difference between two objects or json diff.
109+
110+
## License
111+
112+
MIT - [crashmax](https://github.com/crashmax-dev)

packages/utils/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# @stenodb/utils

0 commit comments

Comments
 (0)