@choksheak/react-utils 0.3.8 → 0.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.
Files changed (87) hide show
  1. package/NoSSR.cjs +7 -30
  2. package/NoSSR.min.cjs +1 -1
  3. package/NoSSR.min.cjs.map +1 -1
  4. package/NoSSR.min.mjs +1 -1
  5. package/NoSSR.min.mjs.map +1 -1
  6. package/NoSSR.mjs +2 -0
  7. package/chunk-33UMQLKY.mjs +43 -0
  8. package/chunk-3V7WBGWQ.mjs +16 -0
  9. package/chunk-3X25NN6X.cjs +195 -0
  10. package/chunk-5DO7KC3L.cjs +43 -0
  11. package/chunk-5PDGU37E.cjs +104 -0
  12. package/chunk-6ZZ54XM5.min.mjs +2 -0
  13. package/chunk-6ZZ54XM5.min.mjs.map +1 -0
  14. package/chunk-74BS2FAO.cjs +12 -0
  15. package/chunk-F5L32IUC.min.cjs +2 -0
  16. package/chunk-F5L32IUC.min.cjs.map +1 -0
  17. package/chunk-GPV6JIQK.mjs +17 -0
  18. package/chunk-KE3RXVMS.min.cjs +2 -0
  19. package/chunk-KE3RXVMS.min.cjs.map +1 -0
  20. package/chunk-KILGR7YA.min.mjs +2 -0
  21. package/chunk-KILGR7YA.min.mjs.map +1 -0
  22. package/chunk-KRXENFK3.mjs +195 -0
  23. package/chunk-MWDH7YON.min.mjs +2 -0
  24. package/chunk-MWDH7YON.min.mjs.map +1 -0
  25. package/chunk-NTFFK7ZH.min.cjs +2 -0
  26. package/chunk-NTFFK7ZH.min.cjs.map +1 -0
  27. package/chunk-O3RBYG3W.min.cjs +2 -0
  28. package/chunk-O3RBYG3W.min.cjs.map +1 -0
  29. package/chunk-PHLY3LR4.mjs +104 -0
  30. package/chunk-RM4ZGGZ2.min.mjs +2 -0
  31. package/chunk-RM4ZGGZ2.min.mjs.map +1 -0
  32. package/chunk-TEZPF6BG.min.cjs +2 -0
  33. package/chunk-TEZPF6BG.min.cjs.map +1 -0
  34. package/chunk-UFJNJ3WV.cjs +16 -0
  35. package/chunk-UFJQLQFI.min.cjs +2 -0
  36. package/chunk-UFJQLQFI.min.cjs.map +1 -0
  37. package/chunk-V7L3UICC.min.mjs +2 -0
  38. package/chunk-V7L3UICC.min.mjs.map +1 -0
  39. package/chunk-VHMO75EY.min.mjs +2 -0
  40. package/chunk-VHMO75EY.min.mjs.map +1 -0
  41. package/chunk-WVLPJPWG.cjs +17 -0
  42. package/chunk-X6BYQHVC.mjs +12 -0
  43. package/fetcher.cjs +8 -50
  44. package/fetcher.d.mts +3 -3
  45. package/fetcher.d.ts +2 -2
  46. package/fetcher.min.cjs +1 -1
  47. package/fetcher.min.cjs.map +1 -1
  48. package/fetcher.min.mjs +1 -1
  49. package/fetcher.min.mjs.map +1 -1
  50. package/fetcher.mjs +5 -11
  51. package/package.json +124 -29
  52. package/sharedQuery.cjs +132 -392
  53. package/sharedQuery.d.mts +58 -13
  54. package/sharedQuery.d.ts +57 -12
  55. package/sharedQuery.min.cjs +1 -1
  56. package/sharedQuery.min.cjs.map +1 -1
  57. package/sharedQuery.min.mjs +1 -1
  58. package/sharedQuery.min.mjs.map +1 -1
  59. package/sharedQuery.mjs +94 -322
  60. package/sharedState.cjs +15 -304
  61. package/sharedState.d.mts +4 -4
  62. package/sharedState.d.ts +4 -4
  63. package/sharedState.min.cjs +1 -1
  64. package/sharedState.min.cjs.map +1 -1
  65. package/sharedState.min.mjs +1 -1
  66. package/sharedState.min.mjs.map +1 -1
  67. package/sharedState.mjs +10 -269
  68. package/storage.cjs +10 -123
  69. package/storage.d.mts +1 -0
  70. package/storage.d.ts +1 -0
  71. package/storage.min.cjs +1 -1
  72. package/storage.min.cjs.map +1 -1
  73. package/storage.min.mjs +1 -1
  74. package/storage.min.mjs.map +1 -1
  75. package/storage.mjs +6 -92
  76. package/stringify.cjs +8 -57
  77. package/stringify.min.cjs +1 -1
  78. package/stringify.min.cjs.map +1 -1
  79. package/stringify.min.mjs +1 -1
  80. package/stringify.min.mjs.map +1 -1
  81. package/stringify.mjs +6 -30
  82. package/useDeepMemo.cjs +6 -50
  83. package/useDeepMemo.min.cjs +1 -1
  84. package/useDeepMemo.min.cjs.map +1 -1
  85. package/useDeepMemo.min.mjs +1 -1
  86. package/useDeepMemo.min.mjs.map +1 -1
  87. package/useDeepMemo.mjs +4 -13
