@bitsocial/bitsocial-react-hooks 0.2.1 → 0.2.3

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 (117) hide show
  1. package/CHANGELOG.md +31 -0
  2. package/README.md +2 -0
  3. package/dist/hooks/accounts/accounts.d.ts.map +1 -1
  4. package/dist/hooks/accounts/accounts.js +35 -10
  5. package/dist/hooks/accounts/accounts.js.map +1 -1
  6. package/dist/hooks/actions/actions.d.ts.map +1 -1
  7. package/dist/hooks/actions/actions.js +166 -93
  8. package/dist/hooks/actions/actions.js.map +1 -1
  9. package/dist/hooks/authors/author-avatars.d.ts +2 -2
  10. package/dist/hooks/authors/author-avatars.d.ts.map +1 -1
  11. package/dist/hooks/authors/author-avatars.js +48 -20
  12. package/dist/hooks/authors/author-avatars.js.map +1 -1
  13. package/dist/hooks/authors/authors.d.ts.map +1 -1
  14. package/dist/hooks/authors/authors.js +68 -22
  15. package/dist/hooks/authors/authors.js.map +1 -1
  16. package/dist/hooks/comments.d.ts.map +1 -1
  17. package/dist/hooks/comments.js +54 -3
  18. package/dist/hooks/comments.js.map +1 -1
  19. package/dist/hooks/communities.d.ts.map +1 -1
  20. package/dist/hooks/communities.js +41 -12
  21. package/dist/hooks/communities.js.map +1 -1
  22. package/dist/hooks/feeds/feeds.d.ts.map +1 -1
  23. package/dist/hooks/feeds/feeds.js +47 -11
  24. package/dist/hooks/feeds/feeds.js.map +1 -1
  25. package/dist/hooks/pkc-rpc.d.ts.map +1 -1
  26. package/dist/hooks/pkc-rpc.js +33 -20
  27. package/dist/hooks/pkc-rpc.js.map +1 -1
  28. package/dist/hooks/replies.d.ts.map +1 -1
  29. package/dist/hooks/replies.js +30 -4
  30. package/dist/hooks/replies.js.map +1 -1
  31. package/dist/index.d.ts +6 -4
  32. package/dist/index.d.ts.map +1 -1
  33. package/dist/index.js +4 -2
  34. package/dist/index.js.map +1 -1
  35. package/dist/lib/debug-utils.d.ts +4 -4
  36. package/dist/lib/debug-utils.d.ts.map +1 -1
  37. package/dist/lib/debug-utils.js +56 -11
  38. package/dist/lib/debug-utils.js.map +1 -1
  39. package/dist/lib/localforage-lru/localforage-lru.d.ts +1 -0
  40. package/dist/lib/localforage-lru/localforage-lru.d.ts.map +1 -1
  41. package/dist/lib/localforage-lru/localforage-lru.js +48 -10
  42. package/dist/lib/localforage-lru/localforage-lru.js.map +1 -1
  43. package/dist/lib/page-sorts.d.ts +6 -0
  44. package/dist/lib/page-sorts.d.ts.map +1 -1
  45. package/dist/lib/page-sorts.js +45 -9
  46. package/dist/lib/page-sorts.js.map +1 -1
  47. package/dist/lib/pkc-js/pkc-js-mock-content.d.ts.map +1 -1
  48. package/dist/lib/pkc-js/pkc-js-mock-content.js +5 -1
  49. package/dist/lib/pkc-js/pkc-js-mock-content.js.map +1 -1
  50. package/dist/lib/utils/utils.d.ts.map +1 -1
  51. package/dist/lib/utils/utils.js +24 -16
  52. package/dist/lib/utils/utils.js.map +1 -1
  53. package/dist/lib/validator.d.ts +1 -1
  54. package/dist/lib/validator.d.ts.map +1 -1
  55. package/dist/lib/validator.js +7 -1
  56. package/dist/lib/validator.js.map +1 -1
  57. package/dist/stores/accounts/account-generator.d.ts +1 -0
  58. package/dist/stores/accounts/account-generator.d.ts.map +1 -1
  59. package/dist/stores/accounts/account-generator.js +12 -4
  60. package/dist/stores/accounts/account-generator.js.map +1 -1
  61. package/dist/stores/accounts/accounts-actions-internal.d.ts.map +1 -1
  62. package/dist/stores/accounts/accounts-actions-internal.js +24 -6
  63. package/dist/stores/accounts/accounts-actions-internal.js.map +1 -1
  64. package/dist/stores/accounts/accounts-actions.d.ts.map +1 -1
  65. package/dist/stores/accounts/accounts-actions.js +339 -98
  66. package/dist/stores/accounts/accounts-actions.js.map +1 -1
  67. package/dist/stores/accounts/accounts-database.d.ts +1 -0
  68. package/dist/stores/accounts/accounts-database.d.ts.map +1 -1
  69. package/dist/stores/accounts/accounts-database.js +82 -15
  70. package/dist/stores/accounts/accounts-database.js.map +1 -1
  71. package/dist/stores/accounts/accounts-store.d.ts +1 -1
  72. package/dist/stores/accounts/accounts-store.d.ts.map +1 -1
  73. package/dist/stores/accounts/accounts-store.js +1 -1
  74. package/dist/stores/accounts/accounts-store.js.map +1 -1
  75. package/dist/stores/accounts/utils.d.ts +5 -1
  76. package/dist/stores/accounts/utils.d.ts.map +1 -1
  77. package/dist/stores/accounts/utils.js +58 -0
  78. package/dist/stores/accounts/utils.js.map +1 -1
  79. package/dist/stores/authors-comments/authors-comments-store.d.ts.map +1 -1
  80. package/dist/stores/authors-comments/authors-comments-store.js +39 -12
  81. package/dist/stores/authors-comments/authors-comments-store.js.map +1 -1
  82. package/dist/stores/comments/comments-store.d.ts +2 -0
  83. package/dist/stores/comments/comments-store.d.ts.map +1 -1
  84. package/dist/stores/comments/comments-store.js +170 -21
  85. package/dist/stores/comments/comments-store.js.map +1 -1
  86. package/dist/stores/communities/communities-store.d.ts.map +1 -1
  87. package/dist/stores/communities/communities-store.js +27 -7
  88. package/dist/stores/communities/communities-store.js.map +1 -1
  89. package/dist/stores/communities-pages/communities-pages-store.d.ts.map +1 -1
  90. package/dist/stores/communities-pages/communities-pages-store.js +131 -12
  91. package/dist/stores/communities-pages/communities-pages-store.js.map +1 -1
  92. package/dist/stores/feeds/feed-sorter.d.ts +5 -2
  93. package/dist/stores/feeds/feed-sorter.d.ts.map +1 -1
  94. package/dist/stores/feeds/feed-sorter.js +15 -4
  95. package/dist/stores/feeds/feed-sorter.js.map +1 -1
  96. package/dist/stores/feeds/feeds-store.d.ts +3 -0
  97. package/dist/stores/feeds/feeds-store.d.ts.map +1 -1
  98. package/dist/stores/feeds/feeds-store.js +36 -26
  99. package/dist/stores/feeds/feeds-store.js.map +1 -1
  100. package/dist/stores/feeds/utils.d.ts +16 -0
  101. package/dist/stores/feeds/utils.d.ts.map +1 -1
  102. package/dist/stores/feeds/utils.js +82 -26
  103. package/dist/stores/feeds/utils.js.map +1 -1
  104. package/dist/stores/replies/replies-store.d.ts.map +1 -1
  105. package/dist/stores/replies/replies-store.js +32 -6
  106. package/dist/stores/replies/replies-store.js.map +1 -1
  107. package/dist/stores/replies/utils.d.ts +3 -2
  108. package/dist/stores/replies/utils.d.ts.map +1 -1
  109. package/dist/stores/replies/utils.js +38 -5
  110. package/dist/stores/replies/utils.js.map +1 -1
  111. package/dist/stores/replies-pages/replies-pages-store.d.ts.map +1 -1
  112. package/dist/stores/replies-pages/replies-pages-store.js +68 -13
  113. package/dist/stores/replies-pages/replies-pages-store.js.map +1 -1
  114. package/dist/types.d.ts +11 -2
  115. package/dist/types.d.ts.map +1 -1
  116. package/dist/types.js.map +1 -1
  117. package/package.json +2 -2
