@choksheak/react-utils 0.2.2 → 0.2.4

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 (61) hide show
  1. package/README.md +3 -1
  2. package/package.json +39 -33
  3. package/sharedQuery.d.mts +68 -8
  4. package/sharedQuery.d.ts +67 -7
  5. package/sharedQuery.js +240 -79
  6. package/sharedQuery.mjs +228 -77
  7. package/src/sharedQuery.ts +338 -103
  8. package/src/utils/useDeepMemo.ts +19 -0
  9. package/utils/useDeepMemo.d.mts +4 -0
  10. package/utils/useDeepMemo.d.ts +2 -0
  11. package/utils/useDeepMemo.js +51 -0
  12. package/utils/useDeepMemo.mjs +16 -0
  13. package/docs/.nojekyll +0 -1
  14. package/docs/assets/hierarchy.js +0 -1
  15. package/docs/assets/highlight.css +0 -22
  16. package/docs/assets/icons.js +0 -18
  17. package/docs/assets/icons.svg +0 -1
  18. package/docs/assets/main.js +0 -60
  19. package/docs/assets/navigation.js +0 -1
  20. package/docs/assets/search.js +0 -1
  21. package/docs/assets/style.css +0 -1633
  22. package/docs/classes/sharedQuery.SharedQuery.html +0 -17
  23. package/docs/classes/sharedState.SharedState.html +0 -9
  24. package/docs/classes/utils_storage.InMemoryStorageAdapter.html +0 -9
  25. package/docs/classes/utils_storage.IndexedDbAdapter.html +0 -9
  26. package/docs/classes/utils_storage.LocalStorageAdapter.html +0 -9
  27. package/docs/functions/sharedQuery.sharedQuery.html +0 -5
  28. package/docs/functions/sharedQuery.useSharedQuery.html +0 -4
  29. package/docs/functions/sharedState.sharedState.html +0 -3
  30. package/docs/functions/sharedState.useSharedState.html +0 -3
  31. package/docs/functions/sharedState.useSharedStateSetter.html +0 -2
  32. package/docs/functions/sharedState.useSharedStateValue.html +0 -2
  33. package/docs/functions/utils_storage.getStorageAdapter.html +0 -1
  34. package/docs/functions/utils_stringify.stringifyDeterministicForKeys.html +0 -7
  35. package/docs/hierarchy.html +0 -1
  36. package/docs/index.html +0 -2
  37. package/docs/modules/fetcher.html +0 -1
  38. package/docs/modules/index.html +0 -1
  39. package/docs/modules/sharedQuery.html +0 -1
  40. package/docs/modules/sharedState.html +0 -1
  41. package/docs/modules/utils_storage.html +0 -1
  42. package/docs/modules/utils_stringify.html +0 -1
  43. package/docs/modules.html +0 -1
  44. package/docs/types/sharedQuery.FetchFn.html +0 -1
  45. package/docs/types/sharedQuery.PersistTo.html +0 -1
  46. package/docs/types/sharedQuery.QueryStateValue.html +0 -6
  47. package/docs/types/sharedQuery.SharedQueryOptions.html +0 -1
  48. package/docs/types/sharedQuery.SharedQueryState.html +0 -3
  49. package/docs/types/sharedQuery.UseQueryResult.html +0 -1
  50. package/docs/types/sharedState.SharedStateOptions.html +0 -1
  51. package/docs/types/utils_storage.StorageAdapter.html +0 -5
  52. package/docs/types/utils_storage.StorageOptions.html +0 -5
  53. package/docs/variables/fetcher.fetcher.html +0 -2
  54. package/docs/variables/fetcher.fetcherWithRetries.html +0 -2
  55. package/docs/variables/sharedQuery.SharedQueryDefaults.html +0 -2
  56. package/docs/variables/sharedState.SharedStateDefaults.html +0 -6
  57. package/src/utils/stringify.test.ts +0 -46
  58. package/utils/stringify.test.d.mts +0 -2
  59. package/utils/stringify.test.d.ts +0 -2
  60. package/utils/stringify.test.js +0 -69
  61. package/utils/stringify.test.mjs +0 -86
@@ -1,86 +0,0 @@
1
- var __getOwnPropNames = Object.getOwnPropertyNames;
2
- var __esm = (fn, res) => function __init() {
3
- return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
4
- };
5
- var __commonJS = (cb, mod) => function __require() {
6
- return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
7
- };
8
-
9
- // src/utils/stringify.ts
10
- function stringifyDeterministicForKeys(params) {
11
- const cache = /* @__PURE__ */ new Set();
12
- return JSON.stringify(params, (_, value) => {
13
- if (typeof value === "function") {
14
- throw new Error(`Functions should not be passed into query parameters`);
15
- }
16
- if (!value || typeof value !== "object" || Array.isArray(value)) {
17
- return value;
18
- }
19
- if (cache.has(value)) {
20
- return "[Circular]";
21
- }
22
- cache.add(value);
23
- if (value !== params) {
24
- try {
25
- JSON.stringify(value);
26
- } catch {
27
- return "[Unserializable]";
28
- }
29
- }
30
- return Object.keys(value).sort().reduce(
31
- (result, key) => {
32
- result[key] = value[key];
33
- return result;
34
- },
35
- {}
36
- );
37
- });
38
- }
39
- var init_stringify = __esm({
40
- "src/utils/stringify.ts"() {
41
- "use strict";
42
- }
43
- });
44
-
45
- // src/utils/stringify.test.ts
46
- var require_stringify_test = __commonJS({
47
- "src/utils/stringify.test.ts"() {
48
- init_stringify();
49
- describe("stringifyDeterministicForKeys", () => {
50
- test("happy", () => {
51
- const expected = `{"a":1,"b":2,"c":{"e":1,"f":2}}`;
52
- const actual1 = stringifyDeterministicForKeys({
53
- a: 1,
54
- b: 2,
55
- c: { e: 1, f: 2 }
56
- });
57
- expect(actual1).toBe(expected);
58
- const actual2 = stringifyDeterministicForKeys({
59
- c: { f: 2, e: 1 },
60
- b: 2,
61
- a: 1
62
- });
63
- expect(actual2).toBe(expected);
64
- });
65
- test("circular", () => {
66
- const circular = { b: {}, a: 1 };
67
- circular.b = circular;
68
- const actual = stringifyDeterministicForKeys(circular);
69
- expect(actual).toBe(`{"a":1,"b":"[Circular]"}`);
70
- });
71
- test("function", () => {
72
- const fn = { b: {}, a: () => {
73
- } };
74
- expect(() => stringifyDeterministicForKeys(fn)).toThrow(
75
- `Functions should not be passed into query parameters`
76
- );
77
- });
78
- test("array", () => {
79
- const a = [1, "a", { b: 2 }, [true]];
80
- const actual = stringifyDeterministicForKeys(a);
81
- expect(actual).toBe(`[1,"a",{"b":2},[true]]`);
82
- });
83
- });
84
- }
85
- });
86
- export default require_stringify_test();