doxum 0.1.23 → 0.1.26

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 (66) hide show
  1. package/README.md +208 -102
  2. package/dist/advanced.cjs +237 -2
  3. package/dist/advanced.cjs.map +1 -0
  4. package/dist/advanced.d.cts +90 -2
  5. package/dist/advanced.d.ts +90 -2
  6. package/dist/advanced.js +236 -1
  7. package/dist/advanced.js.map +1 -0
  8. package/dist/{contract-ULPQmiEs.d.ts → contract-CNR6BS75.d.cts} +216 -30
  9. package/dist/{contract-SYJFP0lM.d.cts → contract-COgxO5sv.d.ts} +216 -30
  10. package/dist/definition-CDOuvb5C.d.cts +111 -0
  11. package/dist/definition-xgk3YNBp.d.ts +111 -0
  12. package/dist/{driver-yFfvDMX5.js → driver-B5vdPohL.js} +59 -3
  13. package/dist/driver-B5vdPohL.js.map +1 -0
  14. package/dist/{driver-BD3DQOW6.cjs → driver-BL91gn7_.cjs} +107 -9
  15. package/dist/driver-BL91gn7_.cjs.map +1 -0
  16. package/dist/index.cjs +1637 -703
  17. package/dist/index.cjs.map +1 -1
  18. package/dist/index.d.cts +65 -33
  19. package/dist/index.d.ts +65 -33
  20. package/dist/index.js +1432 -497
  21. package/dist/index.js.map +1 -1
  22. package/dist/local-sync.cjs +69 -103
  23. package/dist/local-sync.cjs.map +1 -1
  24. package/dist/local-sync.d.cts +14 -26
  25. package/dist/local-sync.d.ts +14 -26
  26. package/dist/local-sync.js +68 -96
  27. package/dist/local-sync.js.map +1 -1
  28. package/dist/react.cjs +4 -5
  29. package/dist/react.cjs.map +1 -1
  30. package/dist/react.d.cts +6 -8
  31. package/dist/react.d.ts +6 -8
  32. package/dist/react.js +4 -5
  33. package/dist/react.js.map +1 -1
  34. package/dist/record-B2yRhYsc.js +28 -0
  35. package/dist/record-B2yRhYsc.js.map +1 -0
  36. package/dist/record-ChYUi8PP.cjs +45 -0
  37. package/dist/record-ChYUi8PP.cjs.map +1 -0
  38. package/dist/scheduler--137L3j-.js +500 -0
  39. package/dist/scheduler--137L3j-.js.map +1 -0
  40. package/dist/scheduler-D4VthaaK.cjs +589 -0
  41. package/dist/scheduler-D4VthaaK.cjs.map +1 -0
  42. package/package.json +6 -3
  43. package/skills/doxum-runtime/SKILL.md +32 -7
  44. package/skills/doxum-runtime/agents/openai.yaml +1 -1
  45. package/skills/doxum-runtime/references/api.en.md +249 -0
  46. package/skills/doxum-runtime/references/api.zh-CN.md +242 -0
  47. package/skills/doxum-runtime/references/guide.en.md +18 -8
  48. package/skills/doxum-runtime/references/guide.zh-CN.md +14 -6
  49. package/skills/doxum-runtime/references/invariants.en.md +29 -5
  50. package/skills/doxum-runtime/references/invariants.zh-CN.md +24 -6
  51. package/skills/doxum-runtime/references/patterns.en.md +78 -18
  52. package/skills/doxum-runtime/references/patterns.zh-CN.md +76 -18
  53. package/skills/doxum-runtime/references/projections.en.md +209 -119
  54. package/skills/doxum-runtime/references/projections.zh-CN.md +200 -101
  55. package/dist/advanced-CLJCWkHa.d.cts +0 -176
  56. package/dist/advanced-CRNHfJBu.js +0 -1224
  57. package/dist/advanced-CRNHfJBu.js.map +0 -1
  58. package/dist/advanced-Cle5g3B4.cjs +0 -1517
  59. package/dist/advanced-Cle5g3B4.cjs.map +0 -1
  60. package/dist/advanced-d6J61er9.d.ts +0 -176
  61. package/dist/context-BcLKGfq8.cjs +0 -149
  62. package/dist/context-BcLKGfq8.cjs.map +0 -1
  63. package/dist/context-DFEaDUv5.js +0 -84
  64. package/dist/context-DFEaDUv5.js.map +0 -1
  65. package/dist/driver-BD3DQOW6.cjs.map +0 -1
  66. package/dist/driver-yFfvDMX5.js.map +0 -1
