react-mnemonic 1.2.0-beta1 → 1.3.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.
@@ -1405,6 +1405,93 @@ interface MnemonicKeyDescriptor<T, K extends string = string> {
1405
1405
  */
1406
1406
  readonly options: UseMnemonicKeyOptions<T>;
1407
1407
  }
1408
+ /**
1409
+ * Server-rendered seed value for lean optional persistence.
1410
+ *
1411
+ * Unlike the full `MnemonicKeySSRConfig`, the lean optional entrypoint only
1412
+ * supports supplying an initial server value. Hydration policy remains an
1413
+ * application/provider concern so reusable component libraries can stay tiny.
1414
+ */
1415
+ interface OptionalMnemonicKeySSRConfig<T> {
1416
+ /**
1417
+ * Value exposed during SSR and the first hydration snapshot.
1418
+ */
1419
+ serverValue?: T | (() => T);
1420
+ }
1421
+ /**
1422
+ * Reusable, importable contract for a single optionally persistent key.
1423
+ *
1424
+ * This is the descriptor shape consumed by `react-mnemonic/optional`.
1425
+ */
1426
+ interface OptionalMnemonicKeyDescriptor<T, K extends string = string> {
1427
+ /**
1428
+ * Unprefixed storage key name.
1429
+ */
1430
+ readonly key: K;
1431
+ /**
1432
+ * Canonical options for the optional hook contract.
1433
+ */
1434
+ readonly options: OptionalMnemonicKeyOptions<T>;
1435
+ }
1436
+ /**
1437
+ * Lean configuration options for `useMnemonicKeyOptional(...)`.
1438
+ *
1439
+ * These options are intentionally smaller than `UseMnemonicKeyOptions<T>` so
1440
+ * component libraries can depend on a tiny fallback-first shim while still
1441
+ * passing persistence metadata through to an application-provided adapter.
1442
+ */
1443
+ type OptionalMnemonicKeyOptions<T> = {
1444
+ /**
1445
+ * Default value used when no persisted value exists or no provider is mounted.
1446
+ */
1447
+ defaultValue: T | (() => T);
1448
+ /**
1449
+ * Codec metadata forwarded to a provider-backed adapter when one exists.
1450
+ *
1451
+ * Ignored by the in-memory fallback path.
1452
+ */
1453
+ codec?: Codec<T>;
1454
+ /**
1455
+ * Invoked once after the initial value resolves.
1456
+ */
1457
+ onMount?: (value: T) => void;
1458
+ /**
1459
+ * Invoked after the visible value changes.
1460
+ */
1461
+ onChange?: (value: T, previous: T) => void;
1462
+ /**
1463
+ * Minimal SSR support for the lean optional hook.
1464
+ */
1465
+ ssr?: OptionalMnemonicKeySSRConfig<T>;
1466
+ /**
1467
+ * Schema version metadata forwarded to schema-capable providers when present.
1468
+ *
1469
+ * Ignored by the in-memory fallback path and by providers without schema
1470
+ * capabilities.
1471
+ */
1472
+ schema?: {
1473
+ version: number;
1474
+ };
1475
+ };
1476
+ /**
1477
+ * Public metadata exposed by `react-mnemonic/optional`.
1478
+ *
1479
+ * This intentionally avoids exposing the full low-level store API. Applications
1480
+ * that need raw store access should use the required-provider entrypoints.
1481
+ */
1482
+ interface MnemonicOptionalBridge {
1483
+ /**
1484
+ * Active namespace when a provider-backed bridge is mounted.
1485
+ */
1486
+ namespace: string;
1487
+ /**
1488
+ * Capabilities supported by the active provider-backed bridge.
1489
+ */
1490
+ capabilities: {
1491
+ persistence: true;
1492
+ schema: boolean;
1493
+ };
1494
+ }
1408
1495
  /**
1409
1496
  * Key descriptor options inferred from a typed key schema.
1410
1497
  *
@@ -1676,48 +1763,4 @@ type ReconcileContext = {
1676
1763
  latestVersion?: number;
1677
1764
  };
1678
1765
 
1679
- /**
1680
- * Hook for namespace-scoped recovery actions such as hard reset and selective clear.
1681
- *
1682
- * Applications can use this to offer self-service recovery UX for corrupt or
1683
- * legacy persisted state. The hook operates on the current provider namespace.
1684
- *
1685
- * See the
1686
- * [Reset and Recovery guide](https://thirtytwobits.github.io/react-mnemonic/docs/guides/reset-and-recovery)
1687
- * for soft-reset and hard-reset patterns.
1688
- *
1689
- * @param options - Optional recovery callback for telemetry/auditing
1690
- * @returns Namespace recovery helpers
1691
- *
1692
- * @throws {Error} If used outside of a MnemonicProvider
1693
- */
1694
- declare function useMnemonicRecovery(options?: UseMnemonicRecoveryOptions): MnemonicRecoveryHook;
1695
-
1696
- /**
1697
- * Define a reusable, importable contract for a persisted key.
1698
- *
1699
- * This packages the storage key and the canonical `useMnemonicKey(...)`
1700
- * options into a single object that can be shared across components, docs,
1701
- * and generated code.
1702
- *
1703
- * @template K - The literal storage key name
1704
- * @template T - The decoded value type for the key
1705
- *
1706
- * @param key - The unprefixed storage key
1707
- * @param options - Canonical hook options for the key
1708
- * @returns A descriptor that can be passed directly to `useMnemonicKey(...)`
1709
- *
1710
- * @example
1711
- * ```typescript
1712
- * const themeKey = defineMnemonicKey("theme", {
1713
- * defaultValue: "light" as "light" | "dark",
1714
- * listenCrossTab: true,
1715
- * });
1716
- *
1717
- * const { value, set } = useMnemonicKey(themeKey);
1718
- * ```
1719
- */
1720
- declare function defineMnemonicKey<const K extends string, T>(key: K, options: UseMnemonicKeyOptions<T>): MnemonicKeyDescriptor<T, K>;
1721
- declare function defineMnemonicKey<const K extends string, TSchema extends KeySchema<unknown, K, JsonSchema>>(keySchema: TSchema, options: SchemaBoundKeyOptions<TSchema extends KeySchema<infer TValue, string, JsonSchema> ? TValue : never>): MnemonicKeyDescriptor<TSchema extends KeySchema<infer TValue, string, JsonSchema> ? TValue : never, TSchema["key"]>;
1722
-
1723
- export { type JsonSchema as A, type MigrationRule as B, type Codec as C, type CompiledValidator as D, type JsonSchemaType as E, type JsonSchemaValidationError as F, type MigrationPath as G, type SchemaBoundKeyOptions as H, type InferJsonSchemaValue as I, JSONCodec as J, type KeySchema as K, type Listener as L, type MnemonicProviderOptions as M, type TypedKeySchema as N, compileSchema as O, mnemonicSchema as P, validateJsonSchema as Q, type ReconcileContext as R, SchemaError as S, type TypedJsonSchema as T, type UseMnemonicKeyOptions as U, type MnemonicKeyDescriptor as a, type MnemonicKeyState as b, CodecError as c, type Mnemonic as d, type MnemonicDevToolsCapabilities as e, type MnemonicDevToolsMeta as f, type MnemonicDevToolsProviderApi as g, type MnemonicDevToolsProviderDescriptor as h, type MnemonicDevToolsProviderEntry as i, type MnemonicDevToolsRegistry as j, type MnemonicDevToolsWeakRef as k, type MnemonicHydrationMode as l, type MnemonicKeySSRConfig as m, type MnemonicProviderSSRConfig as n, type MnemonicRecoveryAction as o, type MnemonicRecoveryEvent as p, type MnemonicRecoveryHook as q, type SchemaMode as r, type StorageLike as s, type Unsubscribe as t, type UseMnemonicRecoveryOptions as u, createCodec as v, defineMnemonicKey as w, useMnemonicRecovery as x, type CreateSchemaRegistryOptions as y, type SchemaRegistry as z };
1766
+ export { type SchemaBoundKeyOptions as A, type CreateSchemaRegistryOptions as B, type Codec as C, type SchemaRegistry as D, type MigrationRule as E, type CompiledValidator as F, type JsonSchemaType as G, type JsonSchemaValidationError as H, type InferJsonSchemaValue as I, JSONCodec as J, type KeySchema as K, type Listener as L, type MnemonicProviderOptions as M, type MigrationPath as N, type OptionalMnemonicKeyDescriptor as O, type TypedKeySchema as P, compileSchema as Q, type ReconcileContext as R, SchemaError as S, type TypedJsonSchema as T, type UseMnemonicKeyOptions as U, mnemonicSchema as V, validateJsonSchema as W, type MnemonicKeyDescriptor as a, type MnemonicKeyState as b, CodecError as c, type Mnemonic as d, type MnemonicDevToolsCapabilities as e, type MnemonicDevToolsMeta as f, type MnemonicDevToolsProviderApi as g, type MnemonicDevToolsProviderDescriptor as h, type MnemonicDevToolsProviderEntry as i, type MnemonicDevToolsRegistry as j, type MnemonicDevToolsWeakRef as k, type MnemonicHydrationMode as l, type MnemonicKeySSRConfig as m, type MnemonicProviderSSRConfig as n, type MnemonicRecoveryAction as o, type MnemonicRecoveryEvent as p, type MnemonicRecoveryHook as q, type SchemaMode as r, type StorageLike as s, type Unsubscribe as t, type UseMnemonicRecoveryOptions as u, createCodec as v, type OptionalMnemonicKeyOptions as w, type MnemonicOptionalBridge as x, type OptionalMnemonicKeySSRConfig as y, type JsonSchema as z };
@@ -1405,6 +1405,93 @@ interface MnemonicKeyDescriptor<T, K extends string = string> {
1405
1405
  */
1406
1406
  readonly options: UseMnemonicKeyOptions<T>;
1407
1407
  }
