duratom 0.0.0-stage → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +86 -2
- package/dist/chunk-7TXOG3GB.js +973 -0
- package/dist/chunk-URKFBGPT.js +165 -0
- package/dist/core/index.d.ts +150 -0
- package/dist/core/index.js +44 -0
- package/dist/equality-AjtpnVrF.d.ts +20 -0
- package/dist/index.d.ts +102 -0
- package/dist/index.js +182 -0
- package/dist/react/index.d.ts +52 -0
- package/dist/react/index.js +43 -0
- package/dist/shape-CMa7XFjy.d.ts +390 -0
- package/dist/typed-atom-t7tvnXSS.d.ts +127 -0
- package/llms-full.txt +1658 -0
- package/llms.txt +24 -0
- package/package.json +102 -3
- package/skills/duratom/SKILL.md +171 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Karol Novljaković
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,87 @@
|
|
|
1
|
-
#
|
|
1
|
+
# duratom
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Durable, live Jotai atoms over a Y.Doc: read typed values, write validated patches, and re-render only when what an atom shows changes.
|
|
4
|
+
|
|
5
|
+
A [Y.Doc](https://docs.yjs.dev) is the shared, conflict-free state that sync providers keep the same on every device. duratom turns a node of it into a Jotai atom: you read a value your schema has checked, you write a patch that is merged into the doc and validated first, and a component re-renders only when the value it shows changes, whoever changed the doc. Persistence and network sync come from existing Yjs providers; duratom has no provider code of its own.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install duratom jotai jotai-family yjs
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Add a [Standard Schema](https://standardschema.dev) validator for typed atoms, such as zod, valibot or arktype, and React for `duratom/react`. duratom needs `yjs` 13.6.33 or later, `jotai` 2.9 or later and `jotai-family`.
|
|
14
|
+
|
|
15
|
+
## Quick start
|
|
16
|
+
|
|
17
|
+
Paste this into `src/main.tsx` of a new Vite React app (`npm create vite@latest my-app -- --template react-ts`), then `npm install duratom jotai jotai-family yjs zod` and `npm run dev`.
|
|
18
|
+
|
|
19
|
+
<!-- snippet: docs/snippets/quick-start.tsx -->
|
|
20
|
+
|
|
21
|
+
```tsx
|
|
22
|
+
// src/main.tsx of a new Vite React app: npm create vite@latest my-app -- --template react-ts
|
|
23
|
+
import { docAtom, select, typedAtom } from 'duratom'
|
|
24
|
+
import { createStore, Provider, useAtom } from 'jotai'
|
|
25
|
+
import { StrictMode } from 'react'
|
|
26
|
+
import { createRoot } from 'react-dom/client'
|
|
27
|
+
import * as Y from 'yjs'
|
|
28
|
+
import { z } from 'zod'
|
|
29
|
+
|
|
30
|
+
// What a todo is, and where it lives in the doc: the map `first` in the root map `todos`.
|
|
31
|
+
// `title` is collaborative text, so two people typing in it both keep their edits.
|
|
32
|
+
const Todo = z.object({ title: z.string(), done: z.boolean() })
|
|
33
|
+
const todoAtom = typedAtom(select.map('todos').child('first'), Todo, { title: 'text' })
|
|
34
|
+
|
|
35
|
+
// One Y.Doc per Jotai store. A sync provider would connect this doc to other devices.
|
|
36
|
+
const store = createStore()
|
|
37
|
+
store.set(docAtom, new Y.Doc())
|
|
38
|
+
|
|
39
|
+
function TodoRow() {
|
|
40
|
+
// undefined while the todo is missing, { issues } while it's invalid, { value } otherwise.
|
|
41
|
+
const [todo, setTodo] = useAtom(todoAtom)
|
|
42
|
+
if (!todo) {
|
|
43
|
+
// Setting a missing node with a whole valid value creates it.
|
|
44
|
+
return <button onClick={() => setTodo({ title: 'Learn duratom', done: false })}>Add</button>
|
|
45
|
+
}
|
|
46
|
+
if (todo.issues) return <p>Can't read this todo: {todo.issues[0]?.message}</p>
|
|
47
|
+
return (
|
|
48
|
+
<label>
|
|
49
|
+
{/* A patch changes only the fields it names. */}
|
|
50
|
+
<input
|
|
51
|
+
type="checkbox"
|
|
52
|
+
checked={todo.value.done}
|
|
53
|
+
onChange={(e) => setTodo({ done: e.target.checked })}
|
|
54
|
+
/>
|
|
55
|
+
<input value={todo.value.title} onChange={(e) => setTodo({ title: e.target.value })} />
|
|
56
|
+
</label>
|
|
57
|
+
)
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
createRoot(document.getElementById('root')!).render(
|
|
61
|
+
<StrictMode>
|
|
62
|
+
<Provider store={store}>
|
|
63
|
+
<TodoRow />
|
|
64
|
+
</Provider>
|
|
65
|
+
</StrictMode>,
|
|
66
|
+
)
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
<!-- /snippet -->
|
|
70
|
+
|
|
71
|
+
Add a sync provider to the doc ([sync recipe](https://duratom.karolnov.dev/recipes/sync)) and the same atom shows and edits the todo on every device, with no change to the atom or the component.
|
|
72
|
+
|
|
73
|
+
## Docs
|
|
74
|
+
|
|
75
|
+
Everything else is at **[duratom.karolnov.dev](https://duratom.karolnov.dev)**: the guide, recipes for sync and offline storage, and the API reference.
|
|
76
|
+
|
|
77
|
+
For AI agents, the npm package ships [`llms-full.txt`](llms-full.txt) (every doc in one file) and an agent skill, [`skills/duratom/SKILL.md`](skills/duratom/SKILL.md), so an agent finds them in `node_modules/duratom`.
|
|
78
|
+
|
|
79
|
+
## Specs and blueprints
|
|
80
|
+
|
|
81
|
+
What each part of duratom must do is written down as **capability specs**: requirements with GIVEN / WHEN / THEN scenarios, one page per capability (`core/observe`, `schema`, `atoms`, `docs`). A planned change is a **blueprint**: a brief with the decisions, the tasks and a spec delta, plus a review for people. When the change is built, its delta is merged into the specs.
|
|
82
|
+
|
|
83
|
+
These come from the [`/blueprint` skills](https://github.com/KarolNov/skills/tree/main/skills/blueprint) in [KarolNov/skills](https://github.com/KarolNov/skills). The specs live outside the repo; [`.blueprint/`](.blueprint) maps each capability to the code that implements it and records when the two last agreed. `python3 .blueprint/drift.py check` lists capabilities whose code changed since then.
|
|
84
|
+
|
|
85
|
+
## License
|
|
86
|
+
|
|
87
|
+
MIT
|