react-mnemonic 1.1.0-beta0 → 1.2.0-beta1

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.
@@ -0,0 +1,317 @@
1
+ import { M as MnemonicProviderOptions, a as MnemonicKeyDescriptor, b as MnemonicKeyState, U as UseMnemonicKeyOptions, y as CreateSchemaRegistryOptions, z as SchemaRegistry, A as JsonSchema, K as KeySchema, I as InferJsonSchemaValue, B as MigrationRule } from './key-BvFvcKiR.cjs';
2
+ export { C as Codec, c as CodecError, D as CompiledValidator, J as JSONCodec, E as JsonSchemaType, F as JsonSchemaValidationError, L as Listener, G as MigrationPath, d as Mnemonic, e as MnemonicDevToolsCapabilities, f as MnemonicDevToolsMeta, g as MnemonicDevToolsProviderApi, h as MnemonicDevToolsProviderDescriptor, i as MnemonicDevToolsProviderEntry, j as MnemonicDevToolsRegistry, k as MnemonicDevToolsWeakRef, l as MnemonicHydrationMode, m as MnemonicKeySSRConfig, n as MnemonicProviderSSRConfig, o as MnemonicRecoveryAction, p as MnemonicRecoveryEvent, q as MnemonicRecoveryHook, R as ReconcileContext, H as SchemaBoundKeyOptions, S as SchemaError, r as SchemaMode, s as StorageLike, T as TypedJsonSchema, N as TypedKeySchema, t as Unsubscribe, u as UseMnemonicRecoveryOptions, O as compileSchema, v as createCodec, w as defineMnemonicKey, P as mnemonicSchema, x as useMnemonicRecovery, Q as validateJsonSchema } from './key-BvFvcKiR.cjs';
3
+ import * as react_jsx_runtime from 'react/jsx-runtime';
4
+ import { ReactNode } from 'react';
5
+
6
+ /**
7
+ * Props for the MnemonicProvider component.
8
+ *
9
+ * Extends MnemonicProviderOptions with required children prop.
10
+ *
11
+ * @see {@link MnemonicProviderOptions} - Configuration options
12
+ * @see {@link MnemonicProvider} - Provider component
13
+ */
14
+ interface MnemonicProviderProps extends Readonly<MnemonicProviderOptions> {
15
+ /**
16
+ * React children to render within the provider.
17
+ */
18
+ readonly children: ReactNode;
19
+ }
20
+ /**
21
+ * React Context provider for namespace-isolated persistent state.
22
+ *
23
+ * Creates a scoped storage environment where all keys are automatically prefixed
24
+ * with the namespace to prevent collisions. Implements an in-memory cache with
25
+ * read-through behavior to the underlying storage backend (localStorage by default).
26
+ *
27
+ * This provider must wrap any components that use `useMnemonicKey`. Multiple
28
+ * providers with different namespaces can coexist in the same application.
29
+ *
30
+ * @param props - Provider configuration and children
31
+ * @param props.children - React children to render within the provider
32
+ * @param props.namespace - Unique namespace for isolating storage keys
33
+ * @param props.storage - Optional synchronous custom storage backend (defaults to localStorage)
34
+ * @param props.enableDevTools - Enable DevTools debugging interface (defaults to false)
35
+ * @param props.schemaMode - Schema enforcement mode (default: "default")
36
+ * @param props.schemaRegistry - Optional schema registry for storing schemas and migrations
37
+ * @param props.ssr - Optional SSR defaults for descendant hooks
38
+ *
39
+ * @example
40
+ * ```tsx
41
+ * // Basic usage with default settings
42
+ * function App() {
43
+ * return (
44
+ * <MnemonicProvider namespace="myApp">
45
+ * <MyComponents />
46
+ * </MnemonicProvider>
47
+ * );
48
+ * }
49
+ * ```
50
+ *
51
+ * @example
52
+ * ```tsx
53
+ * // With a synchronous custom storage backend
54
+ * function App() {
55
+ * return (
56
+ * <MnemonicProvider
57
+ * namespace="myApp"
58
+ * storage={window.sessionStorage}
59
+ * >
60
+ * <MyComponents />
61
+ * </MnemonicProvider>
62
+ * );
63
+ * }
64
+ * ```
65
+ *
66
+ * @example
67
+ * ```tsx
68
+ * // With DevTools enabled (development only)
69
+ * function App() {
70
+ * return (
71
+ * <MnemonicProvider
72
+ * namespace="myApp"
73
+ * enableDevTools={process.env.NODE_ENV === 'development'}
74
+ * >
75
+ * <MyComponents />
76
+ * </MnemonicProvider>
77
+ * );
78
+ * }
79
+ *
80
+ * // Then in browser console:
81
+ * const dt = window.__REACT_MNEMONIC_DEVTOOLS__.resolve('myApp')
82
+ * dt?.dump()
83
+ * dt?.get('user')
84
+ * dt?.set('theme', 'dark')
85
+ * ```
86
+ *
87
+ * @example
88
+ * ```tsx
89
+ * // Multiple providers with different namespaces
90
+ * function App() {
91
+ * return (
92
+ * <MnemonicProvider namespace="user-prefs">
93
+ * <UserSettings />
94
+ * <MnemonicProvider namespace="app-state">
95
+ * <Dashboard />
96
+ * </MnemonicProvider>
97
+ * </MnemonicProvider>
98
+ * );
99
+ * }
100
+ * ```
101
+ *
102
+ * @example
103
+ * ```tsx
104
+ * // Delay persisted storage reads until after client mount
105
+ * function App() {
106
+ * return (
107
+ * <MnemonicProvider
108
+ * namespace="myApp"
109
+ * ssr={{ hydration: "client-only" }}
110
+ * >
111
+ * <MyComponents />
112
+ * </MnemonicProvider>
113
+ * );
114
+ * }
115
+ * ```
116
+ *
117
+ * @remarks
118
+ * - Creates a stable store instance that only recreates when namespace, storage, or enableDevTools change
119
+ * - All storage operations are cached in memory for fast reads
120
+ * - Storage failures are handled gracefully (logged but not thrown)
121
+ * - `StorageLike` is intentionally synchronous for v1; async persistence must sit behind a sync facade
122
+ * - In SSR environments, the provider is safe by default: hooks render
123
+ * `defaultValue` unless configured with an explicit `ssr.serverValue`
124
+ * - The store implements React's useSyncExternalStore contract for efficient updates
125
+ *
126
+ * @see {@link useMnemonicKey} - Hook for using persistent state
127
+ * @see {@link MnemonicProviderOptions} - Configuration options
128
+ */
129
+ declare function MnemonicProvider({ children, namespace, storage, enableDevTools, schemaMode, schemaRegistry, ssr, }: MnemonicProviderProps): react_jsx_runtime.JSX.Element;
130
+
131
+ /**
132
+ * React hook for persistent, type-safe state management.
133
+ */
134
+ declare function useMnemonicKey<T, K extends string>(descriptor: MnemonicKeyDescriptor<T, K>): MnemonicKeyState<T>;
135
+ declare function useMnemonicKey<T>(key: string, options: UseMnemonicKeyOptions<T>): MnemonicKeyState<T>;
136
+
137
+ /**
138
+ * Create an immutable schema registry for common default/strict-mode setups.
139
+ *
140
+ * The helper indexes schemas and migrations up front, validates duplicate and
141
+ * ambiguous definitions, and returns a {@link SchemaRegistry} ready to pass to
142
+ * `MnemonicProvider`.
143
+ *
144
+ * Most applications should prefer this helper over manually implementing
145
+ * {@link SchemaRegistry}.
146
+ *
147
+ * See the
148
+ * [Schema Migration guide](https://thirtytwobits.github.io/react-mnemonic/docs/guides/schema-migration)
149
+ * for end-to-end registry and migration patterns.
150
+ *
151
+ * @param options - Initial schema and migration definitions
152
+ * @returns An indexed immutable schema registry
153
+ *
154
+ * @throws {SchemaError} With `SCHEMA_REGISTRATION_CONFLICT` for duplicate
155
+ * schemas, or `MIGRATION_GRAPH_INVALID` for invalid migration graphs
156
+ */
157
+ declare function createSchemaRegistry(options?: CreateSchemaRegistryOptions): SchemaRegistry;
158
+
159
+ /**
160
+ * Create a versioned key schema that preserves the decoded value type inferred
161
+ * from a typed schema helper.
162
+ */
163
+ declare function defineKeySchema<const K extends string, TSchema extends JsonSchema>(key: K, version: number, schema: TSchema): KeySchema<InferJsonSchemaValue<TSchema>, K, TSchema>;
164
+ /**
165
+ * Create a typed migration rule between two key schema versions.
166
+ *
167
+ * The `migrate(...)` callback is inferred from the source and target schemas,
168
+ * which keeps migration logic aligned with the registered runtime schemas.
169
+ */
170
+ declare function defineMigration<const K extends string, TFrom, TTo>(fromSchema: KeySchema<TFrom, K>, toSchema: KeySchema<TTo, K>, migrate: (value: TFrom) => TTo): MigrationRule<TFrom, TTo, K>;
171
+ /**
172
+ * Create a typed write-time normalization rule for a single key schema.
173
+ */
174
+ declare function defineWriteMigration<const K extends string, TValue>(schema: KeySchema<TValue, K>, migrate: (value: TValue) => TValue): MigrationRule<TValue, TValue, K>;
175
+
176
+ /**
177
+ * Adapter functions for structural migration helpers.
178
+ *
179
+ * These helpers assume tree-like data, but not a specific node shape. Supply a
180
+ * `StructuralTreeHelpers<T>` when your nodes use custom field names. When your
181
+ * nodes already look like `{ id, children }`, the exported helpers work without
182
+ * any adapter configuration.
183
+ *
184
+ * @template T - Tree node type
185
+ */
186
+ interface StructuralTreeHelpers<T> {
187
+ /**
188
+ * Returns the stable identifier for a node.
189
+ */
190
+ getId: (node: T) => string;
191
+ /**
192
+ * Returns the node's child list, or `undefined` when it has no children.
193
+ */
194
+ getChildren: (node: T) => readonly T[] | undefined;
195
+ /**
196
+ * Returns a copy of the node with a new child list.
197
+ */
198
+ withChildren: (node: T, children: T[]) => T;
199
+ /**
200
+ * Returns a copy of the node with a new identifier.
201
+ */
202
+ withId: (node: T, id: string) => T;
203
+ }
204
+ /**
205
+ * Default tree node shape supported by the structural migration helpers.
206
+ *
207
+ * If your nodes already use `id` and `children`, you can call the helpers
208
+ * directly without supplying `StructuralTreeHelpers`.
209
+ *
210
+ * @template T - Tree node type
211
+ */
212
+ interface StructuralNode<T> {
213
+ /**
214
+ * Stable node identifier used for lookup and rename operations.
215
+ */
216
+ id: string;
217
+ /**
218
+ * Optional child nodes.
219
+ */
220
+ children?: readonly T[];
221
+ }
222
+ /**
223
+ * Finds the first node with the requested id using depth-first traversal.
224
+ *
225
+ * @template T - Tree node type (must extend `{ id: string; children?: readonly T[] }` when `helpers` is omitted)
226
+ * @param root - Root node to search
227
+ * @param id - Target node id
228
+ * @returns The matching node, or `undefined`
229
+ */
230
+ declare function findNodeById<T extends StructuralNode<T>>(root: T, id: string): T | undefined;
231
+ /**
232
+ * Finds the first node with the requested id using depth-first traversal.
233
+ *
234
+ * @template T - Tree node type
235
+ * @param root - Root node to search
236
+ * @param id - Target node id
237
+ * @param helpers - Adapter for custom node shapes
238
+ * @returns The matching node, or `undefined`
239
+ */
240
+ declare function findNodeById<T>(root: T, id: string, helpers: StructuralTreeHelpers<T>): T | undefined;
241
+ /**
242
+ * Inserts a child under the target parent when none of that parent's existing
243
+ * direct children share the same id. Returns the original tree when the parent
244
+ * is missing or the child is already present as a direct child.
245
+ *
246
+ * @template T - Tree node type (must extend `{ id: string; children?: readonly T[] }` when `helpers` is omitted)
247
+ * @param root - Root node to update
248
+ * @param parentId - Parent node that should receive the child
249
+ * @param child - Child node to append
250
+ * @returns Updated tree with the child inserted once
251
+ */
252
+ declare function insertChildIfMissing<T extends StructuralNode<T>>(root: T, parentId: string, child: T): T;
253
+ /**
254
+ * Inserts a child under the target parent when no existing child shares the
255
+ * same id. Returns the original tree when the parent is missing or the child is
256
+ * already present.
257
+ *
258
+ * @template T - Tree node type
259
+ * @param root - Root node to update
260
+ * @param parentId - Parent node that should receive the child
261
+ * @param child - Child node to append
262
+ * @param helpers - Adapter for custom node shapes
263
+ * @returns Updated tree with the child inserted once
264
+ */
265
+ declare function insertChildIfMissing<T>(root: T, parentId: string, child: T, helpers: StructuralTreeHelpers<T>): T;
266
+ /**
267
+ * Renames every node with the source id while preserving tree structure.
268
+ * Returns the original tree when the source id is missing or the target id
269
+ * already exists elsewhere.
270
+ *
271
+ * @template T - Tree node type (must extend `{ id: string; children?: readonly T[] }` when `helpers` is omitted)
272
+ * @param root - Root node to update
273
+ * @param currentId - Existing id to rename
274
+ * @param nextId - Replacement id
275
+ * @returns Updated tree with matching node ids renamed
276
+ */
277
+ declare function renameNode<T extends StructuralNode<T>>(root: T, currentId: string, nextId: string): T;
278
+ /**
279
+ * Renames every node with the source id while preserving tree structure.
280
+ * Returns the original tree when the source id is missing or the target id
281
+ * already exists elsewhere.
282
+ *
283
+ * @template T - Tree node type
284
+ * @param root - Root node to update
285
+ * @param currentId - Existing id to rename
286
+ * @param nextId - Replacement id
287
+ * @param helpers - Adapter for custom node shapes
288
+ * @returns Updated tree with matching node ids renamed
289
+ */
290
+ declare function renameNode<T>(root: T, currentId: string, nextId: string, helpers: StructuralTreeHelpers<T>): T;
291
+ /**
292
+ * Deduplicates each node's immediate children while preserving the first child
293
+ * encountered for each key. The helper traverses the full tree and returns the
294
+ * original root when no duplicates are removed.
295
+ *
296
+ * @template T - Tree node type (must extend `{ id: string; children?: readonly T[] }` when `helpers` is omitted)
297
+ * @template K - Deduplication key type
298
+ * @param root - Root node to normalize
299
+ * @param getKey - Function that computes a dedupe key for each child
300
+ * @returns Updated tree with duplicate siblings removed
301
+ */
302
+ declare function dedupeChildrenBy<T extends StructuralNode<T>, K>(root: T, getKey: (node: T) => K): T;
303
+ /**
304
+ * Deduplicates each node's immediate children while preserving the first child
305
+ * encountered for each key. The helper traverses the full tree and returns the
306
+ * original root when no duplicates are removed.
307
+ *
308
+ * @template T - Tree node type
309
+ * @template K - Deduplication key type
310
+ * @param root - Root node to normalize
311
+ * @param getKey - Function that computes a dedupe key for each child
312
+ * @param helpers - Adapter for custom node shapes
313
+ * @returns Updated tree with duplicate siblings removed
314
+ */
315
+ declare function dedupeChildrenBy<T, K>(root: T, getKey: (node: T) => K, helpers: StructuralTreeHelpers<T>): T;
316
+
317
+ export { CreateSchemaRegistryOptions, InferJsonSchemaValue, JsonSchema, KeySchema, MigrationRule, MnemonicKeyDescriptor, MnemonicKeyState, MnemonicProvider, MnemonicProviderOptions, type MnemonicProviderProps, SchemaRegistry, type StructuralNode, type StructuralTreeHelpers, UseMnemonicKeyOptions, createSchemaRegistry, dedupeChildrenBy, defineKeySchema, defineMigration, defineWriteMigration, findNodeById, insertChildIfMissing, renameNode, useMnemonicKey };
@@ -0,0 +1,317 @@
1
+ import { M as MnemonicProviderOptions, a as MnemonicKeyDescriptor, b as MnemonicKeyState, U as UseMnemonicKeyOptions, y as CreateSchemaRegistryOptions, z as SchemaRegistry, A as JsonSchema, K as KeySchema, I as InferJsonSchemaValue, B as MigrationRule } from './key-BvFvcKiR.js';
2
+ export { C as Codec, c as CodecError, D as CompiledValidator, J as JSONCodec, E as JsonSchemaType, F as JsonSchemaValidationError, L as Listener, G as MigrationPath, d as Mnemonic, e as MnemonicDevToolsCapabilities, f as MnemonicDevToolsMeta, g as MnemonicDevToolsProviderApi, h as MnemonicDevToolsProviderDescriptor, i as MnemonicDevToolsProviderEntry, j as MnemonicDevToolsRegistry, k as MnemonicDevToolsWeakRef, l as MnemonicHydrationMode, m as MnemonicKeySSRConfig, n as MnemonicProviderSSRConfig, o as MnemonicRecoveryAction, p as MnemonicRecoveryEvent, q as MnemonicRecoveryHook, R as ReconcileContext, H as SchemaBoundKeyOptions, S as SchemaError, r as SchemaMode, s as StorageLike, T as TypedJsonSchema, N as TypedKeySchema, t as Unsubscribe, u as UseMnemonicRecoveryOptions, O as compileSchema, v as createCodec, w as defineMnemonicKey, P as mnemonicSchema, x as useMnemonicRecovery, Q as validateJsonSchema } from './key-BvFvcKiR.js';
3
+ import * as react_jsx_runtime from 'react/jsx-runtime';
4
+ import { ReactNode } from 'react';
5
+
6
+ /**
7
+ * Props for the MnemonicProvider component.
8
+ *
9
+ * Extends MnemonicProviderOptions with required children prop.
10
+ *
11
+ * @see {@link MnemonicProviderOptions} - Configuration options
12
+ * @see {@link MnemonicProvider} - Provider component
13
+ */
14
+ interface MnemonicProviderProps extends Readonly<MnemonicProviderOptions> {
15
+ /**
16
+ * React children to render within the provider.
17
+ */
18
+ readonly children: ReactNode;
19
+ }
20
+ /**
21
+ * React Context provider for namespace-isolated persistent state.
22
+ *
23
+ * Creates a scoped storage environment where all keys are automatically prefixed
24
+ * with the namespace to prevent collisions. Implements an in-memory cache with
25
+ * read-through behavior to the underlying storage backend (localStorage by default).
26
+ *
27
+ * This provider must wrap any components that use `useMnemonicKey`. Multiple
28
+ * providers with different namespaces can coexist in the same application.
29
+ *
30
+ * @param props - Provider configuration and children
31
+ * @param props.children - React children to render within the provider
32
+ * @param props.namespace - Unique namespace for isolating storage keys
33
+ * @param props.storage - Optional synchronous custom storage backend (defaults to localStorage)
34
+ * @param props.enableDevTools - Enable DevTools debugging interface (defaults to false)
35
+ * @param props.schemaMode - Schema enforcement mode (default: "default")
36
+ * @param props.schemaRegistry - Optional schema registry for storing schemas and migrations
37
+ * @param props.ssr - Optional SSR defaults for descendant hooks
38
+ *
39
+ * @example
40
+ * ```tsx
41
+ * // Basic usage with default settings
42
+ * function App() {
43
+ * return (
44
+ * <MnemonicProvider namespace="myApp">
45
+ * <MyComponents />
46
+ * </MnemonicProvider>
47
+ * );
48
+ * }
49
+ * ```
50
+ *
51
+ * @example
52
+ * ```tsx
53
+ * // With a synchronous custom storage backend
54
+ * function App() {
55
+ * return (
56
+ * <MnemonicProvider
57
+ * namespace="myApp"
58
+ * storage={window.sessionStorage}
59
+ * >
60
+ * <MyComponents />
61
+ * </MnemonicProvider>
62
+ * );
63
+ * }
64
+ * ```
65
+ *
66
+ * @example
67
+ * ```tsx
68
+ * // With DevTools enabled (development only)
69
+ * function App() {
70
+ * return (
71
+ * <MnemonicProvider
72
+ * namespace="myApp"
73
+ * enableDevTools={process.env.NODE_ENV === 'development'}
74
+ * >
75
+ * <MyComponents />
76
+ * </MnemonicProvider>
77
+ * );
78
+ * }
79
+ *
80
+ * // Then in browser console:
81
+ * const dt = window.__REACT_MNEMONIC_DEVTOOLS__.resolve('myApp')
82
+ * dt?.dump()
83
+ * dt?.get('user')
84
+ * dt?.set('theme', 'dark')
85
+ * ```
86
+ *
87
+ * @example
88
+ * ```tsx
89
+ * // Multiple providers with different namespaces
90
+ * function App() {
91
+ * return (
92
+ * <MnemonicProvider namespace="user-prefs">
93
+ * <UserSettings />
94
+ * <MnemonicProvider namespace="app-state">
95
+ * <Dashboard />
96
+ * </MnemonicProvider>
97
+ * </MnemonicProvider>
98
+ * );
99
+ * }
100
+ * ```
101
+ *
102
+ * @example
103
+ * ```tsx
104
+ * // Delay persisted storage reads until after client mount
105
+ * function App() {
106
+ * return (
107
+ * <MnemonicProvider
108
+ * namespace="myApp"
109
+ * ssr={{ hydration: "client-only" }}
110
+ * >
111
+ * <MyComponents />
112
+ * </MnemonicProvider>
113
+ * );
114
+ * }
115
+ * ```
116
+ *
117
+ * @remarks
118
+ * - Creates a stable store instance that only recreates when namespace, storage, or enableDevTools change
119
+ * - All storage operations are cached in memory for fast reads
120
+ * - Storage failures are handled gracefully (logged but not thrown)
121
+ * - `StorageLike` is intentionally synchronous for v1; async persistence must sit behind a sync facade
122
+ * - In SSR environments, the provider is safe by default: hooks render
123
+ * `defaultValue` unless configured with an explicit `ssr.serverValue`
124
+ * - The store implements React's useSyncExternalStore contract for efficient updates
125
+ *
126
+ * @see {@link useMnemonicKey} - Hook for using persistent state
127
+ * @see {@link MnemonicProviderOptions} - Configuration options
128
+ */
129
+ declare function MnemonicProvider({ children, namespace, storage, enableDevTools, schemaMode, schemaRegistry, ssr, }: MnemonicProviderProps): react_jsx_runtime.JSX.Element;
130
+
131
+ /**
132
+ * React hook for persistent, type-safe state management.
133
+ */
134
+ declare function useMnemonicKey<T, K extends string>(descriptor: MnemonicKeyDescriptor<T, K>): MnemonicKeyState<T>;
135
+ declare function useMnemonicKey<T>(key: string, options: UseMnemonicKeyOptions<T>): MnemonicKeyState<T>;
136
+
137
+ /**
138
+ * Create an immutable schema registry for common default/strict-mode setups.
139
+ *
140
+ * The helper indexes schemas and migrations up front, validates duplicate and
141
+ * ambiguous definitions, and returns a {@link SchemaRegistry} ready to pass to
142
+ * `MnemonicProvider`.
143
+ *
144
+ * Most applications should prefer this helper over manually implementing
145
+ * {@link SchemaRegistry}.
146
+ *
147
+ * See the
148
+ * [Schema Migration guide](https://thirtytwobits.github.io/react-mnemonic/docs/guides/schema-migration)
149
+ * for end-to-end registry and migration patterns.
150
+ *
151
+ * @param options - Initial schema and migration definitions
152
+ * @returns An indexed immutable schema registry
153
+ *
154
+ * @throws {SchemaError} With `SCHEMA_REGISTRATION_CONFLICT` for duplicate
155
+ * schemas, or `MIGRATION_GRAPH_INVALID` for invalid migration graphs
156
+ */
157
+ declare function createSchemaRegistry(options?: CreateSchemaRegistryOptions): SchemaRegistry;
158
+
159
+ /**
160
+ * Create a versioned key schema that preserves the decoded value type inferred
161
+ * from a typed schema helper.
162
+ */
163
+ declare function defineKeySchema<const K extends string, TSchema extends JsonSchema>(key: K, version: number, schema: TSchema): KeySchema<InferJsonSchemaValue<TSchema>, K, TSchema>;
164
+ /**
165
+ * Create a typed migration rule between two key schema versions.
166
+ *
167
+ * The `migrate(...)` callback is inferred from the source and target schemas,
168
+ * which keeps migration logic aligned with the registered runtime schemas.
169
+ */
170
+ declare function defineMigration<const K extends string, TFrom, TTo>(fromSchema: KeySchema<TFrom, K>, toSchema: KeySchema<TTo, K>, migrate: (value: TFrom) => TTo): MigrationRule<TFrom, TTo, K>;
171
+ /**
172
+ * Create a typed write-time normalization rule for a single key schema.
173
+ */
174
+ declare function defineWriteMigration<const K extends string, TValue>(schema: KeySchema<TValue, K>, migrate: (value: TValue) => TValue): MigrationRule<TValue, TValue, K>;
175
+
176
+ /**
177
+ * Adapter functions for structural migration helpers.
178
+ *
179
+ * These helpers assume tree-like data, but not a specific node shape. Supply a
180
+ * `StructuralTreeHelpers<T>` when your nodes use custom field names. When your
181
+ * nodes already look like `{ id, children }`, the exported helpers work without
182
+ * any adapter configuration.
183
+ *
184
+ * @template T - Tree node type
185
+ */
186
+ interface StructuralTreeHelpers<T> {
187
+ /**
188
+ * Returns the stable identifier for a node.
189
+ */
190
+ getId: (node: T) => string;
191
+ /**
192
+ * Returns the node's child list, or `undefined` when it has no children.
193
+ */
194
+ getChildren: (node: T) => readonly T[] | undefined;
195
+ /**
196
+ * Returns a copy of the node with a new child list.
197
+ */
198
+ withChildren: (node: T, children: T[]) => T;
199
+ /**
200
+ * Returns a copy of the node with a new identifier.
201
+ */
202
+ withId: (node: T, id: string) => T;
203
+ }
204
+ /**
205
+ * Default tree node shape supported by the structural migration helpers.
206
+ *
207
+ * If your nodes already use `id` and `children`, you can call the helpers
208
+ * directly without supplying `StructuralTreeHelpers`.
209
+ *
210
+ * @template T - Tree node type
211
+ */
212
+ interface StructuralNode<T> {
213
+ /**
214
+ * Stable node identifier used for lookup and rename operations.
215
+ */
216
+ id: string;
217
+ /**
218
+ * Optional child nodes.
219
+ */
220
+ children?: readonly T[];
221
+ }
222
+ /**
223
+ * Finds the first node with the requested id using depth-first traversal.
224
+ *
225
+ * @template T - Tree node type (must extend `{ id: string; children?: readonly T[] }` when `helpers` is omitted)
226
+ * @param root - Root node to search
227
+ * @param id - Target node id
228
+ * @returns The matching node, or `undefined`
229
+ */
230
+ declare function findNodeById<T extends StructuralNode<T>>(root: T, id: string): T | undefined;
231
+ /**
232
+ * Finds the first node with the requested id using depth-first traversal.
233
+ *
234
+ * @template T - Tree node type
235
+ * @param root - Root node to search
236
+ * @param id - Target node id
237
+ * @param helpers - Adapter for custom node shapes
238
+ * @returns The matching node, or `undefined`
239
+ */
240
+ declare function findNodeById<T>(root: T, id: string, helpers: StructuralTreeHelpers<T>): T | undefined;
241
+ /**
242
+ * Inserts a child under the target parent when none of that parent's existing
243
+ * direct children share the same id. Returns the original tree when the parent
244
+ * is missing or the child is already present as a direct child.
245
+ *
246
+ * @template T - Tree node type (must extend `{ id: string; children?: readonly T[] }` when `helpers` is omitted)
247
+ * @param root - Root node to update
248
+ * @param parentId - Parent node that should receive the child
249
+ * @param child - Child node to append
250
+ * @returns Updated tree with the child inserted once
251
+ */
252
+ declare function insertChildIfMissing<T extends StructuralNode<T>>(root: T, parentId: string, child: T): T;
253
+ /**
254
+ * Inserts a child under the target parent when no existing child shares the
255
+ * same id. Returns the original tree when the parent is missing or the child is
256
+ * already present.
257
+ *
258
+ * @template T - Tree node type
259
+ * @param root - Root node to update
260
+ * @param parentId - Parent node that should receive the child
261
+ * @param child - Child node to append
262
+ * @param helpers - Adapter for custom node shapes
263
+ * @returns Updated tree with the child inserted once
264
+ */
265
+ declare function insertChildIfMissing<T>(root: T, parentId: string, child: T, helpers: StructuralTreeHelpers<T>): T;
266
+ /**
267
+ * Renames every node with the source id while preserving tree structure.
268
+ * Returns the original tree when the source id is missing or the target id
269
+ * already exists elsewhere.
270
+ *
271
+ * @template T - Tree node type (must extend `{ id: string; children?: readonly T[] }` when `helpers` is omitted)
272
+ * @param root - Root node to update
273
+ * @param currentId - Existing id to rename
274
+ * @param nextId - Replacement id
275
+ * @returns Updated tree with matching node ids renamed
276
+ */
277
+ declare function renameNode<T extends StructuralNode<T>>(root: T, currentId: string, nextId: string): T;
278
+ /**
279
+ * Renames every node with the source id while preserving tree structure.
280
+ * Returns the original tree when the source id is missing or the target id
281
+ * already exists elsewhere.
282
+ *
283
+ * @template T - Tree node type
284
+ * @param root - Root node to update
285
+ * @param currentId - Existing id to rename
286
+ * @param nextId - Replacement id
287
+ * @param helpers - Adapter for custom node shapes
288
+ * @returns Updated tree with matching node ids renamed
289
+ */
290
+ declare function renameNode<T>(root: T, currentId: string, nextId: string, helpers: StructuralTreeHelpers<T>): T;
291
+ /**
292
+ * Deduplicates each node's immediate children while preserving the first child
293
+ * encountered for each key. The helper traverses the full tree and returns the
294
+ * original root when no duplicates are removed.
295
+ *
296
+ * @template T - Tree node type (must extend `{ id: string; children?: readonly T[] }` when `helpers` is omitted)
297
+ * @template K - Deduplication key type
298
+ * @param root - Root node to normalize
299
+ * @param getKey - Function that computes a dedupe key for each child
300
+ * @returns Updated tree with duplicate siblings removed
301
+ */
302
+ declare function dedupeChildrenBy<T extends StructuralNode<T>, K>(root: T, getKey: (node: T) => K): T;
303
+ /**
304
+ * Deduplicates each node's immediate children while preserving the first child
305
+ * encountered for each key. The helper traverses the full tree and returns the
306
+ * original root when no duplicates are removed.
307
+ *
308
+ * @template T - Tree node type
309
+ * @template K - Deduplication key type
310
+ * @param root - Root node to normalize
311
+ * @param getKey - Function that computes a dedupe key for each child
312
+ * @param helpers - Adapter for custom node shapes
313
+ * @returns Updated tree with duplicate siblings removed
314
+ */
315
+ declare function dedupeChildrenBy<T, K>(root: T, getKey: (node: T) => K, helpers: StructuralTreeHelpers<T>): T;
316
+
317
+ export { CreateSchemaRegistryOptions, InferJsonSchemaValue, JsonSchema, KeySchema, MigrationRule, MnemonicKeyDescriptor, MnemonicKeyState, MnemonicProvider, MnemonicProviderOptions, type MnemonicProviderProps, SchemaRegistry, type StructuralNode, type StructuralTreeHelpers, UseMnemonicKeyOptions, createSchemaRegistry, dedupeChildrenBy, defineKeySchema, defineMigration, defineWriteMigration, findNodeById, insertChildIfMissing, renameNode, useMnemonicKey };