doxum 0.1.1

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.
Files changed (36) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +218 -0
  3. package/dist/chunk-pbuEa-1d.js +13 -0
  4. package/dist/contract-DwNiKioc.d.ts +480 -0
  5. package/dist/contract-Otb5W6cQ.d.cts +480 -0
  6. package/dist/dependency-BdEMyquf.js +735 -0
  7. package/dist/dependency-BdEMyquf.js.map +1 -0
  8. package/dist/dependency-DLcCvNKq.cjs +1015 -0
  9. package/dist/dependency-DLcCvNKq.cjs.map +1 -0
  10. package/dist/index.cjs +2718 -0
  11. package/dist/index.cjs.map +1 -0
  12. package/dist/index.d.cts +89 -0
  13. package/dist/index.d.ts +87 -0
  14. package/dist/index.js +2689 -0
  15. package/dist/index.js.map +1 -0
  16. package/dist/integration.cjs +15 -0
  17. package/dist/integration.cjs.map +1 -0
  18. package/dist/integration.d.cts +11 -0
  19. package/dist/integration.d.ts +11 -0
  20. package/dist/integration.js +14 -0
  21. package/dist/integration.js.map +1 -0
  22. package/dist/react.cjs +99 -0
  23. package/dist/react.cjs.map +1 -0
  24. package/dist/react.d.cts +16 -0
  25. package/dist/react.d.ts +16 -0
  26. package/dist/react.js +96 -0
  27. package/dist/react.js.map +1 -0
  28. package/package.json +89 -0
  29. package/skills/doxum-runtime/SKILL.md +51 -0
  30. package/skills/doxum-runtime/agents/openai.yaml +4 -0
  31. package/skills/doxum-runtime/references/guide.en.md +295 -0
  32. package/skills/doxum-runtime/references/guide.zh-CN.md +240 -0
  33. package/skills/doxum-runtime/references/invariants.en.md +147 -0
  34. package/skills/doxum-runtime/references/invariants.zh-CN.md +97 -0
  35. package/skills/doxum-runtime/references/patterns.en.md +287 -0
  36. package/skills/doxum-runtime/references/patterns.zh-CN.md +240 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Isrowan
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 ADDED
@@ -0,0 +1,218 @@
1
+ # Doxum
2
+
3
+ Doxum is a typed TypeScript runtime for complex mutable documents. It is built
4
+ for editors and product surfaces that need structured state, atomic updates,
5
+ undo/redo, precise change notifications, and incremental derived data.
6
+
7
+ Licensed under the [MIT License](LICENSE).
8
+
9
+ It is a local in-memory runtime. Persistence, synchronization, authorization,
10
+ and conflict resolution are intentionally application concerns.
11
+
12
+ ## Packages
13
+
14
+ - `doxum` defines schemas, mutations, history, subscriptions, and views.
15
+ - `doxum/react` binds Doxum read models to React 18+ with fine-grained external
16
+ store subscriptions.
17
+
18
+ ## Install
19
+
20
+ ```sh
21
+ pnpm add doxum
22
+ ```
23
+
24
+ For React bindings, install React alongside Doxum and import from `doxum/react`:
25
+
26
+ ```sh
27
+ pnpm add doxum react
28
+ ```
29
+
30
+ Use the package manager that owns your application if it is not pnpm.
31
+
32
+ ## AI Development Guide
33
+
34
+ Doxum ships a task-oriented guide for AI assistants and application developers.
35
+ It is the recommended reference for using `doxum` and `doxum/react` in place
36
+ of a generated, symbol-by-symbol API reference. The guide is included in the
37
+ published `doxum` package at `skills/doxum-runtime`.
38
+
39
+ - [English guide](skills/doxum-runtime/references/guide.en.md)
40
+ - [中文指南](skills/doxum-runtime/references/guide.zh-CN.md)
41
+ - [English patterns](skills/doxum-runtime/references/patterns.en.md)
42
+ - [中文模式参考](skills/doxum-runtime/references/patterns.zh-CN.md)
43
+ - [English invariants](skills/doxum-runtime/references/invariants.en.md)
44
+ - [中文不变量](skills/doxum-runtime/references/invariants.zh-CN.md)
45
+ - [AI skill instructions](skills/doxum-runtime/SKILL.md)
46
+
47
+ Tools that support `SKILL.md` can install or link the complete
48
+ `doxum-runtime` directory as the `$doxum-runtime` skill. The files are also
49
+ ordinary Markdown: read the guide matching your working language, then use the
50
+ patterns and invariants references for the task at hand.
51
+
52
+ ## Quick Start
53
+
54
+ Define the document shape once. Doxum infers the immutable document value and
55
+ the reader and writer APIs from that schema.
56
+
57
+ ```ts
58
+ import { createDocument, field, object, schema, table } from 'doxum';
59
+
60
+ const task = object({
61
+ title: field<string>(),
62
+ completed: field<boolean>(),
63
+ });
64
+
65
+ const taskSchema = schema({
66
+ title: field<string>(),
67
+ tasks: table(task),
68
+ });
69
+
70
+ const runtime = createDocument({
71
+ schema: taskSchema,
72
+ initial: {
73
+ title: 'Launch',
74
+ tasks: {
75
+ ids: ['task-1'],
76
+ byId: {
77
+ 'task-1': { title: 'Write the brief', completed: false },
78
+ },
79
+ },
80
+ },
81
+ });
82
+
83
+ runtime.update(tx => {
84
+ tx.write.tasks.item('task-1').completed.set(true);
85
+ return tx.read.tasks.get('task-1')?.title.get();
86
+ });
87
+ ```
88
+
89
+ An update is synchronous and atomic. `apply` decodes untrusted operation
90
+ payloads before they reach mutation code. A malformed or semantically rejected
91
+ operation returns a typed `MutationIssue`; if an operation is rejected, if the
92
+ transaction calls `tx.reject`, or if user code throws, every preceding change
93
+ in that update is rolled back.
94
+
95
+ Mutation failure codes are a closed public `MutationIssueCode` union. For
96
+ application validation, use `tx.report` or `tx.reject` with a
97
+ `DocumentDiagnostic`; published diagnostic arrays and addresses are copied and
98
+ frozen.
99
+
100
+ ## Read And Subscribe
101
+
102
+ Use `select` for a one-off typed read. Use schema selectors and `subscribe`
103
+ when a non-React consumer needs only relevant commits.
104
+
105
+ ```ts
106
+ import { select } from 'doxum';
107
+
108
+ const taskTitles = select(runtime, read =>
109
+ read.tasks.ids().map(id => read.tasks.get(id)?.title.get())
110
+ );
111
+
112
+ const tasks = taskSchema.collection(path => path.tasks);
113
+ const stop = runtime.subscribe(tasks, commit => {
114
+ const change = commit.impact.collection(tasks);
115
+ if (change.kind === 'incremental') console.log(change.updated);
116
+ });
117
+
118
+ stop();
119
+ ```
120
+
121
+ Each committed update produces a revision, forward operations, inverse
122
+ operations, and a `DocumentImpact`. Collection impacts distinguish added,
123
+ removed, updated, and reordered entries.
124
+
125
+ ## History And Operations
126
+
127
+ Local history is enabled by default with a capacity of 100 commits. Doxum
128
+ records inverse operations, so undo and redo follow the same mutation path as
129
+ ordinary updates.
130
+
131
+ ```ts
132
+ runtime.history.undo();
133
+ runtime.history.redo();
134
+
135
+ runtime.apply([{ type: 'field.set', at: ['title'], value: 'Ship Doxum' }]);
136
+ ```
137
+
138
+ `apply` is the boundary for replaying operations from persistence or a network
139
+ adapter. Doxum does not provide those adapters. A `replace` or a commit marked
140
+ as `remote` invalidates local history because its prior inverse sequence is no
141
+ longer authoritative.
142
+
143
+ The returned result distinguishes `committed`, `unchanged`, and `rejected`.
144
+ Observer failures do not turn a completed write into a rejection: committed
145
+ results expose them in `observerErrors`, after history and canonical state have
146
+ already settled.
147
+
148
+ ## React
149
+
150
+ `useDocumentSelector` learns the paths read by its selector and re-renders only
151
+ when a matching commit changes the selected result.
152
+
153
+ ```tsx
154
+ import { useDocumentSelector } from 'doxum/react';
155
+
156
+ function TaskCount() {
157
+ const count = useDocumentSelector(runtime, read => read.tasks.ids().length);
158
+ return <output>{count}</output>;
159
+ }
160
+ ```
161
+
162
+ Use `useReadable` and `useHistory` with Doxum collection
163
+ views, materialized views, and history state.
164
+
165
+ ## Derived Views
166
+
167
+ `createCollectionView` incrementally projects one table or map into `ids`,
168
+ `all`, and cached `item(id)` readables. `createMaterializedView` is for
169
+ indexes and aggregates that need custom incremental update logic. A materialized
170
+ view may depend on earlier views from the same runtime; Doxum settles that graph
171
+ before notifying external listeners.
172
+
173
+ ## Data Ownership
174
+
175
+ Doxum clones the initial document. Structural values supplied through operations
176
+ are transferred to its mutable canonical document, while published commit and
177
+ history payloads are immutable snapshots. Treat data passed to an update as
178
+ owned by Doxum after the call unless the value is intentionally immutable.
179
+
180
+ Tree replacement snapshots are an exception: Doxum validates and clones the
181
+ tree structure so a caller cannot later corrupt its single-root, connected,
182
+ acyclic representation. Tree insert and move operations preserve the same
183
+ invariant.
184
+
185
+ ## Development
186
+
187
+ ```sh
188
+ pnpm install
189
+ pnpm run check
190
+ pnpm run build
191
+ pnpm run bench
192
+ pnpm run profile
193
+ ```
194
+
195
+ See [the architecture guide](docs/architecture.md) for the runtime pipeline and
196
+ [AGENTS.md](AGENTS.md) for contribution rules.
197
+
198
+ ## Release
199
+
200
+ `doxum` is released as one package. A normal release always increments the
201
+ patch version:
202
+
203
+ ```sh
204
+ pnpm release
205
+ ```
206
+
207
+ Run it only from a clean, synchronized `main` branch. The command verifies the
208
+ logged-in npm account, updates both public package versions, runs the complete
209
+ check and build, verifies the publish tarball, publishes the package, then
210
+ creates and pushes a `vX.Y.Z` release commit and tag.
211
+
212
+ If npm accepts one package but the command cannot finish, it preserves the
213
+ release state rather than reverting a version that may already be public. Fix
214
+ the external failure and continue with:
215
+
216
+ ```sh
217
+ pnpm release:resume
218
+ ```
@@ -0,0 +1,13 @@
1
+ //#region \0rolldown/runtime.js
2
+ var __defProp = Object.defineProperty;
3
+ var __exportAll = (all, no_symbols) => {
4
+ let target = {};
5
+ for (var name in all) __defProp(target, name, {
6
+ get: all[name],
7
+ enumerable: true
8
+ });
9
+ if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
10
+ return target;
11
+ };
12
+ //#endregion
13
+ export { __exportAll as t };