react-mnemonic 1.3.0 → 1.4.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.
@@ -528,6 +528,19 @@ interface MnemonicProviderOptions {
528
528
  * ```
529
529
  */
530
530
  ssr?: MnemonicProviderSSRConfig;
531
+ /**
532
+ * Optional bootstrap snapshot used to seed the provider cache before the
533
+ * first hook subscribes.
534
+ *
535
+ * Pass the object returned by `recallMnemonic(...)` when you synchronously
536
+ * read values before React renders, for example to apply a theme attribute
537
+ * before first paint and then ensure the first `useMnemonicKey(...)` read
538
+ * sees the same raw storage snapshot without re-reading storage.
539
+ *
540
+ * This seed is consumed only during the provider's initial mount. Later
541
+ * prop changes are ignored so rerenders do not recreate the internal store.
542
+ */
543
+ bootstrap?: MnemonicBootstrapSeed;
531
544
  }
532
545
  /**
533
546
  * Controls how the provider enforces versioned schemas on stored values.
@@ -585,6 +598,64 @@ interface MnemonicProviderSSRConfig {
585
598
  */
586
599
  hydration?: MnemonicHydrationMode;
587
600
  }
601
+ /**
602
+ * Initial bootstrap seed for a provider's in-memory cache.
603
+ *
604
+ * This is primarily used with `recallMnemonic(...)` from
605
+ * `react-mnemonic/bootstrap`, allowing apps to synchronously recall values
606
+ * before React renders and then hand the raw snapshot to `MnemonicProvider`
607
+ * so the first hook read does not hit storage again.
608
+ *
609
+ * The provider currently consumes `raw` to seed its internal cache. `values`
610
+ * are included so callers can carry the same snapshot object through app
611
+ * initialization without splitting it apart.
612
+ *
613
+ * @template TValues - Decoded values keyed by unprefixed storage key
614
+ */
615
+ type MnemonicBootstrapSeed<TValues extends Record<string, unknown> = Record<string, unknown>> = {
616
+ /**
617
+ * Raw storage strings keyed by the unprefixed mnemonic key name.
618
+ *
619
+ * Only keys that were read successfully should appear here.
620
+ *
621
+ * A present `null` entry means the key was confirmed absent when the
622
+ * bootstrap snapshot was taken. Providers may still choose to revalidate
623
+ * that absence on first access, so only non-null string entries are
624
+ * guaranteed to short-circuit an initial storage read.
625
+ *
626
+ * If storage was unavailable or unreadable during bootstrap, omit the key
627
+ * entirely so the provider can retry a normal read later.
628
+ */
629
+ raw?: Record<string, string | null>;
630
+ /**
631
+ * Decoded values recalled during the bootstrap step.
632
+ *
633
+ * The provider stores raw snapshots internally, but retaining the decoded
634
+ * values on the same object is convenient for app-level boot code such as
635
+ * first-paint theme application.
636
+ */
637
+ values?: TValues;
638
+ };
639
+ /**
640
+ * Fully populated snapshot returned by `recallMnemonic(...)`.
641
+ *
642
+ * @template TValues - Decoded values keyed by unprefixed storage key
643
+ */
644
+ type MnemonicBootstrapSnapshot<TValues extends Record<string, unknown> = Record<string, unknown>> = {
645
+ /**
646
+ * Raw storage strings keyed by the unprefixed mnemonic key name.
647
+ *
648
+ * Keys are only included when the bootstrap read successfully observed the
649
+ * underlying storage backend. A present `null` still means the key was
650
+ * confirmed absent at recall time, though providers may revalidate that
651
+ * absence before the first hook read.
652
+ */
653
+ raw: Record<string, string | null>;
654
+ /**
655
+ * Decoded values keyed by the unprefixed mnemonic key name.
656
+ */
657
+ values: TValues;
658
+ };
588
659
  /**
589
660
  * Hook-level SSR controls for `useMnemonicKey(...)`.
590
661
  *
@@ -1763,4 +1834,4 @@ type ReconcileContext = {
1763
1834
  latestVersion?: number;
1764
1835
  };
1765
1836
 
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 };
1837
+ export { type MnemonicOptionalBridge as A, type OptionalMnemonicKeySSRConfig as B, type Codec as C, type JsonSchema as D, type SchemaBoundKeyOptions as E, type CreateSchemaRegistryOptions as F, type MigrationRule as G, type CompiledValidator as H, type InferJsonSchemaValue as I, JSONCodec as J, type KeySchema as K, type Listener as L, type MnemonicKeyDescriptor as M, type JsonSchemaType as N, type OptionalMnemonicKeyDescriptor as O, type JsonSchemaValidationError as P, type MigrationPath as Q, type ReconcileContext as R, type StorageLike as S, type TypedJsonSchema as T, type UseMnemonicKeyOptions as U, type TypedKeySchema as V, compileSchema as W, mnemonicSchema as X, validateJsonSchema as Y, type SchemaMode as a, type SchemaRegistry as b, type MnemonicBootstrapSnapshot as c, CodecError as d, type MnemonicBootstrapSeed as e, SchemaError as f, createCodec as g, type MnemonicProviderOptions as h, type MnemonicKeyState as i, type Mnemonic as j, type MnemonicDevToolsCapabilities as k, type MnemonicDevToolsMeta as l, type MnemonicDevToolsProviderApi as m, type MnemonicDevToolsProviderDescriptor as n, type MnemonicDevToolsProviderEntry as o, type MnemonicDevToolsRegistry as p, type MnemonicDevToolsWeakRef as q, type MnemonicHydrationMode as r, type MnemonicKeySSRConfig as s, type MnemonicProviderSSRConfig as t, type MnemonicRecoveryAction as u, type MnemonicRecoveryEvent as v, type MnemonicRecoveryHook as w, type Unsubscribe as x, type UseMnemonicRecoveryOptions as y, type OptionalMnemonicKeyOptions as z };
@@ -528,6 +528,19 @@ interface MnemonicProviderOptions {
528
528
  * ```
529
529
  */
530
530
  ssr?: MnemonicProviderSSRConfig;
531
+ /**
532
+ * Optional bootstrap snapshot used to seed the provider cache before the
533
+ * first hook subscribes.
534
+ *
535
+ * Pass the object returned by `recallMnemonic(...)` when you synchronously
536
+ * read values before React renders, for example to apply a theme attribute
537
+ * before first paint and then ensure the first `useMnemonicKey(...)` read
538
+ * sees the same raw storage snapshot without re-reading storage.
539
+ *
540
+ * This seed is consumed only during the provider's initial mount. Later
541
+ * prop changes are ignored so rerenders do not recreate the internal store.
542
+ */
543
+ bootstrap?: MnemonicBootstrapSeed;
531
544
  }
