duratom 0.1.0 → 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.
@@ -1,6 +1,6 @@
1
1
  export { d as deepEqual, s as shallowEqual } from '../equality-AjtpnVrF.js';
2
- import { E as Exact } from '../shape--EeyM-2X.js';
3
- export { A as ArrayPath, a as At, L as Live, b as LiveSpec, c as Locator, M as MapPath, O as ObserveOptions, P as ProjectOptions, d as Projection, S as Selector, e as at, l as live, o as observeLocated, s as select } from '../shape--EeyM-2X.js';
2
+ import { E as Exact } from '../shape-CMa7XFjy.js';
3
+ export { A as ArrayPath, a as At, K as KeyPath, b as KeyValuePath, L as Live, c as LiveSpec, d as Locator, M as MapPath, O as ObserveOptions, P as ProjectOptions, e as Projection, S as Selector, f as at, l as live, o as observeLocated, s as select } from '../shape-CMa7XFjy.js';
4
4
  import { StandardSchemaV1 } from '@standard-schema/spec';
5
5
  import * as Y from 'yjs';
6
6
 
@@ -101,4 +101,50 @@ declare class UnsupportedValueError extends Error {
101
101
  constructor(path: readonly PropertyKey[]);
102
102
  }
103
103
 
104
- export { AsyncValidationUnsupportedError, type Reader, UnsupportedValueError, create, read, reader, write };
104
+ type Result<Schema extends StandardSchemaV1> = StandardSchemaV1.Result<StandardSchemaV1.InferOutput<Schema>>;
105
+ /**
106
+ * Reads the current value of `key` in a key-value array (y-utility's `YKeyValue`: the rightmost
107
+ * `{ key, val }` entry per key wins) and validates it with `schema`, returning the schema's own
108
+ * result. A missing array or a key with no entry returns `undefined` without validating. A value
109
+ * holding a shared type returns the layer's own issue without validating, since a `YKeyValue`
110
+ * holds plain values only.
111
+ *
112
+ * A current value the schema rejects reads as `{ issues }`, like an invalid map field: it does not
113
+ * fall back to an older entry, which a `YKeyValue` deletes anyway. Writing a valid value repairs it.
114
+ *
115
+ * @example
116
+ * const result = readKey(z.number(), doc.getArray('master'), 'tone')
117
+ * if (result && !result.issues) console.log(result.value)
118
+ */
119
+ declare function readKey<Schema extends StandardSchemaV1>(schema: Schema, array: Y.AbstractType<any> | undefined, key: string): Result<Schema> | undefined;
120
+ /**
121
+ * Validates `value` with `schema` and, if it's valid, sets `key` of the key-value array as
122
+ * `YKeyValue#set` does: pushes `{ key, val }` to its end and deletes every older entry for `key`,
123
+ * in one transaction. Returns the schema's own result; an invalid value changes nothing, and so
124
+ * does a value equal to the current one. Throws `UnsupportedValueError` for a value Yjs can't store
125
+ * as written, since the schema accepted it.
126
+ *
127
+ * @example
128
+ * const result = writeKey(z.number().min(-1).max(1), doc.getArray('master'), 'tone', -0.6)
129
+ * if (result.issues) console.warn(result.issues) // the doc is unchanged
130
+ */
131
+ declare function writeKey<Schema extends StandardSchemaV1>(schema: Schema, array: Y.Array<any>, key: string, value: StandardSchemaV1.InferOutput<Schema>): Result<Schema>;
132
+ /**
133
+ * `readKey(schema, node, key)` packaged as a projection for `select.keyValue(name).project(...)`:
134
+ * it counts only changes that add or delete an entry for `key`, and compares results deeply.
135
+ * `typedAtom(path.key(k), schema)` reads through it.
136
+ *
137
+ * @example
138
+ * const tone = live(doc, select.keyValue('master').project(keyReader(z.number(), 'tone')))
139
+ * tone.subscribe((result) => console.log(result?.issues ?? result?.value))
140
+ */
141
+ declare function keyReader<Schema extends StandardSchemaV1>(schema: Schema, key: string): KeyReader<StandardSchemaV1.InferOutput<Schema>>;
142
+ /** What `keyReader` returns: a projection of one key's validated value, with its event filter. */
143
+ interface KeyReader<T> {
144
+ project: (node: Y.AbstractType<any> | undefined) => StandardSchemaV1.Result<T> | undefined;
145
+ deep: false;
146
+ event: (event: Y.YEvent<any>) => boolean;
147
+ equals: (a: StandardSchemaV1.Result<T> | undefined, b: StandardSchemaV1.Result<T> | undefined) => boolean;
148
+ }
149
+
150
+ export { AsyncValidationUnsupportedError, type KeyReader, type Reader, UnsupportedValueError, create, keyReader, read, readKey, reader, write, writeKey };
@@ -1,34 +1,44 @@
1
1
  import {
2
2
  ArrayPath,
3
3
  AsyncValidationUnsupportedError,
4
+ KeyPath,
5
+ KeyValuePath,
4
6
  Locator,
5
7
  MapPath,
6
8
  UnsupportedValueError,
7
9
  at,
8
10
  create,
9
- deepEqual,
11
+ deepEqual2 as deepEqual,
12
+ keyReader,
10
13
  live,
11
14
  observeLocated,
12
15
  read,
16
+ readKey,
13
17
  reader,
14
18
  select,
15
19
  shallowEqual,
16
- write
17
- } from "../chunk-GTI66UUE.js";
20
+ write,
21
+ writeKey
22
+ } from "../chunk-7TXOG3GB.js";
18
23
  export {
19
24
  ArrayPath,
20
25
  AsyncValidationUnsupportedError,
26
+ KeyPath,
27
+ KeyValuePath,
21
28
  Locator,
22
29
  MapPath,
23
30
  UnsupportedValueError,
24
31
  at,
25
32
  create,
26
33
  deepEqual,
34
+ keyReader,
27
35
  live,
28
36
  observeLocated,
29
37
  read,
38
+ readKey,
30
39
  reader,
31
40
  select,
32
41
  shallowEqual,
33
- write
42
+ write,
43
+ writeKey
34
44
  };