@@ -1,136 +1,235 @@
1
1
  # Projection 参考
2
2
 
3
- 根 Projection 定义惰性且可跨 Runtime 复用;scope 定义惰性但只属于其局部生命周期。默认入口包含 `Projection<T>`、
4
- `ProjectionRuntime`、`input`、`observe` 和 tuple 形式的 `derive`。
3
+ 准确签名见 [API 参考](api.zh-CN.md)。这里说明 ownership、invalidation 与 recovery。
4
+
5
+ ## Ownership 与基础声明
6
+
7
+ Projection definition 是惰性的。root definition 可跨多个 runtime 复用;scope definition
8
+ 属于一个 `ProjectionScope`。公开 `Projection<T>` 本身不保存 materialized value、
9
+ retained state、subscription 或 disposal state。
10
+ `KeyedProjection<K,V>` 是对应的公开 keyed handle,也可以安全出现在下游 package
11
+ 生成的声明中。
5
12
 
6
13
  ```ts
7
14
  const tasks = observe(document, path => path.tasks);
8
15
  const filter = input<'all' | 'open'>('all');
9
- const visible = derive([tasks, filter], (tasks, filter) =>
10
- filter === 'all' ? tasks : new Map([...tasks].filter(([, task]) => !task.done))
16
+ const visible = derive({ tasks, filter }, ({ tasks, filter }) =>
17
+ filter === 'all' ? tasks : filterOpen(tasks)
11
18
  );
19
+
12
20
  const runtime = createProjectionRuntime({ onError: report });
13
- runtime.get(visible);
21
+ runtime.read(visible);
22
+ ```
23
+
24
+ `ProjectionRuntime` 是 materialization、retained state、source attachment、settlement、
25
+ publication 与 recovery 的唯一 owner。稳定 verb 为 `read`、`select`、overloaded
26
+ `update`、`batch`、`scope`、`dispose`。
27
+
28
+ `input(initial, equality?)` 是 scalar Runtime-local state;
29
+ `input.collection(initial?, equality?)` 是 keyed Runtime-local application/UI state。
30
+ 两者都不进入 canonical document 的 history/persistence。
31
+
32
+ ## Source boundary
33
+
34
+ `observe` 是唯一 source declaration 入口,可接入:
35
+
36
+ - whole `ReadonlyDocument` 或 schema-path selection;
37
+ - Doxum `Readable<T>`;
38
+ - 公开 external value/collection source contract。
39
+
40
+ Document 的 `map`、`table`、`list(field, { keyOf })` selection 会成为 keyed projection。
41
+ list identity 来自 schema `keyOf`;原子 array-valued field 仍是 scalar。
42
+
43
+ Tree 复用同一套 source model:
44
+
45
+ ```ts
46
+ const rootId = observe(document, path => path.outline.rootId);
47
+ const nodes = observe(document, path => path.outline.nodes);
48
+ const node = observe(document, path => path.outline.nodes.item(nodeId));
49
+ ```
50
+
51
+ `rootId` 是 scalar,`nodes` 是 keyed,`item(id)` 是单 node value。同一次 document
52
+ commit 影响的 source projection 会在同一个 Runtime causal batch 中 settle。
53
+
54
+ External collection impact 只是边界 invalidation hint。processor 看到之前,Runtime 会把
55
+ 它归一化为精确 `CollectionChange`。
56
+
57
+ ## Pure derive 与 keyed projection
58
+
59
+ `derive(dependencies, compute, equality?)` 始终使用 named dependency object。
60
+ definition 创建后依赖固定且显式。
61
+
62
+ 一个 keyed driver 拥有 output membership/order 时使用 `derive.keyed`:
63
+
64
+ ```ts
65
+ const fieldValues = derive.keyed(records, record => record.values[fieldId]);
66
+ ```
67
+
68
+ 只有受影响 driver entry 会执行 selector。per-entry equality 判定 selected value 相等时,
69
+ 该 key 不发布 `updated`;added、removed、order 语义保持不变。
70
+
71
+ Dynamic keyed lookup 仍使用同一个 API:
72
+
73
+ ```ts
74
+ const cardContent = derive.keyed(
75
+ items,
76
+ {
77
+ record: { source: records, key: item => item.recordId },
78
+ view: activeView,
79
+ fields: visibleFields,
80
+ },
81
+ (item, itemId, { record, view, fields }) => renderCard(itemId, item, record, view, fields)
82
+ );
14
83
  ```
