react-wire-persisted 3.0.0 → 3.1.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.
package/dist/index.d.ts CHANGED
@@ -1,7 +1,13 @@
1
1
  import { ReactNode } from 'react';
2
- import * as utils from '@/utils';
3
2
  import { Wire } from '@forminator/react-wire';
4
3
 
4
+ /**
5
+ * Adds a key to the keys map
6
+ *
7
+ * @param {String} value Key name
8
+ */
9
+ declare const addKey: (value: string) => void;
10
+
5
11
  declare type AnyStorage = InternalStorage | Storage;
6
12
 
7
13
  /**
@@ -16,10 +22,42 @@ export declare const createPersistedWire: <T = null>(key: string, value?: T) =>
16
22
 
17
23
  export declare const defaultOptions: RWPOptions;
18
24
 
25
+ declare const fakeLocalStorage: InternalStorage;
26
+
27
+ /**
28
+ * Check if the client has finished hydrating
29
+ */
30
+ declare const getHasHydrated: () => boolean;
31
+
32
+ /**
33
+ * Check if storage has been hydrated (safe to read from real localStorage)
34
+ */
35
+ declare const getHasHydratedStorage: () => boolean;
36
+
37
+ /**
38
+ * Check if we're running in a browser environment
39
+ */
40
+ declare const getIsClient: () => boolean;
41
+
42
+ /**
43
+ * Convenience method to get internally managed storage keys
44
+ *
45
+ * @returns {Object} InternalStorage keys map
46
+ */
47
+ declare const getKeys: () => Record<string, string>;
48
+
19
49
  export declare const getNamespace: () => string | null;
20
50
 
21
51
  export declare const getOptions: () => RWPOptions;
22
52
 
53
+ /**
54
+ * Helper utility to prefix all keys in a map to use a namespace
55
+ *
56
+ * @param {String} namespace InternalStorage namespace prefix
57
+ * @param {Object} keys (Optional) InternalStorage key/values. Defaults to the internally managed keys map
58
+ */
59
+ declare const getPrefixedKeys: (namespace: string, keys?: Record<string, string> | null) => Record<string, string>;
60
+
23
61
  export declare const getStorage: () => RWPStorageProvider;
24
62
 
25
63
  export declare const HydrationProvider: ({ children, onUpgrade, autoUpgrade }: HydrationProviderProps) => ReactNode;
@@ -45,6 +83,27 @@ declare interface InternalStorage {
45
83
  removeItem: (key: string) => void;
46
84
  }
47
85
 
86
+ /**
87
+ * Check if localStorage is available and safe to use
88
+ */
89
+ declare const isLocalStorageAvailable: () => boolean;
90
+
91
+ /**
92
+ * Checks if a value is a primitive type
93
+ *
94
+ * @param {*} val Value to check
95
+ * @returns {Boolean} True if value is a primitive type
96
+ */
97
+ declare const isPrimitive: (val: unknown) => boolean;
98
+
99
+ /**
100
+ * Adds a key to the keys map
101
+ * (Alias for `addKey`)
102
+ *
103
+ * @param {String} value Key name
104
+ */
105
+ declare const key: (value: string) => void;
106
+
48
107
  /**
49
108
  * A storage provider for `localStorage`
50
109
  * @see `RWPStorageProvider.ts` for documentation
@@ -73,6 +132,11 @@ export declare class LocalStorageProvider extends RWPStorageProvider {
73
132
  isUsingFakeStorage(): boolean;
74
133
  }
75
134
 
135
+ /**
136
+ * Mark storage as hydrated (called after upgradeStorage)
137
+ */
138
+ declare const markStorageAsHydrated: () => void;
139
+
76
140
  export declare class MemoryStorageProvider extends LocalStorageProvider {
77
141
  constructor(namespace: string, registry?: Record<string, unknown>);
78
142
  getStorage(): InternalStorage;
@@ -192,6 +256,21 @@ export declare type UseHydrationOptions = {
192
256
  onUpgrade?: () => void;
193
257
  };
194
258
 
259
+ declare namespace utils {
260
+ export {
261
+ isPrimitive,
262
+ fakeLocalStorage,
263
+ getIsClient,
264
+ getHasHydrated,
265
+ getHasHydratedStorage,
266
+ markStorageAsHydrated,
267
+ isLocalStorageAvailable,
268
+ addKey,
269
+ key,
270
+ getKeys,
271
+ getPrefixedKeys
272
+ }
273
+ }
195
274
  export { utils }
196
275
 
197
276
  export { }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-wire-persisted",
3
- "version": "3.0.0",
3
+ "version": "3.1.0",
4
4
  "author": "Wesley Bliss <wesley.bliss@gmail.com>",
5
5
  "license": "MIT",
6
6
  "type": "module",
package/src/index.ts CHANGED
@@ -1,9 +1,9 @@
1
- import * as utils from '@/utils'
1
+ import * as utils from './utils'
2
2
 
3
- export * from '@/components'
4
- export * from '@/hooks/useHydration'
5
- export * from '@/providers/LocalStorageProvider'
6
- export * from '@/providers/MemoryStorageProvider'
7
- export * from '@/providers/RWPStorageProvider'
8
- export * from '@/react-wire-persisted'
3
+ export * from './components'
4
+ export * from './hooks/useHydration'
5
+ export * from './providers/LocalStorageProvider'
6
+ export * from './providers/MemoryStorageProvider'
7
+ export * from './providers/RWPStorageProvider'
8
+ export * from './react-wire-persisted'
9
9
  export { utils }