package/dist/index.d.ts CHANGED
@@ -1,8 +1,8 @@
1
- import { c as Locator, M as MapPath, E as Exact } from './shape--EeyM-2X.js';
2
- export { f as ArrayKind, A as ArrayPath, a as At, b as LiveSpec, g as MapKind, O as ObserveOptions, P as ProjectOptions, d as Projection, R as RecordKind, S as Selector, h as Shape, i as array, e as at, j as isMap, m as map, r as record, s as select } from './shape--EeyM-2X.js';
1
+ import { d as Locator, M as MapPath, E as Exact, b as KeyValuePath } from './shape-CMa7XFjy.js';
2
+ export { g as ArrayKind, A as ArrayPath, a as At, K as KeyPath, c as LiveSpec, h as MapKind, O as ObserveOptions, P as ProjectOptions, e as Projection, R as RecordKind, S as Selector, i as Shape, j as array, f as at, k as isMap, m as map, r as record, s as select } from './shape-CMa7XFjy.js';
3
3
  export { d as deepEqual, s as shallowEqual } from './equality-AjtpnVrF.js';
4
- import { T as TypedAtom, A as AtomOptions } from './typed-atom-oZaH0A5l.js';
5
- export { P as Patch, d as docAtom, l as liveAtom, t as typedAtom } from './typed-atom-oZaH0A5l.js';
4
+ import { T as TypedAtom, A as AtomOptions } from './typed-atom-t7tvnXSS.js';
5
+ export { K as KeyUpdate, P as Patch, a as TypedKeyAtom, d as docAtom, l as liveAtom, t as typedAtom } from './typed-atom-t7tvnXSS.js';
6
6
  import { StandardSchemaV1 } from '@standard-schema/spec';