15
84
 
16
- `input(initial, equality?)` 属于每个 Runtime,只能通过
17
- `runtime.set(input, value)` 写入。`observe(document, selector)` 延迟编译文档
18
- 边界;集合路径发布只读 map-like 快照,省略 selector 时发布整个文档快照。
19
- 现有 Doxum `Readable` 和带事件的 external source 也在这个边界接入。External
20
- source 通过 `kind: 'value'` 或 `kind: 'collection'` 区分语义,但调用方统一使用
21
- `observe(source)`。
85
+ 普通 Projection dependency 变化时使 driver key set 失效。`{ source, key }` 声明
86
+ output-key → dynamic source-key dependency;Runtime 拥有 forward binding 和 reverse
87
+ invalidation。selected source entry 缺失时仍保留 binding,因此以后新增该 source key
88
+ 会正确触发 dependent output key。
22
89
 
23
- schema map、table 和 `list(field, { keyOf })` 都是 keyed collection path。list
24
- 直接使用 schema 的 `keyOf` 作为稳定 identity,并按文档顺序迭代;数组类型的普通
25
- `field(...)` 仍然是 scalar value observation。
26
- tree 结构复用相同的 source 类型:`path.tree.rootId` 是 scalar,
27
- `path.tree.nodes` 是 keyed collection,`path.tree.nodes.item(id)` 是单节点 value。
28
- tree 的 committed node group 直接路由到受影响的 keyed entry,由现有
29
- `CollectionOutput` 生成普通 `CollectionChange`;未变化节点的 snapshot identity
30
- 保持稳定。
90
+ 这就是 keyed join 协议。不要再添加第二套 join abstraction、wildcard document path
91
+ grammar 或 processor 内 imperative dependency discovery。
31
92
 
32
- External event 不再复用 Runtime context:value event 提供新 `value` 和
33
- `revision`;collection event 提供稳定的 `previous` read、`revision` 和可选的
34
- `impact` hint。Runtime 自己计算精确的 `CollectionChange`,processor 不会直接收到
35
- impact。
93
+ ## Runtime 读取、更新与 scope
36
94
 
37
- `derive(dependencies, compute, equality?)` 使用 tuple,依赖在定义创建时固定。
38
- Processor 不能通过读取另一个 Projection 隐式建立图依赖。
95
+ ```ts
96
+ const value = runtime.read(visible);
97
+ const selected = runtime.select(visible, rows => rows.get(rowId), equality);
98
+ const stop = selected.subscribe(listener);
99
+
100
+ runtime.update(filter, 'open');
101
+ runtime.update(selection, draft => {
102
+ draft.set(rowId, true);
103
+ draft.remove(previousRowId);
104
+ });
105
+
106
+ runtime.batch(run, { cause });
107
+ ```
39
108
 
40
- Runtime 的公开脊柱只有:
109
+ `select` 返回标准 `Readable`。keyed selector 追踪相关 key/structure 读取;只有发生
110
+ 相关 invalidation 后才执行 selector,随后 equality 决定是否发布结果。
111
+
112
+ `CollectionInputDraft` 提供 `get`、`has`、`set`、`remove`,同步 edit callback 返回后
113
+ 失效。callback throw 时该次 edit 不应用。collection input equality 按 entry 比较,
114
+ 默认 `Object.is`,并在接受的本地状态安装前完成;equality 抛错时,published value 与
115
+ 下一次 draft 同样保持更新前状态。equal set 不替换存储值,也不发布。
41
116
 
42
117
  ```ts
43
- runtime.get(projection);
44
- const selected = runtime.readable(projection, value => value.get(id));
45
- selected.subscribe(listener);
46
- runtime.set(input, value);
47
- runtime.update(collectionInput, draft => draft.set(id, value));
48
- runtime.batch({ cause }, run);
49
118
  const scope = runtime.scope();
119
+ const localFilter = scope.own(input<'all' | 'open'>('all'));
120
+ const local = scope.own(
121
+ derive({ tasks, filter: localFilter }, ({ tasks, filter }) =>
122
+ filter === 'all' ? tasks : filterOpen(tasks)
123
+ )
124
+ );
125
+ scope.read(local);
126
+ scope.update(localFilter, 'open');
50
127
  scope.dispose();
51
- runtime.dispose();
52
128
  ```