package/sharedState.mjs CHANGED
@@ -1,272 +1,13 @@
1
- // src/sharedState.ts
2
- import { MS_PER_DAY } from "@choksheak/ts-utils/timeConstants";
3
- import { useSyncExternalStore } from "react";
4
-
5
- // src/storage.ts
6
- import { kvStore } from "@choksheak/ts-utils/kvStore";
7
- import { createLocalStore } from "@choksheak/ts-utils/localStore";
8
- var IS_NOT_BROWSER = typeof window === "undefined";
9
- function getStorageAdapter(options, defaultStoreExpiryMs) {
10
- const { store } = options ?? {};
11
- if (!store) {
12
- return null;
13
- }
14
- if ("persistTo" in store && typeof store.persistTo === "string" && "key" in store && typeof store.key === "string") {
15
- const expiryMs = store.expiryMs || defaultStoreExpiryMs;
16
- const config = { ...store, expiryMs };
17
- switch (store.persistTo) {
18
- case "localStorage":
19
- return localStoreAdapter(config);
20
- case "indexedDb":
21
- return kvStoreAdapter(config);
22
- default:
23
- store.persistTo;
24
- throw new Error(`Unknown store.adapter ${store.persistTo}`);
25
- }
26
- }
27
- return store;
28
- }
29
- function localStoreAdapter({
30
- key,
31
- expiryMs,
32
- isValid
33
- }) {
34
- const adapter = createLocalStore(key, { defaultExpiryMs: expiryMs });
35
- return {
36
- set: (key2, value) => {
37
- if (IS_NOT_BROWSER) return;
38
- adapter.set(key2, value);
39
- },
40
- get: (key2) => {
41
- if (IS_NOT_BROWSER) return void 0;
42
- const value = adapter.get(key2);
43
- if (isValid && !isValid(value)) {
44
- console.warn(
45
- `localStorage adapter: Auto-discard invalid value for ${key2}: ${JSON.stringify(value)}`
46
- );
47
- adapter.delete(key2);
48
- return void 0;
49
- }
50
- return value;
51
- },
52
- delete: (key2) => {
53
- if (IS_NOT_BROWSER) return;
54
- adapter.delete(key2);
55
- },
56
- clear: () => {
57
- if (IS_NOT_BROWSER) return;
58
- adapter.clear();
59
- }
60
- };
61
- }
62
- function kvStoreAdapter({
63
- key,
64
- expiryMs,
65
- isValid
66
- }) {
67
- const keyPrefix = key + ":";
68
- return {
69
- set: async (key2, value) => {
70
- if (IS_NOT_BROWSER) return;
71
- await kvStore.set(keyPrefix + key2, value, expiryMs);
72
- },
73
- get: async (key2) => {
74
- if (IS_NOT_BROWSER) return void 0;
75
- const fullKey = keyPrefix + key2;
76
- const value = await kvStore.get(fullKey);
77
- if (value !== void 0 && isValid && !isValid(value)) {
78
- console.warn(
79
- `indexedDb adapter: Auto-discard invalid value for ${key2}:`,
80
- value
81
- );
82
- await kvStore.delete(fullKey);
83
- return void 0;
84
- }
85
- return value;
86
- },
87
- delete: async (key2) => {
88
- if (IS_NOT_BROWSER) return;
89
- await kvStore.delete(keyPrefix + key2);
90
- },
91
- clear: async () => {
92
- if (IS_NOT_BROWSER) return;
93
- await kvStore.clear();
94
- }
95
- };
96
- }
97
-
98
- // src/sharedState.ts
99
- var SharedStateConfig = {
100
- /**
101
- * Default duration for storage expiration in milliseconds. Initial value
102
- * is 30 days, but can be changed to anything.
103
- */
104
- storeExpiryMs: 30 * MS_PER_DAY,
105
- /**
106
- * True to load from storage only on mount, false (default) to load in
107
- * the top level scope when the shared state is defined.
108
- */
109
- lazyLoad: false
110
- };
111
- function configureSharedState(config) {
112
- Object.assign(SharedStateConfig, config);
113
- }
114
- function createPubSubStore() {
115
- const dataByKey = /* @__PURE__ */ new Map();
116
- const subscribersByKey = /* @__PURE__ */ new Map();
117
- function notify(key, next, prev) {
118
- const subscribers = subscribersByKey.get(key);
119
- if (!subscribers) return;
120
- const copy = Array.from(subscribers.values());
121
- for (const subscriber of copy) {
122
- try {
123
- subscriber(next, prev);
124
- } catch (e) {
125
- console.error(`Error invoking subscriber:`, e);
126
- }
127
- }
128
- }
129
- return {
130
- // This could be undefined if T includes undefined, else it should never
131
- // return undefined because the user has to always specify the default value.
132
- get(key) {
133
- return dataByKey.get(key);
134
- },
135
- set(key, value) {
136
- const prev = dataByKey.get(key);
137
- if (prev === value) return;
138
- dataByKey.set(key, value);
139
- notify(key, value, prev);
140
- },
141
- delete(key) {
142
- dataByKey.delete(key);
143
- },
144
- setNoNotify(key, value) {
145
- dataByKey.set(key, value);
146
- },
147
- // Subscribe to changes of a specific key
148
- subscribe(key, subscriber) {
149
- let subscribers = subscribersByKey.get(key);
150
- if (!subscribers) {
151
- subscribers = /* @__PURE__ */ new Set();
152
- subscribersByKey.set(key, subscribers);
153
- }
154
- subscribers.add(subscriber);
155
- return () => {
156
- subscribers.delete(subscriber);
157
- if (subscribers.size === 0) subscribersByKey.delete(key);
158
- };
159
- }
160
- };
161
- }
162
- var pubSubStore = createPubSubStore();
163
- var STORAGE_KEY = "state";
164
- var stateKey = 0;
165
- function sharedState(defaultValue, options) {
166
- let readyResolve = () => {
167
- };
168
- const readyPromise = new Promise((resolve) => {
169
- readyResolve = resolve;
170
- });
171
- const resolveReadyPromise = readyResolve;
172
- const pubSubKey = String(stateKey++);
173
- const storageAdapter = getStorageAdapter(
174
- options,
175
- SharedStateConfig.storeExpiryMs
176
- );
177
- pubSubStore.setNoNotify(pubSubKey, defaultValue);
178
- const lazyLoad = options?.lazyLoad;
179
- const lazy = lazyLoad !== void 0 ? lazyLoad : SharedStateConfig.lazyLoad;
180
- const obj = {
181
- /** Allow users to await for the completion of data init. */
182
- readyPromise,
183
- lazy,
184
- initStarted: false,
185
- initDone: false,
186
- /** `subscribe` function required by useSyncExternalStore. */
187
- subscribe(subscriber) {
188
- return pubSubStore.subscribe(pubSubKey, () => subscriber());
189
- },
190
- /** Returns true if there is a backing store. */
191
- hasStore() {
192
- return Boolean(storageAdapter);
193
- },
194
- /**
195
- * Set a value directly into the store. Does nothing if there is no
196
- * backing store.
197
- *
198
- * Warning: If you want to set the value properly, you should use
199
- * `setValue()` instead which also updates the in-memory copy.
200
- */
201
- async setInStore(value) {
202
- return await storageAdapter?.set(STORAGE_KEY, value);
203
- },
204
- /**
205
- * Get a value directly from the store. Returns undefined if there is no
206
- * backing store.
207
- */
208
- async getFromStore() {
209
- return await storageAdapter?.get(STORAGE_KEY);
210
- },
211
- /**
212
- * Get the value of the shared state.
213
- * `getSnapshot` function — must return same ref if value unchanged.
214
- * Note that this would return the default value if data init from store is
215
- * not completed yet.
216
- */
217
- getSnapshot() {
218
- return pubSubStore.get(pubSubKey);
219
- },
220
- /** Set the value of the shared state. */
221
- setValue(next) {
222
- if (typeof next === "function") {
223
- const prev = pubSubStore.get(pubSubKey);
224
- next = next(prev);
225
- }
226
- pubSubStore.set(pubSubKey, next);
227
- void obj.setInStore(next);
228
- },
229
- /**
230
- * Remove the value of the shared state. Actually this just sets the value
231
- * back to the given default value.
232
- */
233
- delete() {
234
- pubSubStore.set(pubSubKey, defaultValue);
235
- void storageAdapter?.set(STORAGE_KEY, defaultValue);
236
- },
237
- /** Initial default handling. */
238
- async initDefaultValueOnce() {
239
- if (obj.initDone || obj.initStarted) return;
240
- obj.initStarted = true;
241
- const stored = await obj.getFromStore();
242
- const value = stored !== void 0 ? stored : defaultValue;
243
- pubSubStore.set(pubSubKey, value);
244
- obj.initDone = true;
245
- resolveReadyPromise();
246
- }
247
- };
248
- if (!lazy) {
249
- void obj.initDefaultValueOnce();
250
- }
251
- return obj;
252
- }
253
- function useSharedState(state) {
254
- void state.initDefaultValueOnce();
255
- const value = useSyncExternalStore(
256
- (onStoreChange) => state.subscribe(onStoreChange),
257
- () => state.getSnapshot(),
258
- // getServerSnapshot is needed to prevent SSR dev errors in nextjs.
259
- () => state.getSnapshot()
260
- );
261
- return [value, state.setValue];
262
- }
263
- function useSharedStateValue(state) {
264
- return useSharedState(state)[0];
265
- }
266
- function useSharedStateSetter(state) {
267
- void state.initDefaultValueOnce();
268
- return state.setValue;
269
- }
1
+ import {
2
+ SharedStateConfig,
3
+ configureSharedState,
4
+ sharedState,
5
+ useSharedState,
6
+ useSharedStateSetter,
7
+ useSharedStateValue
8
+ } from "./chunk-KRXENFK3.mjs";
9
+ import "./chunk-PHLY3LR4.mjs";
10
+ import "./chunk-X6BYQHVC.mjs";
270
11
  export {
271
12
  SharedStateConfig,
272
13
  configureSharedState,
package/storage.cjs CHANGED
@@ -1,124 +1,11 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
19
2
 
20
- // src/storage.ts
21
- var storage_exports = {};
22
- __export(storage_exports, {
23
- getStorageAdapter: () => getStorageAdapter,
24
- kvStoreAdapter: () => kvStoreAdapter,
25
- localStoreAdapter: () => localStoreAdapter
26
- });
27
- module.exports = __toCommonJS(storage_exports);
28
- var import_kvStore = require("@choksheak/ts-utils/kvStore");
29
- var import_localStore = require("@choksheak/ts-utils/localStore");
30
- var IS_NOT_BROWSER = typeof window === "undefined";
31
- function getStorageAdapter(options, defaultStoreExpiryMs) {
32
- const { store } = options ?? {};
33
- if (!store) {
34
- return null;
35
- }
36
- if ("persistTo" in store && typeof store.persistTo === "string" && "key" in store && typeof store.key === "string") {
37
- const expiryMs = store.expiryMs || defaultStoreExpiryMs;
38
- const config = { ...store, expiryMs };
39
- switch (store.persistTo) {
40
- case "localStorage":
41
- return localStoreAdapter(config);
42
- case "indexedDb":
43
- return kvStoreAdapter(config);
44
- default:
45
- store.persistTo;
46
- throw new Error(`Unknown store.adapter ${store.persistTo}`);
47
- }
48
- }
49
- return store;
50
- }
51
- function localStoreAdapter({
52
- key,
53
- expiryMs,
54
- isValid
55
- }) {
56
- const adapter = (0, import_localStore.createLocalStore)(key, { defaultExpiryMs: expiryMs });
57
- return {
58
- set: (key2, value) => {
59
- if (IS_NOT_BROWSER) return;
60
- adapter.set(key2, value);
61
- },
62
- get: (key2) => {
63
- if (IS_NOT_BROWSER) return void 0;
64
- const value = adapter.get(key2);
65
- if (isValid && !isValid(value)) {
66
- console.warn(
67
- `localStorage adapter: Auto-discard invalid value for ${key2}: ${JSON.stringify(value)}`
68
- );
69
- adapter.delete(key2);
70
- return void 0;
71
- }
72
- return value;
73
- },
74
- delete: (key2) => {
75
- if (IS_NOT_BROWSER) return;
76
- adapter.delete(key2);
77
- },
78
- clear: () => {
79
- if (IS_NOT_BROWSER) return;
80
- adapter.clear();
81
- }
82
- };
83
- }
84
- function kvStoreAdapter({
85
- key,
86
- expiryMs,
87
- isValid
88
- }) {
89
- const keyPrefix = key + ":";
90
- return {
91
- set: async (key2, value) => {
92
- if (IS_NOT_BROWSER) return;
93
- await import_kvStore.kvStore.set(keyPrefix + key2, value, expiryMs);
94
- },
95
- get: async (key2) => {
96
- if (IS_NOT_BROWSER) return void 0;
97
- const fullKey = keyPrefix + key2;
98
- const value = await import_kvStore.kvStore.get(fullKey);
99
- if (value !== void 0 && isValid && !isValid(value)) {
100
- console.warn(
101
- `indexedDb adapter: Auto-discard invalid value for ${key2}:`,
102
- value
103
- );
104
- await import_kvStore.kvStore.delete(fullKey);
105
- return void 0;
106
- }
107
- return value;
108
- },
109
- delete: async (key2) => {
110
- if (IS_NOT_BROWSER) return;
111
- await import_kvStore.kvStore.delete(keyPrefix + key2);
112
- },
113
- clear: async () => {
114
- if (IS_NOT_BROWSER) return;
115
- await import_kvStore.kvStore.clear();
116
- }
117
- };
118
- }
119
- // Annotate the CommonJS export names for ESM import in node:
120
- 0 && (module.exports = {
121
- getStorageAdapter,
122
- kvStoreAdapter,
123
- localStoreAdapter
124
- });
3
+
4
+
5
+ var _chunk5PDGU37Ecjs = require('./chunk-5PDGU37E.cjs');
6
+ require('./chunk-74BS2FAO.cjs');
7
+
8
+
9
+
10
+
11
+ exports.getStorageAdapter = _chunk5PDGU37Ecjs.getStorageAdapter; exports.kvStoreAdapter = _chunk5PDGU37Ecjs.kvStoreAdapter; exports.localStoreAdapter = _chunk5PDGU37Ecjs.localStoreAdapter;
package/storage.d.mts CHANGED
@@ -47,6 +47,7 @@ declare function localStoreAdapter<T>({ key, expiryMs, isValid, }: StoreConstruc
47
47
  set: (key: string, value: T) => void;
48
48
  get: (key: string) => T | undefined;
49
49
  delete: (key: string) => void;
50
+ /** Note that this will clear all keys in all shared states. */
50
51
  clear: () => void;
51
52
  };
52
53
  /**
package/storage.d.ts CHANGED
@@ -45,6 +45,7 @@ export declare function localStoreAdapter<T>({ key, expiryMs, isValid, }: StoreC
45
45
  set: (key: string, value: T) => void;
46
46
  get: (key: string) => T | undefined;
47
47
  delete: (key: string) => void;
48
+ /** Note that this will clear all keys in all shared states. */
48
49
  clear: () => void;
49
50
  };