7
7
  import { Atom, WritableAtom } from 'jotai';
8
8
  import { AtomFamily } from 'jotai-family';
@@ -63,4 +63,40 @@ interface Collection<T> {
63
63
  */
64
64
  declare function collection<Schema extends StandardSchemaV1, const S extends object>(locator: Locator<any> | MapPath<any>, schema: Schema, shape: Exact<S, StandardSchemaV1.InferOutput<Schema>>, options?: AtomOptions): Collection<StandardSchemaV1.InferOutput<Schema>>;
65
65
 
66
- export { AtomOptions, type Collection, type CreateResult, Locator, MapPath, TypedAtom, collection };
66
+ type Schemas = Record<string, StandardSchemaV1>;
67
+ type Values<S extends Schemas> = {
68
+ [K in keyof S]: StandardSchemaV1.InferOutput<S[K]>;
69
+ };
70
+ /**
71
+ * A Jotai atom over the keys of a key-value array that `schemas` names, each read through its
72
+ * own schema. It reads as an object with one result per key: `undefined` while the key has no
73
+ * entry, `{ issues }` while its value is invalid, `{ value }` otherwise. Setting it takes a patch
74
+ * of the keys to change, or a function of their valid values returning one.
75
+ */
76
+ type KeyValueAtom<S extends Schemas> = WritableAtom<{
77
+ [K in keyof S]: StandardSchemaV1.Result<Values<S>[K]> | undefined;
78
+ }, [
79
+ patch: Partial<Values<S>> | ((prev: Partial<Values<S>>) => Partial<Values<S>>)
80
+ ], StandardSchemaV1.Result<Partial<Values<S>>>>;
81
+ /**
82
+ * A typed, writable atom over a whole key-value array (y-utility's `YKeyValue`), with one schema
83
+ * per key. Keys `schemas` doesn't name are left out of the read and never written. It re-renders
84
+ * only when an entry for one of its keys changes a result; for one key alone, use
85
+ * `typedAtom(path.key(k), schema)`, which also ignores the other keys.
86
+ *
87
+ * Setting it validates every key of the patch first: when any is invalid, nothing is written and
88
+ * the result holds their issues, each path starting at its key. Otherwise each key is written as
89
+ * `YKeyValue#set` does, in one transaction. A missing array changes nothing.
90
+ *
91
+ * @example
92
+ * const master = keyValueAtom(select.keyValue('master'), {
93
+ * tone: z.number().min(-1).max(1),
94
+ * filter: z.object({ x: z.number(), y: z.number() }),
95
+ * })
96
+ *
97
+ * store.get(master).tone // undefined, { issues } or { value }
98
+ * store.set(master, { tone: -0.6 })
99
+ */
100
+ declare function keyValueAtom<const S extends Schemas>(path: KeyValuePath<any>, schemas: S, options?: AtomOptions): KeyValueAtom<S>;
101
+
102
+ export { AtomOptions, type Collection, type CreateResult, type KeyValueAtom, KeyValuePath, Locator, MapPath, TypedAtom, collection, keyValueAtom };
package/dist/index.js CHANGED
@@ -5,22 +5,31 @@ import {
5
5
  refreshedTypedAtom,
6
6
  typedAtom,
7
7
  versionedLiveAtom
8
- } from "./chunk-LTA6HTAG.js";
8
+ } from "./chunk-URKFBGPT.js";
9
9
  import {
10
10
  ArrayPath,
11
+ KeyPath,
12
+ KeyValuePath,
11
13
  Locator,
12
14
  MapPath,
13
15
  array,
16
+ assertStorable,
14
17
  at,
18
+ copy,
15
19
  create,
20
+ currentEntries,
16
21
  deepEqual,
22
+ deepEqual2,
17
23
  isMap,
18
24
  map,
25
+ readValue,
19
26
  record,
20
27
  select,
28
+ setEntry,
21
29
  shallowEqual,
30
+ touchesKeys,
22
31
  validate
23
- } from "./chunk-GTI66UUE.js";
32
+ } from "./chunk-7TXOG3GB.js";
24
33
 