package/dist/index.d.ts CHANGED
@@ -12,9 +12,9 @@ import { getEthWalletFromPkcPrivateKey, getEthPrivateKeyFromPkcPrivateKey, valid
12
12
  import { setPkcJs, restorePkcJs } from "./lib/pkc-js/index.js";
13
13
  import { deleteDatabases, deleteCaches } from "./lib/debug-utils.js";
14
14
  import { createCrosspost } from "./lib/crosspost.js";
15
- import { getAvailablePostSortTypes, getAvailableReplySortTypes, getPreloadedPostSortType, getPreloadedReplySortType, getPostPageSortType, getReplyPageSortType, getSortTimeframeSeconds, isFlatSortType, resolvePostSortType, resolveReplySortType } from "./lib/page-sorts.js";
15
+ import { getAvailablePostSortTypes, getAvailableReplySortTypes, getPreloadedPostSortType, getPreloadedReplySortType, getPreloadedPostSortTypes, getPreloadedReplySortTypes, getPostPageSortType, getReplyPageSortType, getSortTimeframeSeconds, isFlatSortType, resolvePostSortType, resolveReplySortType } from "./lib/page-sorts.js";
16
16
  export * from "./types.js";
17
- export { useAccount, useAccounts, useAccountComment, useAccountComments, useAccountVotes, useAccountVote, useAccountEdits, useAccountCommunities, useNotifications, usePubsubSubscribe, useComment, useComments, useCrosspost, useEditedComment, useValidateComment, validateComment, useReplies, useCommunity, useCommunities, useCommunityStats, useListCommunities, useResolvedCommunityAddress, useAuthor, useAuthorComments, useAuthorAvatar, useResolvedAuthorAddress, useAuthorAddress, setAuthorAvatarsWhitelistedTokenAddresses, resetAuthorAddressCacheForTesting, useFeed, useBufferedFeeds, useSubscribe, useBlock, useSaveComment, usePublishComment, usePublishVote, usePublishCommentEdit, usePublishCommentModeration, usePublishCommunityEdit, useCreateCommunity, useExportCommunity, createAccount, deleteAccount, deleteComment, setAccount, setActiveAccount, setAccountsOrder, importAccount, exportAccount, deleteCommunity, useClientsStates, useCommunitiesStates, usePkcRpcSettings, getEthWalletFromPkcPrivateKey, getEthPrivateKeyFromPkcPrivateKey, validateEthWallet, setPkcJs, restorePkcJs, deleteDatabases, deleteCaches, createCrosspost, getAvailablePostSortTypes, getAvailableReplySortTypes, getPreloadedPostSortType, getPreloadedReplySortType, getPostPageSortType, getReplyPageSortType, getSortTimeframeSeconds, isFlatSortType, resolvePostSortType, resolveReplySortType, };
17
+ export { useAccount, useAccounts, useAccountComment, useAccountComments, useAccountVotes, useAccountVote, useAccountEdits, useAccountCommunities, useNotifications, usePubsubSubscribe, useComment, useComments, useCrosspost, useEditedComment, useValidateComment, validateComment, useReplies, useCommunity, useCommunities, useCommunityStats, useListCommunities, useResolvedCommunityAddress, useAuthor, useAuthorComments, useAuthorAvatar, useResolvedAuthorAddress, useAuthorAddress, setAuthorAvatarsWhitelistedTokenAddresses, resetAuthorAddressCacheForTesting, useFeed, useBufferedFeeds, useSubscribe, useBlock, useSaveComment, usePublishComment, usePublishVote, usePublishCommentEdit, usePublishCommentModeration, usePublishCommunityEdit, useCreateCommunity, useExportCommunity, createAccount, deleteAccount, deleteComment, setAccount, setActiveAccount, setAccountsOrder, importAccount, exportAccount, deleteCommunity, useClientsStates, useCommunitiesStates, usePkcRpcSettings, getEthWalletFromPkcPrivateKey, getEthPrivateKeyFromPkcPrivateKey, validateEthWallet, setPkcJs, restorePkcJs, deleteDatabases, deleteCaches, createCrosspost, getAvailablePostSortTypes, getAvailableReplySortTypes, getPreloadedPostSortType, getPreloadedReplySortType, getPreloadedPostSortTypes, getPreloadedReplySortTypes, getPostPageSortType, getReplyPageSortType, getSortTimeframeSeconds, isFlatSortType, resolvePostSortType, resolveReplySortType, };
18
18
  declare const hooks: {
19
19
  useAccount: typeof useAccount;
20
20
  useAccounts: typeof useAccounts;
@@ -81,13 +81,15 @@ declare const hooks: {
81
81
  validateEthWallet: (wallet: import("./types.js").Wallet, authorAddress: string) => Promise<void>;
82
82
  setPkcJs: typeof setPkcJs;
83
83
  restorePkcJs: typeof restorePkcJs;
84
- deleteDatabases: () => Promise<[void, void, any, any, any]>;
85
- deleteCaches: () => Promise<[any, any, any]>;
84
+ deleteDatabases: () => Promise<void>;
85
+ deleteCaches: () => Promise<void>;
86
86
  createCrosspost: (comment: import("./types.js").Comment) => import("./types.js").Crosspost;
87
87
  getAvailablePostSortTypes: (community?: import("./types.js").Community) => string[];
88
88
  getAvailableReplySortTypes: (comment?: import("./types.js").Comment) => string[];
89
89
  getPreloadedPostSortType: (community?: import("./types.js").Community) => string | undefined;
90
90
  getPreloadedReplySortType: (comment?: import("./types.js").Comment) => string | undefined;
91
+ getPreloadedPostSortTypes: (community?: import("./types.js").Community) => string[];
92
+ getPreloadedReplySortTypes: (comment?: import("./types.js").Comment) => string[];
91
93
  getPostPageSortType: (community: import("./types.js").Community | undefined, requestedSortType?: string) => string | undefined;
92
94
  getReplyPageSortType: (comment: import("./types.js").Comment | undefined, requestedSortType?: string) => string | undefined;
93
95
  getSortTimeframeSeconds: (sortType?: string) => number | undefined;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,UAAU,EACV,WAAW,EACX,iBAAiB,EACjB,kBAAkB,EAClB,eAAe,EACf,cAAc,EACd,eAAe,EACf,gBAAgB,EAChB,gBAAgB,EAChB,qBAAqB,EACrB,kBAAkB,EACnB,MAAM,kBAAkB,CAAC;AAG1B,OAAO,EACL,UAAU,EACV,WAAW,EACX,YAAY,EACZ,kBAAkB,EAClB,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B,EACrB,MAAM,kBAAkB,CAAC;AAG1B,cAAc,SAAS,CAAC;AAGxB,OAAO,EAEL,UAAU,EACV,WAAW,EACX,iBAAiB,EACjB,kBAAkB,EAClB,eAAe,EACf,cAAc,EACd,eAAe,EACf,qBAAqB,EACrB,gBAAgB,EAChB,kBAAkB,EAElB,UAAU,EACV,WAAW,EACX,YAAY,EACZ,gBAAgB,EAChB,kBAAkB,EAClB,eAAe,EAEf,UAAU,EAEV,YAAY,EACZ,cAAc,EACd,iBAAiB,EACjB,kBAAkB,EAClB,2BAA2B,EAE3B,SAAS,EACT,iBAAiB,EACjB,eAAe,EACf,wBAAwB,EACxB,gBAAgB,EAChB,yCAAyC,EACzC,iCAAiC,EAEjC,OAAO,EACP,gBAAgB,EAEhB,YAAY,EACZ,QAAQ,EACR,cAAc,EACd,iBAAiB,EACjB,cAAc,EACd,qBAAqB,EACrB,2BAA2B,EAC3B,uBAAuB,EACvB,kBAAkB,EAClB,kBAAkB,EAElB,aAAa,EACb,aAAa,EACb,aAAa,EACb,UAAU,EACV,gBAAgB,EAChB,gBAAgB,EAChB,aAAa,EACb,aAAa,EACb,eAAe,EAEf,gBAAgB,EAChB,oBAAoB,EAEpB,iBAAiB,EAEjB,6BAA6B,EAC7B,iCAAiC,EACjC,iBAAiB,EAEjB,QAAQ,EACR,YAAY,EACZ,eAAe,EACf,YAAY,EACZ,eAAe,EACf,yBAAyB,EACzB,0BAA0B,EAC1B,wBAAwB,EACxB,yBAAyB,EACzB,mBAAmB,EACnB,oBAAoB,EACpB,uBAAuB,EACvB,cAAc,EACd,mBAAmB,EACnB,oBAAoB,GACrB,CAAC;AAGF,QAAA,MAAM,KAAK;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAoFV,CAAC;AAEF,eAAe,KAAK,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings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AAmB,EACnB,oBAAoB,EACpB,uBAAuB,EACvB,cAAc,EACd,mBAAmB,EACnB,oBAAoB,GACrB,CAAC;AAGF,QAAA,MAAM,KAAK;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAsFV,CAAC;AAEF,eAAe,KAAK,CAAC"}
package/dist/index.js CHANGED
@@ -26,7 +26,7 @@ import { getEthWalletFromPkcPrivateKey, getEthPrivateKeyFromPkcPrivateKey, valid
26
26
  import { setPkcJs, restorePkcJs } from "./lib/pkc-js/index.js";
27
27
  import { deleteDatabases, deleteCaches } from "./lib/debug-utils.js";
28
28
  import { createCrosspost } from "./lib/crosspost.js";
29
- import { getAvailablePostSortTypes, getAvailableReplySortTypes, getPreloadedPostSortType, getPreloadedReplySortType, getPostPageSortType, getReplyPageSortType, getSortTimeframeSeconds, isFlatSortType, resolvePostSortType, resolveReplySortType, } from "./lib/page-sorts.js";
29
+ import { getAvailablePostSortTypes, getAvailableReplySortTypes, getPreloadedPostSortType, getPreloadedReplySortType, getPreloadedPostSortTypes, getPreloadedReplySortTypes, getPostPageSortType, getReplyPageSortType, getSortTimeframeSeconds, isFlatSortType, resolvePostSortType, resolveReplySortType, } from "./lib/page-sorts.js";
30
30
  // types
31
31
  export * from "./types.js";
32
32
  // IMPORTANT: should be the same as 'export default hooks'
@@ -54,7 +54,7 @@ usePkcRpcSettings,
54
54
  // chain
55
55
  getEthWalletFromPkcPrivateKey, getEthPrivateKeyFromPkcPrivateKey, validateEthWallet,
56
56
  // utils
57
- setPkcJs, restorePkcJs, deleteDatabases, deleteCaches, createCrosspost, getAvailablePostSortTypes, getAvailableReplySortTypes, getPreloadedPostSortType, getPreloadedReplySortType, getPostPageSortType, getReplyPageSortType, getSortTimeframeSeconds, isFlatSortType, resolvePostSortType, resolveReplySortType, };
57
+ setPkcJs, restorePkcJs, deleteDatabases, deleteCaches, createCrosspost, getAvailablePostSortTypes, getAvailableReplySortTypes, getPreloadedPostSortType, getPreloadedReplySortType, getPreloadedPostSortTypes, getPreloadedReplySortTypes, getPostPageSortType, getReplyPageSortType, getSortTimeframeSeconds, isFlatSortType, resolvePostSortType, resolveReplySortType, };
58
58
  // IMPORTANT: should be the same as 'export {}'
59
59
  const hooks = {
60
60
  // accounts
@@ -134,6 +134,8 @@ const hooks = {
134
134
  getAvailableReplySortTypes,
135
135
  getPreloadedPostSortType,
136
136
  getPreloadedReplySortType,
137
+ getPreloadedPostSortTypes,
138
+ getPreloadedReplySortTypes,
137
139
  getPostPageSortType,
138
140
  getReplyPageSortType,
139
141
  getSortTimeframeSeconds,
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,gBAAgB,CAAC;AACtC,QAAQ,EAAE,CAAC;AAEX,WAAW;AACX,OAAO,EACL,UAAU,EACV,WAAW,EACX,iBAAiB,EACjB,kBAAkB,EAClB,eAAe,EACf,cAAc,EACd,eAAe,EACf,gBAAgB,EAChB,gBAAgB,EAChB,qBAAqB,EACrB,kBAAkB,GACnB,MAAM,kBAAkB,CAAC;AAE1B,WAAW;AACX,OAAO,EACL,UAAU,EACV,WAAW,EACX,YAAY,EACZ,kBAAkB,EAClB,eAAe,GAChB,MAAM,kBAAkB,CAAC;AAE1B,UAAU;AACV,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAE7C,cAAc;AACd,OAAO,EACL,YAAY,EACZ,cAAc,EACd,iBAAiB,EACjB,kBAAkB,EAClB,2BAA2B,GAC5B,MAAM,qBAAqB,CAAC;AAE7B,QAAQ;AACR,OAAO,EAAE,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAE1D,UAAU;AACV,OAAO,EACL,SAAS,EACT,iBAAiB,EACjB,eAAe,EACf,wBAAwB,EACxB,gBAAgB,EAChB,yCAAyC,EACzC,i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B,2BAA2B;IAC3B,UAAU;IACV,SAAS;IACT,iBAAiB;IACjB,eAAe;IACf,wBAAwB;IACxB,gBAAgB;IAChB,yCAAyC;IACzC,iCAAiC;IACjC,QAAQ;IACR,OAAO;IACP,gBAAgB;IAChB,UAAU;IACV,YAAY;IACZ,QAAQ;IACR,cAAc;IACd,iBAAiB;IACjB,cAAc;IACd,qBAAqB;IACrB,2BAA2B;IAC3B,uBAAuB;IACvB,kBAAkB;IAClB,kBAAkB;IAClB,8CAA8C;IAC9C,aAAa;IACb,aAAa;IACb,aAAa;IACb,UAAU;IACV,gBAAgB;IAChB,gBAAgB;IAChB,aAAa;IACb,aAAa;IACb,eAAe;IACf,SAAS;IACT,gBAAgB;IAChB,oBAAoB;IACpB,UAAU;IACV,iBAAiB;IACjB,QAAQ;IACR,6BAA6B;IAC7B,iCAAiC;IACjC,iBAAiB;IACjB,QAAQ;IACR,QAAQ;IACR,YAAY;IACZ,eAAe;IACf,YAAY;IACZ,eAAe;IACf,yBAAyB;IACzB,0BAA0B;IAC1B,wBAAwB;IACxB,yBAAyB;IACzB,mBAAmB;IACnB,oBAAoB;IACpB,uBAAuB;IACvB,cAAc;IACd,mBAAmB;IACnB,oBAAoB;CACrB,CAAC;AAEF,eAAe,KAAK,CAAC","sourcesContent":["import polyfill from \"./lib/polyfill\";\npolyfill();\n\n// accounts\nimport {\n useAccount,\n useAccounts,\n useAccountComment,\n useAccountComments,\n useAccountVotes,\n useAccountVote,\n useAccountEdits,\n useEditedComment,\n useNotifications,\n useAccountCommunities,\n usePubsubSubscribe,\n} from \"./hooks/accounts\";\n\n// comments\nimport {\n useComment,\n useComments,\n useCrosspost,\n useValidateComment,\n validateComment,\n} from \"./hooks/comments\";\n\n// replies\nimport { useReplies } from \"./hooks/replies\";\n\n// communities\nimport {\n useCommunity,\n useCommunities,\n useCommunityStats,\n useListCommunities,\n useResolvedCommunityAddress,\n} from \"./hooks/communities\";\n\n// feeds\nimport { useFeed, useBufferedFeeds } from \"./hooks/feeds\";\n\n// authors\nimport {\n useAuthor,\n useAuthorComments,\n useAuthorAvatar,\n useResolvedAuthorAddress,\n useAuthorAddress,\n setAuthorAvatarsWhitelistedTokenAddresses,\n resetAuthorAddressCacheForTesting,\n} from \"./hooks/authors\";\n\n// actions\nimport {\n useSubscribe,\n useBlock,\n useSaveComment,\n usePublishComment,\n usePublishVote,\n useCreateCommunity,\n usePublishCommentEdit,\n usePublishCommentModeration,\n usePublishCommunityEdit,\n useExportCommunity,\n} from \"./hooks/actions\";\n\n// actions that don't have their own hooks yet\nimport {\n createAccount,\n deleteAccount,\n deleteComment,\n setAccount,\n setActiveAccount,\n setAccountsOrder,\n importAccount,\n exportAccount,\n deleteCommunity,\n} from \"./stores/accounts/accounts-actions\";\n\n// states\nimport { useClientsStates, useCommunitiesStates } from \"./hooks/states\";\n\n// pkc-rpc\nimport { usePkcRpcSettings } from \"./hooks/pkc-rpc\";\n\n// chain\nimport {\n getEthWalletFromPkcPrivateKey,\n getEthPrivateKeyFromPkcPrivateKey,\n validateEthWallet,\n} from \"./lib/chain\";\n\n// utils\nimport { setPkcJs, restorePkcJs } from \"./lib/pkc-js\";\nimport { deleteDatabases, deleteCaches } from \"./lib/debug-utils\";\nimport { createCrosspost } from \"./lib/crosspost\";\nimport {\n getAvailablePostSortTypes,\n getAvailableReplySortTypes,\n getPreloadedPostSortType,\n getPreloadedReplySortType,\n getPostPageSortType,\n getReplyPageSortType,\n getSortTimeframeSeconds,\n isFlatSortType,\n resolvePostSortType,\n resolveReplySortType,\n} from \"./lib/page-sorts\";\n\n// types\nexport * from \"./types\";\n\n// IMPORTANT: should be the same as 'export default hooks'\nexport {\n // accounts\n useAccount,\n useAccounts,\n useAccountComment,\n useAccountComments,\n useAccountVotes,\n useAccountVote,\n useAccountEdits,\n useAccountCommunities,\n useNotifications,\n usePubsubSubscribe,\n // comments\n useComment,\n useComments,\n useCrosspost,\n useEditedComment,\n useValidateComment,\n validateComment,\n // replies\n useReplies,\n // communities\n useCommunity,\n useCommunities,\n useCommunityStats,\n useListCommunities,\n useResolvedCommunityAddress,\n // authors\n useAuthor,\n useAuthorComments,\n useAuthorAvatar,\n useResolvedAuthorAddress,\n useAuthorAddress,\n setAuthorAvatarsWhitelistedTokenAddresses,\n resetAuthorAddressCacheForTesting,\n // feeds\n useFeed,\n useBufferedFeeds,\n // actions\n useSubscribe,\n useBlock,\n useSaveComment,\n usePublishComment,\n usePublishVote,\n usePublishCommentEdit,\n usePublishCommentModeration,\n usePublishCommunityEdit,\n useCreateCommunity,\n useExportCommunity,\n // actions that don't have their own hooks yet\n createAccount,\n deleteAccount,\n deleteComment,\n setAccount,\n setActiveAccount,\n setAccountsOrder,\n importAccount,\n exportAccount,\n deleteCommunity,\n // states\n useClientsStates,\n useCommunitiesStates,\n // pkc-rpc\n usePkcRpcSettings,\n // chain\n getEthWalletFromPkcPrivateKey,\n getEthPrivateKeyFromPkcPrivateKey,\n validateEthWallet,\n // utils\n setPkcJs,\n restorePkcJs,\n deleteDatabases,\n deleteCaches,\n createCrosspost,\n getAvailablePostSortTypes,\n getAvailableReplySortTypes,\n getPreloadedPostSortType,\n getPreloadedReplySortType,\n getPostPageSortType,\n getReplyPageSortType,\n getSortTimeframeSeconds,\n isFlatSortType,\n resolvePostSortType,\n resolveReplySortType,\n};\n\n// IMPORTANT: should be the same as 'export {}'\nconst hooks = {\n // accounts\n useAccount,\n useAccounts,\n useAccountComment,\n useAccountComments,\n useAccountVotes,\n useAccountVote,\n useAccountEdits,\n useAccountCommunities,\n useNotifications,\n usePubsubSubscribe,\n // comments\n useComment,\n useComments,\n useCrosspost,\n useEditedComment,\n useValidateComment,\n validateComment,\n // replies\n useReplies,\n // communities\n useCommunity,\n useCommunities,\n useCommunityStats,\n useListCommunities,\n useResolvedCommunityAddress,\n // authors\n useAuthor,\n useAuthorComments,\n useAuthorAvatar,\n useResolvedAuthorAddress,\n useAuthorAddress,\n setAuthorAvatarsWhitelistedTokenAddresses,\n resetAuthorAddressCacheForTesting,\n // feeds\n useFeed,\n useBufferedFeeds,\n // actions\n useSubscribe,\n useBlock,\n useSaveComment,\n usePublishComment,\n usePublishVote,\n usePublishCommentEdit,\n usePublishCommentModeration,\n usePublishCommunityEdit,\n useCreateCommunity,\n useExportCommunity,\n // actions that don't have their own hooks yet\n createAccount,\n deleteAccount,\n deleteComment,\n setAccount,\n setActiveAccount,\n setAccountsOrder,\n importAccount,\n exportAccount,\n deleteCommunity,\n // states\n useClientsStates,\n useCommunitiesStates,\n // pkc-rpc\n usePkcRpcSettings,\n // chain\n getEthWalletFromPkcPrivateKey,\n getEthPrivateKeyFromPkcPrivateKey,\n validateEthWallet,\n // utils\n setPkcJs,\n restorePkcJs,\n deleteDatabases,\n deleteCaches,\n createCrosspost,\n getAvailablePostSortTypes,\n getAvailableReplySortTypes,\n getPreloadedPostSortType,\n getPreloadedReplySortType,\n getPostPageSortType,\n getReplyPageSortType,\n getSortTimeframeSeconds,\n isFlatSortType,\n resolvePostSortType,\n resolveReplySortType,\n};\n\nexport default hooks;\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,gBAAgB,CAAC;AACtC,QAAQ,EAAE,CAAC;AAEX,WAAW;AACX,OAAO,EACL,UAAU,EACV,WAAW,EACX,iBAAiB,EACjB,kBAAkB,EAClB,eAAe,EACf,cAAc,EACd,eAAe,EACf,gBAAgB,EAChB,gBAAgB,EAChB,qBAAqB,EACrB,kBAAkB,GACnB,MAAM,kBAAkB,CAAC;AAE1B,WAAW;AACX,OAAO,EACL,UAAU,EACV,WAAW,EACX,YAAY,EACZ,kBAAkB,EAClB,eAAe,GAChB,MAAM,kBAAkB,CAAC;AAE1B,UAAU;AACV,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAE7C,cAAc;AACd,OAAO,EACL,YAAY,EACZ,cAAc,EACd,iBAAiB,EACjB,kBAAkB,EAClB,2BAA2B,GAC5B,MAAM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ACjB,kBAAkB;IAClB,eAAe;IACf,cAAc;IACd,eAAe;IACf,qBAAqB;IACrB,gBAAgB;IAChB,kBAAkB;IAClB,WAAW;IACX,UAAU;IACV,WAAW;IACX,YAAY;IACZ,gBAAgB;IAChB,kBAAkB;IAClB,eAAe;IACf,UAAU;IACV,UAAU;IACV,cAAc;IACd,YAAY;IACZ,cAAc;IACd,iBAAiB;IACjB,kBAAkB;IAClB,2BAA2B;IAC3B,UAAU;IACV,SAAS;IACT,iBAAiB;IACjB,eAAe;IACf,wBAAwB;IACxB,gBAAgB;IAChB,yCAAyC;IACzC,iCAAiC;IACjC,QAAQ;IACR,OAAO;IACP,gBAAgB;IAChB,UAAU;IACV,YAAY;IACZ,QAAQ;IACR,cAAc;IACd,iBAAiB;IACjB,cAAc;IACd,qBAAqB;IACrB,2BAA2B;IAC3B,uBAAuB;IACvB,kBAAkB;IAClB,kBAAkB;IAClB,8CAA8C;IAC9C,aAAa;IACb,aAAa;IACb,aAAa;IACb,UAAU;IACV,gBAAgB;IAChB,gBAAgB;IAChB,aAAa;IACb,aAAa;IACb,eAAe;IACf,SAAS;IACT,gBAAgB;IAChB,oBAAoB;IACpB,UAAU;IACV,iBAAiB;IACjB,QAAQ;IACR,6BAA6B;IAC7B,iCAAiC;IACjC,iBAAiB;IACjB,QAAQ;IACR,QAAQ;IACR,YAAY;IACZ,eAAe;IACf,YAAY;IACZ,eAAe;IACf,yBAAyB;IACzB,0BAA0B;IAC1B,wBAAwB;IACxB,yBAAyB;IACzB,yBAAyB;IACzB,0BAA0B;IAC1B,mBAAmB;IACnB,oBAAoB;IACpB,uBAAuB;IACvB,cAAc;IACd,mBAAmB;IACnB,oBAAoB;CACrB,CAAC;AAEF,eAAe,KAAK,CAAC","sourcesContent":["import polyfill from \"./lib/polyfill\";\npolyfill();\n\n// accounts\nimport {\n useAccount,\n useAccounts,\n useAccountComment,\n useAccountComments,\n useAccountVotes,\n useAccountVote,\n useAccountEdits,\n useEditedComment,\n useNotifications,\n useAccountCommunities,\n usePubsubSubscribe,\n} from \"./hooks/accounts\";\n\n// comments\nimport {\n useComment,\n useComments,\n useCrosspost,\n useValidateComment,\n validateComment,\n} from \"./hooks/comments\";\n\n// replies\nimport { useReplies } from \"./hooks/replies\";\n\n// communities\nimport {\n useCommunity,\n useCommunities,\n useCommunityStats,\n useListCommunities,\n useResolvedCommunityAddress,\n} from \"./hooks/communities\";\n\n// feeds\nimport { useFeed, useBufferedFeeds } from \"./hooks/feeds\";\n\n// authors\nimport {\n useAuthor,\n useAuthorComments,\n useAuthorAvatar,\n useResolvedAuthorAddress,\n useAuthorAddress,\n setAuthorAvatarsWhitelistedTokenAddresses,\n resetAuthorAddressCacheForTesting,\n} from \"./hooks/authors\";\n\n// actions\nimport {\n useSubscribe,\n useBlock,\n useSaveComment,\n usePublishComment,\n usePublishVote,\n useCreateCommunity,\n usePublishCommentEdit,\n usePublishCommentModeration,\n usePublishCommunityEdit,\n useExportCommunity,\n} from \"./hooks/actions\";\n\n// actions that don't have their own hooks yet\nimport {\n createAccount,\n deleteAccount,\n deleteComment,\n setAccount,\n setActiveAccount,\n setAccountsOrder,\n importAccount,\n exportAccount,\n deleteCommunity,\n} from \"./stores/accounts/accounts-actions\";\n\n// states\nimport { useClientsStates, useCommunitiesStates } from \"./hooks/states\";\n\n// pkc-rpc\nimport { usePkcRpcSettings } from \"./hooks/pkc-rpc\";\n\n// chain\nimport {\n getEthWalletFromPkcPrivateKey,\n getEthPrivateKeyFromPkcPrivateKey,\n validateEthWallet,\n} from \"./lib/chain\";\n\n// utils\nimport { setPkcJs, restorePkcJs } from \"./lib/pkc-js\";\nimport { deleteDatabases, deleteCaches } from \"./lib/debug-utils\";\nimport { createCrosspost } from \"./lib/crosspost\";\nimport {\n getAvailablePostSortTypes,\n getAvailableReplySortTypes,\n getPreloadedPostSortType,\n getPreloadedReplySortType,\n getPreloadedPostSortTypes,\n getPreloadedReplySortTypes,\n getPostPageSortType,\n getReplyPageSortType,\n getSortTimeframeSeconds,\n isFlatSortType,\n resolvePostSortType,\n resolveReplySortType,\n} from \"./lib/page-sorts\";\n\n// types\nexport * from \"./types\";\n\n// IMPORTANT: should be the same as 'export default hooks'\nexport {\n // accounts\n useAccount,\n useAccounts,\n useAccountComment,\n useAccountComments,\n useAccountVotes,\n useAccountVote,\n useAccountEdits,\n useAccountCommunities,\n useNotifications,\n usePubsubSubscribe,\n // comments\n useComment,\n useComments,\n useCrosspost,\n useEditedComment,\n useValidateComment,\n validateComment,\n // replies\n useReplies,\n // communities\n useCommunity,\n useCommunities,\n useCommunityStats,\n useListCommunities,\n useResolvedCommunityAddress,\n // authors\n useAuthor,\n useAuthorComments,\n useAuthorAvatar,\n useResolvedAuthorAddress,\n useAuthorAddress,\n setAuthorAvatarsWhitelistedTokenAddresses,\n resetAuthorAddressCacheForTesting,\n // feeds\n useFeed,\n useBufferedFeeds,\n // actions\n useSubscribe,\n useBlock,\n useSaveComment,\n usePublishComment,\n usePublishVote,\n usePublishCommentEdit,\n usePublishCommentModeration,\n usePublishCommunityEdit,\n useCreateCommunity,\n useExportCommunity,\n // actions that don't have their own hooks yet\n createAccount,\n deleteAccount,\n deleteComment,\n setAccount,\n setActiveAccount,\n setAccountsOrder,\n importAccount,\n exportAccount,\n deleteCommunity,\n // states\n useClientsStates,\n useCommunitiesStates,\n // pkc-rpc\n usePkcRpcSettings,\n // chain\n getEthWalletFromPkcPrivateKey,\n getEthPrivateKeyFromPkcPrivateKey,\n validateEthWallet,\n // utils\n setPkcJs,\n restorePkcJs,\n deleteDatabases,\n deleteCaches,\n createCrosspost,\n getAvailablePostSortTypes,\n getAvailableReplySortTypes,\n getPreloadedPostSortType,\n getPreloadedReplySortType,\n getPreloadedPostSortTypes,\n getPreloadedReplySortTypes,\n getPostPageSortType,\n getReplyPageSortType,\n getSortTimeframeSeconds,\n isFlatSortType,\n resolvePostSortType,\n resolveReplySortType,\n};\n\n// IMPORTANT: should be the same as 'export {}'\nconst hooks = {\n // accounts\n useAccount,\n useAccounts,\n useAccountComment,\n useAccountComments,\n useAccountVotes,\n useAccountVote,\n useAccountEdits,\n useAccountCommunities,\n useNotifications,\n usePubsubSubscribe,\n // comments\n useComment,\n useComments,\n useCrosspost,\n useEditedComment,\n useValidateComment,\n validateComment,\n // replies\n useReplies,\n // communities\n useCommunity,\n useCommunities,\n useCommunityStats,\n useListCommunities,\n useResolvedCommunityAddress,\n // authors\n useAuthor,\n useAuthorComments,\n useAuthorAvatar,\n useResolvedAuthorAddress,\n useAuthorAddress,\n setAuthorAvatarsWhitelistedTokenAddresses,\n resetAuthorAddressCacheForTesting,\n // feeds\n useFeed,\n useBufferedFeeds,\n // actions\n useSubscribe,\n useBlock,\n useSaveComment,\n usePublishComment,\n usePublishVote,\n usePublishCommentEdit,\n usePublishCommentModeration,\n usePublishCommunityEdit,\n useCreateCommunity,\n useExportCommunity,\n // actions that don't have their own hooks yet\n createAccount,\n deleteAccount,\n deleteComment,\n setAccount,\n setActiveAccount,\n setAccountsOrder,\n importAccount,\n exportAccount,\n deleteCommunity,\n // states\n useClientsStates,\n useCommunitiesStates,\n // pkc-rpc\n usePkcRpcSettings,\n // chain\n getEthWalletFromPkcPrivateKey,\n getEthPrivateKeyFromPkcPrivateKey,\n validateEthWallet,\n // utils\n setPkcJs,\n restorePkcJs,\n deleteDatabases,\n deleteCaches,\n createCrosspost,\n getAvailablePostSortTypes,\n getAvailableReplySortTypes,\n getPreloadedPostSortType,\n getPreloadedReplySortType,\n getPreloadedPostSortTypes,\n getPreloadedReplySortTypes,\n getPostPageSortType,\n getReplyPageSortType,\n getSortTimeframeSeconds,\n isFlatSortType,\n resolvePostSortType,\n resolveReplySortType,\n};\n\nexport default hooks;\n"]}
@@ -1,8 +1,8 @@
1
- declare const deleteDatabases: () => Promise<[void, void, any, any, any]>;
2
- declare const deleteCaches: () => Promise<[any, any, any]>;
1
+ declare const deleteCaches: () => Promise<void>;
2
+ declare const deleteDatabases: () => Promise<void>;
3
3
  declare const debugUtils: {
4
- deleteDatabases: () => Promise<[void, void, any, any, any]>;
5
- deleteCaches: () => Promise<[any, any, any]>;
4
+ deleteDatabases: () => Promise<void>;
5
+ deleteCaches: () => Promise<void>;
6
6
  };
7
7
  export { deleteDatabases, deleteCaches };
8
8
  export default debugUtils;
@@ -1 +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"}
1
+ {"version":3,"file":"debug-utils.d.ts","sourceRoot":"","sources":["../../src/lib/debug-utils.ts"],"names":[],"mappings":"AAqCA,QAAA,MAAM,YAAY,QAAa,OAAO,CAAC,IAAI,CAE1C,CAAC;AAEF,QAAA,MAAM,eAAe,QAAa,OAAO,CAAC,IAAI,CAyB7C,CAAC;AAEF,QAAA,MAAM,UAAU;2BA3BkB,OAAO,CAAC,IAAI,CAAC;wBAJhB,OAAO,CAAC,IAAI,CAAC;CAkC3C,CAAC;AAEF,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,CAAC;AACzC,eAAe,UAAU,CAAC"}
@@ -1,17 +1,62 @@
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
+ };
1
10
  import localForage from "localforage";
2
11
  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(),
12
+ import accountsDatabase from "../stores/accounts/accounts-database.js";
13
+ const cacheDatabaseNames = [
14
+ "bitsocialReactHooks-communities",
15
+ "bitsocialReactHooks-comments",
16
+ "bitsocialReactHooks-communitiesPages",
17
+ "bitsocialReactHooks-repliesPages",
18
+ ];
19
+ // clear an account's databases, getDatabaseName gives each database's full name
20
+ const deleteAccountDatabases = (getDatabaseName) => Promise.all([
21
+ ...["accountComments", "accountVotes", "accountEdits"].map((databaseName) => localForage.createInstance({ name: getDatabaseName(databaseName) }).clear()),
22
+ localForageLru.clearInstance(getDatabaseName("accountCommentsReplies")),
14
23
  ]);
24
+ // the ids of the accounts listed in the metadata database or stored in the accounts database
25
+ const getAccountIds = (accountsStorage, accountsMetadataStorage) => __awaiter(void 0, void 0, void 0, function* () {
26
+ const [listedAccountIds, storedAccountIds] = yield Promise.all([
27
+ accountsMetadataStorage.getItem("accountIds"),
28
+ accountsStorage.keys(),
29
+ ]);
30
+ return [
31
+ ...new Set([
32
+ ...(Array.isArray(listedAccountIds) ? listedAccountIds : []),
33
+ ...storedAccountIds,
34
+ ]),
35
+ ];
36
+ });
37
+ const deleteCaches = () => __awaiter(void 0, void 0, void 0, function* () {
38
+ yield Promise.all(cacheDatabaseNames.map((name) => localForageLru.clearInstance(name)));
39
+ });
40
+ const deleteDatabases = () => __awaiter(void 0, void 0, void 0, function* () {
41
+ // the unprefixed databases of older versions: accountsDatabase.migrate() copies them back on the
42
+ // next load if they're left, because the prefixed accounts metadata is empty then
43
+ const legacyAccountsDatabase = localForage.createInstance({ name: "accounts" });
44
+ const legacyAccountsMetadataDatabase = localForage.createInstance({ name: "accountsMetadata" });
45
+ // read the account ids before deleting the accounts, they name the accounts' databases
46
+ const [accountIds, legacyAccountIds] = yield Promise.all([
47
+ getAccountIds(accountsDatabase.accountsDatabase, accountsDatabase.accountsMetadataDatabase),
48
+ getAccountIds(legacyAccountsDatabase, legacyAccountsMetadataDatabase),
49
+ ]);
50
+ yield Promise.all([
51
+ accountsDatabase.accountsMetadataDatabase.clear(),
52
+ accountsDatabase.accountsDatabase.clear(),
53
+ legacyAccountsMetadataDatabase.clear(),
54
+ legacyAccountsDatabase.clear(),
55
+ ...accountIds.map((accountId) => deleteAccountDatabases((databaseName) => accountsDatabase.getPerAccountDatabaseName(databaseName, accountId))),
56
+ ...legacyAccountIds.map((accountId) => deleteAccountDatabases((databaseName) => `${databaseName}-${accountId}`)),
57
+ deleteCaches(),
58
+ ]);
59
+ });
15
60
  const debugUtils = {
16
61
  deleteDatabases,
17
62
  deleteCaches,
@@ -1 +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"]}
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;AACpD,OAAO,gBAAgB,MAAM,sCAAsC,CAAC;AAEpE,MAAM,kBAAkB,GAAG;IACzB,iCAAiC;IACjC,8BAA8B;IAC9B,sCAAsC;IACtC,kCAAkC;CACnC,CAAC;AAEF,gFAAgF;AAChF,MAAM,sBAAsB,GAAG,CAAC,eAAiD,EAAE,EAAE,CACnF,OAAO,CAAC,GAAG,CAAC;IACV,GAAG,CAAC,iBAAiB,EAAE,cAAc,EAAE,cAAc,CAAC,CAAC,GAAG,CAAC,CAAC,YAAY,EAAE,EAAE,CAC1E,WAAW,CAAC,cAAc,CAAC,EAAE,IAAI,EAAE,eAAe,CAAC,YAAY,CAAC,EAAE,CAAC,CAAC,KAAK,EAAE,CAC5E;IACD,cAAc,CAAC,aAAa,CAAC,eAAe,CAAC,wBAAwB,CAAC,CAAC;CACxE,CAAC,CAAC;AAEL,6FAA6F;AAC7F,MAAM,aAAa,GAAG,CACpB,eAA4B,EAC5B,uBAAoC,EACpC,EAAE;IACF,MAAM,CAAC,gBAAgB,EAAE,gBAAgB,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;QAC7D,uBAAuB,CAAC,OAAO,CAAC,YAAY,CAAC;QAC7C,eAAe,CAAC,IAAI,EAAE;KACvB,CAAC,CAAC;IACH,OAAO;QACL,GAAG,IAAI,GAAG,CAAS;YACjB,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC,EAAE,CAAC;YAC5D,GAAG,gBAAgB;SACpB,CAAC;KACH,CAAC;AACJ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,CAAC,CACzE;QACD,YAAY,EAAE;KACf,CAAC,CAAC;AACL,CAAC,CAAA,CAAC;AAEF,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\";\nimport accountsDatabase from \"../stores/accounts/accounts-database\";\n\nconst cacheDatabaseNames = [\n \"bitsocialReactHooks-communities\",\n \"bitsocialReactHooks-comments\",\n \"bitsocialReactHooks-communitiesPages\",\n \"bitsocialReactHooks-repliesPages\",\n];\n\n// clear an account's databases, getDatabaseName gives each database's full name\nconst deleteAccountDatabases = (getDatabaseName: (databaseName: string) => string) =>\n Promise.all([\n ...[\"accountComments\", \"accountVotes\", \"accountEdits\"].map((databaseName) =>\n localForage.createInstance({ name: getDatabaseName(databaseName) }).clear(),\n ),\n localForageLru.clearInstance(getDatabaseName(\"accountCommentsReplies\")),\n ]);\n\n// the ids of the accounts listed in the metadata database or stored in the accounts database\nconst getAccountIds = async (\n accountsStorage: LocalForage,\n accountsMetadataStorage: LocalForage,\n) => {\n const [listedAccountIds, storedAccountIds] = await Promise.all([\n accountsMetadataStorage.getItem(\"accountIds\"),\n accountsStorage.keys(),\n ]);\n return [\n ...new Set<string>([\n ...(Array.isArray(listedAccountIds) ? listedAccountIds : []),\n ...storedAccountIds,\n ]),\n ];\n};\n\nconst deleteCaches = async (): Promise<void> => {\n await Promise.all(cacheDatabaseNames.map((name) => localForageLru.clearInstance(name)));\n};\n\nconst deleteDatabases = async (): Promise<void> => {\n // the unprefixed databases of older versions: accountsDatabase.migrate() copies them back on the\n // next load if they're left, because the prefixed accounts metadata is empty then\n const legacyAccountsDatabase = localForage.createInstance({ name: \"accounts\" });\n const legacyAccountsMetadataDatabase = localForage.createInstance({ name: \"accountsMetadata\" });\n // read the account ids before deleting the accounts, they name the accounts' databases\n const [accountIds, legacyAccountIds] = await Promise.all([\n getAccountIds(accountsDatabase.accountsDatabase, accountsDatabase.accountsMetadataDatabase),\n getAccountIds(legacyAccountsDatabase, legacyAccountsMetadataDatabase),\n ]);\n await Promise.all([\n accountsDatabase.accountsMetadataDatabase.clear(),\n accountsDatabase.accountsDatabase.clear(),\n legacyAccountsMetadataDatabase.clear(),\n legacyAccountsDatabase.clear(),\n ...accountIds.map((accountId) =>\n deleteAccountDatabases((databaseName) =>\n accountsDatabase.getPerAccountDatabaseName(databaseName, accountId),\n ),\n ),\n ...legacyAccountIds.map((accountId) =>\n deleteAccountDatabases((databaseName) => `${databaseName}-${accountId}`),\n ),\n deleteCaches(),\n ]);\n};\n\nconst debugUtils = {\n deleteDatabases,\n deleteCaches,\n};\n\nexport { deleteDatabases, deleteCaches };\nexport default debugUtils;\n"]}
@@ -1,6 +1,7 @@
1
1
  export declare const instances: any;
2
2
  declare const _default: {
3
3
  createInstance: (localForageLruOptions: any) => any;
4
+ clearInstance: (name: string) => Promise<void>;
4
5
  };
5
6
  export default _default;
6
7
  //# sourceMappingURL=localforage-lru.d.ts.map
@@ -1 +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"}
1
+ {"version":3,"file":"localforage-lru.d.ts","sourceRoot":"","sources":["../../../src/lib/localforage-lru/localforage-lru.ts"],"names":[],"mappings":"AAqLA,eAAO,MAAM,SAAS,EAAE,GAAQ,CAAC;;4CAEc,GAAG;0BAoBf,MAAM;;AAWzC,wBAAiD"}
@@ -8,32 +8,49 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  });
9
9
  };