532
545
  /**
533
546
  * Controls how the provider enforces versioned schemas on stored values.
@@ -585,6 +598,64 @@ interface MnemonicProviderSSRConfig {
585
598
  */
586
599
  hydration?: MnemonicHydrationMode;
587
600
  }
601
+ /**
602
+ * Initial bootstrap seed for a provider's in-memory cache.
603
+ *
604
+ * This is primarily used with `recallMnemonic(...)` from
605
+ * `react-mnemonic/bootstrap`, allowing apps to synchronously recall values
606
+ * before React renders and then hand the raw snapshot to `MnemonicProvider`
607
+ * so the first hook read does not hit storage again.
608
+ *
609
+ * The provider currently consumes `raw` to seed its internal cache. `values`
610
+ * are included so callers can carry the same snapshot object through app
611
+ * initialization without splitting it apart.
612
+ *
613
+ * @template TValues - Decoded values keyed by unprefixed storage key
614
+ */
615
+ type MnemonicBootstrapSeed<TValues extends Record<string, unknown> = Record<string, unknown>> = {
616
+ /**
617
+ * Raw storage strings keyed by the unprefixed mnemonic key name.
618
+ *
619
+ * Only keys that were read successfully should appear here.
620
+ *
621
+ * A present `null` entry means the key was confirmed absent when the
622
+ * bootstrap snapshot was taken. Providers may still choose to revalidate
623
+ * that absence on first access, so only non-null string entries are
624
+ * guaranteed to short-circuit an initial storage read.
625
+ *
626
+ * If storage was unavailable or unreadable during bootstrap, omit the key
627
+ * entirely so the provider can retry a normal read later.
628
+ */
629
+ raw?: Record<string, string | null>;
630
+ /**
631
+ * Decoded values recalled during the bootstrap step.
632
+ *
633
+ * The provider stores raw snapshots internally, but retaining the decoded
634
+ * values on the same object is convenient for app-level boot code such as
635
+ * first-paint theme application.
636
+ */
637
+ values?: TValues;
638
+ };
639
+ /**
640
+ * Fully populated snapshot returned by `recallMnemonic(...)`.
641
+ *
642
+ * @template TValues - Decoded values keyed by unprefixed storage key
643
+ */
644
+ type MnemonicBootstrapSnapshot<TValues extends Record<string, unknown> = Record<string, unknown>> = {
645
+ /**
646
+ * Raw storage strings keyed by the unprefixed mnemonic key name.
647
+ *
648
+ * Keys are only included when the bootstrap read successfully observed the
649
+ * underlying storage backend. A present `null` still means the key was
650
+ * confirmed absent at recall time, though providers may revalidate that
651
+ * absence before the first hook read.
652
+ */
653
+ raw: Record<string, string | null>;
654
+ /**
655
+ * Decoded values keyed by the unprefixed mnemonic key name.
656
+ */
657
+ values: TValues;
658
+ };
588
659
  /**
589
660
  * Hook-level SSR controls for `useMnemonicKey(...)`.
590
661
  *
@@ -1763,4 +1834,4 @@ type ReconcileContext = {
1763
1834
  latestVersion?: number;
1764
1835
  };
1765
1836
 
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 };
1837
+ export { type MnemonicOptionalBridge as A, type OptionalMnemonicKeySSRConfig as B, type Codec as C, type JsonSchema as D, type SchemaBoundKeyOptions as E, type CreateSchemaRegistryOptions as F, type MigrationRule as G, type CompiledValidator as H, type InferJsonSchemaValue as I, JSONCodec as J, type KeySchema as K, type Listener as L, type MnemonicKeyDescriptor as M, type JsonSchemaType as N, type OptionalMnemonicKeyDescriptor as O, type JsonSchemaValidationError as P, type MigrationPath as Q, type ReconcileContext as R, type StorageLike as S, type TypedJsonSchema as T, type UseMnemonicKeyOptions as U, type TypedKeySchema as V, compileSchema as W, mnemonicSchema as X, validateJsonSchema as Y, type SchemaMode as a, type SchemaRegistry as b, type MnemonicBootstrapSnapshot as c, CodecError as d, type MnemonicBootstrapSeed as e, SchemaError as f, createCodec as g, type MnemonicProviderOptions as h, type MnemonicKeyState as i, type Mnemonic as j, type MnemonicDevToolsCapabilities as k, type MnemonicDevToolsMeta as l, type MnemonicDevToolsProviderApi as m, type MnemonicDevToolsProviderDescriptor as n, type MnemonicDevToolsProviderEntry as o, type MnemonicDevToolsRegistry as p, type MnemonicDevToolsWeakRef as q, type MnemonicHydrationMode as r, type MnemonicKeySSRConfig as s, type MnemonicProviderSSRConfig as t, type MnemonicRecoveryAction as u, type MnemonicRecoveryEvent as v, type MnemonicRecoveryHook as w, type Unsubscribe as x, type UseMnemonicRecoveryOptions as y, type OptionalMnemonicKeyOptions as z };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-mnemonic",
3
- "version": "1.3.0",
3
+ "version": "1.4.0",
4
4
  "description": "Persistent, type-safe state management for React",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -42,6 +42,15 @@
42
42
  "import": "./dist/optional.js",
43
43
  "require": "./dist/optional.cjs",
44
44
  "default": "./dist/optional.js"
45
+ },
46
+ "./bootstrap": {
47
+ "types": {
48
+ "import": "./dist/bootstrap.d.ts",
49
+ "require": "./dist/bootstrap.d.cts"
50
+ },
51
+ "import": "./dist/bootstrap.js",
52
+ "require": "./dist/bootstrap.cjs",
53
+ "default": "./dist/bootstrap.js"
45
54
  }
46
55
  },
47
56
  "files": [