53
129
 
54
- `input.collection<K, V>(initial?)` 声明 Runtime 本地 keyed 状态。`update` 的借用 draft
55
- 提供 `get`、`has`、`set`、`remove`;单次 callback 同步且原子,Runtime batch 发布一次
56
- 精确的净 `CollectionChange`。scope 用 `scope.input`、`scope.derive`、
57
- `scope.incremental` 声明局部投影,直接依赖同一 Runtime 中的根投影;dispose 只释放
58
- 局部 producer、状态和订阅。
130
+ scope 与 parent Runtime 共享 scheduler/materialization owner。`scope.own` 为 projection
131
+ definition 或静态 nested projection tree 赋予 lifecycle。scoped definition 可以依赖
132
+ root definition;root 或 sibling scope 不能依赖 scoped definition,同一个 definition
133
+ 也不能属于两个 scope。必须在 definition 首次作为 root materialize 之前确定 scope
134
+ ownership。
135
+
136
+ ## 唯一的 collection change 协议
137
+
138
+ 所有 keyed projection source/output 都使用:
139
+
140
+ ```ts
141
+ type CollectionChange<K extends string, V> =
142
+ | { kind: 'reset' }
143
+ | {
144
+ kind: 'incremental';
145
+ added: readonly { key: K; after: V }[];
146
+ updated: readonly { key: K; before: V; after: V }[];
147
+ removed: readonly { key: K; before: V }[];
148
+ order?: { before: readonly K[]; after: readonly K[] };
149
+ };
150
+ ```
151
+
152
+ advanced processor 需要显式标注该 transport type 时,从 `doxum/advanced` 导入
153
+ `CollectionChange`;root projection consumer 不需要从 package root 导入它。
154
+
155
+ initial materialization 和 source reset 对 advanced processor 报告 `reset`。
156
+ incremental transition 是 settle 后 batch 边界上的 exact net change。
59
157
 
60
- Runtime 的 scheduler/output internals、item handle、rebuild、release 都是内部事实,不是应用层操作;
61
- 只有 `Readable` 自己的 publication revision 为 store 集成保留为公开事实。
62
- Materialization、keyed storage、故障恢复和释放只有一个 owner。
158
+ ## Advanced processor
63
159
 
64
- ## 增量 Processor
160
+ 只有 retained state、cross-key index 或直接 incremental output patch 无法用
161
+ `derive` / `derive.keyed` 清晰表达时,才从 `doxum/advanced` 引入 `incremental`。
65
162
 
66
- 保留状态和 keyed patch 从 `doxum/advanced` 引入:
163
+ 所有 advanced processor 都使用 named dependencies,并且 `process` 必需。只有确实需要
164
+ retained state 时才声明 `state()`:
67
165
 
68
166
  ```ts
69
- const total = incremental([tasks], ({ sources, previous, state }) => {
70
- state.calls = Number(state.calls ?? 0) + 1;
71
- return sources[0].size + Number(state.calls) + (previous ?? 0);
72
- });
167
+ const weights = incremental.collection(
168
+ { tasks },
169
+ {
170
+ state: () => ({ initialized: false }),
171
+ process: ({ values, changes, output, state, reset }) => {
172
+ if (reset) {
173
+ for (const [id, task] of values.tasks) output.set(id, task.weight);
174
+ output.order([...values.tasks.keys()]);
175
+ state.initialized = true;
176
+ return;
177
+ }
178
+
179
+ const change = changes.tasks;
180
+ if (!change || change.kind === 'reset') return;
181
+ for (const entry of change.added) output.set(entry.key, entry.after.weight);
182
+ for (const entry of change.updated) output.set(entry.key, entry.after.weight);
183
+ for (const entry of change.removed) output.remove(entry.key);
184
+ if (change.order) output.order([...values.tasks.keys()]);
185
+ },
186
+ }
187
+ );
188
+ ```
73
189
 
74
- const doubled = incremental.collection([tasks], ({ sources, output }) => {
75
- for (const [id, task] of sources[0]) output.set(id, task.value * 2);
76
- });
190
+ `values`、`changes` 按 dependency 名称读取。scalar dependency 没有 collection change
191
+ metadata。collection processor 额外提供 keyed `previous`、`next` 和 borrowed
192
+ `output` draft。
193
+
194
+ 多输出 processor 使用一个 closed group definition:
77
195
 