25
34
  // src/atoms/collection.ts
26
35
  import { atom } from "jotai";
@@ -85,16 +94,85 @@ function randomId() {
85
94
  const hex = Array.from(bytes, (b) => b.toString(16).padStart(2, "0")).join("");
86
95
  return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
87
96
  }
97
+
98
+ // src/atoms/key-value-atom.ts
99
+ import { atom as atom2 } from "jotai";
100
+ import * as Y from "yjs";
101
+ function keyValueAtom(path, schemas, options = {}) {
102
+ if (!(path instanceof KeyValuePath)) throw new TypeError("keyValueAtom needs a KeyValuePath.");
103
+ const keys = Object.keys(schemas);
104
+ const project = (node) => {
105
+ const entries = node instanceof Y.Array ? currentEntries(node) : void 0;
106
+ const out = {};
107
+ for (const key of keys) {
108
+ const entry = entries?.get(key);
109
+ out[key] = entry && readValue(schemas[key], entry.val, key);
110
+ }
111
+ return out;
112
+ };
113
+ const { live, version } = versionedLiveAtom(
114
+ { locate: () => path.locator, project, event: touchesKeys(keys), equals: deepEqual },
115
+ options
116
+ );
117
+ return atom2(
118
+ (get) => get(live),
119
+ (get, set, update) => {
120
+ const doc = readDoc(get, options);
121
+ let result;
122
+ doc.transact(() => {
123
+ const array2 = path.locator.resolve(doc);
124
+ if (!(array2 instanceof Y.Array)) {
125
+ result = { issues: [{ message: "The key-value Y.Array is missing" }] };
126
+ return;
127
+ }
128
+ let patch = update;
129
+ if (typeof update === "function") {
130
+ const prev = {};
131
+ for (const [key, read] of Object.entries(project(array2)))
132
+ if (read && !read.issues) prev[key] = read.value;
133
+ patch = update(prev);
134
+ }
135
+ const issues = [];
136
+ const valid = [];
137
+ const output = {};
138
+ for (const [key, value] of Object.entries(patch)) {
139
+ const schema = Object.hasOwn(schemas, key) ? schemas[key] : void 0;
140
+ if (!schema) {
141
+ issues.push({ message: `Unknown key ${JSON.stringify(key)}`, path: [key] });
142
+ continue;
143
+ }
144
+ const checked = validate(schema, value);
145
+ if (checked.issues)
146
+ for (const issue of checked.issues)
147
+ issues.push({ ...issue, path: [key, ...issue.path ?? []] });
148
+ else {
149
+ valid.push([key, value]);
150
+ output[key] = checked.value;
151
+ }
152
+ }
153
+ if (issues.length > 0) return void (result = { issues });
154
+ for (const [key, value] of valid) assertStorable(value, { key, parent: void 0 });
155
+ for (const [key, value] of valid) setEntry(array2, key, copy(value), deepEqual);
156
+ result = { value: output };
157
+ });
158
+ if (!result.issues) set(version, (n) => n + 1);
159
+ return result;
160
+ }
161
+ );
162
+ }
88
163
  export {
89
164
  ArrayPath,
165
+ KeyPath,
166
+ KeyValuePath,
90
167
  Locator,
91
168
  MapPath,
92
169
  array,
93
170
  at,
94
171
  collection,
95
- deepEqual,
172
+ deepEqual2 as deepEqual,
96
173
  docAtom,
97
174
  isMap,
175
+ keyValueAtom,
98
176
  liveAtom,
99
177
  map,
100
178
  record,
@@ -1,8 +1,8 @@
1
1
  import { StandardSchemaV1 } from '@standard-schema/spec';
2
2
  import { DependencyList } from 'react';
3
3
  import * as Y from 'yjs';
4
- import { A as AtomOptions, P as Patch } from '../typed-atom-oZaH0A5l.js';
5
- import { b as LiveSpec, c as Locator, M as MapPath, E as Exact } from '../shape--EeyM-2X.js';
4
+ import { A as AtomOptions, P as Patch } from '../typed-atom-t7tvnXSS.js';
5
+ import { c as LiveSpec, d as Locator, M as MapPath, E as Exact } from '../shape-CMa7XFjy.js';
6
6
  import 'jotai';
7
7
 
8
8
  type SpecOptions<N extends Y.AbstractType<any>, T> = Omit<LiveSpec<N, T>, 'locate' | 'project'> & AtomOptions;
@@ -1,8 +1,8 @@
1
1
  import {
2
2
  liveAtom,
3
3
  typedAtom
4
- } from "../chunk-LTA6HTAG.js";
5
- import "../chunk-GTI66UUE.js";
4
+ } from "../chunk-URKFBGPT.js";
5
+ import "../chunk-7TXOG3GB.js";
6
6
 