10
10
  import localForage from "localforage";
11
+ // the database made active by the last rotation holds the highest generation under this key, so a
12
+ // reload finds the active database even after removeItem changed how many items each one holds
13
+ const activeGenerationKey = "__localForageLruActiveGeneration";
11
14
  function createLocalForageInstance(localForageLruOptions) {
12
15
  if (typeof (localForageLruOptions === null || localForageLruOptions === void 0 ? void 0 : localForageLruOptions.size) !== "number") {
13
16
  throw Error(`LocalForageLru.createInstance localForageLruOptions.size '${localForageLruOptions === null || localForageLruOptions === void 0 ? void 0 : localForageLruOptions.size}' not a number`);
14
17
  }
15
18
  const localForageOptions = Object.assign({}, localForageLruOptions);
16
19
  delete localForageOptions.size;
17
- let database1, database2, databaseSize, initialized = false;
20
+ let database1, database2, databaseSize, activeGeneration, initialized = false;
18
21
  const initializationPromize = new Promise((resolve) => __awaiter(this, void 0, void 0, function* () {
19
22
  const localForage1 = localForage.createInstance(Object.assign(Object.assign({}, localForageOptions), { name: localForageLruOptions.name }));
20
23
  const localForage2 = localForage.createInstance(Object.assign(Object.assign({}, localForageOptions), { name: localForageLruOptions.name + "2" }));
21
- const [localForage1Size, localForage2Size] = yield Promise.all([
24
+ const [localForage1Size, localForage2Size, localForage1Generation, localForage2Generation] = yield Promise.all([
22
25
  localForage1.length(),
23
26
  localForage2.length(),
27
+ localForage1.getItem(activeGenerationKey),
28
+ localForage2.getItem(activeGenerationKey),
24
29
  ]);
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) {
30
+ const generation1 = typeof localForage1Generation === "number" ? localForage1Generation : -1;
31
+ const generation2 = typeof localForage2Generation === "number" ? localForage2Generation : -1;
32
+ let localForage1IsActive;
33
+ if (generation1 !== -1 || generation2 !== -1) {
34
+ localForage1IsActive = generation1 > generation2;
35
+ }
36
+ else {
37
+ // databases that never rotated with the generation key:
38
+ // largest db is always active db, unless is max size, because max sized db is always inactive
39
+ localForage1IsActive =
40
+ (localForage1Size >= localForage2Size && localForage1Size !== localForageLruOptions.size) ||
41
+ localForage2Size === localForageLruOptions.size;
42
+ }
43
+ if (localForage1IsActive) {
28
44
  database2 = localForage2;
29
45
  database1 = localForage1;
30
- databaseSize = localForage1Size;
46
+ databaseSize = localForage1Size - (generation1 !== -1 ? 1 : 0);
31
47
  }
32
48
  else {
33
49
  database2 = localForage1;
34
50
  database1 = localForage2;
35
- databaseSize = localForage2Size;
51
+ databaseSize = localForage2Size - (generation2 !== -1 ? 1 : 0);
36
52
  }
53
+ activeGeneration = Math.max(generation1, generation2, 0);
37
54
  initialized = true;
38
55
  resolve(undefined);
39
56
  }));
@@ -96,7 +113,7 @@ function createLocalForageInstance(localForageLruOptions) {
96
113
  return __awaiter(this, void 0, void 0, function* () {
97
114
  yield initialization();
98
115
  const [keys1, keys2] = yield Promise.all([database1.keys(), database2.keys()]);
99
- return [...new Set([...keys1, ...keys2])];
116
+ return [...new Set([...keys1, ...keys2])].filter((key) => key !== activeGenerationKey);
100
117
  });
101
118
  },
102
119
  // useful to init a react state on load
@@ -104,7 +121,7 @@ function createLocalForageInstance(localForageLruOptions) {
104
121
  return __awaiter(this, void 0, void 0, function* () {
105
122
  yield initialization();
106
123
  const [keys1, keys2] = yield Promise.all([database1.keys(), database2.keys()]);
107
- const keys = [...new Set([...keys1, ...keys2])];
124
+ const keys = [...new Set([...keys1, ...keys2])].filter((key) => key !== activeGenerationKey);
108
125
  const entries = [];
109
126
  const getItem = (key) => __awaiter(this, void 0, void 0, function* () {
110
127
  const [value, value2] = yield Promise.all([database1.getItem(key), database2.getItem(key)]);
@@ -152,6 +169,15 @@ function createLocalForageInstance(localForageLruOptions) {
152
169
  database2 = database1Temp;
153
170
  database1 = database2Temp;
154
171
  yield database1.clear();
172
+ try {
173
+ yield database1.setItem(activeGenerationKey, ++activeGeneration);
174
+ }
175
+ catch (error) {
176
+ console.error("localforageLru updateDatabases setItem active generation error", {
177
+ error,
178
+ errorMessage: error === null || error === void 0 ? void 0 : error.message,
179
+ });
180
+ }
155
181
  }
156
182
  });
157
183
  }
@@ -178,5 +204,17 @@ const createInstance = (localForageLruOptions) => {
178
204
  instances[localForageLruOptions.name] = createLocalForageInstance(localForageLruOptions);
179
205
  return instances[localForageLruOptions.name];
180
206
  };
181
- export default { createInstance };
207
+ // clear an instance's databases, also when this session hasn't created the instance, e.g. the
208
+ // databases of an account that wasn't loaded
209
+ const clearInstance = (name) => __awaiter(void 0, void 0, void 0, function* () {
210
+ if (instances[name]) {
211
+ yield instances[name].clear();
212
+ return;
213
+ }
214
+ yield Promise.all([
215
+ localForage.createInstance({ name }).clear(),
216
+ localForage.createInstance({ name: name + "2" }).clear(),
217
+ ]);
218
+ });
219
+ export default { createInstance, clearInstance };
182
220
  //# sourceMappingURL=localforage-lru.js.map
@@ -1 +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,EAAE,qBAAqB,CAAC,IA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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"]}
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,kGAAkG;AAClG,+FAA+F;AAC/F,MAAM,mBAAmB,GAAG,kCAAkC,CAAC;AAE/D,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,CAA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AAC,qBAAqB,CAAC,IAAI,CAAC,CAAC;AAC/C,CAAC,CAAC;AAEF,8FAA8F;AAC9F,6CAA6C;AAC7C,MAAM,aAAa,GAAG,CAAO,IAAY,EAAE,EAAE;IAC3C,IAAI,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC;QACpB,MAAM,SAAS,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,CAAC;QAC9B,OAAO;IACT,CAAC;IACD,MAAM,OAAO,CAAC,GAAG,CAAC;QAChB,WAAW,CAAC,cAAc,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,KAAK,EAAE;QAC5C,WAAW,CAAC,cAAc,CAAC,EAAE,IAAI,EAAE,IAAI,GAAG,GAAG,EAAE,CAAC,CAAC,KAAK,EAAE;KACzD,CAAC,CAAC;AACL,CAAC,CAAA,CAAC;AAEF,eAAe,EAAE,cAAc,EAAE,aAAa,EAAE,CAAC","sourcesContent":["import localForage from \"localforage\";\n\n// the database made active by the last rotation holds the highest generation under this key, so a\n// reload finds the active database even after removeItem changed how many items each one holds\nconst activeGenerationKey = \"__localForageLruActiveGeneration\";\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 activeGeneration: 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, localForage1Generation, localForage2Generation] =\n await Promise.all([\n localForage1.length(),\n localForage2.length(),\n localForage1.getItem(activeGenerationKey),\n localForage2.getItem(activeGenerationKey),\n ]);\n const generation1 = typeof localForage1Generation === \"number\" ? localForage1Generation : -1;\n const generation2 = typeof localForage2Generation === \"number\" ? localForage2Generation : -1;\n let localForage1IsActive: boolean;\n if (generation1 !== -1 || generation2 !== -1) {\n localForage1IsActive = generation1 > generation2;\n } else {\n // databases that never rotated with the generation key:\n // largest db is always active db, unless is max size, because max sized db is always inactive\n localForage1IsActive =\n (localForage1Size >= localForage2Size && localForage1Size !== localForageLruOptions.size) ||\n localForage2Size === localForageLruOptions.size;\n }\n if (localForage1IsActive) {\n database2 = localForage2;\n database1 = localForage1;\n databaseSize = localForage1Size - (generation1 !== -1 ? 1 : 0);\n } else {\n database2 = localForage1;\n database1 = localForage2;\n databaseSize = localForage2Size - (generation2 !== -1 ? 1 : 0);\n }\n activeGeneration = Math.max(generation1, generation2, 0);\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])].filter((key) => key !== activeGenerationKey);\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])].filter((key) => key !== activeGenerationKey);\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 try {\n await database1.setItem(activeGenerationKey, ++activeGeneration);\n } catch (error: any) {\n console.error(\"localforageLru updateDatabases setItem active generation error\", {\n error,\n errorMessage: error?.message,\n });\n }\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\n// clear an instance's databases, also when this session hasn't created the instance, e.g. the\n// databases of an account that wasn't loaded\nconst clearInstance = async (name: string) => {\n if (instances[name]) {\n await instances[name].clear();\n return;\n }\n await Promise.all([\n localForage.createInstance({ name }).clear(),\n localForage.createInstance({ name: name + \"2\" }).clear(),\n ]);\n};\n\nexport default { createInstance, clearInstance };\n"]}
@@ -3,11 +3,17 @@ export declare const isFlatSortType: (sortType?: string) => boolean;
3
3
  export declare const getSortTimeframeSeconds: (sortType?: string) => number | undefined;
4
4
  export declare const getAvailablePostSortTypes: (community?: Community) => string[];
5
5
  export declare const getAvailableReplySortTypes: (comment?: Comment) => string[];
6
+ export declare const getPreloadedPostSortTypes: (community?: Community) => string[];
7
+ export declare const getPreloadedReplySortTypes: (comment?: Comment) => string[];
6
8
  export declare const getPreloadedPostSortType: (community?: Community) => string | undefined;
7
9
  export declare const getPreloadedReplySortType: (comment?: Comment) => string | undefined;
10
+ export declare const isPostSortTypeUnavailable: (community: Community | undefined, requestedSortType?: string) => boolean;
11
+ export declare const isReplySortTypeUnavailable: (comment: Comment | undefined, requestedSortType?: string) => boolean;
8
12
  export declare const resolvePostSortType: (community: Community | undefined, requestedSortType?: string) => string | undefined;
9
13
  export declare const resolveReplySortType: (comment: Comment | undefined, requestedSortType?: string) => string | undefined;
10
14
  export declare const isBuiltInPostSortType: (community: Community | undefined, sortType: string | undefined) => boolean;
11
15
  export declare const getPostPageSortType: (community: Community | undefined, requestedSortType?: string) => string | undefined;
12
16
  export declare const getReplyPageSortType: (comment: Comment | undefined, requestedSortType?: string) => string | undefined;
17
+ export declare const isPinnedFirstPostSortType: (community: Community | undefined, sortType?: string) => boolean;
18
+ export declare const isPinnedFirstReplySortType: (community: Community | undefined, comment: Comment | undefined, sortType?: string) => boolean;
13
19
  //# sourceMappingURL=page-sorts.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"page-sorts.d.ts","sourceRoot":"","sources":["../../src/lib/page-sorts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,SAAS,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F,eAAO,MAAM,yBAAyB,GACpC,WAAW,SAAS,GAAG,SAAS,EAChC,WAAW,MAAM,KAChB,OACgG,CAAC;AAEpG,eAAO,MAAM,0BAA0B,GACrC,WAAW,SAAS,GAAG,SAAS,EAChC,SAAS,OAAO,GAAG,SAAS,EAC5B,WAAW,MAAM,KAChB,OAMA,CAAC"}
@@ -1,6 +1,6 @@
1
1
  // Standard pkc-js sorts (pkc-js src/pages/util.ts) whose scoring the feed sorter reproduces. pkc-js
2
- // preloads a single sort and only publishes pageCids once that page overflows, so a record whose
3
- // comments all fit in the preloaded page can serve any of these by re-sorting that page client-side.
2
+ // only publishes pageCids once a preloaded page overflows, so a record whose comments all fit in
3
+ // its preloaded pages can serve any of these by re-sorting such a page client-side.
4
4
  const CLIENT_SORTABLE_POST_SORT_TYPES = [
5
5
  "hot",
6
6
  "new",
@@ -103,17 +103,33 @@ const getAvailablePageSortTypes = (record, clientSortableSortTypes) => {
103
103
  }
104
104
  return sortTypes;
105
105
  };
106
- const getPreloadedPageSortType = (record) => {
107
- const preloadedSortType = Object.keys((record === null || record === void 0 ? void 0 : record.pages) || {}).find(Boolean);
108
- return preloadedSortType || getPublishedPageSortTypes(record)[0];
109
- };
106
+ // the sorts whose first page the record embeds, in the record's key order. pkc-js publishes records
107
+ // with sorted keys, so that order is not guaranteed to be the one the community configured and the
108
+ // first sort is not necessarily its preference. A community may preload several sorts, or none: a
109
+ // record with empty `pages` has no preloaded sort, even when it publishes `pageCids`.
110
+ const getPreloadedPageSortTypes = (record) => Object.keys((record === null || record === void 0 ? void 0 : record.pages) || {}).filter(Boolean);
111
+ // whether the record publishes any comment: a page cid, or a preloaded page that holds comments or
112
+ // continues. A record with no comments can still carry empty preloaded pages (`comments: []`).
113
+ const hasPublishedComments = (record) => Object.keys((record === null || record === void 0 ? void 0 : record.pageCids) || {}).length > 0 ||
114
+ Object.values((record === null || record === void 0 ? void 0 : record.pages) || {}).some((page) => {
115
+ const { comments, nextCid } = page || {};
116
+ return Boolean(nextCid) || (Array.isArray(comments) && comments.length > 0);
117
+ });
118
+ // a requested sort the record does not serve, as opposed to a record that has not loaded or has no
119
+ // comments at all, where there is nothing a different sort would show
120
+ const isPageSortTypeUnavailable = (record, requestedSortType, clientSortableSortTypes) => requestedSortType !== undefined &&
121
+ hasPublishedComments(record) &&
122
+ !getAvailablePageSortTypes(record, clientSortableSortTypes).includes(requestedSortType);
110
123
  const resolvePageSortType = (record, requestedSortType, clientSortableSortTypes) => {
124
+ var _a;
111
125
  if (requestedSortType !== undefined) {
112
126
  return getAvailablePageSortTypes(record, clientSortableSortTypes).includes(requestedSortType)
113
127
  ? requestedSortType
114
128
  : undefined;
115
129
  }
116
- return getPreloadedPageSortType(record);
130
+ // no sort requested: use the first preloaded sort in the record's key order. A record that preloads
131
+ // nothing still has to load something, so it falls back to the first sort it publishes page cids for.
132
+ return (_a = getPreloadedPageSortTypes(record)[0]) !== null && _a !== void 0 ? _a : getPublishedPageSortTypes(record)[0];
117
133
  };
118
134
  // the page that serves a resolved sort: its published page, or the complete preloaded page the
119
135
  // client re-sorts (a flat sort prefers a complete flat page, else flattens a hierarchical one)
@@ -134,8 +150,13 @@ const getPageSortTypeToRead = (record, sortType) => {
134
150
  };
135
151
  export const getAvailablePostSortTypes = (community) => getAvailablePageSortTypes(community === null || community === void 0 ? void 0 : community.posts, CLIENT_SORTABLE_POST_SORT_TYPES);
136
152
  export const getAvailableReplySortTypes = (comment) => getAvailablePageSortTypes(comment === null || comment === void 0 ? void 0 : comment.replies, getClientSortableReplySortTypes(comment));
137
- export const getPreloadedPostSortType = (community) => getPreloadedPageSortType(community === null || community === void 0 ? void 0 : community.posts);
138
- export const getPreloadedReplySortType = (comment) => getPreloadedPageSortType(comment === null || comment === void 0 ? void 0 : comment.replies);
153
+ export const getPreloadedPostSortTypes = (community) => getPreloadedPageSortTypes(community === null || community === void 0 ? void 0 : community.posts);
154
+ export const getPreloadedReplySortTypes = (comment) => getPreloadedPageSortTypes(comment === null || comment === void 0 ? void 0 : comment.replies);
155
+ // the first preloaded sort in the record's key order, undefined when the record preloads none
156
+ export const getPreloadedPostSortType = (community) => getPreloadedPostSortTypes(community)[0];
157
+ export const getPreloadedReplySortType = (comment) => getPreloadedReplySortTypes(comment)[0];
158
+ export const isPostSortTypeUnavailable = (community, requestedSortType) => isPageSortTypeUnavailable(community === null || community === void 0 ? void 0 : community.posts, requestedSortType, CLIENT_SORTABLE_POST_SORT_TYPES);
159
+ export const isReplySortTypeUnavailable = (comment, requestedSortType) => isPageSortTypeUnavailable(comment === null || comment === void 0 ? void 0 : comment.replies, requestedSortType, getClientSortableReplySortTypes(comment));
139
160
  export const resolvePostSortType = (community, requestedSortType) => resolvePageSortType(community === null || community === void 0 ? void 0 : community.posts, requestedSortType, CLIENT_SORTABLE_POST_SORT_TYPES);
140
161
  export const resolveReplySortType = (comment, requestedSortType) => resolvePageSortType(comment === null || comment === void 0 ? void 0 : comment.replies, requestedSortType, getClientSortableReplySortTypes(comment));
141
162
  // the options pkc-js applies to every sort; any other published option belongs to the sort file itself
@@ -164,4 +185,19 @@ export const isBuiltInPostSortType = (community, sortType) => {
164
185
  // single-page community serves `active` client-side; undefined when the sort cannot be served
165
186
  export const getPostPageSortType = (community, requestedSortType) => getPageSortTypeToRead(community === null || community === void 0 ? void 0 : community.posts, resolvePostSortType(community, requestedSortType));
166
187
  export const getReplyPageSortType = (comment, requestedSortType) => getPageSortTypeToRead(comment === null || comment === void 0 ? void 0 : comment.replies, resolveReplySortType(comment, requestedSortType));
188
+ // whether a sort puts pinned comments first. A community configured with `settings.pages` publishes
189
+ // every sort's reserved options in `community.pageSorts`, so `pinnedFirst: "false"` (pinned comments
190
+ // ranked and filtered like any other) is readable from the record; pkc-js defaults it to "true", which
191
+ // is also what an unconfigured community, publishing no `pageSorts`, has always done. A sort the
192
+ // client computes from another sort's complete page follows that page's placement when the community
193
+ // published nothing about the requested sort.
194
+ const isPinnedFirstPageSortType = (community, scope, sortType, pageSortType) => {
195
+ var _a, _b, _c;
196
+ const publishedPageSorts = (_a = community === null || community === void 0 ? void 0 : community.pageSorts) === null || _a === void 0 ? void 0 : _a[scope];
197
+ const publishedPageSort = (_b = (sortType !== undefined ? publishedPageSorts === null || publishedPageSorts === void 0 ? void 0 : publishedPageSorts[sortType] : undefined)) !== null && _b !== void 0 ? _b : (pageSortType !== undefined ? publishedPageSorts === null || publishedPageSorts === void 0 ? void 0 : publishedPageSorts[pageSortType] : undefined);
198
+ const pinnedFirst = (_c = publishedPageSort === null || publishedPageSort === void 0 ? void 0 : publishedPageSort.publicOptions) === null || _c === void 0 ? void 0 : _c.pinnedFirst;
199
+ return !(typeof pinnedFirst === "string" && pinnedFirst.trim().toLowerCase() === "false");
200
+ };
201
+ export const isPinnedFirstPostSortType = (community, sortType) => isPinnedFirstPageSortType(community, "posts", sortType, getPostPageSortType(community, sortType));
202
+ export const isPinnedFirstReplySortType = (community, comment, sortType) => isPinnedFirstPageSortType(community, "replies", sortType, getReplyPageSortType(comment, sortType));
167
203
  //# sourceMappingURL=page-sorts.js.map