196
+ ```ts
78
197
  const render = incremental.group(
79
- [tasks],
80
- define => ({
81
- node: {
82
- shell: define.collection<string, Shell>(),
83
- content: define.collection<string, Content>(),
198
+ { tasks },
199
+ {
200
+ output: define => ({
201
+ shell: define.collection<RowId, Shell>(),
202
+ count: define.value<number>(),
203
+ }),
204
+ state: () => ({ runs: 0 }),
205
+ process: ({ values, output, state }) => {
206
+ state.runs++;
207
+ for (const [id, task] of values.tasks) output.shell.set(id, makeShell(task));
208
+ output.count.set(values.tasks.size);
84
209
  },
85
- labels: define.collection<string, Label>(),
86
- chrome: define.value<Chrome>(),
87
- revision: define.value<number>(),
88
- }),
89
- ({ sources, outputs }) => {
90
- for (const [id, task] of sources[0]) {
91
- outputs.node.shell.set(id, makeShell(task));
92
- outputs.node.content.set(id, makeContent(task));
93
- outputs.labels.set(id, makeLabel(task));
94
- }
95
- outputs.chrome.set(makeChrome(sources[0]));
96
- outputs.revision.set(sources[0].size);
97
210
  }
98
211
  );
99
212
  ```
100
213
 
101
- 两种 processor context 都包含 `sources`、按依赖位置对齐的 `changes` tuple、
102
- `previous`、`reset`、`cause` 和持久 `state`。`changes[i]` 只对应第 `i` 个依赖:
103
- 标量依赖为 `undefined`,集合依赖则是 `reset`,或带完整 `before`/`after` 值的
104
- `added`/`updated`/`removed` 分组,并可选提供 `order.before`/`order.after`。初次
105
- build 对集合依赖报告 `reset`;一次已提交的 batch 已经合并成一个净 transition。
106
- `sources` 内的集合值是 callback-local 的惰性 `ReadonlyMap` 视图,不能保存或直接
107
- 返回。`get`/`has` 保持按 key 读取,迭代才显式扫描整个集合。
108
-
109
- `incremental.collection(...)` 使用独立的 collection processor 协议,另外提供借用的
110
- `previous`/`next` keyed read,以及
111
- 只在同步 callback 内有效的 `output` draft。Draft 只有 `set`、`remove`、`order`;
112
- Runtime 在 callback 返回后校验并 seal,计算 keyed transitions,发布
113
- 一个不可变 map-like 值。reset 或故障恢复由 Runtime 内部完成。
114
- `incremental.group(...)` 是多个命名 value / keyed collection output 的组合边界。
115
- `define.value<T>(equality?)` 声明 scalar leaf,`define.collection<K, V>(equality?)`
116
- 声明 keyed leaf。嵌套 namespace 只是静态 API 组织,不是新的 producer、Runtime、scheduler 或事件协议。
117
- 每个叶子都是指向同一个 processor producer 某个 output 的普通 `Projection`;一次 processor 执行先 seal 所有 leaf,再原子发布真正
118
- 变化的 leaf,下游直接依赖这些叶子。initial build / rebuild 必须 set 每个 value leaf;
119
- 普通增量轮次可以不触碰 value leaf,此时保留其现值和 revision。首次读取任一叶子只会
120
- 物化该 producer 一次;scope dispose 也只会释放该 producer 和其保留状态一次。
121
-
122
- ## React selector 追踪
123
-
124
- ```tsx
125
- const task = useProjection(visible, tasks => tasks.get(taskId));
126
- const [mode, setMode] = useInput(filter);
127
- ```
214
+ `define.collection<K,V>(equality?)`、`define.value<T>(equality?)` 只存在于 `output`
215
+ callback 内。返回的静态 object tree 会映射为同一 producer 的 projection leaves:
216
+ collection 为 `KeyedProjection<K,V>`,value 为 `Projection<T>`。
217
+ initial build 和 Runtime recovery 必须建立每个 value leaf;普通 incremental run 中未触碰
218
+ value leaf 会保留已发布值。
219
+
220
+ 普通 source reset 保留已声明的 retained state。processor fault 的恢复由 Runtime 完成:
221
+ 重新创建已声明的 state 并执行 reset evaluation;stateless processor 走同一恢复路径但没有
222
+ state object。没有公开 rebuild token 或手工 recovery hook。
223
+
224
+ ## React
128
225
 
