# live-data-sync

> Persist and restore the application state.

Latest version **1.0.5** (published 2026-01-27) · BSD-2-Clause license · 0 weekly downloads

## Install

```sh
npm install live-data-sync
pnpm add live-data-sync
yarn add live-data-sync
bun add live-data-sync
```

## Health

**Score 60/100 (C)** — status: stable.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 1.0.5 |
| Published | 2026-01-27 |
| First published | 2021-11-02 |
| Weekly downloads | 0 |
| License | BSD-2-Clause |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 4 |
| Unpacked size | 66.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Beeno Tung |
| Maintainers | beenotung |
| Keywords | persistent, immutable, in-memory, better-sqlite3, data-store, web-redux, redux-store, sync |

## Links

- npm: https://www.npmjs.com/package/live-data-sync
- Repository: https://github.com/beenotung/live-data-sync
- Homepage: https://github.com/beenotung/live-data-sync#readme
- Issues: https://github.com/beenotung/live-data-sync/issues
- npm.io page: https://npm.io/package/live-data-sync

## Dependencies (4)

- [tslib](https://npm.io/package/tslib.md) ^2.8.1
- [better-sqlite3](https://npm.io/package/better-sqlite3.md) ^12.6.2
- [better-sqlite3-schema](https://npm.io/package/better-sqlite3-schema.md) ^3.1.10
- [@beenotung/better-sqlite3-helper](https://npm.io/package/@beenotung/better-sqlite3-helper.md) ^4.1.9

## Alternatives

- [@reckona/mreact-store](https://npm.io/package/@reckona/mreact-store.md) — 976 weekly downloads
- [regular-state](https://npm.io/package/regular-state.md) — 410 weekly downloads
- [@pacote/flux-actions](https://npm.io/package/@pacote/flux-actions.md) — 65 weekly downloads
- [@pilotlab/lux-debug](https://npm.io/package/@pilotlab/lux-debug.md) — 39 weekly downloads
- [vue-persist-state](https://npm.io/package/vue-persist-state.md) — 19 weekly downloads

## Recent versions

- 1.0.5 (latest) — 2026-01-27
- 1.0.4 — 2026-01-27
- 1.0.3 — 2022-01-30
- 1.0.2 — 2021-12-26
- 1.0.1 — 2021-12-25
- 1.0.0 — 2021-11-14
- 0.0.0 — 2021-11-02

## README

# live-data-sync

Persist and restore the application state. Designed for [web-redux](https://github.com/beenotung/web-redux)

[![npm Package Version](https://img.shields.io/npm/v/live-data-sync.svg?maxAge=3600)](https://www.npmjs.com/package/live-data-sync)

## Features

- Support nested array and object
- Only store incremental update (instead of full snapshot)
- Backed by sqlite in sync mode (which is faster than async mode)
- 100% test coverage
- Using append-only log, with on-demand compaction

## Usage Example

### Create a better-sqlite3 DBInstance

```typescript
import { newDB } from 'better-sqlite3-schema'

let db = newDB({
  path: 'state.db',
  migrate: false,
})
```

### Create a persistent Dict

A dict can contains multiple objects.
Each object is a "singleton" key-value pair.

```typescript
import { Dict } from 'live-data-sync'

let dict = new Dict(db)

// init values if not exists
dict.init('config', {
  version: '1.0.0',
  JWT_SECRET: process.env.JWT_SECRET,
})

dict.data.version
// '1.0.0'

// partial update
dict.update('config', {
  version: '1.0.1',
})

dict.data.version
// '1.0.1'

dict.delete('config')
dict.data.config
// {}
```

For more usage example, refers to [dict.spec.ts](./test/dict.spec.ts)

### Create a persistent Collection

A collection can contains multiple type of objects.
Each object is an "instance of" key-value pair sharing similar fields of it's type.

```typescript
import { Collection, Int, ObjectDict } from 'live-data-sync'

let collection = new Collection<{
  users: ObjectDict<{ name: string }>
  posts: ObjectDict<{ user_id: Int; content: string }>
}>(db)

let user_id = collection.add('users', { name: 'alice' })
// 1
let post_id = collection.add('posts', { user_id, content: 'Hello World' })
// 2

collection.data.posts[post_id as number].content
// 'Hello World'

// partial update
collection.update('posts', post_id, { content: 'Hi' })

collection.data.posts[post_id as number]
// { user_id: 1, content: 'Hi' }

collection.delete('posts', post_id)

collection.data.posts[post_id as number]
// undefined
```

For more usage example, refers to [collection.spec.ts](./test/collection.spec.ts)

## License

This project is licensed with [BSD-2-Clause](./LICENSE)

This is free, libre, and open-source software. It comes down to four essential freedoms [[ref]](https://seirdy.one/2021/01/27/whatsapp-and-the-domestication-of-users.html#fnref:2):

- The freedom to run the program as you wish, for any purpose
- The freedom to study how the program works, and change it so it does your computing as you wish
- The freedom to redistribute copies so you can help others
- The freedom to distribute copies of your modified versions to others

---
_Source: https://npm.io/package/live-data-sync · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