50
51
  /**
package/storage.min.cjs CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";var u=Object.defineProperty;var l=Object.getOwnPropertyDescriptor;var g=Object.getOwnPropertyNames;var T=Object.prototype.hasOwnProperty;var S=(n,r)=>{for(var t in r)u(n,t,{get:r[t],enumerable:!0})},y=(n,r,t,o)=>{if(r&&typeof r=="object"||typeof r=="function")for(let e of g(r))!T.call(n,e)&&e!==t&&u(n,e,{get:()=>r[e],enumerable:!(o=l(r,e))||o.enumerable});return n};var m=n=>y(u({},"__esModule",{value:!0}),n);var x={};S(x,{getStorageAdapter:()=>v,kvStoreAdapter:()=>c,localStoreAdapter:()=>f});module.exports=m(x);var a=require("@choksheak/ts-utils/kvStore"),p=require("@choksheak/ts-utils/localStore"),s=typeof window>"u";function v(n,r){let{store:t}=n??{};if(!t)return null;if("persistTo"in t&&typeof t.persistTo=="string"&&"key"in t&&typeof t.key=="string"){let o=t.expiryMs||r,e={...t,expiryMs:o};switch(t.persistTo){case"localStorage":return f(e);case"indexedDb":return c(e);default:throw t.persistTo,new Error(`Unknown store.adapter ${t.persistTo}`)}}return t}function f({key:n,expiryMs:r,isValid:t}){let o=(0,p.createLocalStore)(n,{defaultExpiryMs:r});return{set:(e,i)=>{s||o.set(e,i)},get:e=>{if(s)return;let i=o.get(e);if(t&&!t(i)){console.warn(`localStorage adapter: Auto-discard invalid value for ${e}: ${JSON.stringify(i)}`),o.delete(e);return}return i},delete:e=>{s||o.delete(e)},clear:()=>{s||o.clear()}}}function c({key:n,expiryMs:r,isValid:t}){let o=n+":";return{set:async(e,i)=>{s||await a.kvStore.set(o+e,i,r)},get:async e=>{if(s)return;let i=o+e,d=await a.kvStore.get(i);if(d!==void 0&&t&&!t(d)){console.warn(`indexedDb adapter: Auto-discard invalid value for ${e}:`,d),await a.kvStore.delete(i);return}return d},delete:async e=>{s||await a.kvStore.delete(o+e)},clear:async()=>{s||await a.kvStore.clear()}}}0&&(module.exports={getStorageAdapter,kvStoreAdapter,localStoreAdapter});
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkUFJQLQFImincjs = require('./chunk-UFJQLQFI.min.cjs');require('./chunk-KE3RXVMS.min.cjs');exports.getStorageAdapter = _chunkUFJQLQFImincjs.a; exports.kvStoreAdapter = _chunkUFJQLQFImincjs.c; exports.localStoreAdapter = _chunkUFJQLQFImincjs.b;
2
2
  //# sourceMappingURL=storage.min.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/storage.ts"],"sourcesContent":["/**\n * @packageDocumentation\n *\n * Backing storage implementation for the shared state. Note that this uses the\n * LocalStore and KvStore from package \"@choksheak/ts-utils\", but is customized\n * to be used for shared states.\n *\n * Normally you will not need to use this module directly, but if you have a\n * need for it, feel free to use it.\n */\n\nimport { Duration } from \"@choksheak/ts-utils/duration\";\nimport { kvStore } from \"@choksheak/ts-utils/kvStore\";\nimport { createLocalStore } from \"@choksheak/ts-utils/localStore\";\nimport { StorageAdapter } from \"@choksheak/ts-utils/storageAdapter\";\n\n/** List of all available pre-built persistence options. */\nexport type PersistTo = \"localStorage\" | \"indexedDb\";\n\n/** Options to configure a pre-built store adapter. */\nexport type StoreOptions = {\n /** Choose which pre-built store adapter to use. */\n persistTo: PersistTo;\n\n /** Storage key to act as a namespace to store the data. */\n key: string;\n\n /** How long to wait before the value is considered expired. */\n expiryMs?: number | Duration;\n\n /** Returns true if the given value supposed to be of type T is valid. */\n isValid?: (u: unknown) => boolean;\n};\n\nexport type StoreConstructorArgs = Omit<StoreOptions, \"persistTo\">;\n\n/** Either use a pre-built store, or a custom one you provide. */\nexport type StorageOptions<T> = {\n /**\n * You can either specify the storage adapter directly to use a custom\n * store, or specify the properties to use the pre-built ones.\n */\n store?: StorageAdapter<T> | StoreOptions;\n};\n\n// In SSR (Server-Side Rendering) mode, we never want to use our storage\n// adapters for anything.\nconst IS_NOT_BROWSER = typeof window === \"undefined\";\n\n/**\n * Convert a StorageOptions<T> config object into an actual storage adapter, or\n * returns null if a storage adapter is not configured.\n */\nexport function getStorageAdapter<T>(\n options: StorageOptions<T> | undefined,\n defaultStoreExpiryMs: number,\n): StorageAdapter<T> | null {\n const { store } = options ?? {};\n\n if (!store) {\n return null;\n }\n\n if (\n \"persistTo\" in store &&\n typeof store.persistTo === \"string\" &&\n \"key\" in store &&\n typeof store.key === \"string\"\n ) {\n const expiryMs = store.expiryMs || defaultStoreExpiryMs;\n const config = { ...store, expiryMs };\n\n switch (store.persistTo) {\n case \"localStorage\":\n return localStoreAdapter<T>(config);\n\n case \"indexedDb\":\n return kvStoreAdapter<T>(config);\n\n default:\n store.persistTo satisfies never;\n throw new Error(`Unknown store.adapter ${store.persistTo}`);\n }\n }\n\n return store as StorageAdapter<T>;\n}\n\n/**\n * Create a new SSR-safe local store adapter, which allows users to reuse the\n * same adapter in multiple shared states or shared queries.\n */\nexport function localStoreAdapter<T>({\n key,\n expiryMs,\n isValid,\n}: StoreConstructorArgs) {\n const adapter = createLocalStore(key, { defaultExpiryMs: expiryMs });\n\n return {\n set: (key: string, value: T): void => {\n if (IS_NOT_BROWSER) return; // handle SSR\n\n // Also apply the custom expiryMs on every item in this store.\n adapter.set(key, value);\n },\n\n get: (key: string): T | undefined => {\n if (IS_NOT_BROWSER) return undefined; // handle SSR\n\n const value = adapter.get<T>(key);\n\n if (isValid && !isValid(value)) {\n console.warn(\n `localStorage adapter: Auto-discard invalid value for ${key}: ${JSON.stringify(value)}`,\n );\n adapter.delete(key);\n return undefined;\n }\n\n return value;\n },\n\n delete: (key: string): void => {\n if (IS_NOT_BROWSER) return; // handle SSR\n\n adapter.delete(key);\n },\n\n clear: (): void => {\n if (IS_NOT_BROWSER) return; // handle SSR\n\n adapter.clear();\n },\n };\n}\n\n/**\n * Create a new SSR-safe indexed DB KV store adapter, which allows users to\n * reuse the same adapter in multiple shared states or shared queries.\n */\nexport function kvStoreAdapter<T>({\n key,\n expiryMs,\n isValid,\n}: StoreConstructorArgs) {\n // Use the key prefix as a unique namespace for this store.\n const keyPrefix = key + \":\";\n\n // Prefix all keys using `keyPrefix` so that we can keep all data in\n // the same store in the same DB. If we keep the data in different\n // DB stores, then GC will not be able to clean up abandoned stores.\n return {\n set: async (key: string, value: T): Promise<void> => {\n if (IS_NOT_BROWSER) return; // handle SSR\n\n // Also apply the custom expiryMs on every item in this store.\n await kvStore.set(keyPrefix + key, value, expiryMs);\n },\n get: async (key: string): Promise<T | undefined> => {\n if (IS_NOT_BROWSER) return undefined; // handle SSR\n\n const fullKey = keyPrefix + key;\n const value = await kvStore.get<T>(fullKey);\n\n // If there is no value, don't try to check for validatity.\n if (value !== undefined && isValid && !isValid(value)) {\n console.warn(\n `indexedDb adapter: Auto-discard invalid value for ${key}:`,\n value,\n );\n await kvStore.delete(fullKey);\n return undefined;\n }\n\n return value;\n },\n delete: async (key: string): Promise<void> => {\n if (IS_NOT_BROWSER) return; // handle SSR\n\n await kvStore.delete(keyPrefix + key);\n },\n clear: async (): Promise<void> => {\n if (IS_NOT_BROWSER) return; // handle SSR\n\n await kvStore.clear();\n },\n };\n}\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,uBAAAE,EAAA,mBAAAC,EAAA,sBAAAC,IAAA,eAAAC,EAAAL,GAYA,IAAAM,EAAwB,uCACxBC,EAAiC,0CAkC3BC,EAAiB,OAAO,OAAW,IAMlC,SAASN,EACdO,EACAC,EAC0B,CAC1B,GAAM,CAAE,MAAAC,CAAM,EAAIF,GAAW,CAAC,EAE9B,GAAI,CAACE,EACH,OAAO,KAGT,GACE,cAAeA,GACf,OAAOA,EAAM,WAAc,UAC3B,QAASA,GACT,OAAOA,EAAM,KAAQ,SACrB,CACA,IAAMC,EAAWD,EAAM,UAAYD,EAC7BG,EAAS,CAAE,GAAGF,EAAO,SAAAC,CAAS,EAEpC,OAAQD,EAAM,UAAW,CACvB,IAAK,eACH,OAAOP,EAAqBS,CAAM,EAEpC,IAAK,YACH,OAAOV,EAAkBU,CAAM,EAEjC,QACE,MAAAF,EAAM,UACA,IAAI,MAAM,yBAAyBA,EAAM,SAAS,EAAE,CAC9D,CACF,CAEA,OAAOA,CACT,CAMO,SAASP,EAAqB,CACnC,IAAAU,EACA,SAAAF,EACA,QAAAG,CACF,EAAyB,CACvB,IAAMC,KAAU,oBAAiBF,EAAK,CAAE,gBAAiBF,CAAS,CAAC,EAEnE,MAAO,CACL,IAAK,CAACE,EAAaG,IAAmB,CAChCT,GAGJQ,EAAQ,IAAIF,EAAKG,CAAK,CACxB,EAEA,IAAMH,GAA+B,CACnC,GAAIN,EAAgB,OAEpB,IAAMS,EAAQD,EAAQ,IAAOF,CAAG,EAEhC,GAAIC,GAAW,CAACA,EAAQE,CAAK,EAAG,CAC9B,QAAQ,KACN,wDAAwDH,CAAG,KAAK,KAAK,UAAUG,CAAK,CAAC,EACvF,EACAD,EAAQ,OAAOF,CAAG,EAClB,MACF,CAEA,OAAOG,CACT,EAEA,OAASH,GAAsB,CACzBN,GAEJQ,EAAQ,OAAOF,CAAG,CACpB,EAEA,MAAO,IAAY,CACbN,GAEJQ,EAAQ,MAAM,CAChB,CACF,CACF,CAMO,SAASb,EAAkB,CAChC,IAAAW,EACA,SAAAF,EACA,QAAAG,CACF,EAAyB,CAEvB,IAAMG,EAAYJ,EAAM,IAKxB,MAAO,CACL,IAAK,MAAOA,EAAaG,IAA4B,CAC/CT,GAGJ,MAAM,UAAQ,IAAIU,EAAYJ,EAAKG,EAAOL,CAAQ,CACpD,EACA,IAAK,MAAOE,GAAwC,CAClD,GAAIN,EAAgB,OAEpB,IAAMW,EAAUD,EAAYJ,EACtBG,EAAQ,MAAM,UAAQ,IAAOE,CAAO,EAG1C,GAAIF,IAAU,QAAaF,GAAW,CAACA,EAAQE,CAAK,EAAG,CACrD,QAAQ,KACN,qDAAqDH,CAAG,IACxDG,CACF,EACA,MAAM,UAAQ,OAAOE,CAAO,EAC5B,MACF,CAEA,OAAOF,CACT,EACA,OAAQ,MAAOH,GAA+B,CACxCN,GAEJ,MAAM,UAAQ,OAAOU,EAAYJ,CAAG,CACtC,EACA,MAAO,SAA2B,CAC5BN,GAEJ,MAAM,UAAQ,MAAM,CACtB,CACF,CACF","names":["storage_exports","__export","getStorageAdapter","kvStoreAdapter","localStoreAdapter","__toCommonJS","import_kvStore","import_localStore","IS_NOT_BROWSER","options","defaultStoreExpiryMs","store","expiryMs","config","key","isValid","adapter","value","keyPrefix","fullKey"]}
