@bitsocial/bitsocial-react-hooks 0.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.
Files changed (269) hide show
  1. package/LICENSE +674 -0
  2. package/README.md +1365 -0
  3. package/dist/hooks/accounts/accounts.d.ts +64 -0
  4. package/dist/hooks/accounts/accounts.d.ts.map +1 -0
  5. package/dist/hooks/accounts/accounts.js +706 -0
  6. package/dist/hooks/accounts/accounts.js.map +1 -0
  7. package/dist/hooks/accounts/index.d.ts +2 -0
  8. package/dist/hooks/accounts/index.d.ts.map +1 -0
  9. package/dist/hooks/accounts/index.js +2 -0
  10. package/dist/hooks/accounts/index.js.map +1 -0
  11. package/dist/hooks/accounts/utils.d.ts +6 -0
  12. package/dist/hooks/accounts/utils.d.ts.map +1 -0
  13. package/dist/hooks/accounts/utils.js +226 -0
  14. package/dist/hooks/accounts/utils.js.map +1 -0
  15. package/dist/hooks/actions/actions.d.ts +19 -0
  16. package/dist/hooks/actions/actions.d.ts.map +1 -0
  17. package/dist/hooks/actions/actions.js +552 -0
  18. package/dist/hooks/actions/actions.js.map +1 -0
  19. package/dist/hooks/actions/index.d.ts +2 -0
  20. package/dist/hooks/actions/index.d.ts.map +1 -0
  21. package/dist/hooks/actions/index.js +2 -0
  22. package/dist/hooks/actions/index.js.map +1 -0
  23. package/dist/hooks/authors/author-avatars.d.ts +28 -0
  24. package/dist/hooks/authors/author-avatars.d.ts.map +1 -0
  25. package/dist/hooks/authors/author-avatars.js +191 -0
  26. package/dist/hooks/authors/author-avatars.js.map +1 -0
  27. package/dist/hooks/authors/authors.d.ts +37 -0
  28. package/dist/hooks/authors/authors.d.ts.map +1 -0
  29. package/dist/hooks/authors/authors.js +509 -0
  30. package/dist/hooks/authors/authors.js.map +1 -0
  31. package/dist/hooks/authors/index.d.ts +2 -0
  32. package/dist/hooks/authors/index.d.ts.map +1 -0
  33. package/dist/hooks/authors/index.js +2 -0
  34. package/dist/hooks/authors/index.js.map +1 -0
  35. package/dist/hooks/authors/utils.d.ts +4 -0
  36. package/dist/hooks/authors/utils.d.ts.map +1 -0
  37. package/dist/hooks/authors/utils.js +21 -0
  38. package/dist/hooks/authors/utils.js.map +1 -0
  39. package/dist/hooks/comments.d.ts +17 -0
  40. package/dist/hooks/comments.d.ts.map +1 -0
  41. package/dist/hooks/comments.js +351 -0
  42. package/dist/hooks/comments.js.map +1 -0
  43. package/dist/hooks/communities.d.ts +31 -0
  44. package/dist/hooks/communities.d.ts.map +1 -0
  45. package/dist/hooks/communities.js +389 -0
  46. package/dist/hooks/communities.js.map +1 -0
  47. package/dist/hooks/feeds/feeds.d.ts +18 -0
  48. package/dist/hooks/feeds/feeds.d.ts.map +1 -0
  49. package/dist/hooks/feeds/feeds.js +315 -0
  50. package/dist/hooks/feeds/feeds.js.map +1 -0
  51. package/dist/hooks/feeds/index.d.ts +2 -0
  52. package/dist/hooks/feeds/index.d.ts.map +1 -0
  53. package/dist/hooks/feeds/index.js +2 -0
  54. package/dist/hooks/feeds/index.js.map +1 -0
  55. package/dist/hooks/pkc-rpc.d.ts +7 -0
  56. package/dist/hooks/pkc-rpc.d.ts.map +1 -0
  57. package/dist/hooks/pkc-rpc.js +88 -0
  58. package/dist/hooks/pkc-rpc.js.map +1 -0
  59. package/dist/hooks/replies.d.ts +5 -0
  60. package/dist/hooks/replies.d.ts.map +1 -0
  61. package/dist/hooks/replies.js +155 -0
  62. package/dist/hooks/replies.js.map +1 -0
  63. package/dist/hooks/states.d.ts +15 -0
  64. package/dist/hooks/states.d.ts.map +1 -0
  65. package/dist/hooks/states.js +213 -0
  66. package/dist/hooks/states.js.map +1 -0
  67. package/dist/hooks/utils/use-interval.d.ts +3 -0
  68. package/dist/hooks/utils/use-interval.d.ts.map +1 -0
  69. package/dist/hooks/utils/use-interval.js +36 -0
  70. package/dist/hooks/utils/use-interval.js.map +1 -0
  71. package/dist/hooks/utils/use-previous.d.ts +1 -0
  72. package/dist/hooks/utils/use-previous.js +10 -0
  73. package/dist/index.d.ts +82 -0
  74. package/dist/index.d.ts.map +1 -0
  75. package/dist/index.js +128 -0
  76. package/dist/index.js.map +1 -0
  77. package/dist/lib/chain/chain.d.ts +36 -0
  78. package/dist/lib/chain/chain.d.ts.map +1 -0
  79. package/dist/lib/chain/chain.js +195 -0
  80. package/dist/lib/chain/chain.js.map +1 -0
  81. package/dist/lib/chain/index.d.ts +4 -0
  82. package/dist/lib/chain/index.d.ts.map +1 -0
  83. package/dist/lib/chain/index.js +4 -0
  84. package/dist/lib/chain/index.js.map +1 -0
  85. package/dist/lib/community-address.d.ts +6 -0
  86. package/dist/lib/community-address.d.ts.map +1 -0
  87. package/dist/lib/community-address.js +26 -0
  88. package/dist/lib/community-address.js.map +1 -0
  89. package/dist/lib/community-ref.d.ts +23 -0
  90. package/dist/lib/community-ref.d.ts.map +1 -0
  91. package/dist/lib/community-ref.js +113 -0
  92. package/dist/lib/community-ref.js.map +1 -0
  93. package/dist/lib/debug-utils.d.ts +9 -0
  94. package/dist/lib/debug-utils.d.ts.map +1 -0
  95. package/dist/lib/debug-utils.js +21 -0
  96. package/dist/lib/debug-utils.js.map +1 -0
  97. package/dist/lib/feed-sort-type.d.ts +2 -0
  98. package/dist/lib/feed-sort-type.d.ts.map +1 -0
  99. package/dist/lib/feed-sort-type.js +22 -0
  100. package/dist/lib/feed-sort-type.js.map +1 -0
  101. package/dist/lib/localforage-lru/index.d.ts +3 -0
  102. package/dist/lib/localforage-lru/index.d.ts.map +1 -0
  103. package/dist/lib/localforage-lru/index.js +46 -0
  104. package/dist/lib/localforage-lru/index.js.map +1 -0
  105. package/dist/lib/localforage-lru/localforage-lru.d.ts +6 -0
  106. package/dist/lib/localforage-lru/localforage-lru.d.ts.map +1 -0
  107. package/dist/lib/localforage-lru/localforage-lru.js +182 -0
  108. package/dist/lib/localforage-lru/localforage-lru.js.map +1 -0
  109. package/dist/lib/pkc-compat.d.ts +25 -0
  110. package/dist/lib/pkc-compat.d.ts.map +1 -0
  111. package/dist/lib/pkc-compat.js +131 -0
  112. package/dist/lib/pkc-compat.js.map +1 -0
  113. package/dist/lib/pkc-js/fixtures/markdown-example.d.ts +3 -0
  114. package/dist/lib/pkc-js/fixtures/markdown-example.d.ts.map +1 -0
  115. package/dist/lib/pkc-js/fixtures/markdown-example.js +280 -0
  116. package/dist/lib/pkc-js/fixtures/markdown-example.js.map +1 -0
  117. package/dist/lib/pkc-js/index.d.ts +11 -0
  118. package/dist/lib/pkc-js/index.d.ts.map +1 -0
  119. package/dist/lib/pkc-js/index.js +85 -0
  120. package/dist/lib/pkc-js/index.js.map +1 -0
  121. package/dist/lib/pkc-js/pkc-js-mock-content.d.ts +3 -0
  122. package/dist/lib/pkc-js/pkc-js-mock-content.d.ts.map +1 -0
  123. package/dist/lib/pkc-js/pkc-js-mock-content.js +1235 -0
  124. package/dist/lib/pkc-js/pkc-js-mock-content.js.map +1 -0
  125. package/dist/lib/pkc-js/pkc-js-mock.d.ts +137 -0
  126. package/dist/lib/pkc-js/pkc-js-mock.d.ts.map +1 -0
  127. package/dist/lib/pkc-js/pkc-js-mock.js +644 -0
  128. package/dist/lib/pkc-js/pkc-js-mock.js.map +1 -0
  129. package/dist/lib/polyfill.d.ts +3 -0
  130. package/dist/lib/polyfill.d.ts.map +1 -0
  131. package/dist/lib/polyfill.js +14 -0
  132. package/dist/lib/polyfill.js.map +1 -0
  133. package/dist/lib/protocol-compat.d.ts +14 -0
  134. package/dist/lib/protocol-compat.d.ts.map +1 -0
  135. package/dist/lib/protocol-compat.js +67 -0
  136. package/dist/lib/protocol-compat.js.map +1 -0
  137. package/dist/lib/test-utils.d.ts +29 -0
  138. package/dist/lib/test-utils.d.ts.map +1 -0
  139. package/dist/lib/test-utils.js +184 -0
  140. package/dist/lib/test-utils.js.map +1 -0
  141. package/dist/lib/utils/comment-moderation.d.ts +4 -0
  142. package/dist/lib/utils/comment-moderation.d.ts.map +1 -0
  143. package/dist/lib/utils/comment-moderation.js +56 -0
  144. package/dist/lib/utils/comment-moderation.js.map +1 -0
  145. package/dist/lib/utils/index.d.ts +4 -0
  146. package/dist/lib/utils/index.d.ts.map +1 -0
  147. package/dist/lib/utils/index.js +4 -0
  148. package/dist/lib/utils/index.js.map +1 -0
  149. package/dist/lib/utils/utils.d.ts +23 -0
  150. package/dist/lib/utils/utils.d.ts.map +1 -0
  151. package/dist/lib/utils/utils.js +375 -0
  152. package/dist/lib/utils/utils.js.map +1 -0
  153. package/dist/lib/validator.d.ts +30 -0
  154. package/dist/lib/validator.d.ts.map +1 -0
  155. package/dist/lib/validator.js +307 -0
  156. package/dist/lib/validator.js.map +1 -0
  157. package/dist/stores/accounts/account-generator.d.ts +51 -0
  158. package/dist/stores/accounts/account-generator.d.ts.map +1 -0
  159. package/dist/stores/accounts/account-generator.js +160 -0
  160. package/dist/stores/accounts/account-generator.js.map +1 -0
  161. package/dist/stores/accounts/accounts-actions-internal.d.ts +8 -0
  162. package/dist/stores/accounts/accounts-actions-internal.d.ts.map +1 -0
  163. package/dist/stores/accounts/accounts-actions-internal.js +403 -0
  164. package/dist/stores/accounts/accounts-actions-internal.js.map +1 -0
  165. package/dist/stores/accounts/accounts-actions.d.ts +46 -0
  166. package/dist/stores/accounts/accounts-actions.d.ts.map +1 -0
  167. package/dist/stores/accounts/accounts-actions.js +1341 -0
  168. package/dist/stores/accounts/accounts-actions.js.map +1 -0
  169. package/dist/stores/accounts/accounts-database.d.ts +34 -0
  170. package/dist/stores/accounts/accounts-database.d.ts.map +1 -0
  171. package/dist/stores/accounts/accounts-database.js +685 -0
  172. package/dist/stores/accounts/accounts-database.js.map +1 -0
  173. package/dist/stores/accounts/accounts-store.d.ts +32 -0
  174. package/dist/stores/accounts/accounts-store.d.ts.map +1 -0
  175. package/dist/stores/accounts/accounts-store.js +169 -0
  176. package/dist/stores/accounts/accounts-store.js.map +1 -0
  177. package/dist/stores/accounts/index.d.ts +4 -0
  178. package/dist/stores/accounts/index.d.ts.map +1 -0
  179. package/dist/stores/accounts/index.js +4 -0
  180. package/dist/stores/accounts/index.js.map +1 -0
  181. package/dist/stores/accounts/utils.d.ts +49 -0
  182. package/dist/stores/accounts/utils.d.ts.map +1 -0
  183. package/dist/stores/accounts/utils.js +419 -0
  184. package/dist/stores/accounts/utils.js.map +1 -0
  185. package/dist/stores/authors-comments/authors-comments-store.d.ts +37 -0
  186. package/dist/stores/authors-comments/authors-comments-store.d.ts.map +1 -0
  187. package/dist/stores/authors-comments/authors-comments-store.js +338 -0
  188. package/dist/stores/authors-comments/authors-comments-store.js.map +1 -0
  189. package/dist/stores/authors-comments/index.d.ts +4 -0
  190. package/dist/stores/authors-comments/index.d.ts.map +1 -0
  191. package/dist/stores/authors-comments/index.js +4 -0
  192. package/dist/stores/authors-comments/index.js.map +1 -0
  193. package/dist/stores/authors-comments/utils.d.ts +14 -0
  194. package/dist/stores/authors-comments/utils.d.ts.map +1 -0
  195. package/dist/stores/authors-comments/utils.js +81 -0
  196. package/dist/stores/authors-comments/utils.js.map +1 -0
  197. package/dist/stores/comments/comments-store.d.ts +19 -0
  198. package/dist/stores/comments/comments-store.d.ts.map +1 -0
  199. package/dist/stores/comments/comments-store.js +385 -0
  200. package/dist/stores/comments/comments-store.js.map +1 -0
  201. package/dist/stores/comments/index.d.ts +4 -0
  202. package/dist/stores/comments/index.d.ts.map +1 -0
  203. package/dist/stores/comments/index.js +4 -0
  204. package/dist/stores/comments/index.js.map +1 -0
  205. package/dist/stores/communities/communities-store.d.ts +17 -0
  206. package/dist/stores/communities/communities-store.d.ts.map +1 -0
  207. package/dist/stores/communities/communities-store.js +304 -0
  208. package/dist/stores/communities/communities-store.js.map +1 -0
  209. package/dist/stores/communities/index.d.ts +4 -0
  210. package/dist/stores/communities/index.d.ts.map +1 -0
  211. package/dist/stores/communities/index.js +4 -0
  212. package/dist/stores/communities/index.js.map +1 -0
  213. package/dist/stores/communities-pages/communities-pages-store.d.ts +23 -0
  214. package/dist/stores/communities-pages/communities-pages-store.d.ts.map +1 -0
  215. package/dist/stores/communities-pages/communities-pages-store.js +316 -0
  216. package/dist/stores/communities-pages/communities-pages-store.js.map +1 -0
  217. package/dist/stores/communities-pages/index.d.ts +4 -0
  218. package/dist/stores/communities-pages/index.d.ts.map +1 -0
  219. package/dist/stores/communities-pages/index.js +4 -0
  220. package/dist/stores/communities-pages/index.js.map +1 -0
  221. package/dist/stores/feeds/feed-sorter.d.ts +5 -0
  222. package/dist/stores/feeds/feed-sorter.d.ts.map +1 -0
  223. package/dist/stores/feeds/feed-sorter.js +135 -0
  224. package/dist/stores/feeds/feed-sorter.js.map +1 -0
  225. package/dist/stores/feeds/feeds-store.d.ts +25 -0
  226. package/dist/stores/feeds/feeds-store.d.ts.map +1 -0
  227. package/dist/stores/feeds/feeds-store.js +459 -0
  228. package/dist/stores/feeds/feeds-store.js.map +1 -0
  229. package/dist/stores/feeds/index.d.ts +4 -0
  230. package/dist/stores/feeds/index.d.ts.map +1 -0
  231. package/dist/stores/feeds/index.js +4 -0
  232. package/dist/stores/feeds/index.js.map +1 -0
  233. package/dist/stores/feeds/utils.d.ts +43 -0
  234. package/dist/stores/feeds/utils.d.ts.map +1 -0
  235. package/dist/stores/feeds/utils.js +736 -0
  236. package/dist/stores/feeds/utils.js.map +1 -0
  237. package/dist/stores/replies/index.d.ts +4 -0
  238. package/dist/stores/replies/index.d.ts.map +1 -0
  239. package/dist/stores/replies/index.js +4 -0
  240. package/dist/stores/replies/index.js.map +1 -0
  241. package/dist/stores/replies/replies-comments-store.d.ts +8 -0
  242. package/dist/stores/replies/replies-comments-store.d.ts.map +1 -0
  243. package/dist/stores/replies/replies-comments-store.js +23 -0
  244. package/dist/stores/replies/replies-comments-store.js.map +1 -0
  245. package/dist/stores/replies/replies-store.d.ts +29 -0
  246. package/dist/stores/replies/replies-store.d.ts.map +1 -0
  247. package/dist/stores/replies/replies-store.js +413 -0
  248. package/dist/stores/replies/replies-store.js.map +1 -0
  249. package/dist/stores/replies/utils.d.ts +25 -0
  250. package/dist/stores/replies/utils.d.ts.map +1 -0
  251. package/dist/stores/replies/utils.js +549 -0
  252. package/dist/stores/replies/utils.js.map +1 -0
  253. package/dist/stores/replies-pages/index.d.ts +4 -0
  254. package/dist/stores/replies-pages/index.d.ts.map +1 -0
  255. package/dist/stores/replies-pages/index.js +4 -0
  256. package/dist/stores/replies-pages/index.js.map +1 -0
  257. package/dist/stores/replies-pages/replies-pages-store.d.ts +20 -0
  258. package/dist/stores/replies-pages/replies-pages-store.d.ts.map +1 -0
  259. package/dist/stores/replies-pages/replies-pages-store.js +270 -0
  260. package/dist/stores/replies-pages/replies-pages-store.js.map +1 -0
  261. package/dist/stores/replies-pages/utils.d.ts +3 -0
  262. package/dist/stores/replies-pages/utils.d.ts.map +1 -0
  263. package/dist/stores/replies-pages/utils.js +43 -0
  264. package/dist/stores/replies-pages/utils.js.map +1 -0
  265. package/dist/types.d.ts +638 -0
  266. package/dist/types.d.ts.map +1 -0
  267. package/dist/types.js +3 -0
  268. package/dist/types.js.map +1 -0
  269. package/package.json +160 -0