129
- `get`/`has` 记录单 key,`keys` 记录 key/order 结构,`values` 或迭代记录整个
130
- 集合。无关 key 的更新不会执行 selector;相关更新后才执行 selector,并由
131
- `equality`(默认 `Object.is`)决定 readable 是否发布。这是消费端优化,不会反向
132
- 构建 Projection processor 依赖。
226
+ `ProjectionProvider` 提供 Runtime 或 scope。`useProjection(projection, selector,
227
+ equality?)` 使用同一套 Core selector 语义;`useInput` 同时支持 scalar/collection input。
228
+ Document 读取独立使用:
229
+
230
+ ```ts
231
+ const value = useDocumentSelector(document, selector, equality);
232
+ ```
133
233
 
134
- Processor 先于 listener settle。通知期间禁止写入。listener 错误不会回滚已经
135
- 接受的文档 commit;processor 错误交给 Runtime error callback,并由 Runtime
136
- 内部恢复。
234
+ processor 先于 projection listener settle;processing/notifying 时禁止写。
235
+ listener failure 不会 rollback 已接受的 document commit。
@@ -1,176 +0,0 @@
1
- import { F as CollectionPath, K as ObjectNode, N as CollectionEntry, P as CollectionId, U as Infer, X as ReadonlyValue, Y as PathValueOf, Z as SchemaPath, _ as Unsubscribe, b as CollectionImpact, g as Readable, o as DocumentReadable, p as Synchronous } from "./contract-SYJFP0lM.cjs";
2
-
3
- //#region core/src/projection/contract.d.ts
4
- /** The one processor-facing collection transition protocol. */
5
- type CollectionChange<K extends string, V> = {
6
- readonly kind: 'reset';
7
- } | {
8
- readonly kind: 'incremental';
9
- readonly added: readonly {
10
- readonly key: K;
11
- readonly after: V;
12
- }[];
13
- readonly updated: readonly {
14
- readonly key: K;
15
- readonly before: V;
16
- readonly after: V;
17
- }[];
18
- readonly removed: readonly {
19
- readonly key: K;
20
- readonly before: V;
21
- }[];
22
- readonly order?: {
23
- readonly before: readonly K[];
24
- readonly after: readonly K[];
25
- };
26
- };
27
- type CollectionRead<K extends string, V> = {
28
- get(key: K): V | undefined;
29
- has(key: K): boolean;
30
- ids(): readonly K[];
31
- };
32
- type ExternalCollectionRead<K extends string, V> = {
33
- readonly get: (key: K) => V | undefined;
34
- readonly has: (key: K) => boolean;
35
- readonly ids: () => readonly K[];
36
- };
37
- type ExternalValueSource<T> = {
38
- readonly kind: 'value';
39
- current(): T;
40
- revision(): number;
41
- subscribe(listener: (event: ExternalValueEvent<T>) => void): Unsubscribe;
42
- };
43
- type ExternalCollectionSource<K extends string, V> = {
44
- readonly kind: 'collection';
45
- current(): ExternalCollectionRead<K, V>;
46
- revision(): number;
47
- subscribe(listener: (event: ExternalCollectionEvent<K, V>) => void): Unsubscribe;
48
- };
49
- type ExternalValueEvent<T> = {
50
- readonly value: T;
51
- readonly revision: number;
52
- readonly reset?: boolean;
53
- readonly cause?: unknown;
54
- };
55
- type ExternalCollectionEvent<K extends string, V> = {
56
- /** Stable read from the source before this event or external batch. */readonly previous: ExternalCollectionRead<K, V>;
57
- readonly revision: number; /** Optional document-style hint; the adapter resolves the canonical change. */
58
- readonly impact?: CollectionImpact<K>;
59
- readonly cause?: unknown;
60
- };
61
- type CollectionDraft<K extends string, V> = {
62
- set(key: K, value: V): void;
63
- remove(key: K): void;
64
- order(ids: readonly K[]): void;
65
- };
66
- declare class ProjectionError extends Error {
67
- readonly phase: 'processor' | 'listener' | 'source' | 'blocked';
68
- readonly identity: string;
69
- readonly revisions: readonly number[];
70
- constructor(phase: 'processor' | 'listener' | 'source' | 'blocked', identity: string, revisions: readonly number[], cause: unknown);
71
- }
72
- declare class ProjectionDisposedError extends Error {
73
- constructor();
74
- }
75
- //#endregion
76
- //#region core/src/projection/definition.d.ts
77
- declare const projectionDefinition: unique symbol;
78
- declare const projectionChanges: unique symbol;
79
- declare const writableInput: unique symbol;
80
- /** A lazy output reference with no materialized Runtime state. */
81
- type Projection<T, C = undefined> = {
82
- readonly [projectionDefinition]: T;
83
- readonly [projectionChanges]: C;
84
- };
85
- /** A writable source projection. */
86
- type Input<T, C = undefined> = Projection<T, C> & {
87
- readonly [writableInput]: true;
88
- };
89
- type ProjectionValues$1<D extends readonly Projection<unknown, unknown>[]> = { readonly [K in keyof D]: D[K] extends Projection<infer T, unknown> ? T : never };
90
- type Rebuild = {
91
- readonly kind: 'rebuild';
92
- };
93
- declare const input: (<T>(initial: T, equality?: (previous: T, next: T) => boolean) => Input<T>) & {
94
- collection: <K extends string, V>(initial?: ReadonlyMap<K, V>) => Input<ReadonlyMap<K, V>, CollectionChange<K, V>>;
95
- };
96
- /** Establish a lazy reactive boundary from a document, readable, or external source. */
97
- declare function observe<S extends ObjectNode>(document: DocumentReadable<S>): Projection<Infer<S>>;
98
- declare function observe<T>(source: ExternalValueSource<T>): Projection<T>;
99
- declare function observe<K extends string, V>(source: ExternalCollectionSource<K, V>): Projection<ReadonlyMap<K, V>, CollectionChange<K, V>>;
100
- declare function observe<T>(readable: Readable<T>): Projection<T>;
101
- declare function observe<S extends ObjectNode, P extends CollectionPath>(document: DocumentReadable<S>, selector: (path: SchemaPath<S['shape']>) => P): Projection<ReadonlyMap<CollectionId<P>, ReadonlyValue<CollectionEntry<P>>>, CollectionChange<CollectionId<P>, ReadonlyValue<CollectionEntry<P>>>>;
102
- declare function observe<S extends ObjectNode, P>(document: DocumentReadable<S>, selector: (path: SchemaPath<S['shape']>) => P): Projection<PathValueOf<P>>;
103
- declare function derive<const D extends readonly Projection<unknown, unknown>[], T>(dependencies: D, compute: (...values: ProjectionValues$1<D>) => Synchronous<T>, equality?: (previous: T, next: T) => boolean): Projection<T>;
104
- //#endregion
105
- //#region core/src/projection/advanced.d.ts
106
- type ProjectionValues<D extends readonly Projection<unknown, unknown>[]> = { readonly [K in keyof D]: D[K] extends Projection<infer T, unknown> ? T : never };
107
- type ProjectionChanges<D extends readonly Projection<unknown, unknown>[]> = { readonly [K in keyof D]: D[K] extends Projection<unknown, infer C> ? [C] extends [undefined] ? undefined : C | undefined : undefined };
108
- type IncrementalValueContext<D extends readonly Projection<unknown, unknown>[], T> = {
109
- readonly sources: ProjectionValues<D>;
110
- readonly changes: ProjectionChanges<D>;
111
- readonly previous: T | undefined;
112
- readonly reset: boolean;
113
- readonly cause: unknown;
114
- readonly state: Record<string, unknown>;
115
- };
116
- type IncrementalValueProcessor<D extends readonly Projection<unknown, unknown>[], T> = (context: IncrementalValueContext<D, T>) => T | Rebuild;
117
- type IncrementalCollectionContext<D extends readonly Projection<unknown, unknown>[], K extends string, V> = {
118
- readonly sources: ProjectionValues<D>;
119
- readonly changes: ProjectionChanges<D>;
120
- readonly previous: CollectionRead<K, V>;
121
- readonly next: CollectionRead<K, V>;
122
- readonly reset: boolean;
123
- readonly cause: unknown;
124
- readonly state: Record<string, unknown>;
125
- readonly output: CollectionDraft<K, V>;
126
- };
127
- type IncrementalCollectionProcessor<D extends readonly Projection<unknown, unknown>[], K extends string, V> = (context: IncrementalCollectionContext<D, K, V>) => void | Rebuild;
128
- declare const groupOutput: unique symbol;
129
- type GroupCollectionOutput<K extends string, V> = {
130
- readonly [groupOutput]: {
131
- readonly kind: 'collection';
132
- readonly key: K;
133
- readonly value: V;
134
- };
135
- };
136
- type GroupValueOutput<T> = {
137
- readonly [groupOutput]: {
138
- readonly kind: 'value';
139
- readonly value: T;
140
- };
141
- };
142
- type GroupOutputShape = {
143
- readonly [name: string]: GroupCollectionOutput<string, unknown> | GroupValueOutput<unknown> | GroupOutputShape;
144
- };
145
- type IncrementalGroupOutputTree = GroupOutputShape;
146
- type GroupOutputBuilder = {
147
- collection<K extends string, V>(equality?: (previous: V, next: V) => boolean): GroupCollectionOutput<K, V>;
148
- value<T>(equality?: (previous: T, next: T) => boolean): GroupValueOutput<T>;
149
- };
150
- type IncrementalGroupDefine = GroupOutputBuilder;
151
- type GroupProjections<O> = O extends GroupCollectionOutput<infer K, infer V> ? Projection<ReadonlyMap<K, V>, CollectionChange<K, V>> : O extends GroupValueOutput<infer T> ? Projection<T> : { readonly [P in keyof O]: GroupProjections<O[P]> };
152
- type GroupReads<O> = O extends GroupCollectionOutput<infer K, infer V> ? CollectionRead<K, V> : O extends GroupValueOutput<infer T> ? T | undefined : { readonly [P in keyof O]: GroupReads<O[P]> };
153
- type GroupDrafts<O> = O extends GroupCollectionOutput<infer K, infer V> ? CollectionDraft<K, V> : O extends GroupValueOutput<infer T> ? {
154
- set(value: T): void;
155
- } : { readonly [P in keyof O]: GroupDrafts<O[P]> };
156
- type IncrementalGroupContext<D extends readonly Projection<unknown, unknown>[], O extends GroupOutputShape> = {
157
- readonly sources: ProjectionValues<D>;
158
- readonly changes: ProjectionChanges<D>;
159
- readonly previous: GroupReads<O>;
160
- readonly next: GroupReads<O>;
161
- readonly outputs: GroupDrafts<O>;
162
- readonly reset: boolean;
163
- readonly cause: unknown;
164
- readonly state: Record<string, unknown>;
165
- };
166
- type IncrementalGroupProcessor<D extends readonly Projection<unknown, unknown>[], O extends GroupOutputShape> = (context: IncrementalGroupContext<D, O>) => void | Rebuild;
167
- declare function createIncrementalValue<const D extends readonly Projection<unknown, unknown>[], T>(dependencies: D, processor: IncrementalValueProcessor<D, T>): Projection<T>;
168
- declare function createIncrementalCollection<const D extends readonly Projection<unknown, unknown>[], K extends string, V>(dependencies: D, processor: IncrementalCollectionProcessor<D, K, V>): Projection<ReadonlyMap<K, V>, CollectionChange<K, V>>;
169
- declare function createIncrementalGroup<const D extends readonly Projection<unknown, unknown>[], const O extends GroupOutputShape>(dependencies: D, defineOutputs: (define: GroupOutputBuilder) => O, processor: IncrementalGroupProcessor<D, O>): GroupProjections<O>;
170
- declare const incremental: typeof createIncrementalValue & {
171
- collection: typeof createIncrementalCollection;
172
- group: typeof createIncrementalGroup;
173
- };
174
- //#endregion
175
- export { ProjectionError as C, ProjectionDisposedError as S, ExternalCollectionEvent as _, IncrementalGroupDefine as a, ExternalValueEvent as b, IncrementalValueContext as c, Input as d, Projection as f, CollectionChange as g, observe as h, IncrementalGroupContext as i, IncrementalValueProcessor as l, input as m, IncrementalCollectionContext as n, IncrementalGroupOutputTree as o, derive as p, IncrementalCollectionProcessor as r, IncrementalGroupProcessor as s, GroupProjections as t, incremental as u, ExternalCollectionRead as v, ExternalValueSource as x, ExternalCollectionSource as y };
176
- //# sourceMappingURL=advanced-CLJCWkHa.d.cts.map