7
7
  // src/react/index.ts
8
8
  import { useAtom, useAtomValue } from "jotai";
@@ -190,6 +190,8 @@ declare class MapPath<V = unknown> extends Path<Y.Map<V>> {
190
190
  child<W = V extends Y.Map<infer X> ? X : unknown>(key: string): MapPath<W>;
191
191
  /** Descend into the `Y.Array` stored under `key`. */
192
192
  child<W = V extends Y.Array<infer X> ? X : unknown>(key: string, kind: 'array'): ArrayPath<W>;
193
+ /** Descend into the `Y.Array` under `key` that holds a y-utility `YKeyValue`. */
194
+ child<W = unknown>(key: string, kind: 'keyValue'): KeyValuePath<W>;
193
195
  /** The value under `key`, or `undefined` when it or the map is missing. Observes only `key`. */
194
196
  get(key: string): Selector<V | undefined>;
195
197
  /**
@@ -240,6 +242,52 @@ declare class ArrayPath<V = unknown> extends Path<Y.Array<V>> {
240
242
  /** `toJSON()` of the array and everything under it, `[]` when missing. Observes deeply; compared deeply. */
241
243
  toJSON(): Selector<unknown[]>;
242
244
  }
245
+ /**
246
+ * A path to a `Y.Array` that holds y-utility's `YKeyValue`: `{ key, val }` entries where the
247
+ * rightmost entry per key is the current one. duratom reads and writes the same entries as
248
+ * `YKeyValue`, so the two can share a doc. Items that aren't entries are skipped. End it with a
249
+ * projection, or pass `key(k)` to `typedAtom` for a validated, writable atom over one key.
250
+ *
251
+ * @example
252
+ * const master = select.keyValue('master')
253
+ * const tone = liveAtom(master.get('tone', 0))
254
+ * const toneAtom = typedAtom(master.key('tone'), z.number().min(-1).max(1))
255
+ */
256
+ declare class KeyValuePath<V = unknown> extends Path<Y.Array<unknown>> {
257
+ protected is(node: unknown): node is Y.Array<unknown>;
258
+ /** The entry for `key`, for `typedAtom(path.key(k), schema)`. */
259
+ key(key: string): KeyPath;
260
+ /**
261
+ * The current value of `key` as stored, `undefined` when it has no entry or the array is
262
+ * missing. Notifies only when an entry for `key` is added or deleted and the value changed.
263
+ */
264
+ get(key: string): Selector<V | undefined>;
265
+ /**
266
+ * The current value of `key` when it has `fallback`'s kind, else `fallback`, as `MapPath#get`
267
+ * checks it. Notifies only when an entry for `key` changes the value.
268
+ */
269
+ get<D>(key: string, fallback: D): Selector<undefined extends D ? V | Checked<D> : Checked<D>>;
270
+ /** The keys that have an entry, sorted so every peer sees the same order. `[]` when missing. */
271
+ keys(): Selector<string[]>;
272
+ /** The current value of every key, as stored. `{}` when missing. Compared deeply. */
273
+ toJSON(): Selector<Record<string, V>>;
274
+ }
275
+ /**
276
+ * One key of a key-value array (see `KeyValuePath`): `select.keyValue(name).key(k)`. `typedAtom`
277
+ * takes one for a validated atom over that key's current value.
278
+ *
279
+ * @example
280
+ * const tone = select.keyValue('master').key('tone')
281
+ * const toneAtom = typedAtom(tone, z.number())
282
+ */
283
+ declare class KeyPath {
284
+ /** Where the key-value array is. */
285
+ readonly locator: Locator<Y.Array<unknown>>;
286
+ readonly key: string;
287
+ constructor(
288
+ /** Where the key-value array is. */
289
+ locator: Locator<Y.Array<unknown>>, key: string);
290
+ }
243
291
  /**
244
292
  * Builds selectors: `select.map('cards').child(id).get('title', '')`. Starts
245
293
  * at a root type of the doc, like `at`.
@@ -248,10 +296,13 @@ declare class ArrayPath<V = unknown> extends Path<Y.Array<V>> {
248
296
  * const title = liveAtom(select.map('cards').child('card-1').get('title', ''))
249
297
  * const ids = liveAtom(select.map('cards').keys())
250
298
  * const order = liveAtom(select.array<string>('order').toArray())
299
+ * const tone = liveAtom(select.keyValue('master').get('tone', 0))
251
300
  */