@@ -0,0 +1,113 @@
1
+ import assert from "assert";
2
+ import { areEquivalentCommunityAddresses } from "./community-address.js";
3
+ const getLegacyCommunityAddress = (communityRef) => communityRef.address;
4
+ export const getCommunityRefKey = (communityRef) => {
5
+ const communityKey = communityRef.publicKey || getLegacyCommunityAddress(communityRef) || communityRef.name;
6
+ assert(typeof communityKey === "string" && communityKey.length > 0, "community ref missing key");
7
+ return communityKey;
8
+ };
9
+ export const getCommunityRefKeys = (communityRefs) => communityRefs.map(getCommunityRefKey);
10
+ export const getCommunityLookupOptions = (communityRefOrAddress) => {
11
+ if (typeof communityRefOrAddress === "string") {
12
+ return { address: communityRefOrAddress };
13
+ }
14
+ const legacyCommunityAddress = getLegacyCommunityAddress(communityRefOrAddress);
15
+ if (legacyCommunityAddress) {
16
+ return { address: legacyCommunityAddress };
17
+ }
18
+ if (!communityRefOrAddress.publicKey && communityRefOrAddress.name) {
19
+ return { address: communityRefOrAddress.name };
20
+ }
21
+ const options = {};
22
+ if (communityRefOrAddress.name) {
23
+ options.name = communityRefOrAddress.name;
24
+ }
25
+ if (communityRefOrAddress.publicKey) {
26
+ options.publicKey = communityRefOrAddress.publicKey;
27
+ }
28
+ return options;
29
+ };
30
+ export const mergeCommunityRefs = (base, extra) => {
31
+ const mergedAddress = getLegacyCommunityAddress(base) || getLegacyCommunityAddress(extra);
32
+ const mergedName = base.name || extra.name;
33
+ const mergedPublicKey = base.publicKey || extra.publicKey;
34
+ if (mergedPublicKey) {
35
+ return Object.assign(Object.assign({ publicKey: mergedPublicKey }, (mergedAddress ? { address: mergedAddress } : undefined)), (mergedName ? { name: mergedName } : undefined));
36
+ }
37
+ if (mergedAddress) {
38
+ return Object.assign({ address: mergedAddress }, (mergedName ? { name: mergedName } : undefined));
39
+ }
40
+ assert(typeof mergedName === "string" && mergedName.length > 0, "community ref missing name");
41
+ return { name: mergedName };
42
+ };
43
+ export const getUniqueSortedCommunityRefs = (communityRefs) => {
44
+ const refsByKey = new Map();
45
+ for (const communityRef of communityRefs || []) {
46
+ const communityKey = getCommunityRefKey(communityRef);
47
+ const existingCommunityRef = refsByKey.get(communityKey);
48
+ refsByKey.set(communityKey, existingCommunityRef ? mergeCommunityRefs(existingCommunityRef, communityRef) : communityRef);
49
+ }
50
+ return [...refsByKey.entries()]
51
+ .sort(([leftKey], [rightKey]) => leftKey.localeCompare(rightKey))
52
+ .map(([, communityRef]) => communityRef);
53
+ };
54
+ export const isCommunityRef = (value) => {
55
+ if (!value || typeof value !== "object" || Array.isArray(value)) {
56
+ return false;
57
+ }
58
+ const communityRef = value;
59
+ const hasName = typeof communityRef.name === "string" && communityRef.name.length > 0;
60
+ const hasPublicKey = typeof communityRef.publicKey === "string" && communityRef.publicKey.length > 0;
61
+ return hasName || hasPublicKey;
62
+ };
63
+ export function assertCommunityRef(value, label) {
64
+ assert(isCommunityRef(value), `${label} must be an object with name or publicKey`);
65
+ }
66
+ export const doesAddressMatchCommunityRef = (communityAddress, communityRef, community) => {
67
+ if (typeof communityAddress !== "string") {
68
+ return false;
69
+ }
70
+ const legacyCommunityAddress = getLegacyCommunityAddress(communityRef);
71
+ if (legacyCommunityAddress) {
72
+ if (communityAddress === legacyCommunityAddress) {
73
+ return true;
74
+ }
75
+ if (areEquivalentCommunityAddresses(communityAddress, legacyCommunityAddress)) {
76
+ return true;
77
+ }
78
+ }
79
+ if (communityRef.publicKey && communityAddress === communityRef.publicKey) {
80
+ return true;
81
+ }
82
+ if (communityRef.name) {
83
+ if (communityAddress === communityRef.name) {
84
+ return true;
85
+ }
86
+ if (areEquivalentCommunityAddresses(communityAddress, communityRef.name)) {
87
+ return true;
88
+ }
89
+ }
90
+ const communityIdentifiers = [community === null || community === void 0 ? void 0 : community.address, community === null || community === void 0 ? void 0 : community.publicKey, community === null || community === void 0 ? void 0 : community.name];
91
+ for (const identifier of communityIdentifiers) {
92
+ if (typeof identifier !== "string") {
93
+ continue;
94
+ }
95
+ if (communityAddress === identifier) {
96
+ return true;
97
+ }
98
+ if (areEquivalentCommunityAddresses(communityAddress, identifier)) {
99
+ return true;
100
+ }
101
+ }
102
+ return false;
103
+ };
104
+ export const getMatchingCommunityRefKeys = (communityRefs, communityAddress, community) => {
105
+ const matchingCommunityKeys = new Set();
106
+ for (const communityRef of communityRefs) {
107
+ if (doesAddressMatchCommunityRef(communityAddress, communityRef, community)) {
108
+ matchingCommunityKeys.add(getCommunityRefKey(communityRef));
109
+ }
110
+ }
111
+ return [...matchingCommunityKeys];
112
+ };
113
+ //# sourceMappingURL=community-ref.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"community-ref.js","sourceRoot":"","sources":["../../src/lib/community-ref.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAE5B,OAAO,EAAE,+BAA+B,EAAE,MAAM,qBAAqB,CAAC;AAUtE,MAAM,yBAAyB,GAAG,CAAC,YAAgC,EAAE,EAAE,CACpE,YAAmC,CAAC,OAAO,CAAC;AAE/C,MAAM,CAAC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EF,MAAM,CAAC,MAAM,2BAA2B,GAAG,CACzC,aAAmC,EACnC,gBAAoC,EACpC,SAAqB,EACrB,EAAE;IACF,MAAM,qBAAqB,GAAG,IAAI,GAAG,EAAU,CAAC;IAChD,KAAK,MAAM,YAAY,IAAI,aAAa,EAAE,CAAC;QACzC,IAAI,4BAA4B,CAAC,gBAAgB,EAAE,YAAY,EAAE,SAAS,CAAC,EAAE,CAAC;YAC5E,qBAAqB,CAAC,GAAG,CAAC,kBAAkB,CAAC,YAAY,CAAC,CAAC,CAAC;QAC9D,CAAC;IACH,CAAC;IACD,OAAO,CAAC,GAAG,qBAAqB,CAAC,CAAC;AACpC,CAAC,CAAC","sourcesContent":["import assert from \"assert\";\nimport { Community, CommunityIdentifier } from \"../types\";\nimport { areEquivalentCommunityAddresses } from \"./community-address\";\n\ntype LegacyCommunityRef = {\n address: string;\n name?: string;\n publicKey?: string;\n};\n\nexport type CommunityLookupRef = CommunityIdentifier | LegacyCommunityRef;\n\nconst getLegacyCommunityAddress = (communityRef: CommunityLookupRef) =>\n (communityRef as LegacyCommunityRef).address;\n\nexport const getCommunityRefKey = (communityRef: CommunityLookupRef): string => {\n const communityKey =\n communityRef.publicKey || getLegacyCommunityAddress(communityRef) || communityRef.name;\n assert(typeof communityKey === \"string\" && communityKey.length > 0, \"community ref missing key\");\n return communityKey;\n};\n\nexport const getCommunityRefKeys = (communityRefs: CommunityLookupRef[]) =>\n communityRefs.map(getCommunityRefKey);\n\nexport const getCommunityLookupOptions = (communityRefOrAddress: CommunityLookupRef | string) => {\n if (typeof communityRefOrAddress === \"string\") {\n return { address: communityRefOrAddress };\n }\n\n const legacyCommunityAddress = getLegacyCommunityAddress(communityRefOrAddress);\n if (legacyCommunityAddress) {\n return { address: legacyCommunityAddress };\n }\n if (!communityRefOrAddress.publicKey && communityRefOrAddress.name) {\n return { address: communityRefOrAddress.name };\n }\n\n const options: { name?: string; publicKey?: string } = {};\n if (communityRefOrAddress.name) {\n options.name = communityRefOrAddress.name;\n }\n if (communityRefOrAddress.publicKey) {\n options.publicKey = communityRefOrAddress.publicKey;\n }\n return options;\n};\n\nexport const mergeCommunityRefs = (\n base: CommunityLookupRef,\n extra: CommunityLookupRef,\n): CommunityLookupRef => {\n const mergedAddress = getLegacyCommunityAddress(base) || getLegacyCommunityAddress(extra);\n const mergedName = base.name || extra.name;\n const mergedPublicKey = base.publicKey || extra.publicKey;\n if (mergedPublicKey) {\n return {\n publicKey: mergedPublicKey,\n ...(mergedAddress ? { address: mergedAddress } : undefined),\n ...(mergedName ? { name: mergedName } : undefined),\n };\n }\n if (mergedAddress) {\n return {\n address: mergedAddress,\n ...(mergedName ? { name: mergedName } : undefined),\n };\n }\n assert(typeof mergedName === \"string\" && mergedName.length > 0, \"community ref missing name\");\n return { name: mergedName };\n};\n\nexport const getUniqueSortedCommunityRefs = (communityRefs?: CommunityLookupRef[]) => {\n const refsByKey = new Map<string, CommunityLookupRef>();\n for (const communityRef of communityRefs || []) {\n const communityKey = getCommunityRefKey(communityRef);\n const existingCommunityRef = refsByKey.get(communityKey);\n refsByKey.set(\n communityKey,\n existingCommunityRef ? mergeCommunityRefs(existingCommunityRef, communityRef) : communityRef,\n );\n }\n return [...refsByKey.entries()]\n .sort(([leftKey], [rightKey]) => leftKey.localeCompare(rightKey))\n .map(([, communityRef]) => communityRef);\n};\n\nexport const isCommunityRef = (value: unknown): value is CommunityIdentifier => {\n if (!value || typeof value !== \"object\" || Array.isArray(value)) {\n return false;\n }\n\n const communityRef = value as { name?: unknown; publicKey?: unknown };\n const hasName = typeof communityRef.name === \"string\" && communityRef.name.length > 0;\n const hasPublicKey =\n typeof communityRef.publicKey === \"string\" && communityRef.publicKey.length > 0;\n\n return hasName || hasPublicKey;\n};\n\nexport function assertCommunityRef(\n value: unknown,\n label: string,\n): asserts value is CommunityIdentifier {\n assert(isCommunityRef(value), `${label} must be an object with name or publicKey`);\n}\n\nexport const doesAddressMatchCommunityRef = (\n communityAddress: string | undefined,\n communityRef: CommunityLookupRef,\n community?: Community,\n) => {\n if (typeof communityAddress !== \"string\") {\n return false;\n }\n\n const legacyCommunityAddress = getLegacyCommunityAddress(communityRef);\n if (legacyCommunityAddress) {\n if (communityAddress === legacyCommunityAddress) {\n return true;\n }\n if (areEquivalentCommunityAddresses(communityAddress, legacyCommunityAddress)) {\n return true;\n }\n }\n if (communityRef.publicKey && communityAddress === communityRef.publicKey) {\n return true;\n }\n if (communityRef.name) {\n if (communityAddress === communityRef.name) {\n return true;\n }\n if (areEquivalentCommunityAddresses(communityAddress, communityRef.name)) {\n return true;\n }\n }\n\n const communityIdentifiers = [community?.address, community?.publicKey, community?.name];\n for (const identifier of communityIdentifiers) {\n if (typeof identifier !== \"string\") {\n continue;\n }\n if (communityAddress === identifier) {\n return true;\n }\n if (areEquivalentCommunityAddresses(communityAddress, identifier)) {\n return true;\n }\n }\n\n return false;\n};\n\nexport const getMatchingCommunityRefKeys = (\n communityRefs: CommunityLookupRef[],\n communityAddress: string | undefined,\n community?: Community,\n) => {\n const matchingCommunityKeys = new Set<string>();\n for (const communityRef of communityRefs) {\n if (doesAddressMatchCommunityRef(communityAddress, communityRef, community)) {\n matchingCommunityKeys.add(getCommunityRefKey(communityRef));\n }\n }\n return [...matchingCommunityKeys];\n};\n"]}
@@ -0,0 +1,9 @@
1
+ declare const deleteDatabases: () => Promise<[void, void, any, any, any]>;
2
+ declare const deleteCaches: () => Promise<[any, any, any]>;
3
+ declare const debugUtils: {
4
+ deleteDatabases: () => Promise<[void, void, any, any, any]>;
5
+ deleteCaches: () => Promise<[any, any, any]>;
6
+ };
7
+ export { deleteDatabases, deleteCaches };
8
+ export default debugUtils;
9
+ //# sourceMappingURL=debug-utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"debug-utils.d.ts","sourceRoot":"","sources":["../../src/lib/debug-utils.ts"],"names":[],"mappings":"AAGA,QAAA,MAAM,eAAe,4CAOjB,CAAC;AAEL,QAAA,MAAM,YAAY,gCAKd,CAAC;AAEL,QAAA,MAAM,UAAU;;;CAGf,CAAC;AAEF,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,CAAC;AACzC,eAAe,UAAU,CAAC"}
@@ -0,0 +1,21 @@
1
+ import localForage from "localforage";
2
+ import localForageLru from "../lib/localforage-lru/index.js";
3
+ const deleteDatabases = () => Promise.all([
4
+ localForage.createInstance({ name: "bitsocialReactHooks-accountsMetadata" }).clear(),
5
+ localForage.createInstance({ name: "bitsocialReactHooks-accounts" }).clear(),
6
+ localForageLru.createInstance({ name: "bitsocialReactHooks-communities" }).clear(),
7
+ localForageLru.createInstance({ name: "bitsocialReactHooks-comments" }).clear(),
8
+ localForageLru.createInstance({ name: "bitsocialReactHooks-communitiesPages" }).clear(),
9
+ ]);
10
+ const deleteCaches = () => Promise.all([
11
+ localForageLru.createInstance({ name: "bitsocialReactHooks-communities" }).clear(),
12
+ localForageLru.createInstance({ name: "bitsocialReactHooks-comments" }).clear(),
13
+ localForageLru.createInstance({ name: "bitsocialReactHooks-communitiesPages" }).clear(),
14
+ ]);
15
+ const debugUtils = {
16
+ deleteDatabases,
17
+ deleteCaches,
18
+ };
19
+ export { deleteDatabases, deleteCaches };
20
+ export default debugUtils;
21
+ //# sourceMappingURL=debug-utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"debug-utils.js","sourceRoot":"","sources":["../../src/lib/debug-utils.ts"],"names":[],"mappings":"AAAA,OAAO,WAAW,MAAM,aAAa,CAAC;AACtC,OAAO,cAAc,MAAM,wBAAwB,CAAC;AAEpD,MAAM,eAAe,GAAG,GAAG,EAAE,CAC3B,OAAO,CAAC,GAAG,CAAC;IACV,WAAW,CAAC,cAAc,CAAC,EAAE,IAAI,EAAE,sCAAsC,EAAE,CAAC,CAAC,KAAK,EAAE;IACpF,WAAW,CAAC,cAAc,CAAC,EAAE,IAAI,EAAE,8BAA8B,EAAE,CAAC,CAAC,KAAK,EAAE;IAC5E,cAAc,CAAC,cAAc,CAAC,EAAE,IAAI,EAAE,iCAAiC,EAAE,CAAC,CAAC,KAAK,EAAE;IAClF,cAAc,CAAC,cAAc,CAAC,EAAE,IAAI,EAAE,8BAA8B,EAAE,CAAC,CAAC,KAAK,EAAE;IAC/E,cAAc,CAAC,cAAc,CAAC,EAAE,IAAI,EAAE,sCAAsC,EAAE,CAAC,CAAC,KAAK,EAAE;CACxF,CAAC,CAAC;AAEL,MAAM,YAAY,GAAG,GAAG,EAAE,CACxB,OAAO,CAAC,GAAG,CAAC;IACV,cAAc,CAAC,cAAc,CAAC,EAAE,IAAI,EAAE,iCAAiC,EAAE,CAAC,CAAC,KAAK,EAAE;IAClF,cAAc,CAAC,cAAc,CAAC,EAAE,IAAI,EAAE,8BAA8B,EAAE,CAAC,CAAC,KAAK,EAAE;IAC/E,cAAc,CAAC,cAAc,CAAC,EAAE,IAAI,EAAE,sCAAsC,EAAE,CAAC,CAAC,KAAK,EAAE;CACxF,CAAC,CAAC;AAEL,MAAM,UAAU,GAAG;IACjB,eAAe;IACf,YAAY;CACb,CAAC;AAEF,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,CAAC;AACzC,eAAe,UAAU,CAAC","sourcesContent":["import localForage from \"localforage\";\nimport localForageLru from \"../lib/localforage-lru\";\n\nconst deleteDatabases = () =>\n Promise.all([\n localForage.createInstance({ name: \"bitsocialReactHooks-accountsMetadata\" }).clear(),\n localForage.createInstance({ name: \"bitsocialReactHooks-accounts\" }).clear(),\n localForageLru.createInstance({ name: \"bitsocialReactHooks-communities\" }).clear(),\n localForageLru.createInstance({ name: \"bitsocialReactHooks-comments\" }).clear(),\n localForageLru.createInstance({ name: \"bitsocialReactHooks-communitiesPages\" }).clear(),\n ]);\n\nconst deleteCaches = () =>\n Promise.all([\n localForageLru.createInstance({ name: \"bitsocialReactHooks-communities\" }).clear(),\n localForageLru.createInstance({ name: \"bitsocialReactHooks-comments\" }).clear(),\n localForageLru.createInstance({ name: \"bitsocialReactHooks-communitiesPages\" }).clear(),\n ]);\n\nconst debugUtils = {\n deleteDatabases,\n deleteCaches,\n};\n\nexport { deleteDatabases, deleteCaches };\nexport default debugUtils;\n"]}
@@ -0,0 +1,2 @@
1
+ export declare const deriveFeedSortType: (sortType?: string, newerThan?: number) => string;
2
+ //# sourceMappingURL=feed-sort-type.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"feed-sort-type.d.ts","sourceRoot":"","sources":["../../src/lib/feed-sort-type.ts"],"names":[],"mappings":"AAOA,eAAO,MAAM,kBAAkB,GAAI,WAAW,MAAM,EAAE,YAAY,MAAM,KAAG,MAY1E,CAAC"}
@@ -0,0 +1,22 @@
1
+ const NEWER_THAN_LIMITS = [
2
+ [60 * 60 * 24, "Day"],
3
+ [60 * 60 * 24 * 7, "Week"],
4
+ [60 * 60 * 24 * 31, "Month"],
5
+ [60 * 60 * 24 * 365, "Year"],
6
+ ];
7
+ export const deriveFeedSortType = (sortType, newerThan) => {
8
+ const base = sortType || "hot";
9
+ if (!newerThan || (base !== "topAll" && base !== "controversialAll"))
10
+ return base;
11
+ let time;
12
+ for (const [limit, name] of NEWER_THAN_LIMITS) {
13
+ if (newerThan <= limit) {
14
+ time = name;
15
+ break;
16
+ }
17
+ }
18
+ if (!time)
19
+ return base;
20
+ return base === "topAll" ? `top${time}` : `controversial${time}`;
21
+ };
22
+ //# sourceMappingURL=feed-sort-type.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"feed-sort-type.js","sourceRoot":"","sources":["../../src/lib/feed-sort-type.ts"],"names":[],"mappings":"AAAA,MAAM,iBAAiB,GAAG;IACxB,CAAC,EAAE,GAAG,EAAE,GAAG,EAAE,EAAE,KAAK,CAAC;IACrB,CAAC,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,EAAE,MAAM,CAAC;IAC1B,CAAC,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,EAAE,OAAO,CAAC;IAC5B,CAAC,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,GAAG,EAAE,MAAM,CAAC;CACpB,CAAC;AAEX,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,QAAiB,EAAE,SAAkB,EAAU,EAAE;IAClF,MAAM,IAAI,GAAG,QAAQ,IAAI,KAAK,CAAC;IAC/B,IAAI,CAAC,SAAS,IAAI,CAAC,IAAI,KAAK,QAAQ,IAAI,IAAI,KAAK,kBAAkB,CAAC;QAAE,OAAO,IAAI,CAAC;IAClF,IAAI,IAAwB,CAAC;IAC7B,KAAK,MAAM,CAAC,KAAK,EAAE,IAAI,CAAC,IAAI,iBAAiB,EAAE,CAAC;QAC9C,IAAI,SAAS,IAAI,KAAK,EAAE,CAAC;YACvB,IAAI,GAAG,IAAI,CAAC;YACZ,MAAM;QACR,CAAC;IACH,CAAC;IACD,IAAI,CAAC,IAAI;QAAE,OAAO,IAAI,CAAC;IACvB,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,IAAI,EAAE,CAAC,CAAC,CAAC,gBAAgB,IAAI,EAAE,CAAC;AACnE,CAAC,CAAC","sourcesContent":["const NEWER_THAN_LIMITS = [\n [60 * 60 * 24, \"Day\"],\n [60 * 60 * 24 * 7, \"Week\"],\n [60 * 60 * 24 * 31, \"Month\"],\n [60 * 60 * 24 * 365, \"Year\"],\n] as const;\n\nexport const deriveFeedSortType = (sortType?: string, newerThan?: number): string => {\n const base = sortType || \"hot\";\n if (!newerThan || (base !== \"topAll\" && base !== \"controversialAll\")) return base;\n let time: string | undefined;\n for (const [limit, name] of NEWER_THAN_LIMITS) {\n if (newerThan <= limit) {\n time = name;\n break;\n }\n }\n if (!time) return base;\n return base === \"topAll\" ? `top${time}` : `controversial${time}`;\n};\n"]}
@@ -0,0 +1,3 @@
1
+ import localForageLru from "./localforage-lru.js";
2
+ export default localForageLru;
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/lib/localforage-lru/index.ts"],"names":[],"mappings":"AAAA,OAAO,cAAc,MAAM,mBAAmB,CAAC;AAwB/C,eAAe,cAAc,CAAC"}
@@ -0,0 +1,46 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import localForageLru from "./localforage-lru.js";
11
+ try {
12
+ // for debugging without caching
13
+ if (process.env.REACT_APP_BITSOCIAL_REACT_HOOKS_NO_CACHE) {
14
+ // @ts-ignore
15
+ localForageLru.createInstance = () => {
16
+ console.warn("@bitsocial/bitsocial-react-hooks cache is disabled for testing");
17
+ return {
18
+ getItem: function (key) {
19
+ return __awaiter(this, void 0, void 0, function* () { });
20
+ },
21
+ setItem: function (key, value) {
22
+ return __awaiter(this, void 0, void 0, function* () { });
23
+ },
24
+ removeItem: function (key) {
25
+ return __awaiter(this, void 0, void 0, function* () { });
26
+ },
27
+ clear: function () {
28
+ return __awaiter(this, void 0, void 0, function* () { });
29
+ },
30
+ keys: function () {
31
+ return __awaiter(this, void 0, void 0, function* () {
32
+ return [];
33
+ });
34
+ },
35
+ entries: function () {
36
+ return __awaiter(this, void 0, void 0, function* () {
37
+ return [];
38
+ });
39
+ },
40
+ };
41
+ };
42
+ }
43
+ }
44
+ catch (e) { }
45
+ export default localForageLru;
46
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/lib/localforage-lru/index.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,cAAc,MAAM,mBAAmB,CAAC;AAE/C,IAAI,CAAC;IACH,gCAAgC;IAChC,IAAI,OAAO,CAAC,GAAG,CAAC,wCAAwC,EAAE,CAAC;QACzD,aAAa;QACb,cAAc,CAAC,cAAc,GAAG,GAAG,EAAE;YACnC,OAAO,CAAC,IAAI,CAAC,gEAAgE,CAAC,CAAC;YAC/E,OAAO;gBACL,OAAO,EAAE,UAAgB,GAAW;0EAAG,CAAC;iBAAA;gBACxC,OAAO,EAAE,UAAgB,GAAW,EAAE,KAAU;0EAAG,CAAC;iBAAA;gBACpD,UAAU,EAAE,UAAgB,GAAW;0EAAG,CAAC;iBAAA;gBAC3C,KAAK,EAAE;0EAAmB,CAAC;iBAAA;gBAC3B,IAAI,EAAE;;wBACJ,OAAO,EAAE,CAAC;oBACZ,CAAC;iBAAA;gBACD,OAAO,EAAE;;wBACP,OAAO,EAAE,CAAC;oBACZ,CAAC;iBAAA;aACF,CAAC;QACJ,CAAC,CAAC;IACJ,CAAC;AACH,CAAC;AAAC,OAAO,CAAC,EAAE,CAAC,CAAA,CAAC;AAEd,eAAe,cAAc,CAAC","sourcesContent":["import localForageLru from \"./localforage-lru\";\n\ntry {\n // for debugging without caching\n if (process.env.REACT_APP_BITSOCIAL_REACT_HOOKS_NO_CACHE) {\n // @ts-ignore\n localForageLru.createInstance = () => {\n console.warn(\"@bitsocial/bitsocial-react-hooks cache is disabled for testing\");\n return {\n getItem: async function (key: string) {},\n setItem: async function (key: string, value: any) {},\n removeItem: async function (key: string) {},\n clear: async function () {},\n keys: async function () {\n return [];\n },\n entries: async function () {\n return [];\n },\n };\n };\n }\n} catch (e) {}\n\nexport default localForageLru;\n"]}
@@ -0,0 +1,6 @@
1
+ export declare const instances: any;
2
+ declare const _default: {
3
+ createInstance: (localForageLruOptions: any) => any;
4
+ };
5
+ export default _default;
6
+ //# sourceMappingURL=localforage-lru.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"localforage-lru.d.ts","sourceRoot":"","sources":["../../../src/lib/localforage-lru/localforage-lru.ts"],"names":[],"mappings":"AA4JA,eAAO,MAAM,SAAS,EAAE,GAAQ,CAAC;;4CAEc,GAAG;;AAkBlD,wBAAkC"}
@@ -0,0 +1,182 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import localForage from "localforage";
11
+ function createLocalForageInstance(localForageLruOptions) {
12
+ if (typeof (localForageLruOptions === null || localForageLruOptions === void 0 ? void 0 : localForageLruOptions.size) !== "number") {
13
+ throw Error(`LocalForageLru.createInstance localForageLruOptions.size '${localForageLruOptions === null || localForageLruOptions === void 0 ? void 0 : localForageLruOptions.size}' not a number`);
14
+ }
15
+ const localForageOptions = Object.assign({}, localForageLruOptions);
16
+ delete localForageOptions.size;
17
+ let database1, database2, databaseSize, initialized = false;
18
+ const initializationPromize = new Promise((resolve) => __awaiter(this, void 0, void 0, function* () {
19
+ const localForage1 = localForage.createInstance(Object.assign(Object.assign({}, localForageOptions), { name: localForageLruOptions.name }));
20
+ const localForage2 = localForage.createInstance(Object.assign(Object.assign({}, localForageOptions), { name: localForageLruOptions.name + "2" }));
21
+ const [localForage1Size, localForage2Size] = yield Promise.all([
22
+ localForage1.length(),
23
+ localForage2.length(),
24
+ ]);
25
+ // largest db is always active db, unless is max size, because max sized db is always inactive
26
+ if ((localForage1Size >= localForage2Size && localForage1Size !== localForageLruOptions.size) ||
27
+ localForage2Size === localForageLruOptions.size) {
28
+ database2 = localForage2;
29
+ database1 = localForage1;
30
+ databaseSize = localForage1Size;
31
+ }
32
+ else {
33
+ database2 = localForage1;
34
+ database1 = localForage2;
35
+ databaseSize = localForage2Size;
36
+ }
37
+ initialized = true;
38
+ resolve(undefined);
39
+ }));
40
+ return {
41
+ getItem: function (key) {
42
+ return __awaiter(this, void 0, void 0, function* () {
43
+ yield initialization();
44
+ const [value, value2] = yield Promise.all([database1.getItem(key), database2.getItem(key)]);
45
+ let returnValue = value;
46
+ if (returnValue !== null && returnValue !== undefined)
47
+ return returnValue;
48
+ if ((returnValue = value2) !== null && (returnValue = value2) !== undefined) {
49
+ yield updateDatabases(key, returnValue);
50
+ return returnValue;
51
+ }
52
+ });
53
+ },
54
+ setItem: function (key, value) {
55
+ return __awaiter(this, void 0, void 0, function* () {
56
+ yield initialization();
57
+ const databaseValue = yield database1.getItem(key);
58
+ if (databaseValue !== null && databaseValue !== undefined) {
59
+ try {
60
+ yield database1.setItem(key, value);
61
+ }
62
+ catch (error) {
63
+ console.error("localforageLru.setItem setItem error", {
64
+ error,
65
+ errorMessage: error === null || error === void 0 ? void 0 : error.message,
66
+ key,
67
+ value,
68
+ });
69
+ throw error;
70
+ }
71
+ }
72
+ else {
73
+ yield updateDatabases(key, value);
74
+ }
75
+ });
76
+ },
77
+ removeItem: function (key) {
78
+ return __awaiter(this, void 0, void 0, function* () {
79
+ yield initialization();
80
+ yield Promise.all([database1.removeItem(key), database2.removeItem(key)]);
81
+ });
82
+ },
83
+ clear: function () {
84
+ return __awaiter(this, void 0, void 0, function* () {
85
+ yield initialization();
86
+ yield Promise.all([database1.clear(), database2.clear()]);
87
+ });
88
+ },
89
+ key: function (keyIndex) {
90
+ return __awaiter(this, void 0, void 0, function* () {
91
+ throw Error("not implemented");
92
+ });
93
+ },
94
+ // don't use for init react state, use entries() instead
95
+ keys: function () {
96
+ return __awaiter(this, void 0, void 0, function* () {
97
+ yield initialization();
98
+ const [keys1, keys2] = yield Promise.all([database1.keys(), database2.keys()]);
99
+ return [...new Set([...keys1, ...keys2])];
100
+ });
101
+ },
102
+ // useful to init a react state on load
103
+ entries: function () {
104
+ return __awaiter(this, void 0, void 0, function* () {
105
+ yield initialization();
106
+ const [keys1, keys2] = yield Promise.all([database1.keys(), database2.keys()]);
107
+ const keys = [...new Set([...keys1, ...keys2])];
108
+ const entries = [];
109
+ const getItem = (key) => __awaiter(this, void 0, void 0, function* () {
110
+ const [value, value2] = yield Promise.all([database1.getItem(key), database2.getItem(key)]);
111
+ if (value !== null && value !== undefined) {
112
+ return value;
113
+ }
114
+ return value2;
115
+ });
116
+ yield Promise.all(keys.map((key, i) => getItem(key).then((value) => {
117
+ entries[i] = [key, value];
118
+ })));
119
+ return entries;
120
+ });
121
+ },
122
+ length: function () {
123
+ return __awaiter(this, void 0, void 0, function* () {
124
+ throw Error("not implemented");
125
+ });
126
+ },
127
+ };
128
+ function updateDatabases(key, value) {
129
+ return __awaiter(this, void 0, void 0, function* () {
130
+ var _a, _b;
131
+ try {
132
+ yield database1.setItem(key, value);
133
+ }
134
+ catch (error) {
135
+ console.error("localforageLru updateDatabases setItem error", {
136
+ error,
137
+ errorMessage: error === null || error === void 0 ? void 0 : error.message,
138
+ key,
139
+ value,
140
+ });
141
+ // ignore this error, don't know why it happens
142
+ if ((_b = (_a = error === null || error === void 0 ? void 0 : error.message) === null || _a === void 0 ? void 0 : _a.includes) === null || _b === void 0 ? void 0 : _b.call(_a, "unit storage quota has been exceeded")) {
143
+ return;
144
+ }
145
+ throw error;
146
+ }
147
+ databaseSize++;
148
+ if (databaseSize >= localForageLruOptions.size) {
149
+ databaseSize = 0;
150
+ const database1Temp = database1;
151
+ const database2Temp = database2;
152
+ database2 = database1Temp;
153
+ database1 = database2Temp;
154
+ yield database1.clear();
155
+ }
156
+ });
157
+ }
158
+ function initialization() {
159
+ return __awaiter(this, void 0, void 0, function* () {
160
+ if (initialized) {
161
+ return;
162
+ }
163
+ return initializationPromize;
164
+ });
165
+ }
166
+ }
167
+ export const instances = {};
168
+ const createInstance = (localForageLruOptions) => {
169
+ if (typeof (localForageLruOptions === null || localForageLruOptions === void 0 ? void 0 : localForageLruOptions.name) !== "string") {
170
+ throw Error(`LocalForageLru.createInstance localForageLruOptions.name '${localForageLruOptions === null || localForageLruOptions === void 0 ? void 0 : localForageLruOptions.name}' not a string`);
171
+ }
172
+ if (instances[localForageLruOptions.name]) {
173
+ if (localForageLruOptions.size) {
174
+ throw Error(`LocalForageLru.createInstance with name '${localForageLruOptions.name}' already created, remove localForageLruOptions.size, size cannot be changed`);
175
+ }
176
+ return instances[localForageLruOptions.name];
177
+ }
178
+ instances[localForageLruOptions.name] = createLocalForageInstance(localForageLruOptions);
179
+ return instances[localForageLruOptions.name];
180
+ };
181
+ export default { createInstance };
182
+ //# sourceMappingURL=localforage-lru.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"localforage-lru.js","sourceRoot":"","sources":["../../../src/lib/localforage-lru/localforage-lru.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,WAAW,MAAM,aAAa,CAAC;AAEtC,SAAS,yBAAyB,CAAC,qBAA0B;IAC3D,IAAI,OAAO,CAAA,qBAAqB,aAArB,qBAAqB,uBAArB,qBAAqB,CAAE,IAAI,CAAA,KAAK,QAAQ,EAAE,CAAC;QACpD,MAAM,KAAK,CACT,6DAA6D,qBAAqB,aAArB,qBAAqB,uBAArB,qBAAqB,CAAE,IAAI,gBAAgB,CACzG,CAAC;IACJ,CAAC;IACD,MAAM,kBAAkB,qBAAQ,qBAAqB,CAAE,CAAC;IACxD,OAAO,kBAAkB,CAAC,IAAI,CAAC;IAC/B,IAAI,SAAc,EAChB,SAAc,EACd,YAAoB,EACpB,WAAW,GAAG,KAAK,CAAC;IAEtB,MAAM,qBAAqB,GAAG,IAAI,OAAO,CAAC,CAAO,OAAO,EAAE,EAAE;QAC1D,MAAM,YAAY,GAAG,WAAW,CAAC,cAAc,iCAC1C,kBAAkB,KACrB,IAAI,EAAE,qBAAqB,CAAC,IAAI,IAChC,CAAC;QACH,MAAM,YAAY,GAAG,WAAW,CAAC,cAAc,iCAC1C,kBAAkB,KACrB,IAAI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C;KAAA;AACH,CAAC;AAED,MAAM,CAAC,MAAM,SAAS,GAAQ,EAAE,CAAC;AAEjC,MAAM,cAAc,GAAG,CAAC,qBAA0B,EAAE,EAAE;IACpD,IAAI,OAAO,CAAA,qBAAqB,aAArB,qBAAqB,uBAArB,qBAAqB,CAAE,IAAI,CAAA,KAAK,QAAQ,EAAE,CAAC;QACpD,MAAM,KAAK,CACT,6DAA6D,qBAAqB,aAArB,qBAAqB,uBAArB,qBAAqB,CAAE,IAAI,gBAAgB,CACzG,CAAC;IACJ,CAAC;IACD,IAAI,SAAS,CAAC,qBAAqB,CAAC,IAAI,CAAC,EAAE,CAAC;QAC1C,IAAI,qBAAqB,CAAC,IAAI,EAAE,CAAC;YAC/B,MAAM,KAAK,CACT,4CAA4C,qBAAqB,CAAC,IAAI,8EAA8E,CACrJ,CAAC;QACJ,CAAC;QACD,OAAO,SAAS,CAAC,qBAAqB,CAAC,IAAI,CAAC,CAAC;IAC/C,CAAC;IACD,SAAS,CAAC,qBAAqB,CAAC,IAAI,CAAC,GAAG,yBAAyB,CAAC,qBAAqB,CAAC,CAAC;IACzF,OAAO,SAAS,CAAC,qBAAqB,CAAC,IAAI,CAAC,CAAC;AAC/C,CAAC,CAAC;AAEF,eAAe,EAAE,cAAc,EAAE,CAAC","sourcesContent":["import localForage from \"localforage\";\n\nfunction createLocalForageInstance(localForageLruOptions: any): any {\n if (typeof localForageLruOptions?.size !== \"number\") {\n throw Error(\n `LocalForageLru.createInstance localForageLruOptions.size '${localForageLruOptions?.size}' not a number`,\n );\n }\n const localForageOptions = { ...localForageLruOptions };\n delete localForageOptions.size;\n let database1: any,\n database2: any,\n databaseSize: number,\n initialized = false;\n\n const initializationPromize = new Promise(async (resolve) => {\n const localForage1 = localForage.createInstance({\n ...localForageOptions,\n name: localForageLruOptions.name,\n });\n const localForage2 = localForage.createInstance({\n ...localForageOptions,\n name: localForageLruOptions.name + \"2\",\n });\n const [localForage1Size, localForage2Size] = await Promise.all([\n localForage1.length(),\n localForage2.length(),\n ]);\n // largest db is always active db, unless is max size, because max sized db is always inactive\n if (\n (localForage1Size >= localForage2Size && localForage1Size !== localForageLruOptions.size) ||\n localForage2Size === localForageLruOptions.size\n ) {\n database2 = localForage2;\n database1 = localForage1;\n databaseSize = localForage1Size;\n } else {\n database2 = localForage1;\n database1 = localForage2;\n databaseSize = localForage2Size;\n }\n initialized = true;\n resolve(undefined);\n });\n\n return {\n getItem: async function (key: string) {\n await initialization();\n const [value, value2] = await Promise.all([database1.getItem(key), database2.getItem(key)]);\n\n let returnValue = value;\n if (returnValue !== null && returnValue !== undefined) return returnValue;\n if ((returnValue = value2) !== null && (returnValue = value2) !== undefined) {\n await updateDatabases(key, returnValue);\n return returnValue;\n }\n },\n setItem: async function (key: string, value: any) {\n await initialization();\n const databaseValue = await database1.getItem(key);\n if (databaseValue !== null && databaseValue !== undefined) {\n try {\n await database1.setItem(key, value);\n } catch (error: any) {\n console.error(\"localforageLru.setItem setItem error\", {\n error,\n errorMessage: error?.message,\n key,\n value,\n });\n throw error;\n }\n } else {\n await updateDatabases(key, value);\n }\n },\n removeItem: async function (key: string) {\n await initialization();\n await Promise.all([database1.removeItem(key), database2.removeItem(key)]);\n },\n clear: async function () {\n await initialization();\n await Promise.all([database1.clear(), database2.clear()]);\n },\n key: async function (keyIndex: number) {\n throw Error(\"not implemented\");\n },\n // don't use for init react state, use entries() instead\n keys: async function () {\n await initialization();\n const [keys1, keys2] = await Promise.all([database1.keys(), database2.keys()]);\n return [...new Set([...keys1, ...keys2])];\n },\n // useful to init a react state on load\n entries: async function () {\n await initialization();\n const [keys1, keys2] = await Promise.all([database1.keys(), database2.keys()]);\n const keys = [...new Set([...keys1, ...keys2])];\n const entries: any[] = [];\n const getItem = async (key: string) => {\n const [value, value2] = await Promise.all([database1.getItem(key), database2.getItem(key)]);\n if (value !== null && value !== undefined) {\n return value;\n }\n return value2;\n };\n await Promise.all(\n keys.map((key, i) =>\n getItem(key).then((value) => {\n entries[i] = [key, value];\n }),\n ),\n );\n return entries;\n },\n length: async function () {\n throw Error(\"not implemented\");\n },\n };\n\n async function updateDatabases(key: string, value: any) {\n try {\n await database1.setItem(key, value);\n } catch (error: any) {\n console.error(\"localforageLru updateDatabases setItem error\", {\n error,\n errorMessage: error?.message,\n key,\n value,\n });\n\n // ignore this error, don't know why it happens\n if (error?.message?.includes?.(\"unit storage quota has been exceeded\")) {\n return;\n }\n throw error;\n }\n databaseSize++;\n if (databaseSize >= localForageLruOptions.size) {\n databaseSize = 0;\n const database1Temp = database1;\n const database2Temp = database2;\n database2 = database1Temp;\n database1 = database2Temp;\n await database1.clear();\n }\n }\n\n async function initialization() {\n if (initialized) {\n return;\n }\n return initializationPromize;\n }\n}\n\nexport const instances: any = {};\n\nconst createInstance = (localForageLruOptions: any) => {\n if (typeof localForageLruOptions?.name !== \"string\") {\n throw Error(\n `LocalForageLru.createInstance localForageLruOptions.name '${localForageLruOptions?.name}' not a string`,\n );\n }\n if (instances[localForageLruOptions.name]) {\n if (localForageLruOptions.size) {\n throw Error(\n `LocalForageLru.createInstance with name '${localForageLruOptions.name}' already created, remove localForageLruOptions.size, size cannot be changed`,\n );\n }\n return instances[localForageLruOptions.name];\n }\n instances[localForageLruOptions.name] = createLocalForageInstance(localForageLruOptions);\n return instances[localForageLruOptions.name];\n};\n\nexport default { createInstance };\n"]}
@@ -0,0 +1,25 @@
1
+ export declare const getProtocolClient: (account: any) => any;
2
+ export declare const getProtocolOptions: (account: any) => any;
3
+ export declare const getChainProviders: (account: any) => any;
4
+ export declare const getNameResolversChainProviders: (account: any) => any;
5
+ export declare const getRpcClients: (protocolClient: any) => any;
6
+ export declare const getPageRpcClients: (clients: any) => any;
7
+ export declare const getProtocolNameResolverClients: (protocolClient: any) => any;
8
+ export type NameResolverInfo = {
9
+ key: string;
10
+ nameSystem: string;
11
+ chainTicker: string;
12
+ provider: string;
13
+ providerLabel: string;
14
+ };
15
+ export declare const getConfiguredNameResolverInfoByKey: (account: any) => Record<string, NameResolverInfo>;
16
+ export declare const getMatchingNameResolvers: (account: any, address?: string) => NameResolverInfo[];
17
+ export declare const resolveAuthorNameWithProtocol: (protocolClient: any, options: {
18
+ address?: string;
19
+ } | Record<string, any>) => any;
20
+ export declare const normalizeOptionsForPkcClient: <T extends Record<string, any> | undefined>(options: T) => T;
21
+ export declare const getPkcClientOptions: <T extends Record<string, any> | undefined>(account: any, options: T) => T;
22
+ export declare const normalizeAccountProtocolConfig: <T extends Record<string, any> | undefined>(account: T, defaultChainProviders?: Record<string, any>) => T;
23
+ export declare const withProtocolAliases: <T extends Record<string, any>>(account: T, protocolClient?: any, protocolOptions?: any) => T;
24
+ export * from "./protocol-compat.js";
25
+ //# sourceMappingURL=pkc-compat.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pkc-compat.d.ts","sourceRoot":"","sources":["../../src/lib/pkc-compat.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,iBAAiB,GAAI,SAAS,GAAG,QAAiB,CAAC;AAEhE,eAAO,MAAM,kBAAkB,GAAI,SAAS,GAAG,QAAwB,CAAC;AAExE,eAAO,MAAM,iBAAiB,GAAI,SAAS,GAAG,QAC0B,CAAC;AAEzE,eAAO,MAAM,8BAA8B,GAAI,SAAS,GAAG,QACuC,CAAC;AAEnG,eAAO,MAAM,aAAa,GAAI,gBAAgB,GAAG,QAAiD,CAAC;AAEnG,eAAO,MAAM,iBAAiB,GAAI,SAAS,GAAG,QAAiC,CAAC;AAEhF,eAAO,MAAM,8BAA8B,GAAI,gBAAgB,GAAG,QAG9D,CAAC;AAEL,MAAM,MAAM,gBAAgB,GAAG;IAC7B,GAAG,EAAE,MAAM,CAAC;IACZ,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,aAAa,EAAE,MAAM,CAAC;CACvB,CAAC;AAkCF,eAAO,MAAM,kCAAkC,GAC7C,SAAS,GAAG,KACX,MAAM,CAAC,MAA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