1408
+ /**
1409
+ * Server-rendered seed value for lean optional persistence.
1410
+ *
1411
+ * Unlike the full `MnemonicKeySSRConfig`, the lean optional entrypoint only
1412
+ * supports supplying an initial server value. Hydration policy remains an
1413
+ * application/provider concern so reusable component libraries can stay tiny.
1414
+ */
1415
+ interface OptionalMnemonicKeySSRConfig<T> {
1416
+ /**
1417
+ * Value exposed during SSR and the first hydration snapshot.
1418
+ */
1419
+ serverValue?: T | (() => T);
1420
+ }
1421
+ /**
1422
+ * Reusable, importable contract for a single optionally persistent key.
1423
+ *
1424
+ * This is the descriptor shape consumed by `react-mnemonic/optional`.
1425
+ */
1426
+ interface OptionalMnemonicKeyDescriptor<T, K extends string = string> {
1427
+ /**
1428
+ * Unprefixed storage key name.
1429
+ */
1430
+ readonly key: K;
1431
+ /**
1432
+ * Canonical options for the optional hook contract.
1433
+ */
1434
+ readonly options: OptionalMnemonicKeyOptions<T>;
1435
+ }
1436
+ /**
1437
+ * Lean configuration options for `useMnemonicKeyOptional(...)`.
1438
+ *
1439
+ * These options are intentionally smaller than `UseMnemonicKeyOptions<T>` so
1440
+ * component libraries can depend on a tiny fallback-first shim while still
1441
+ * passing persistence metadata through to an application-provided adapter.
1442
+ */
1443
+ type OptionalMnemonicKeyOptions<T> = {
1444
+ /**
1445
+ * Default value used when no persisted value exists or no provider is mounted.
1446
+ */
1447
+ defaultValue: T | (() => T);
1448
+ /**
1449
+ * Codec metadata forwarded to a provider-backed adapter when one exists.
1450
+ *
1451
+ * Ignored by the in-memory fallback path.
1452
+ */
1453
+ codec?: Codec<T>;
1454
+ /**
1455
+ * Invoked once after the initial value resolves.
1456
+ */
1457
+ onMount?: (value: T) => void;
1458
+ /**
1459
+ * Invoked after the visible value changes.
1460
+ */
1461
+ onChange?: (value: T, previous: T) => void;
1462
+ /**
1463
+ * Minimal SSR support for the lean optional hook.
1464
+ */
1465
+ ssr?: OptionalMnemonicKeySSRConfig<T>;
1466
+ /**
1467
+ * Schema version metadata forwarded to schema-capable providers when present.
1468
+ *
1469
+ * Ignored by the in-memory fallback path and by providers without schema
1470
+ * capabilities.
1471
+ */
1472
+ schema?: {
1473
+ version: number;
1474
+ };
1475
+ };
1476
+ /**
1477
+ * Public metadata exposed by `react-mnemonic/optional`.
1478
+ *
1479
+ * This intentionally avoids exposing the full low-level store API. Applications
1480
+ * that need raw store access should use the required-provider entrypoints.
1481
+ */
1482
+ interface MnemonicOptionalBridge {
1483
+ /**
1484
+ * Active namespace when a provider-backed bridge is mounted.
1485
+ */
1486
+ namespace: string;
1487
+ /**
1488
+ * Capabilities supported by the active provider-backed bridge.
1489
+ */
1490
+ capabilities: {
1491
+ persistence: true;
1492
+ schema: boolean;
1493
+ };
1494
+ }
1408
1495
  /**
1409
1496
  * Key descriptor options inferred from a typed key schema.
1410
1497
  *
@@ -1676,48 +1763,4 @@ type ReconcileContext = {
1676
1763
  latestVersion?: number;
1677
1764
  };
1678
1765
 
1679
- /**
1680
- * Hook for namespace-scoped recovery actions such as hard reset and selective clear.
1681
- *
1682
- * Applications can use this to offer self-service recovery UX for corrupt or
1683
- * legacy persisted state. The hook operates on the current provider namespace.
1684
- *
1685
- * See the
1686
- * [Reset and Recovery guide](https://thirtytwobits.github.io/react-mnemonic/docs/guides/reset-and-recovery)
1687
- * for soft-reset and hard-reset patterns.
1688
- *
1689
- * @param options - Optional recovery callback for telemetry/auditing
1690
- * @returns Namespace recovery helpers
1691
- *
1692
- * @throws {Error} If used outside of a MnemonicProvider
1693
- */
1694
- declare function useMnemonicRecovery(options?: UseMnemonicRecoveryOptions): MnemonicRecoveryHook;
1695
-
1696
- /**
1697
- * Define a reusable, importable contract for a persisted key.
1698
- *
1699
- * This packages the storage key and the canonical `useMnemonicKey(...)`
1700
- * options into a single object that can be shared across components, docs,
1701
- * and generated code.
1702
- *
1703
- * @template K - The literal storage key name
1704
- * @template T - The decoded value type for the key
1705
- *
1706
- * @param key - The unprefixed storage key
1707
- * @param options - Canonical hook options for the key
1708
- * @returns A descriptor that can be passed directly to `useMnemonicKey(...)`
1709
- *
1710
- * @example
1711
- * ```typescript
1712
- * const themeKey = defineMnemonicKey("theme", {
1713
- * defaultValue: "light" as "light" | "dark",
1714
- * listenCrossTab: true,
1715
- * });
1716
- *
1717
- * const { value, set } = useMnemonicKey(themeKey);
1718
- * ```
1719
- */
1720
- declare function defineMnemonicKey<const K extends string, T>(key: K, options: UseMnemonicKeyOptions<T>): MnemonicKeyDescriptor<T, K>;
1721
- declare function defineMnemonicKey<const K extends string, TSchema extends KeySchema<unknown, K, JsonSchema>>(keySchema: TSchema, options: SchemaBoundKeyOptions<TSchema extends KeySchema<infer TValue, string, JsonSchema> ? TValue : never>): MnemonicKeyDescriptor<TSchema extends KeySchema<infer TValue, string, JsonSchema> ? TValue : never, TSchema["key"]>;
1722
-
1723
- export { type JsonSchema as A, type MigrationRule as B, type Codec as C, type CompiledValidator as D, type JsonSchemaType as E, type JsonSchemaValidationError as F, type MigrationPath as G, type SchemaBoundKeyOptions as H, type InferJsonSchemaValue as I, JSONCodec as J, type KeySchema as K, type Listener as L, type MnemonicProviderOptions as M, type TypedKeySchema as N, compileSchema as O, mnemonicSchema as P, validateJsonSchema as Q, type ReconcileContext as R, SchemaError as S, type TypedJsonSchema as T, type UseMnemonicKeyOptions as U, type MnemonicKeyDescriptor as a, type MnemonicKeyState as b, CodecError as c, type Mnemonic as d, type MnemonicDevToolsCapabilities as e, type MnemonicDevToolsMeta as f, type MnemonicDevToolsProviderApi as g, type MnemonicDevToolsProviderDescriptor as h, type MnemonicDevToolsProviderEntry as i, type MnemonicDevToolsRegistry as j, type MnemonicDevToolsWeakRef as k, type MnemonicHydrationMode as l, type MnemonicKeySSRConfig as m, type MnemonicProviderSSRConfig as n, type MnemonicRecoveryAction as o, type MnemonicRecoveryEvent as p, type MnemonicRecoveryHook as q, type SchemaMode as r, type StorageLike as s, type Unsubscribe as t, type UseMnemonicRecoveryOptions as u, createCodec as v, defineMnemonicKey as w, useMnemonicRecovery as x, type CreateSchemaRegistryOptions as y, type SchemaRegistry as z };
1766
+ export { type SchemaBoundKeyOptions as A, type CreateSchemaRegistryOptions as B, type Codec as C, type SchemaRegistry as D, type MigrationRule as E, type CompiledValidator as F, type JsonSchemaType as G, type JsonSchemaValidationError as H, type InferJsonSchemaValue as I, JSONCodec as J, type KeySchema as K, type Listener as L, type MnemonicProviderOptions as M, type MigrationPath as N, type OptionalMnemonicKeyDescriptor as O, type TypedKeySchema as P, compileSchema as Q, type ReconcileContext as R, SchemaError as S, type TypedJsonSchema as T, type UseMnemonicKeyOptions as U, mnemonicSchema as V, validateJsonSchema as W, type MnemonicKeyDescriptor as a, type MnemonicKeyState as b, CodecError as c, type Mnemonic as d, type MnemonicDevToolsCapabilities as e, type MnemonicDevToolsMeta as f, type MnemonicDevToolsProviderApi as g, type MnemonicDevToolsProviderDescriptor as h, type MnemonicDevToolsProviderEntry as i, type MnemonicDevToolsRegistry as j, type MnemonicDevToolsWeakRef as k, type MnemonicHydrationMode as l, type MnemonicKeySSRConfig as m, type MnemonicProviderSSRConfig as n, type MnemonicRecoveryAction as o, type MnemonicRecoveryEvent as p, type MnemonicRecoveryHook as q, type SchemaMode as r, type StorageLike as s, type Unsubscribe as t, type UseMnemonicRecoveryOptions as u, createCodec as v, type OptionalMnemonicKeyOptions as w, type MnemonicOptionalBridge as x, type OptionalMnemonicKeySSRConfig as y, type JsonSchema as z };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-mnemonic",
3
- "version": "1.2.0-beta1",
3
+ "version": "1.3.0",
4
4
  "description": "Persistent, type-safe state management for React",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -33,6 +33,15 @@