252
301
  declare const select: {
253
302
  map: <V = unknown>(name: string) => MapPath<V>;
254
303
  array: <V = unknown>(name: string) => ArrayPath<V>;
304
+ /** A root `Y.Array` that holds a y-utility `YKeyValue`. */
305
+ keyValue: <V = unknown>(name: string) => KeyValuePath<V>;
255
306
  };
256
307
 
257
308
  /**
@@ -336,4 +387,4 @@ type ExactKind<V, F> = V extends MapKind<infer N> ? MapKind<Exact<N, ObjectOf<F>
336
387
  */
337
388
  declare const isMap: (value: unknown) => value is Y.Map<unknown>;
338
389
 
339
- export { ArrayPath as A, type Exact as E, type Live as L, MapPath as M, type ObserveOptions as O, type ProjectOptions as P, type RecordKind as R, type Selector as S, type At as a, type LiveSpec as b, Locator as c, type Projection as d, at as e, type ArrayKind as f, type MapKind as g, type Shape as h, array as i, isMap as j, live as l, map as m, observeLocated as o, record as r, select as s };
390
+ export { ArrayPath as A, type Exact as E, KeyPath as K, type Live as L, MapPath as M, type ObserveOptions as O, type ProjectOptions as P, type RecordKind as R, type Selector as S, type At as a, KeyValuePath as b, type LiveSpec as c, Locator as d, type Projection as e, at as f, type ArrayKind as g, type MapKind as h, type Shape as i, array as j, isMap as k, live as l, map as m, observeLocated as o, record as r, select as s };
@@ -1,6 +1,6 @@
1
1
  import { StandardSchemaV1 } from '@standard-schema/spec';
2
2
  import { Atom, PrimitiveAtom, WritableAtom } from 'jotai';
3
- import { b as LiveSpec, c as Locator, M as MapPath, E as Exact } from './shape--EeyM-2X.js';
3
+ import { c as LiveSpec, d as Locator, M as MapPath, E as Exact, K as KeyPath } from './shape-CMa7XFjy.js';
4
4
  import * as Y from 'yjs';
5
5
 