1
+ {"version":3,"sources":["/Users/choksheaklau/src/react-utils/dist/storage.min.cjs"],"names":[],"mappings":"AAAA,wIAA2C,oCAAiC,wJAA0E","file":"/Users/choksheaklau/src/react-utils/dist/storage.min.cjs"}
package/storage.min.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import{kvStore as a}from"@choksheak/ts-utils/kvStore";import{createLocalStore as u}from"@choksheak/ts-utils/localStore";var n=typeof window>"u";function g(i,s){let{store:e}=i??{};if(!e)return null;if("persistTo"in e&&typeof e.persistTo=="string"&&"key"in e&&typeof e.key=="string"){let r=e.expiryMs||s,t={...e,expiryMs:r};switch(e.persistTo){case"localStorage":return p(t);case"indexedDb":return f(t);default:throw e.persistTo,new Error(`Unknown store.adapter ${e.persistTo}`)}}return e}function p({key:i,expiryMs:s,isValid:e}){let r=u(i,{defaultExpiryMs:s});return{set:(t,o)=>{n||r.set(t,o)},get:t=>{if(n)return;let o=r.get(t);if(e&&!e(o)){console.warn(`localStorage adapter: Auto-discard invalid value for ${t}: ${JSON.stringify(o)}`),r.delete(t);return}return o},delete:t=>{n||r.delete(t)},clear:()=>{n||r.clear()}}}function f({key:i,expiryMs:s,isValid:e}){let r=i+":";return{set:async(t,o)=>{n||await a.set(r+t,o,s)},get:async t=>{if(n)return;let o=r+t,d=await a.get(o);if(d!==void 0&&e&&!e(d)){console.warn(`indexedDb adapter: Auto-discard invalid value for ${t}:`,d),await a.delete(o);return}return d},delete:async t=>{n||await a.delete(r+t)},clear:async()=>{n||await a.clear()}}}export{g as getStorageAdapter,f as kvStoreAdapter,p as localStoreAdapter};
1
+ import{a,b,c}from"./chunk-VHMO75EY.min.mjs";import"./chunk-MWDH7YON.min.mjs";export{a as getStorageAdapter,c as kvStoreAdapter,b as localStoreAdapter};
2
2
  //# sourceMappingURL=storage.min.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/storage.ts"],"sourcesContent":["/**\n * @packageDocumentation\n *\n * Backing storage implementation for the shared state. Note that this uses the\n * LocalStore and KvStore from package \"@choksheak/ts-utils\", but is customized\n * to be used for shared states.\n *\n * Normally you will not need to use this module directly, but if you have a\n * need for it, feel free to use it.\n */\n\nimport { Duration } from \"@choksheak/ts-utils/duration\";\nimport { kvStore } from \"@choksheak/ts-utils/kvStore\";\nimport { createLocalStore } from \"@choksheak/ts-utils/localStore\";\nimport { StorageAdapter } from \"@choksheak/ts-utils/storageAdapter\";\n\n/** List of all available pre-built persistence options. */\nexport type PersistTo = \"localStorage\" | \"indexedDb\";\n\n/** Options to configure a pre-built store adapter. */\nexport type StoreOptions = {\n /** Choose which pre-built store adapter to use. */\n persistTo: PersistTo;\n\n /** Storage key to act as a namespace to store the data. */\n key: string;\n\n /** How long to wait before the value is considered expired. */\n expiryMs?: number | Duration;\n\n /** Returns true if the given value supposed to be of type T is valid. */\n isValid?: (u: unknown) => boolean;\n};\n\nexport type StoreConstructorArgs = Omit<StoreOptions, \"persistTo\">;\n\n/** Either use a pre-built store, or a custom one you provide. */\nexport type StorageOptions<T> = {\n /**\n * You can either specify the storage adapter directly to use a custom\n * store, or specify the properties to use the pre-built ones.\n */\n store?: StorageAdapter<T> | StoreOptions;\n};\n\n// In SSR (Server-Side Rendering) mode, we never want to use our storage\n// adapters for anything.\nconst IS_NOT_BROWSER = typeof window === \"undefined\";\n\n/**\n * Convert a StorageOptions<T> config object into an actual storage adapter, or\n * returns null if a storage adapter is not configured.\n */\nexport function getStorageAdapter<T>(\n options: StorageOptions<T> | undefined,\n defaultStoreExpiryMs: number,\n): StorageAdapter<T> | null {\n const { store } = options ?? {};\n\n if (!store) {\n return null;\n }\n\n if (\n \"persistTo\" in store &&\n typeof store.persistTo === \"string\" &&\n \"key\" in store &&\n typeof store.key === \"string\"\n ) {\n const expiryMs = store.expiryMs || defaultStoreExpiryMs;\n const config = { ...store, expiryMs };\n\n switch (store.persistTo) {\n case \"localStorage\":\n return localStoreAdapter<T>(config);\n\n case \"indexedDb\":\n return kvStoreAdapter<T>(config);\n\n default:\n store.persistTo satisfies never;\n throw new Error(`Unknown store.adapter ${store.persistTo}`);\n }\n }\n\n return store as StorageAdapter<T>;\n}\n\n/**\n * Create a new SSR-safe local store adapter, which allows users to reuse the\n * same adapter in multiple shared states or shared queries.\n */\nexport function localStoreAdapter<T>({\n key,\n expiryMs,\n isValid,\n}: StoreConstructorArgs) {\n const adapter = createLocalStore(key, { defaultExpiryMs: expiryMs });\n\n return {\n set: (key: string, value: T): void => {\n if (IS_NOT_BROWSER) return; // handle SSR\n\n // Also apply the custom expiryMs on every item in this store.\n adapter.set(key, value);\n },\n\n get: (key: string): T | undefined => {\n if (IS_NOT_BROWSER) return undefined; // handle SSR\n\n const value = adapter.get<T>(key);\n\n if (isValid && !isValid(value)) {\n console.warn(\n `localStorage adapter: Auto-discard invalid value for ${key}: ${JSON.stringify(value)}`,\n );\n adapter.delete(key);\n return undefined;\n }\n\n return value;\n },\n\n delete: (key: string): void => {\n if (IS_NOT_BROWSER) return; // handle SSR\n\n adapter.delete(key);\n },\n\n clear: (): void => {\n if (IS_NOT_BROWSER) return; // handle SSR\n\n adapter.clear();\n },\n };\n}\n\n/**\n * Create a new SSR-safe indexed DB KV store adapter, which allows users to\n * reuse the same adapter in multiple shared states or shared queries.\n */\nexport function kvStoreAdapter<T>({\n key,\n expiryMs,\n isValid,\n}: StoreConstructorArgs) {\n // Use the key prefix as a unique namespace for this store.\n const keyPrefix = key + \":\";\n\n // Prefix all keys using `keyPrefix` so that we can keep all data in\n // the same store in the same DB. If we keep the data in different\n // DB stores, then GC will not be able to clean up abandoned stores.\n return {\n set: async (key: string, value: T): Promise<void> => {\n if (IS_NOT_BROWSER) return; // handle SSR\n\n // Also apply the custom expiryMs on every item in this store.\n await kvStore.set(keyPrefix + key, value, expiryMs);\n },\n get: async (key: string): Promise<T | undefined> => {\n if (IS_NOT_BROWSER) return undefined; // handle SSR\n\n const fullKey = keyPrefix + key;\n const value = await kvStore.get<T>(fullKey);\n\n // If there is no value, don't try to check for validatity.\n if (value !== undefined && isValid && !isValid(value)) {\n console.warn(\n `indexedDb adapter: Auto-discard invalid value for ${key}:`,\n value,\n );\n await kvStore.delete(fullKey);\n return undefined;\n }\n\n return value;\n },\n delete: async (key: string): Promise<void> => {\n if (IS_NOT_BROWSER) return; // handle SSR\n\n await kvStore.delete(keyPrefix + key);\n },\n clear: async (): Promise<void> => {\n if (IS_NOT_BROWSER) return; // handle SSR\n\n await kvStore.clear();\n },\n };\n}\n"],"mappings":"AAYA,OAAS,WAAAA,MAAe,8BACxB,OAAS,oBAAAC,MAAwB,iCAkCjC,IAAMC,EAAiB,OAAO,OAAW,IAMlC,SAASC,EACdC,EACAC,EAC0B,CAC1B,GAAM,CAAE,MAAAC,CAAM,EAAIF,GAAW,CAAC,EAE9B,GAAI,CAACE,EACH,OAAO,KAGT,GACE,cAAeA,GACf,OAAOA,EAAM,WAAc,UAC3B,QAASA,GACT,OAAOA,EAAM,KAAQ,SACrB,CACA,IAAMC,EAAWD,EAAM,UAAYD,EAC7BG,EAAS,CAAE,GAAGF,EAAO,SAAAC,CAAS,EAEpC,OAAQD,EAAM,UAAW,CACvB,IAAK,eACH,OAAOG,EAAqBD,CAAM,EAEpC,IAAK,YACH,OAAOE,EAAkBF,CAAM,EAEjC,QACE,MAAAF,EAAM,UACA,IAAI,MAAM,yBAAyBA,EAAM,SAAS,EAAE,CAC9D,CACF,CAEA,OAAOA,CACT,CAMO,SAASG,EAAqB,CACnC,IAAAE,EACA,SAAAJ,EACA,QAAAK,CACF,EAAyB,CACvB,IAAMC,EAAUZ,EAAiBU,EAAK,CAAE,gBAAiBJ,CAAS,CAAC,EAEnE,MAAO,CACL,IAAK,CAACI,EAAaG,IAAmB,CAChCZ,GAGJW,EAAQ,IAAIF,EAAKG,CAAK,CACxB,EAEA,IAAMH,GAA+B,CACnC,GAAIT,EAAgB,OAEpB,IAAMY,EAAQD,EAAQ,IAAOF,CAAG,EAEhC,GAAIC,GAAW,CAACA,EAAQE,CAAK,EAAG,CAC9B,QAAQ,KACN,wDAAwDH,CAAG,KAAK,KAAK,UAAUG,CAAK,CAAC,EACvF,EACAD,EAAQ,OAAOF,CAAG,EAClB,MACF,CAEA,OAAOG,CACT,EAEA,OAASH,GAAsB,CACzBT,GAEJW,EAAQ,OAAOF,CAAG,CACpB,EAEA,MAAO,IAAY,CACbT,GAEJW,EAAQ,MAAM,CAChB,CACF,CACF,CAMO,SAASH,EAAkB,CAChC,IAAAC,EACA,SAAAJ,EACA,QAAAK,CACF,EAAyB,CAEvB,IAAMG,EAAYJ,EAAM,IAKxB,MAAO,CACL,IAAK,MAAOA,EAAaG,IAA4B,CAC/CZ,GAGJ,MAAMF,EAAQ,IAAIe,EAAYJ,EAAKG,EAAOP,CAAQ,CACpD,EACA,IAAK,MAAOI,GAAwC,CAClD,GAAIT,EAAgB,OAEpB,IAAMc,EAAUD,EAAYJ,EACtBG,EAAQ,MAAMd,EAAQ,IAAOgB,CAAO,EAG1C,GAAIF,IAAU,QAAaF,GAAW,CAACA,EAAQE,CAAK,EAAG,CACrD,QAAQ,KACN,qDAAqDH,CAAG,IACxDG,CACF,EACA,MAAMd,EAAQ,OAAOgB,CAAO,EAC5B,MACF,CAEA,OAAOF,CACT,EACA,OAAQ,MAAOH,GAA+B,CACxCT,GAEJ,MAAMF,EAAQ,OAAOe,EAAYJ,CAAG,CACtC,EACA,MAAO,SAA2B,CAC5BT,GAEJ,MAAMF,EAAQ,MAAM,CACtB,CACF,CACF","names":["kvStore","createLocalStore","IS_NOT_BROWSER","getStorageAdapter","options","defaultStoreExpiryMs","store","expiryMs","config","localStoreAdapter","kvStoreAdapter","key","isValid","adapter","value","keyPrefix","fullKey"]}
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
package/storage.mjs CHANGED
@@ -1,95 +1,9 @@
1
- // src/storage.ts
2
- import { kvStore } from "@choksheak/ts-utils/kvStore";
3
- import { createLocalStore } from "@choksheak/ts-utils/localStore";
4
- var IS_NOT_BROWSER = typeof window === "undefined";
5
- function getStorageAdapter(options, defaultStoreExpiryMs) {
6
- const { store } = options ?? {};
7
- if (!store) {
8
- return null;
9
- }
10
- if ("persistTo" in store && typeof store.persistTo === "string" && "key" in store && typeof store.key === "string") {
11
- const expiryMs = store.expiryMs || defaultStoreExpiryMs;
12
- const config = { ...store, expiryMs };
13
- switch (store.persistTo) {
14
- case "localStorage":
15
- return localStoreAdapter(config);
16
- case "indexedDb":
17
- return kvStoreAdapter(config);
18
- default:
19
- store.persistTo;
20
- throw new Error(`Unknown store.adapter ${store.persistTo}`);
21
- }
22
- }
23
- return store;
24
- }
25
- function localStoreAdapter({
26
- key,
27
- expiryMs,
28
- isValid
29
- }) {
30
- const adapter = createLocalStore(key, { defaultExpiryMs: expiryMs });
31
- return {
32
- set: (key2, value) => {
33
- if (IS_NOT_BROWSER) return;
34
- adapter.set(key2, value);
35
- },
36
- get: (key2) => {
37
- if (IS_NOT_BROWSER) return void 0;
38
- const value = adapter.get(key2);
39
- if (isValid && !isValid(value)) {
40
- console.warn(
41
- `localStorage adapter: Auto-discard invalid value for ${key2}: ${JSON.stringify(value)}`
42
- );
43
- adapter.delete(key2);
44
- return void 0;
45
- }
46
- return value;
47
- },
48
- delete: (key2) => {
49
- if (IS_NOT_BROWSER) return;
50
- adapter.delete(key2);
51
- },
52
- clear: () => {
53
- if (IS_NOT_BROWSER) return;
54
- adapter.clear();
55
- }
56
- };
57
- }
58
- function kvStoreAdapter({
59
- key,
60
- expiryMs,
61
- isValid
62
- }) {
63
- const keyPrefix = key + ":";
64
- return {
65
- set: async (key2, value) => {
66
- if (IS_NOT_BROWSER) return;
67
- await kvStore.set(keyPrefix + key2, value, expiryMs);
68
- },
69
- get: async (key2) => {
70
- if (IS_NOT_BROWSER) return void 0;
71
- const fullKey = keyPrefix + key2;
72
- const value = await kvStore.get(fullKey);
73
- if (value !== void 0 && isValid && !isValid(value)) {
74
- console.warn(
75
- `indexedDb adapter: Auto-discard invalid value for ${key2}:`,
76
- value
77
- );
78
- await kvStore.delete(fullKey);
79
- return void 0;
80
- }
81
- return value;
82
- },
83
- delete: async (key2) => {
84
- if (IS_NOT_BROWSER) return;
85
- await kvStore.delete(keyPrefix + key2);
86
- },
87
- clear: async () => {
88
- if (IS_NOT_BROWSER) return;
89
- await kvStore.clear();
90
- }
91
- };
92
- }
1
+ import {
2
+ getStorageAdapter,
3
+ kvStoreAdapter,
4
+ localStoreAdapter
5
+ } from "./chunk-PHLY3LR4.mjs";
6
+ import "./chunk-X6BYQHVC.mjs";
93
7
  export {
94
8
  getStorageAdapter,
95
9
  kvStoreAdapter,
package/stringify.cjs CHANGED
@@ -1,58 +1,9 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
19
2
 
20
- // src/stringify.ts
21
- var stringify_exports = {};
22
- __export(stringify_exports, {
23
- stringifyDeterministicForKeys: () => stringifyDeterministicForKeys
24
- });
25
- module.exports = __toCommonJS(stringify_exports);
26
- function stringifyDeterministicForKeys(params) {
27
- const cache = /* @__PURE__ */ new Set();
28
- return JSON.stringify(params, (_, value) => {
29
- if (typeof value === "function") {
30
- throw new Error(`Functions should not be passed into query parameters`);
31
- }
32
- if (!value || typeof value !== "object" || Array.isArray(value)) {
33
- return value;
34
- }
35
- if (cache.has(value)) {
36
- return "[Circular]";
37
- }
38
- cache.add(value);
39
- if (value !== params) {
40
- try {
41
- JSON.stringify(value);
42
- } catch {
43
- return "[Unserializable]";
44
- }
45
- }
46
- return Object.keys(value).sort().reduce(
47
- (result, key) => {
48
- result[key] = value[key];
49
- return result;
50
- },
51
- {}
52
- );
53
- });
54
- }
55
- // Annotate the CommonJS export names for ESM import in node:
56
- 0 && (module.exports = {
57
- stringifyDeterministicForKeys
58
- });
3
+
4
+ var _chunk5DO7KC3Lcjs = require('./chunk-5DO7KC3L.cjs');
5
+ require('./chunk-74BS2FAO.cjs');
6
+ _chunk5DO7KC3Lcjs.init_stringify.call(void 0, );
7
+
8
+
9
+ exports.stringifyDeterministicForKeys = _chunk5DO7KC3Lcjs.stringifyDeterministicForKeys;
package/stringify.min.cjs CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";var s=Object.defineProperty;var c=Object.getOwnPropertyDescriptor;var f=Object.getOwnPropertyNames;var y=Object.prototype.hasOwnProperty;var d=(t,n)=>{for(var o in n)s(t,o,{get:n[o],enumerable:!0})},g=(t,n,o,r)=>{if(n&&typeof n=="object"||typeof n=="function")for(let i of f(n))!y.call(t,i)&&i!==o&&s(t,i,{get:()=>n[i],enumerable:!(r=c(n,i))||r.enumerable});return t};var w=t=>g(s({},"__esModule",{value:!0}),t);var u={};d(u,{stringifyDeterministicForKeys:()=>h});module.exports=w(u);function h(t){let n=new Set;return JSON.stringify(t,(o,r)=>{if(typeof r=="function")throw new Error("Functions should not be passed into query parameters");if(!r||typeof r!="object"||Array.isArray(r))return r;if(n.has(r))return"[Circular]";if(n.add(r),r!==t)try{JSON.stringify(r)}catch{return"[Unserializable]"}return Object.keys(r).sort().reduce((i,e)=>(i[e]=r[e],i),{})})}0&&(module.exports={stringifyDeterministicForKeys});
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkTEZPF6BGmincjs = require('./chunk-TEZPF6BG.min.cjs');require('./chunk-KE3RXVMS.min.cjs');_chunkTEZPF6BGmincjs.b.call(void 0, );exports.stringifyDeterministicForKeys = _chunkTEZPF6BGmincjs.a;
2
2
  //# sourceMappingURL=stringify.min.cjs.map