33
33
  "import": "./dist/schema.js",
34
34
  "require": "./dist/schema.cjs",
35
35
  "default": "./dist/schema.js"
36
+ },
37
+ "./optional": {
38
+ "types": {
39
+ "import": "./dist/optional.d.ts",
40
+ "require": "./dist/optional.d.cts"
41
+ },
42
+ "import": "./dist/optional.js",
43
+ "require": "./dist/optional.cjs",
44
+ "default": "./dist/optional.js"
36
45
  }
37
46
  },
38
47
  "files": [
@@ -44,12 +53,15 @@
44
53
  "test": "vitest run",
45
54
  "test:consumers": "node ./scripts/run-consumer-fixtures.mjs",
46
55
  "test:coverage": "vitest run --coverage",
56
+ "test:optional-bundle": "node ./scripts/check-optional-bundle.mjs",
47
57
  "test:watch": "vitest",
48
58
  "ai:check": "node ./website/scripts/generate-ai-assets.mjs --check && node ./scripts/generate-agent-instructions.mjs --check",
49
59
  "lint": "tsc -p tsconfig.json --noEmit",
50
60
  "format": "prettier --write .",
51
61
  "format:check": "prettier --check .",
52
62
  "docs:ai": "node ./website/scripts/generate-ai-assets.mjs && node ./scripts/generate-agent-instructions.mjs",
63
+ "docs:version": "npm --prefix website run typedoc && npm run docs:ai && npm --prefix website run docusaurus -- docs:version",
64
+ "release:prepare": "node ./scripts/prepare-release.mjs",
53
65
  "docs": "typedoc",
54
66
  "docs:watch": "typedoc --watch",
55
67
  "docs:site": "npm --prefix website run build",