6
6
  /**
@@ -59,6 +59,20 @@ type Patch<T> = Partial<T> | ((prev: T | undefined) => Partial<T>);
59
59
  type TypedAtom<T> = WritableAtom<StandardSchemaV1.Result<T> | undefined, [
60
60
  patch: Patch<T>
61
61
  ], StandardSchemaV1.Result<T>>;
62
+ /**
63
+ * What a key atom's setter takes: the whole new value, or a function of the key's value as it is
64
+ * in the doc at write time (`undefined` while it has no valid value) returning one.
65
+ */
66
+ type KeyUpdate<T> = T | ((prev: T | undefined) => T);
67
+ /**
68
+ * A Jotai atom over one key of a key-value array (y-utility's `YKeyValue`), read through a schema.
69
+ * It reads as `undefined` while the key has no entry, `{ issues }` while its current value doesn't
70
+ * satisfy the schema, and `{ value }` otherwise. Setting it validates and writes the whole value,
71
+ * and returns the schema's result.
72
+ */
73
+ type TypedKeyAtom<T> = WritableAtom<StandardSchemaV1.Result<T> | undefined, [
74
+ update: KeyUpdate<T>
75
+ ], StandardSchemaV1.Result<T>>;
62
76
  /**
63
77
  * A typed, writable atom over the `Y.Map` at `locator`, read through `schema` and `shape`: a
64
78
  * `liveAtom` over `reader(schema, shape)` with a setter. It observes only that node, skips edits
@@ -89,5 +103,25 @@ type TypedAtom<T> = WritableAtom<StandardSchemaV1.Result<T> | undefined, [
89
103
  * store.set(cardAtom, { priority: 'high' }) // changes only priority
90
104
  */
91
105
  declare function typedAtom<Schema extends StandardSchemaV1, const S extends object>(locator: Locator<any> | MapPath<any>, schema: Schema, shape: Exact<S, StandardSchemaV1.InferOutput<Schema>>, options?: AtomOptions): TypedAtom<StandardSchemaV1.InferOutput<Schema>>;
106
+ /**
107
+ * A typed, writable atom over one key of a key-value array (y-utility's `YKeyValue`), read
108
+ * through `schema`: `select.keyValue(name).key(k)`. It reads the key's current entry (the
109
+ * rightmost) as `undefined`, `{ issues }` or `{ value }`, and re-renders only when an entry for
110
+ * that key changes its result, not when other keys change or a stale entry is cleaned up. A
111
+ * current value the schema rejects reads as `{ issues }`; it does not fall back to an older entry.
112
+ *
113
+ * Setting it validates the whole value, then writes it as `YKeyValue#set` does: pushes
114
+ * `{ key, val }` and deletes the key's older entries, so a `YKeyValue` on the same doc reads it.
115
+ * A function gets the key's valid value at write time, or `undefined`. `{ issues }` changes
116
+ * nothing, and so does a missing array. Values are plain: a `YKeyValue` holds no shared types.
117
+ *
118
+ * @example
119
+ * const toneAtom = typedAtom(select.keyValue('master').key('tone'), z.number().min(-1).max(1))
120
+ *
121
+ * store.get(toneAtom) // undefined, { issues } or { value }
122
+ * store.set(toneAtom, -0.6)
123
+ * store.set(toneAtom, (prev) => Math.min(1, (prev ?? 0) + 0.1))
124
+ */
125
+ declare function typedAtom<Schema extends StandardSchemaV1>(key: KeyPath, schema: Schema, options?: AtomOptions): TypedKeyAtom<StandardSchemaV1.InferOutput<Schema>>;
92
126
 
93
- export { type AtomOptions as A, type Patch as P, type TypedAtom as T, docAtom as d, liveAtom as l, typedAtom as t };
127
+ export { type AtomOptions as A, type KeyUpdate as K, type Patch as P, type TypedAtom as T, type TypedKeyAtom as a, docAtom as d, liveAtom as l, typedAtom as t };