@bitsocial/bitsocial-react-hooks 0.1.52 → 0.1.54

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 (96) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/README.md +52 -1507
  3. package/dist/hooks/accounts/accounts.js +2 -2
  4. package/dist/hooks/accounts/accounts.js.map +1 -1
  5. package/dist/hooks/accounts/utils.d.ts.map +1 -1
  6. package/dist/hooks/accounts/utils.js +3 -12
  7. package/dist/hooks/accounts/utils.js.map +1 -1
  8. package/dist/hooks/actions/actions.js +1 -1
  9. package/dist/hooks/actions/actions.js.map +1 -1
  10. package/dist/hooks/authors/author-avatars.js +1 -1
  11. package/dist/hooks/authors/author-avatars.js.map +1 -1
  12. package/dist/hooks/authors/authors.js +1 -1
  13. package/dist/hooks/authors/authors.js.map +1 -1
  14. package/dist/hooks/authors/utils.js.map +1 -1
  15. package/dist/hooks/comments.js +1 -1
  16. package/dist/hooks/comments.js.map +1 -1
  17. package/dist/hooks/communities.js +1 -1
  18. package/dist/hooks/communities.js.map +1 -1
  19. package/dist/hooks/feeds/feeds.d.ts.map +1 -1
  20. package/dist/hooks/feeds/feeds.js +9 -1
  21. package/dist/hooks/feeds/feeds.js.map +1 -1
  22. package/dist/hooks/pkc-rpc.js +1 -1
  23. package/dist/hooks/pkc-rpc.js.map +1 -1
  24. package/dist/hooks/replies.js +1 -1
  25. package/dist/hooks/replies.js.map +1 -1
  26. package/dist/hooks/states.js +1 -1
  27. package/dist/hooks/states.js.map +1 -1
  28. package/dist/lib/assert.d.ts +6 -0
  29. package/dist/lib/assert.d.ts.map +1 -0
  30. package/dist/lib/assert.js +17 -0
  31. package/dist/lib/assert.js.map +1 -0
  32. package/dist/lib/chain/chain.js +1 -1
  33. package/dist/lib/chain/chain.js.map +1 -1
  34. package/dist/lib/community-ref.js +1 -1
  35. package/dist/lib/community-ref.js.map +1 -1
  36. package/dist/lib/crosspost.js +1 -1
  37. package/dist/lib/crosspost.js.map +1 -1
  38. package/dist/lib/is-equal.d.ts +6 -0
  39. package/dist/lib/is-equal.d.ts.map +1 -0
  40. package/dist/lib/is-equal.js +100 -0
  41. package/dist/lib/is-equal.js.map +1 -0
  42. package/dist/lib/memoize.d.ts +9 -0
  43. package/dist/lib/memoize.d.ts.map +1 -0
  44. package/dist/lib/memoize.js +24 -0
  45. package/dist/lib/memoize.js.map +1 -0
  46. package/dist/lib/pkc-compat.js +1 -1
  47. package/dist/lib/pkc-compat.js.map +1 -1
  48. package/dist/lib/pkc-js/index.d.ts.map +1 -1
  49. package/dist/lib/pkc-js/index.js +23 -12
  50. package/dist/lib/pkc-js/index.js.map +1 -1
  51. package/dist/lib/pkc-js/pkc-js-mock-content.js +1 -1
  52. package/dist/lib/pkc-js/pkc-js-mock-content.js.map +1 -1
  53. package/dist/lib/protocol-compat.js +1 -1
  54. package/dist/lib/protocol-compat.js.map +1 -1
  55. package/dist/lib/utils/utils.js +1 -1
  56. package/dist/lib/utils/utils.js.map +1 -1
  57. package/dist/lib/validator.js +1 -1
  58. package/dist/lib/validator.js.map +1 -1
  59. package/dist/stores/accounts/accounts-actions-internal.js +2 -2
  60. package/dist/stores/accounts/accounts-actions-internal.js.map +1 -1
  61. package/dist/stores/accounts/accounts-actions.js +2 -2
  62. package/dist/stores/accounts/accounts-actions.js.map +1 -1
  63. package/dist/stores/accounts/accounts-database.js +2 -2
  64. package/dist/stores/accounts/accounts-database.js.map +1 -1
  65. package/dist/stores/accounts/accounts-store.js +1 -1
  66. package/dist/stores/accounts/accounts-store.js.map +1 -1
  67. package/dist/stores/accounts/utils.js +1 -1
  68. package/dist/stores/accounts/utils.js.map +1 -1
  69. package/dist/stores/authors-comments/authors-comments-store.js +1 -1
  70. package/dist/stores/authors-comments/authors-comments-store.js.map +1 -1
  71. package/dist/stores/authors-comments/utils.js.map +1 -1
  72. package/dist/stores/communities/communities-store.js +1 -1
  73. package/dist/stores/communities/communities-store.js.map +1 -1
  74. package/dist/stores/communities-pages/communities-pages-store.js +1 -1
  75. package/dist/stores/communities-pages/communities-pages-store.js.map +1 -1
  76. package/dist/stores/feeds/feed-sorter.d.ts +4 -0
  77. package/dist/stores/feeds/feed-sorter.d.ts.map +1 -1
  78. package/dist/stores/feeds/feed-sorter.js +35 -1
  79. package/dist/stores/feeds/feed-sorter.js.map +1 -1
  80. package/dist/stores/feeds/feeds-store.d.ts +3 -0
  81. package/dist/stores/feeds/feeds-store.d.ts.map +1 -1
  82. package/dist/stores/feeds/feeds-store.js +27 -4
  83. package/dist/stores/feeds/feeds-store.js.map +1 -1
  84. package/dist/stores/feeds/utils.d.ts +9 -0
  85. package/dist/stores/feeds/utils.d.ts.map +1 -1
  86. package/dist/stores/feeds/utils.js +81 -66
  87. package/dist/stores/feeds/utils.js.map +1 -1
  88. package/dist/stores/replies/replies-store.js +1 -1
  89. package/dist/stores/replies/replies-store.js.map +1 -1
  90. package/dist/stores/replies/utils.js.map +1 -1
  91. package/dist/stores/replies-pages/replies-pages-store.js +1 -1
  92. package/dist/stores/replies-pages/replies-pages-store.js.map +1 -1
  93. package/dist/types.d.ts +1 -0
  94. package/dist/types.d.ts.map +1 -1
  95. package/dist/types.js.map +1 -1
  96. package/package.json +1 -6
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/lib/utils/utils.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,QAAQ,MAAM,WAAW,CAAC;AACjC,OAAO,MAAM,MAAM,yBAAyB,CAAC;AAG7C,OAAO,EAAE,+BAA+B,EAAE,MAAM,sBAAsB,CAAC;AACvE,OAAO,EAAE,0BAA0B,EAAE,mCAAmC,EAAE,MAAM,eAAe,CAAC;AAChG,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAClD,MAAM,GAAG,GAAG,MAAM,CAAC,6BAA6B,CAAC,CAAC;AAElD,MAAM,KAAK,GAAG,CA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GAAG,CAAC,CAAC;YACjB,IAAI,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,uBAAuB,GAAG,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC;YACtF,OAAO,GAAG,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,KAAK,CAAC,uBAAuB,CAAC,CAAC;YAC3D,MAAM,KAAK,CAAC,OAAO,CAAC,CAAC;QACvB,CAAC;IACH,CAAC;AACH,CAAC,CAAA,CAAC;AACF,KAAK,CAAC,aAAa,GAAG,aAAa,CAAC;AAEpC,eAAe,KAAK,CAAC","sourcesContent":["import assert from \"assert\";\nimport QuickLru from \"quick-lru\";\nimport Logger from \"@pkcprotocol/pkc-logger\";\nimport PkcJs from \"../pkc-js\";\nimport { Comment } from \"../../types\";\nimport { areEquivalentCommunityAddresses } from \"../community-address\";\nimport { getCommentCommunityAddress, normalizePublicationOptionsForStore } from \"../pkc-compat\";\nimport { getPageRpcClients } from \"../pkc-compat\";\nconst log = Logger(\"bitsocial-react-hooks:utils\");\n\nconst merge = (...args: any) => {\n // @ts-ignore\n const clonedArgs = args.map((arg) => {\n assert(arg && typeof arg === \"object\", `utils.merge argument '${arg}' not an object`);\n return clone(arg);\n });\n const mergedObj: any = {};\n while (clonedArgs.length) {\n const currentArg = clonedArgs.shift();\n for (const i in currentArg) {\n if (currentArg[i] === undefined || currentArg[i] === null) {\n continue;\n }\n mergedObj[i] = currentArg[i];\n }\n }\n return mergedObj;\n};\n\nconst clone = (obj: any) => {\n assert(obj && typeof obj === \"object\", `utils.clone argument '${obj}' not an object`);\n let clonedObj: any = {};\n\n // clean the object to be cloned\n for (const i in obj) {\n // remove functions\n if (typeof obj[i] === \"function\") {\n continue;\n }\n // remove internal props\n if (i.startsWith(\"_\")) {\n continue;\n }\n if (obj[i] === undefined || obj[i] === null) {\n continue;\n }\n // pkc-js has a bug where pkc instances have circular deps\n if (obj[i]?.constructor?.name === \"PKC\") {\n continue;\n }\n clonedObj[i] = obj[i];\n }\n\n // clone the object\n clonedObj = JSON.parse(JSON.stringify(clonedObj));\n return clonedObj;\n};\n\n// this function should not clone the comments to not waste memory\nexport const flattenCommentsPages = (pageInstanceOrPagesInstance: any) => {\n const flattenedComments = [];\n\n // if is a Page instance\n if (pageInstanceOrPagesInstance?.comments) {\n for (const comment of pageInstanceOrPagesInstance.comments) {\n flattenedComments.push(comment);\n if (comment.replies?.pages && Object.keys(comment.replies.pages).length) {\n flattenedComments.push(...flattenCommentsPages(comment.replies));\n }\n }\n }\n\n // if is a Pages instance\n else if (pageInstanceOrPagesInstance?.pages) {\n for (const sortType in pageInstanceOrPagesInstance.pages) {\n flattenedComments.push(...flattenCommentsPages(pageInstanceOrPagesInstance.pages[sortType]));\n }\n }\n\n // if is a Pages.pages instance\n else {\n for (const sortType in pageInstanceOrPagesInstance) {\n const page = pageInstanceOrPagesInstance[sortType];\n if (page?.comments?.length) {\n flattenedComments.push(...flattenCommentsPages(page));\n }\n }\n }\n\n // remove duplicate comments\n const flattenedCommentsObject = {};\n for (const comment of flattenedComments) {\n // @ts-ignore\n flattenedCommentsObject[comment.cid] = comment;\n }\n const uniqueFlattened = [];\n for (const cid in flattenedCommentsObject) {\n // @ts-ignore\n uniqueFlattened.push(flattenedCommentsObject[cid]);\n }\n\n return uniqueFlattened;\n};\n\nconst memo = (functionToMemo: Function, memoOptions: any) => {\n assert(typeof functionToMemo === \"function\", `memo first argument must be a function`);\n const pendingPromises: any = new Map();\n const cache = new QuickLru(memoOptions);\n\n // preserve function name\n const memoedFunctionName = functionToMemo.name || \"memoedFunction\";\n const obj = {\n [memoedFunctionName]: async (...args: any) => {\n let cacheKey = args[0];\n if (args.length > 1) {\n cacheKey = \"\";\n for (const arg of args) {\n if (\n typeof arg !== \"string\" &&\n typeof arg !== \"number\" &&\n arg !== undefined &&\n arg !== null\n ) {\n const argumentIndex = args.indexOf(arg);\n throw Error(\n `memoed function '${memoedFunctionName}' invalid argument number '${argumentIndex}' '${arg}', memoed function can only use multiple arguments if they are all of type string, number, undefined or null`,\n );\n }\n cacheKey += arg;\n }\n }\n\n // has cached result\n const cached = cache.get(cacheKey);\n if (cached) {\n return cached;\n }\n\n // don't request the same thing twice if fetching is pending\n let pendingPromise = pendingPromises.get(cacheKey);\n if (pendingPromise) {\n return pendingPromise;\n }\n\n // create the pending promise\n let resolve: any, reject: any;\n pendingPromise = new Promise((_resolve, _reject) => {\n resolve = _resolve;\n reject = _reject;\n });\n pendingPromises.set(cacheKey, pendingPromise);\n\n // execute the function\n try {\n const result = await functionToMemo(...args);\n cache.set(cacheKey, result);\n pendingPromises.delete(cacheKey);\n resolve?.(result);\n } catch (error) {\n pendingPromises.delete(cacheKey);\n reject?.(error);\n }\n\n return pendingPromise;\n },\n };\n return obj[memoedFunctionName];\n};\n\nconst memoSync = (functionToMemo: Function, memoOptions: any) => {\n assert(typeof functionToMemo === \"function\", `memo first argument must be a function`);\n const cache = new QuickLru(memoOptions);\n\n // preserve function name\n const memoedFunctionName = functionToMemo.name || \"memoedFunction\";\n const obj = {\n [memoedFunctionName]: (...args: any) => {\n let cacheKey = args[0];\n if (args.length > 1) {\n cacheKey = \"\";\n for (const arg of args) {\n if (\n typeof arg !== \"string\" &&\n typeof arg !== \"number\" &&\n arg !== undefined &&\n arg !== null\n ) {\n const argumentIndex = args.indexOf(arg);\n throw Error(\n `memoed function '${memoedFunctionName}' invalid argument number '${argumentIndex}' '${arg}', memoed function can only use multiple arguments if they are all of type string, number, undefined or null`,\n );\n }\n cacheKey += arg;\n }\n }\n\n // has cached result\n const cached = cache.get(cacheKey);\n if (cached) {\n return cached;\n }\n\n // execute the function\n const result = functionToMemo(...args);\n if (typeof result?.then === \"function\") {\n throw Error(\n `memoed function '${memoedFunctionName}' is an async function, cannot be used with memoSync, use memo instead`,\n );\n }\n cache.set(cacheKey, result);\n return result;\n },\n };\n return obj[memoedFunctionName];\n};\n\nconst clientsOnStateChange = (clients: any, onStateChange: Function) => {\n for (const clientUrl in clients?.ipfsGateways) {\n clients?.ipfsGateways?.[clientUrl].on(\"statechange\", (state: string) =>\n onStateChange(state, \"ipfsGateways\", clientUrl),\n );\n }\n for (const clientUrl in clients?.kuboRpcClients) {\n clients?.kuboRpcClients?.[clientUrl].on(\"statechange\", (state: string) =>\n onStateChange(state, \"kuboRpcClients\", clientUrl),\n );\n }\n for (const clientUrl in clients?.pubsubKuboRpcClients) {\n clients?.pubsubKuboRpcClients?.[clientUrl].on(\"statechange\", (state: string) =>\n onStateChange(state, \"pubsubKuboRpcClients\", clientUrl),\n );\n }\n const rpcClients = getPageRpcClients(clients);\n for (const clientUrl in rpcClients) {\n rpcClients?.[clientUrl].on(\"statechange\", (state: string) =>\n onStateChange(state, \"pkcRpcClients\", clientUrl),\n );\n }\n for (const clientUrl in clients?.libp2pJsClients) {\n clients?.libp2pJsClients?.[clientUrl].on(\"statechange\", (state: string) =>\n onStateChange(state, \"libp2pJsClients\", clientUrl),\n );\n }\n for (const chainTicker in clients?.chainProviders) {\n for (const clientUrl in clients?.chainProviders?.[chainTicker]) {\n clients?.chainProviders?.[chainTicker]?.[clientUrl].on(\"statechange\", (state: string) =>\n onStateChange(state, \"chainProviders\", clientUrl, chainTicker),\n );\n }\n }\n for (const resolverKey in clients?.nameResolvers) {\n clients?.nameResolvers?.[resolverKey].on(\"statechange\", (state: string) =>\n onStateChange(state, \"nameResolvers\", resolverKey),\n );\n }\n};\n\nconst pageClientsOnStateChange = (clients: any, onStateChange: Function) => {\n for (const sortType in clients?.ipfsGateways) {\n for (const clientUrl in clients?.ipfsGateways?.[sortType]) {\n clients?.ipfsGateways?.[sortType]?.[clientUrl].on(\"statechange\", (state: string) =>\n onStateChange(state, \"ipfsGateways\", sortType, clientUrl),\n );\n }\n }\n for (const sortType in clients?.kuboRpcClients) {\n for (const clientUrl in clients?.kuboRpcClients?.[sortType]) {\n clients?.kuboRpcClients?.[sortType]?.[clientUrl].on(\"statechange\", (state: string) =>\n onStateChange(state, \"kuboRpcClients\", sortType, clientUrl),\n );\n }\n }\n const rpcPageClients = getPageRpcClients(clients);\n for (const sortType in rpcPageClients) {\n for (const clientUrl in rpcPageClients?.[sortType]) {\n rpcPageClients?.[sortType]?.[clientUrl].on(\"statechange\", (state: string) =>\n onStateChange(state, \"pkcRpcClients\", sortType, clientUrl),\n );\n }\n }\n for (const sortType in clients?.libp2pJsClients) {\n for (const clientUrl in clients?.libp2pJsClients?.[sortType]) {\n clients?.libp2pJsClients?.[sortType]?.[clientUrl].on(\"statechange\", (state: string) =>\n onStateChange(state, \"libp2pJsClients\", sortType, clientUrl),\n );\n }\n }\n};\n\nexport const communityPostsCacheExpired = (community: any) => {\n // NOTE: fetchedAt is undefined on owner communities\n if (!community || community.fetchedAt == null) {\n return false;\n }\n // if community cache is older than 1 hour, its community.posts are considered expired\n const oneHourAgo = Date.now() / 1000 - 60 * 60;\n return oneHourAgo > community.fetchedAt;\n};\n\nexport const removeInvalidComments = async (\n comments: Comment[],\n { validateReplies, blockCommunity }: any,\n pkc: any,\n) => {\n if (!comments.length) {\n return [];\n }\n const isValid = await Promise.all(\n comments.map((comment) => commentIsValid(comment, { validateReplies, blockCommunity }, pkc)),\n );\n const validComments = comments.filter((_, i) => isValid[i]);\n return validComments;\n};\n\nconst communitiesWithInvalidComments: { [communityAddress: string]: boolean } = {};\nexport const commentIsValid = async (\n comment: Comment,\n { validateReplies, blockCommunity }: any = {},\n pkc: any,\n) => {\n validateReplies = Boolean(validateReplies);\n if (blockCommunity === undefined || blockCommunity === null) {\n blockCommunity = true;\n }\n if (!comment) {\n return false;\n }\n if (communitiesWithInvalidComments[comment.communityAddress]) {\n console.log(\n `community '${comment.communityAddress}' had an invalid comment, invalidate all its future comments to avoid wasting resources`,\n );\n return false;\n }\n try {\n await pkc.validateComment(comment, { validateReplies });\n } catch (e) {\n if (blockCommunity) {\n communitiesWithInvalidComments[comment.communityAddress] = true;\n }\n console.log(\"invalid comment\", { comment, error: e });\n return false;\n }\n return true;\n};\n\nconst repliesAreValid = async (\n comment: Comment,\n { validateReplies, blockCommunity }: any = {},\n pkc: any,\n) => {\n validateReplies = Boolean(validateReplies);\n if (blockCommunity === undefined || blockCommunity === null) {\n blockCommunity = true;\n }\n if (!comment) {\n return false;\n }\n const commentCommunityAddress = getCommentCommunityAddress(comment);\n if (commentCommunityAddress && communitiesWithInvalidComments[commentCommunityAddress]) {\n console.log(\n `community '${commentCommunityAddress}' had an invalid comment, invalidate all its future comments to avoid wasting resources`,\n );\n return false;\n }\n const replyPageArray: any[] = Object.values(comment.replies?.pages || {});\n const replies = replyPageArray.flatMap((replyPage: any) => replyPage?.comments || []);\n const normalizedReplies = replies.map((reply) => {\n const normalizedReply = normalizePublicationOptionsForStore(reply) as Comment;\n normalizedReply.communityAddress =\n getCommentCommunityAddress(normalizedReply) || commentCommunityAddress;\n return normalizedReply;\n });\n\n // manual validation\n for (const reply of normalizedReplies) {\n if (\n !areEquivalentCommunityAddresses(\n getCommentCommunityAddress(reply),\n commentCommunityAddress,\n ) ||\n reply.depth !== comment.depth + 1 ||\n reply.parentCid !== comment.cid\n ) {\n if (blockCommunity && commentCommunityAddress) {\n communitiesWithInvalidComments[commentCommunityAddress] = true;\n }\n console.log(\"invalid comment\", {\n comment: reply,\n error:\n \"!areEquivalentCommunityAddresses(reply.communityAddress, comment.communityAddress) || reply.depth !== comment.depth + 1 || reply.parentCid !== comment.cid\",\n });\n return false;\n }\n }\n\n // signature verification\n try {\n const promises = normalizedReplies.map((reply) =>\n commentIsValid(reply, { validateReplies: false, blockCommunity: true }, pkc),\n );\n await Promise.all(promises);\n } catch (e: any) {\n if (blockCommunity && commentCommunityAddress) {\n communitiesWithInvalidComments[commentCommunityAddress] = true;\n }\n console.log(\"invalid comment\", { comment, error: e });\n return false;\n }\n return true;\n};\n\nconst utils = {\n merge,\n clone,\n flattenCommentsPages,\n memo,\n memoSync,\n retryInfinity: (f: any, o?: any): any => {},\n // export timeout values to mock them in tests\n retryInfinityMinTimeout: 1000,\n retryInfinityMaxTimeout: 1000 * 60 * 60 * 24,\n clientsOnStateChange,\n pageClientsOnStateChange,\n communityPostsCacheExpired,\n commentIsValid,\n removeInvalidComments,\n repliesAreValid,\n};\n\nconst retryInfinity = async (functionToRetry: any, options?: any) => {\n const sleep = (ms: number) => new Promise((r) => setTimeout(r, ms));\n let attempt = 0;\n while (true) {\n try {\n const res = await functionToRetry();\n return res;\n } catch (e) {\n options?.onError(e || Error(`retryInfinity failed attempt ${attempt}`));\n const factor = 2;\n let timeout = Math.round(utils.retryInfinityMinTimeout * Math.pow(factor, attempt++));\n timeout = Math.min(timeout, utils.retryInfinityMaxTimeout);\n await sleep(timeout);\n }\n }\n};\nutils.retryInfinity = retryInfinity;\n\nexport default utils;\n"]}
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/lib/utils/utils.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,MAAM,MAAM,WAAW,CAAC;AAC/B,OAAO,QAAQ,MAAM,WAAW,CAAC;AACjC,OAAO,MAAM,MAAM,yBAAyB,CAAC;AAG7C,OAAO,EAAE,+BAA+B,EAAE,MAAM,sBAAsB,CAAC;AACvE,OAAO,EAAE,0BAA0B,EAAE,mCAAmC,EAAE,MAAM,eAAe,CAAC;AAChG,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAClD,MAAM,GAAG,GAAG,MAAM,CAAC,6BAA6B,CAAC,CAAC;AAElD,MAAM,KAAK,GAAG,CAAC,GAAG,IAAS,EAAE,EAAE;IAC7B,aAAa;IACb,MAAM,UAAU,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE;QAClC,MAAM,CAAC,GAAG,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE,yBAAyB,GAAG,iBAAiB,CAAC,CAAC;QACtF,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC;IACpB,CAAC,CAAC,CAAC;IACH,MAAM,SAAS,GAAQ,EAAE,CAAC;IAC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H,CAAC,CAAA,CAAC;AACF,KAAK,CAAC,aAAa,GAAG,aAAa,CAAC;AAEpC,eAAe,KAAK,CAAC","sourcesContent":["import assert from \"../assert\";\nimport QuickLru from \"quick-lru\";\nimport Logger from \"@pkcprotocol/pkc-logger\";\nimport PkcJs from \"../pkc-js\";\nimport { Comment } from \"../../types\";\nimport { areEquivalentCommunityAddresses } from \"../community-address\";\nimport { getCommentCommunityAddress, normalizePublicationOptionsForStore } from \"../pkc-compat\";\nimport { getPageRpcClients } from \"../pkc-compat\";\nconst log = Logger(\"bitsocial-react-hooks:utils\");\n\nconst merge = (...args: any) => {\n // @ts-ignore\n const clonedArgs = args.map((arg) => {\n assert(arg && typeof arg === \"object\", `utils.merge argument '${arg}' not an object`);\n return clone(arg);\n });\n const mergedObj: any = {};\n while (clonedArgs.length) {\n const currentArg = clonedArgs.shift();\n for (const i in currentArg) {\n if (currentArg[i] === undefined || currentArg[i] === null) {\n continue;\n }\n mergedObj[i] = currentArg[i];\n }\n }\n return mergedObj;\n};\n\nconst clone = (obj: any) => {\n assert(obj && typeof obj === \"object\", `utils.clone argument '${obj}' not an object`);\n let clonedObj: any = {};\n\n // clean the object to be cloned\n for (const i in obj) {\n // remove functions\n if (typeof obj[i] === \"function\") {\n continue;\n }\n // remove internal props\n if (i.startsWith(\"_\")) {\n continue;\n }\n if (obj[i] === undefined || obj[i] === null) {\n continue;\n }\n // pkc-js has a bug where pkc instances have circular deps\n if (obj[i]?.constructor?.name === \"PKC\") {\n continue;\n }\n clonedObj[i] = obj[i];\n }\n\n // clone the object\n clonedObj = JSON.parse(JSON.stringify(clonedObj));\n return clonedObj;\n};\n\n// this function should not clone the comments to not waste memory\nexport const flattenCommentsPages = (pageInstanceOrPagesInstance: any) => {\n const flattenedComments = [];\n\n // if is a Page instance\n if (pageInstanceOrPagesInstance?.comments) {\n for (const comment of pageInstanceOrPagesInstance.comments) {\n flattenedComments.push(comment);\n if (comment.replies?.pages && Object.keys(comment.replies.pages).length) {\n flattenedComments.push(...flattenCommentsPages(comment.replies));\n }\n }\n }\n\n // if is a Pages instance\n else if (pageInstanceOrPagesInstance?.pages) {\n for (const sortType in pageInstanceOrPagesInstance.pages) {\n flattenedComments.push(...flattenCommentsPages(pageInstanceOrPagesInstance.pages[sortType]));\n }\n }\n\n // if is a Pages.pages instance\n else {\n for (const sortType in pageInstanceOrPagesInstance) {\n const page = pageInstanceOrPagesInstance[sortType];\n if (page?.comments?.length) {\n flattenedComments.push(...flattenCommentsPages(page));\n }\n }\n }\n\n // remove duplicate comments\n const flattenedCommentsObject = {};\n for (const comment of flattenedComments) {\n // @ts-ignore\n flattenedCommentsObject[comment.cid] = comment;\n }\n const uniqueFlattened = [];\n for (const cid in flattenedCommentsObject) {\n // @ts-ignore\n uniqueFlattened.push(flattenedCommentsObject[cid]);\n }\n\n return uniqueFlattened;\n};\n\nconst memo = (functionToMemo: Function, memoOptions: any) => {\n assert(typeof functionToMemo === \"function\", `memo first argument must be a function`);\n const pendingPromises: any = new Map();\n const cache = new QuickLru(memoOptions);\n\n // preserve function name\n const memoedFunctionName = functionToMemo.name || \"memoedFunction\";\n const obj = {\n [memoedFunctionName]: async (...args: any) => {\n let cacheKey = args[0];\n if (args.length > 1) {\n cacheKey = \"\";\n for (const arg of args) {\n if (\n typeof arg !== \"string\" &&\n typeof arg !== \"number\" &&\n arg !== undefined &&\n arg !== null\n ) {\n const argumentIndex = args.indexOf(arg);\n throw Error(\n `memoed function '${memoedFunctionName}' invalid argument number '${argumentIndex}' '${arg}', memoed function can only use multiple arguments if they are all of type string, number, undefined or null`,\n );\n }\n cacheKey += arg;\n }\n }\n\n // has cached result\n const cached = cache.get(cacheKey);\n if (cached) {\n return cached;\n }\n\n // don't request the same thing twice if fetching is pending\n let pendingPromise = pendingPromises.get(cacheKey);\n if (pendingPromise) {\n return pendingPromise;\n }\n\n // create the pending promise\n let resolve: any, reject: any;\n pendingPromise = new Promise((_resolve, _reject) => {\n resolve = _resolve;\n reject = _reject;\n });\n pendingPromises.set(cacheKey, pendingPromise);\n\n // execute the function\n try {\n const result = await functionToMemo(...args);\n cache.set(cacheKey, result);\n pendingPromises.delete(cacheKey);\n resolve?.(result);\n } catch (error) {\n pendingPromises.delete(cacheKey);\n reject?.(error);\n }\n\n return pendingPromise;\n },\n };\n return obj[memoedFunctionName];\n};\n\nconst memoSync = (functionToMemo: Function, memoOptions: any) => {\n assert(typeof functionToMemo === \"function\", `memo first argument must be a function`);\n const cache = new QuickLru(memoOptions);\n\n // preserve function name\n const memoedFunctionName = functionToMemo.name || \"memoedFunction\";\n const obj = {\n [memoedFunctionName]: (...args: any) => {\n let cacheKey = args[0];\n if (args.length > 1) {\n cacheKey = \"\";\n for (const arg of args) {\n if (\n typeof arg !== \"string\" &&\n typeof arg !== \"number\" &&\n arg !== undefined &&\n arg !== null\n ) {\n const argumentIndex = args.indexOf(arg);\n throw Error(\n `memoed function '${memoedFunctionName}' invalid argument number '${argumentIndex}' '${arg}', memoed function can only use multiple arguments if they are all of type string, number, undefined or null`,\n );\n }\n cacheKey += arg;\n }\n }\n\n // has cached result\n const cached = cache.get(cacheKey);\n if (cached) {\n return cached;\n }\n\n // execute the function\n const result = functionToMemo(...args);\n if (typeof result?.then === \"function\") {\n throw Error(\n `memoed function '${memoedFunctionName}' is an async function, cannot be used with memoSync, use memo instead`,\n );\n }\n cache.set(cacheKey, result);\n return result;\n },\n };\n return obj[memoedFunctionName];\n};\n\nconst clientsOnStateChange = (clients: any, onStateChange: Function) => {\n for (const clientUrl in clients?.ipfsGateways) {\n clients?.ipfsGateways?.[clientUrl].on(\"statechange\", (state: string) =>\n onStateChange(state, \"ipfsGateways\", clientUrl),\n );\n }\n for (const clientUrl in clients?.kuboRpcClients) {\n clients?.kuboRpcClients?.[clientUrl].on(\"statechange\", (state: string) =>\n onStateChange(state, \"kuboRpcClients\", clientUrl),\n );\n }\n for (const clientUrl in clients?.pubsubKuboRpcClients) {\n clients?.pubsubKuboRpcClients?.[clientUrl].on(\"statechange\", (state: string) =>\n onStateChange(state, \"pubsubKuboRpcClients\", clientUrl),\n );\n }\n const rpcClients = getPageRpcClients(clients);\n for (const clientUrl in rpcClients) {\n rpcClients?.[clientUrl].on(\"statechange\", (state: string) =>\n onStateChange(state, \"pkcRpcClients\", clientUrl),\n );\n }\n for (const clientUrl in clients?.libp2pJsClients) {\n clients?.libp2pJsClients?.[clientUrl].on(\"statechange\", (state: string) =>\n onStateChange(state, \"libp2pJsClients\", clientUrl),\n );\n }\n for (const chainTicker in clients?.chainProviders) {\n for (const clientUrl in clients?.chainProviders?.[chainTicker]) {\n clients?.chainProviders?.[chainTicker]?.[clientUrl].on(\"statechange\", (state: string) =>\n onStateChange(state, \"chainProviders\", clientUrl, chainTicker),\n );\n }\n }\n for (const resolverKey in clients?.nameResolvers) {\n clients?.nameResolvers?.[resolverKey].on(\"statechange\", (state: string) =>\n onStateChange(state, \"nameResolvers\", resolverKey),\n );\n }\n};\n\nconst pageClientsOnStateChange = (clients: any, onStateChange: Function) => {\n for (const sortType in clients?.ipfsGateways) {\n for (const clientUrl in clients?.ipfsGateways?.[sortType]) {\n clients?.ipfsGateways?.[sortType]?.[clientUrl].on(\"statechange\", (state: string) =>\n onStateChange(state, \"ipfsGateways\", sortType, clientUrl),\n );\n }\n }\n for (const sortType in clients?.kuboRpcClients) {\n for (const clientUrl in clients?.kuboRpcClients?.[sortType]) {\n clients?.kuboRpcClients?.[sortType]?.[clientUrl].on(\"statechange\", (state: string) =>\n onStateChange(state, \"kuboRpcClients\", sortType, clientUrl),\n );\n }\n }\n const rpcPageClients = getPageRpcClients(clients);\n for (const sortType in rpcPageClients) {\n for (const clientUrl in rpcPageClients?.[sortType]) {\n rpcPageClients?.[sortType]?.[clientUrl].on(\"statechange\", (state: string) =>\n onStateChange(state, \"pkcRpcClients\", sortType, clientUrl),\n );\n }\n }\n for (const sortType in clients?.libp2pJsClients) {\n for (const clientUrl in clients?.libp2pJsClients?.[sortType]) {\n clients?.libp2pJsClients?.[sortType]?.[clientUrl].on(\"statechange\", (state: string) =>\n onStateChange(state, \"libp2pJsClients\", sortType, clientUrl),\n );\n }\n }\n};\n\nexport const communityPostsCacheExpired = (community: any) => {\n // NOTE: fetchedAt is undefined on owner communities\n if (!community || community.fetchedAt == null) {\n return false;\n }\n // if community cache is older than 1 hour, its community.posts are considered expired\n const oneHourAgo = Date.now() / 1000 - 60 * 60;\n return oneHourAgo > community.fetchedAt;\n};\n\nexport const removeInvalidComments = async (\n comments: Comment[],\n { validateReplies, blockCommunity }: any,\n pkc: any,\n) => {\n if (!comments.length) {\n return [];\n }\n const isValid = await Promise.all(\n comments.map((comment) => commentIsValid(comment, { validateReplies, blockCommunity }, pkc)),\n );\n const validComments = comments.filter((_, i) => isValid[i]);\n return validComments;\n};\n\nconst communitiesWithInvalidComments: { [communityAddress: string]: boolean } = {};\nexport const commentIsValid = async (\n comment: Comment,\n { validateReplies, blockCommunity }: any = {},\n pkc: any,\n) => {\n validateReplies = Boolean(validateReplies);\n if (blockCommunity === undefined || blockCommunity === null) {\n blockCommunity = true;\n }\n if (!comment) {\n return false;\n }\n if (communitiesWithInvalidComments[comment.communityAddress]) {\n console.log(\n `community '${comment.communityAddress}' had an invalid comment, invalidate all its future comments to avoid wasting resources`,\n );\n return false;\n }\n try {\n await pkc.validateComment(comment, { validateReplies });\n } catch (e) {\n if (blockCommunity) {\n communitiesWithInvalidComments[comment.communityAddress] = true;\n }\n console.log(\"invalid comment\", { comment, error: e });\n return false;\n }\n return true;\n};\n\nconst repliesAreValid = async (\n comment: Comment,\n { validateReplies, blockCommunity }: any = {},\n pkc: any,\n) => {\n validateReplies = Boolean(validateReplies);\n if (blockCommunity === undefined || blockCommunity === null) {\n blockCommunity = true;\n }\n if (!comment) {\n return false;\n }\n const commentCommunityAddress = getCommentCommunityAddress(comment);\n if (commentCommunityAddress && communitiesWithInvalidComments[commentCommunityAddress]) {\n console.log(\n `community '${commentCommunityAddress}' had an invalid comment, invalidate all its future comments to avoid wasting resources`,\n );\n return false;\n }\n const replyPageArray: any[] = Object.values(comment.replies?.pages || {});\n const replies = replyPageArray.flatMap((replyPage: any) => replyPage?.comments || []);\n const normalizedReplies = replies.map((reply) => {\n const normalizedReply = normalizePublicationOptionsForStore(reply) as Comment;\n normalizedReply.communityAddress =\n getCommentCommunityAddress(normalizedReply) || commentCommunityAddress;\n return normalizedReply;\n });\n\n // manual validation\n for (const reply of normalizedReplies) {\n if (\n !areEquivalentCommunityAddresses(\n getCommentCommunityAddress(reply),\n commentCommunityAddress,\n ) ||\n reply.depth !== comment.depth + 1 ||\n reply.parentCid !== comment.cid\n ) {\n if (blockCommunity && commentCommunityAddress) {\n communitiesWithInvalidComments[commentCommunityAddress] = true;\n }\n console.log(\"invalid comment\", {\n comment: reply,\n error:\n \"!areEquivalentCommunityAddresses(reply.communityAddress, comment.communityAddress) || reply.depth !== comment.depth + 1 || reply.parentCid !== comment.cid\",\n });\n return false;\n }\n }\n\n // signature verification\n try {\n const promises = normalizedReplies.map((reply) =>\n commentIsValid(reply, { validateReplies: false, blockCommunity: true }, pkc),\n );\n await Promise.all(promises);\n } catch (e: any) {\n if (blockCommunity && commentCommunityAddress) {\n communitiesWithInvalidComments[commentCommunityAddress] = true;\n }\n console.log(\"invalid comment\", { comment, error: e });\n return false;\n }\n return true;\n};\n\nconst utils = {\n merge,\n clone,\n flattenCommentsPages,\n memo,\n memoSync,\n retryInfinity: (f: any, o?: any): any => {},\n // export timeout values to mock them in tests\n retryInfinityMinTimeout: 1000,\n retryInfinityMaxTimeout: 1000 * 60 * 60 * 24,\n clientsOnStateChange,\n pageClientsOnStateChange,\n communityPostsCacheExpired,\n commentIsValid,\n removeInvalidComments,\n repliesAreValid,\n};\n\nconst retryInfinity = async (functionToRetry: any, options?: any) => {\n const sleep = (ms: number) => new Promise((r) => setTimeout(r, ms));\n let attempt = 0;\n while (true) {\n try {\n const res = await functionToRetry();\n return res;\n } catch (e) {\n options?.onError(e || Error(`retryInfinity failed attempt ${attempt}`));\n const factor = 2;\n let timeout = Math.round(utils.retryInfinityMinTimeout * Math.pow(factor, attempt++));\n timeout = Math.min(timeout, utils.retryInfinityMaxTimeout);\n await sleep(timeout);\n }\n }\n};\nutils.retryInfinity = retryInfinity;\n\nexport default utils;\n"]}
@@ -1,4 +1,4 @@
1
- import assert from "assert";
1
+ import assert from "./assert.js";
2
2
  import { assertCommunityRef } from "./community-ref.js";
3
3
  const toString = (value) => {
4
4
  if (typeof value === "string") {
@@ -1 +1 @@
1
- {"version":3,"file":"validator.js","sourceRoot":"","sources":["../../src/lib/validator.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAErD,MAAM,QAAQ,GAAG,CAAC,KAAU,EAAE,EAAE;IAC9B,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,OAAO,KAAK,CAAC;IACf,CAAC;IACD,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;QACrC,OAAO,MAAM,CAAC;IAChB,CAAC;IAAC,WAAM,CAAC,CAAA,CAAC;IACV,OAAO,KAAK,CAAC;AACf,CAAC,CAAC;AAEF,MAAM,8BAA8B,GAAG,CAAC,OAAY,EAAE,EAAE,CACtD,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,gBAAgB,MAAI,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,gBAAgB,CAAA,CAAC;AACzD,MAAM,wBAAwB,GAAG,CAAC,OAAY,EAAE,EAAE,CAAC,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,GAAG,MAAI,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,GAAG,CAAA,CAAC;AAEhF,MAAM,8CAA8C,GAAG,CAAC,EACtD,qBAAqB,EACrB,WAAW,EACX,OAAO,GACH,EAAE,EAAE;IACR,MAAM,CACJ,CAAC,WAAW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S,gBAAgB,CAC5F,CAAC;QACF,MAAM,CACJ,CAAC,eAAe,CAAC,MAAM,IAAI,OAAO,eAAe,CAAC,MAAM,KAAK,SAAS,EACtE,+CAA+C,eAAe,CAAC,MAAM,iBAAiB,CACvF,CAAC;IACJ,CAAC;IACD,IAAI,MAAM,EAAE,CAAC;QACX,MAAM,CACJ,OAAO,MAAM,CAAC,MAAM,KAAK,UAAU,EACnC,sCAAsC,MAAM,CAAC,MAAM,yHAAyH,CAC7K,CAAC;QACF,MAAM,CACJ,OAAO,MAAM,CAAC,GAAG,KAAK,QAAQ,EAC9B,mCAAmC,MAAM,CAAC,GAAG,yEAAyE,CACvH,CAAC;IACJ,CAAC;AACH,CAAC,CAAC;AAEF,MAAM,SAAS,GAAG;IAChB,8CAA8C;IAC9C,kDAAkD;IAClD,wDAAwD;IACxD,oDAAoD;IACpD,2CAA2C;IAC3C,6CAA6C;IAC7C,gDAAgD;IAChD,0CAA0C;IAC1C,gDAAgD;IAChD,2CAA2C;IAC3C,4CAA4C;IAC5C,oCAAoC;IACpC,2BAA2B;IAC3B,4BAA4B;IAC5B,6BAA6B;IAC7B,kCAAkC;IAClC,+BAA+B;IAC/B,qCAAqC;IACrC,oBAAoB;IACpB,wBAAwB;IACxB,iCAAiC;IACjC,uBAAuB;IACvB,2BAA2B;CAC5B,CAAC;AAEF,eAAe,SAAS,CAAC","sourcesContent":["import assert from \"assert\";\nimport { assertCommunityRef } from \"./community-ref\";\n\nconst toString = (value: any) => {\n if (typeof value === \"string\") {\n return value;\n }\n try {\n const string = JSON.stringify(value);\n return string;\n } catch {}\n return value;\n};\n\nconst getPublicationCommunityAddress = (options: any) =>\n options?.communityAddress || options?.communityAddress;\nconst getAccountProtocolClient = (account: any) => account?.pkc || account?.pkc;\n\nconst validateAccountsActionsPublishCommentArguments = ({\n publishCommentOptions,\n accountName,\n account,\n}: any) => {\n assert(\n !accountName || typeof accountName === \"string\",\n `publishComment accountName '${accountName}' not a string`,\n );\n assert(accountName !== \"\", `publishComment accountName argument is empty string`);\n assert(\n !accountName || account,\n `publishComment no account with name '${accountName}' in accountsStore`,\n );\n assert(\n publishCommentOptions && typeof publishCommentOptions === \"object\",\n \"publishComment publishCommentOptions not an object\",\n );\n assert(\n typeof publishCommentOptions.onChallenge === \"function\",\n \"publishComment publishCommentOptions.onChallenge not a function\",\n );\n assert(\n typeof publishCommentOptions.onChallengeVerification === \"function\",\n \"publishComment publishCommentOptions.onChallengeVerification not a function\",\n );\n assert(\n !publishCommentOptions.onError || typeof publishCommentOptions.onError === \"function\",\n \"publishComment publishCommentOptions.onError not a function\",\n );\n assert(\n publishCommentOptions.onPendingComment == null ||\n typeof publishCommentOptions.onPendingComment === \"function\",\n \"publishComment publishCommentOptions.onPendingComment not a function\",\n );\n assert(\n typeof getPublicationCommunityAddress(publishCommentOptions) === \"string\",\n \"publishComment publishCommentOptions.communityAddress/communityAddress not a string\",\n );\n assert(\n !publishCommentOptions.parentCid || typeof publishCommentOptions.parentCid === \"string\",\n \"publishComment publishCommentOptions.parentCid not a string\",\n );\n assert(\n !publishCommentOptions.timestamp || typeof publishCommentOptions.timestamp === \"number\",\n \"publishComment publishCommentOptions.timestamp is not a number\",\n );\n\n // validate content\n assert(\n !publishCommentOptions.content || typeof publishCommentOptions.content === \"string\",\n \"publishComment publishCommentOptions.content not a string\",\n );\n assert(\n publishCommentOptions.content !== \"\",\n \"publishComment publishCommentOptions.content is an empty string\",\n );\n assert(\n !publishCommentOptions.link || typeof publishCommentOptions.link === \"string\",\n \"publishComment publishCommentOptions.link not a string\",\n );\n assert(\n publishCommentOptions.link !== \"\",\n \"publishComment publishCommentOptions.link is an empty string\",\n );\n assert(\n !publishCommentOptions.title || typeof publishCommentOptions.title === \"string\",\n \"publishComment publishCommentOptions.title not a string\",\n );\n assert(\n publishCommentOptions.title !== \"\",\n \"publishComment publishCommentOptions.title is an empty string\",\n );\n};\n\nconst validateAccountsActionsPublishVoteArguments = ({\n publishVoteOptions,\n accountName,\n account,\n}: any) => {\n assert(\n !accountName || typeof accountName === \"string\",\n `publishVote accountName '${accountName}' not a string`,\n );\n assert(accountName !== \"\", `publishVote accountName argument is empty string`);\n assert(\n !accountName || account,\n `publishVote no account with name '${accountName}' in accountsStore`,\n );\n assert(\n publishVoteOptions && typeof publishVoteOptions === \"object\",\n \"publishVote publishVoteOptions not an object\",\n );\n assert(\n typeof publishVoteOptions.onChallenge === \"function\",\n \"publishVote publishVoteOptions.onChallenge not a function\",\n );\n assert(\n typeof publishVoteOptions.onChallengeVerification === \"function\",\n \"publishVote publishVoteOptions.onChallengeVerification not a function\",\n );\n assert(\n !publishVoteOptions.onError || typeof publishVoteOptions.onError === \"function\",\n \"publishVote publishVoteOptions.onError not a function\",\n );\n assert(\n typeof getPublicationCommunityAddress(publishVoteOptions) === \"string\",\n \"publishVote publishVoteOptions.communityAddress/communityAddress not a string\",\n );\n assert(\n typeof publishVoteOptions.commentCid === \"string\",\n \"publishVote publishVoteOptions.commentCid not a string\",\n );\n assert(\n publishVoteOptions.vote === 1 ||\n publishVoteOptions.vote === 0 ||\n publishVoteOptions.vote === -1,\n \"publishVote publishVoteOptions.vote not 1, 0 or -1\",\n );\n assert(\n !publishVoteOptions.timestamp || typeof publishVoteOptions.timestamp === \"number\",\n \"publishVote publishVoteOptions.timestamp is not a number\",\n );\n};\n\nconst validateAccountsActionsPublishCommentEditArguments = ({\n publishCommentEditOptions,\n accountName,\n account,\n}: any) => {\n assert(\n !accountName || typeof accountName === \"string\",\n `publishCommentEdit accountName '${accountName}' not a string`,\n );\n assert(accountName !== \"\", `publishCommentEdit accountName argument is empty string`);\n assert(\n !accountName || account,\n `publishCommentEdit no account with name '${accountName}' in accountsStore`,\n );\n assert(\n publishCommentEditOptions && typeof publishCommentEditOptions === \"object\",\n \"publishCommentEdit publishCommentEditOptions not an object\",\n );\n assert(\n typeof publishCommentEditOptions.onChallenge === \"function\",\n \"publishCommentEdit publishCommentEditOptions.onChallenge not a function\",\n );\n assert(\n typeof publishCommentEditOptions.onChallengeVerification === \"function\",\n \"publishCommentEdit publishCommentEditOptions.onChallengeVerification not a function\",\n );\n assert(\n !publishCommentEditOptions.onError || typeof publishCommentEditOptions.onError === \"function\",\n \"publishCommentEditOptions publishCommentEditOptions.onError not a function\",\n );\n assert(\n typeof getPublicationCommunityAddress(publishCommentEditOptions) === \"string\",\n \"publishCommentEdit publishCommentEditOptions.communityAddress/communityAddress not a string\",\n );\n assert(\n typeof publishCommentEditOptions.commentCid === \"string\",\n \"publishCommentEdit publishCommentEditOptions.commentCid not a string\",\n );\n assert(\n !publishCommentEditOptions.timestamp || typeof publishCommentEditOptions.timestamp === \"number\",\n \"publishCommentEdit publishCommentEditOptions.timestamp is not a number\",\n );\n};\n\nconst validateAccountsActionsPublishCommentModerationArguments = ({\n publishCommentModerationOptions,\n accountName,\n account,\n}: any) => {\n assert(\n !accountName || typeof accountName === \"string\",\n `publishCommentModeration accountName '${accountName}' not a string`,\n );\n assert(accountName !== \"\", `publishCommentModeration accountName argument is empty string`);\n assert(\n !accountName || account,\n `publishCommentModeration no account with name '${accountName}' in accountsStore`,\n );\n assert(\n publishCommentModerationOptions && typeof publishCommentModerationOptions === \"object\",\n \"publishCommentModeration publishCommentModerationOptions not an object\",\n );\n assert(\n typeof publishCommentModerationOptions.onChallenge === \"function\",\n \"publishCommentModeration publishCommentModerationOptions.onChallenge not a function\",\n );\n assert(\n typeof publishCommentModerationOptions.onChallengeVerification === \"function\",\n \"publishCommentModeration publishCommentModerationOptions.onChallengeVerification not a function\",\n );\n assert(\n !publishCommentModerationOptions.onError ||\n typeof publishCommentModerationOptions.onError === \"function\",\n \"publishCommentModerationOptions publishCommentModerationOptions.onError not a function\",\n );\n assert(\n typeof getPublicationCommunityAddress(publishCommentModerationOptions) === \"string\",\n \"publishCommentModeration publishCommentModerationOptions.communityAddress/communityAddress not a string\",\n );\n assert(\n typeof publishCommentModerationOptions.commentCid === \"string\",\n \"publishCommentModeration publishCommentModerationOptions.commentCid not a string\",\n );\n assert(\n !publishCommentModerationOptions.timestamp ||\n typeof publishCommentModerationOptions.timestamp === \"number\",\n \"publishCommentModeration publishCommentModerationOptions.timestamp is not a number\",\n );\n assert(\n publishCommentModerationOptions.commentModeration &&\n typeof publishCommentModerationOptions.commentModeration === \"object\",\n \"publishCommentModeration publishCommentModerationOptions.commentModeration is not an object\",\n );\n};\n\nconst validateAccountsActionsPublishCommunityEditArguments = ({\n communityAddress,\n publishCommunityEditOptions,\n accountName,\n account,\n}: any) => {\n assert(\n !accountName || typeof accountName === \"string\",\n `publishCommunityEdit accountName '${accountName}' not a string`,\n );\n assert(accountName !== \"\", `publishCommunityEdit accountName argument is empty string`);\n assert(\n !accountName || account,\n `publishCommunityEdit no account with name '${accountName}' in accountsStore`,\n );\n assert(\n publishCommunityEditOptions && typeof publishCommunityEditOptions === \"object\",\n \"publishCommunityEdit publishCommunityEditOptions not an object\",\n );\n assert(\n typeof publishCommunityEditOptions.onChallenge === \"function\",\n \"publishCommunityEdit publishCommunityEditOptions.onChallenge not a function\",\n );\n assert(\n typeof publishCommunityEditOptions.onChallengeVerification === \"function\",\n \"publishCommunityEdit publishCommunityEditOptions.onChallengeVerification not a function\",\n );\n assert(\n !publishCommunityEditOptions.onError ||\n typeof publishCommunityEditOptions.onError === \"function\",\n \"publishCommunityEdit publishCommunityEditOptions.onError not a function\",\n );\n assert(communityAddress !== \"\", `publishCommunityEdit communityAddress argument is empty string`);\n assert(\n typeof communityAddress === \"string\",\n \"publishCommunityEdit communityAddress not a string\",\n );\n assert(\n !publishCommunityEditOptions.timestamp ||\n typeof publishCommunityEditOptions.timestamp === \"number\",\n \"publishCommunityEdit publishCommunityEditOptions.timestamp is not a number\",\n );\n};\n\nconst validateAccountsActionsExportAccountArguments = (accountName: any) => {\n assert(\n typeof accountName === \"string\",\n `exportAccount accountName '${accountName}' not a string`,\n );\n assert(accountName !== \"\", `exportAccount accountName argument is empty string`);\n};\n\nconst validateAccountsActionsSetAccountsOrderArguments = (\n newOrderedAccountNames: any,\n accountNames: any,\n) => {\n assert(\n JSON.stringify([...accountNames].sort()) === JSON.stringify([...newOrderedAccountNames].sort()),\n `previous account names '${accountNames} contain different account names than argument newOrderedAccountNames '${newOrderedAccountNames}'`,\n );\n};\n\nconst validateAccountsActionsSetAccountArguments = (account: any) => {\n assert(account && typeof account === \"object\", `setAccount account '${account}' not an object`);\n assert(\n typeof account.name === \"string\",\n `setAccount account.name '${account.name}' not a string`,\n );\n assert(account.name !== \"\", `setAccount account.name is empty string`);\n assert(typeof account.id === \"string\", `setAccount account.id '${account.id}' not a string`);\n assert(account.id !== \"\", `setAccount account.id is empty string`);\n};\n\nconst validateAccountsActionsSetActiveAccountArguments = (accountName: any) => {\n assert(\n typeof accountName === \"string\",\n `setActiveAccountName accountName '${accountName}' not a string`,\n );\n assert(accountName !== \"\", `setActiveAccountName accountName argument is empty string`);\n};\n\nconst validateAccountsDatabaseGetAccountsArguments = (accountIds: any) => {\n assert(\n Array.isArray(accountIds),\n `accountsDatabase.getAccounts accountIds '${accountIds}' not an array`,\n );\n assert(accountIds.length > 0, `accountsDatabase.getAccounts accountIds array is empty`);\n for (const accountId of accountIds) {\n assert(\n typeof accountId === \"string\",\n `accountsDatabase.getAccountsaccountIds '${accountIds}' accountId '${accountId}' not a string`,\n );\n assert(\n accountId !== \"\",\n `accountsDatabase.getAccounts accountIds '${accountIds}' an accountId argument is empty string`,\n );\n }\n};\n\nconst validateAccountsDatabaseAccountNames = (accountNames: any) => {\n assert(\n Array.isArray(accountNames),\n `accountsDatabase accountNames '${accountNames}' not an array`,\n );\n for (const accountName of accountNames) {\n assert(\n typeof accountName === \"string\",\n `accountsDatabase accountNames '${accountNames}' accountName '${accountName}' not a string`,\n );\n }\n};\n\nconst validateAccountsDatabaseAddAccountArguments = (account: any) => {\n assert(\n account && typeof account === \"object\",\n `accountsDatabase.addAccount '${account}' not an object`,\n );\n assert(\n typeof account.name === \"string\",\n `accountsDatabase.addAccount account.name '${account.name}' not a string`,\n );\n assert(account.name !== \"\", `accountsDatabase.addAccount account.name is empty string`);\n assert(\n typeof account.id === \"string\",\n `accountsDatabase.addAccount account.id '${account.id}' not a string`,\n );\n assert(account.id !== \"\", `accountsDatabase.addAccount account.id is empty string`);\n};\n\nconst validateUseCommentArguments = (commentCid: any, account: any) => {\n assert(typeof commentCid === \"string\", `useComment commentCid '${commentCid}' not a string`);\n assert(\n getAccountProtocolClient(account) && typeof getAccountProtocolClient(account) === \"object\",\n `useComment account.pkc/account.pkc '${getAccountProtocolClient(account)}' not an object`,\n );\n};\n\nconst validateUseCommentsArguments = (commentCids: any, account: any) => {\n assert(\n Array.isArray(commentCids),\n `useComment commentCids '${toString(commentCids)}' not an array`,\n );\n for (const commentCid of commentCids) {\n assert(\n typeof commentCid === \"string\",\n `useComments commentCids '${toString(commentCids)}' commentCid '${toString(commentCid)}' not a string`,\n );\n }\n assert(\n getAccountProtocolClient(account) && typeof getAccountProtocolClient(account) === \"object\",\n `useComments account.pkc/account.pkc '${getAccountProtocolClient(account)}' not an object`,\n );\n};\n\nconst validateCommunityIdentifierArguments = (\n community: any,\n legacyCommunityAddress: any,\n scope: string,\n) => {\n assert(\n legacyCommunityAddress === undefined,\n `${scope} communityAddress has been removed, pass { community: { name, publicKey } }`,\n );\n if (community === undefined) {\n return;\n }\n assertCommunityRef(community, `${scope} community`);\n};\n\nconst validateUseCommunityArguments = ({ community, communityAddress, account }: any) => {\n validateCommunityIdentifierArguments(community, communityAddress, \"useCommunity\");\n if (account !== undefined && account !== null) {\n assert(\n getAccountProtocolClient(account) && typeof getAccountProtocolClient(account) === \"object\",\n `useCommunity account.pkc/account.pkc '${getAccountProtocolClient(account)}' not an object`,\n );\n }\n};\n\nconst validateUseCommunityStatsArguments = ({ community, communityAddress }: any) => {\n validateCommunityIdentifierArguments(community, communityAddress, \"useCommunityStats\");\n};\n\nconst validateCommunitiesArguments = (\n communities: any,\n communityRefs: any,\n communityAddresses: any,\n scope: string,\n) => {\n assert(\n communityRefs === undefined,\n `${scope} communityRefs has been removed, pass communities instead`,\n );\n assert(\n communityAddresses === undefined,\n `${scope} communityAddresses has been removed, pass communities instead`,\n );\n if (communities !== undefined) {\n assert(\n Array.isArray(communities),\n `${scope} communities '${toString(communities)}' not an array`,\n );\n for (const community of communities) {\n assertCommunityRef(\n community,\n `${scope} communities '${toString(communities)}' community '${toString(community)}'`,\n );\n }\n }\n};\n\nconst validateUseCommunitiesArguments = ({\n communities,\n communityRefs,\n communityAddresses,\n account,\n}: any) => {\n validateCommunitiesArguments(communities, communityRefs, communityAddresses, \"useCommunities\");\n if (account !== undefined && account !== null) {\n assert(\n getAccountProtocolClient(account) && typeof getAccountProtocolClient(account) === \"object\",\n `useCommunity account.pkc/account.pkc '${getAccountProtocolClient(account)}' not an object`,\n );\n }\n};\n\nconst validateFeedSortType = (sortType: any) => {\n assert(\n sortType === undefined || (typeof sortType === \"string\" && sortType.length > 0),\n `invalid feed sort type '${sortType}'`,\n );\n};\nconst validateUseFeedArguments = ({\n communities,\n communityRefs,\n communityAddresses,\n sortType,\n accountName,\n postsPerPage,\n filter,\n newerThan,\n accountComments,\n}: any) => {\n validateCommunitiesArguments(communities, communityRefs, communityAddresses, \"useFeed\");\n assert(\n sortType === undefined || (typeof sortType === \"string\" && sortType.length > 0),\n `useFeed sortType argument '${sortType}' invalid`,\n );\n if (accountName) {\n assert(\n typeof accountName === \"string\",\n `useFeed accountName argument '${accountName}' not a string`,\n );\n }\n if (postsPerPage !== undefined && postsPerPage !== null) {\n assert(\n typeof postsPerPage === \"number\",\n `useFeed postsPerPage argument '${postsPerPage}' not a number`,\n );\n }\n if (filter) {\n assert(\n typeof filter.filter === \"function\",\n `useFeed filter.filter argument '${filter.filter}' not a function, useFeedOptions.filter is now an object Filter {filter: (comment: Comment) => Boolean, key: string}`,\n );\n assert(\n typeof filter.key === \"string\",\n `useFeed filter.key argument '${filter.key}' not a string, a unique filter.key is now required to cache the filter`,\n );\n }\n if (newerThan !== undefined && newerThan !== null) {\n assert(typeof newerThan === \"number\", `useFeed newerThan argument '${newerThan}' not a number`);\n }\n if (accountComments) {\n assert(\n typeof accountComments === \"object\",\n `useFeed accountComments argument '${accountComments}' not an object`,\n );\n assert(\n typeof accountComments.newerThan === \"number\",\n `useFeed accountComments.newerThan argument '${accountComments}' not a number`,\n );\n }\n};\nconst validateUseBufferedFeedsArguments = ({\n feedsOptions,\n accountName,\n}: {\n feedsOptions?: any;\n accountName?: any;\n}) => {\n assert(\n Array.isArray(feedsOptions),\n `useBufferedFeeds feedsOptions argument '${toString(feedsOptions)}' not an array`,\n );\n for (const {\n communities,\n communityRefs,\n communityAddresses,\n sortType,\n postsPerPage,\n filter,\n newerThan,\n } of feedsOptions) {\n validateCommunitiesArguments(\n communities,\n communityRefs,\n communityAddresses,\n \"useBufferedFeeds feedOptions\",\n );\n assert(\n sortType === undefined || (typeof sortType === \"string\" && sortType.length > 0),\n `useBufferedFeeds feedOptions.sortType argument '${sortType}' invalid`,\n );\n if (postsPerPage !== undefined && postsPerPage !== null) {\n assert(\n typeof postsPerPage === \"number\",\n `useBufferedFeeds feedOptions.postsPerPage argument '${postsPerPage}' not a number`,\n );\n }\n if (filter) {\n assert(\n typeof filter.filter === \"function\",\n `useBufferedFeeds feedOptions.filter.filter argument '${filter.filter}' not a function, useFeedOptions.filter is now an object Filter {filter: (comment: Comment) => Boolean, key: string}`,\n );\n assert(\n typeof filter.key === \"string\",\n `useBufferedFeeds feedOptions.filter.key argument '${filter.key}' not a string, a unique filter.key is now required to cache the filter`,\n );\n }\n if (newerThan !== undefined && newerThan !== null) {\n assert(\n typeof newerThan === \"number\",\n `useBufferedFeeds feedOptions.newerThan argument '${newerThan}' not a number`,\n );\n }\n }\n if (accountName) {\n assert(\n typeof accountName === \"string\",\n `useBufferedFeeds accountName argument '${accountName}' not a string`,\n );\n }\n};\n\nconst validateUseCommunitiesStatesArguments = ({\n communities,\n communityRefs,\n communityAddresses,\n}: any) => {\n validateCommunitiesArguments(\n communities,\n communityRefs,\n communityAddresses,\n \"useCommunitiesStates\",\n );\n};\n\nconst validateRepliesSortType = (sortType: any) => {\n assert(\n sortType === undefined || (typeof sortType === \"string\" && sortType.length > 0),\n `invalid replies sort type '${sortType}'`,\n );\n};\nconst validateUseRepliesArguments = (\n comment?: any,\n sortType?: any,\n accountName?: any,\n onlyIfCached?: any,\n flat?: any,\n accountComments?: any,\n postsPerPage?: any,\n filter?: any,\n) => {\n assert(\n !comment || typeof comment === \"object\",\n `useReplies comment argument '${comment}' not an object`,\n );\n assert(\n !comment?.cid || typeof comment.cid === \"string\",\n `useReplies comment.cid argument '${comment?.cid}' not a string`,\n );\n assert(\n sortType === undefined || (typeof sortType === \"string\" && sortType.length > 0),\n `useReplies sortType argument '${sortType}' invalid`,\n );\n if (accountName) {\n assert(\n typeof accountName === \"string\",\n `useReplies accountName argument '${accountName}' not a string`,\n );\n }\n if (onlyIfCached !== undefined && onlyIfCached !== null) {\n assert(\n typeof onlyIfCached === \"boolean\",\n `useReplies onlyIfCached argument '${onlyIfCached}' not a boolean`,\n );\n }\n if (postsPerPage !== undefined && postsPerPage !== null) {\n assert(\n typeof postsPerPage === \"number\",\n `useReplies postsPerPage argument '${postsPerPage}' not a number`,\n );\n }\n if (flat !== undefined && flat !== null) {\n assert(typeof flat === \"boolean\", `useReplies flat argument '${flat}' not a boolean`);\n }\n if (accountComments !== undefined && accountComments !== null) {\n assert(\n typeof accountComments.newerThan === \"number\",\n `useReplies accountComments.newerThan argument '${accountComments.newerThan}' not a number`,\n );\n assert(\n !accountComments.append || typeof accountComments.append === \"boolean\",\n `useReplies accountComments.append argument '${accountComments.append}' not a boolean`,\n );\n }\n if (filter) {\n assert(\n typeof filter.filter === \"function\",\n `useReplies filter.filter argument '${filter.filter}' not a function, useRepliesOptions.filter is now an object Filter {filter: (comment: Comment) => Boolean, key: string}`,\n );\n assert(\n typeof filter.key === \"string\",\n `useReplies filter.key argument '${filter.key}' not a string, a unique filter.key is now required to cache the filter`,\n );\n }\n};\n\nconst validator = {\n validateAccountsActionsPublishCommentArguments,\n validateAccountsActionsPublishCommentEditArguments,\n validateAccountsActionsPublishCommentModerationArguments,\n validateAccountsActionsPublishCommunityEditArguments,\n validateAccountsActionsPublishVoteArguments,\n validateAccountsActionsExportAccountArguments,\n validateAccountsActionsSetAccountsOrderArguments,\n validateAccountsActionsSetAccountArguments,\n validateAccountsActionsSetActiveAccountArguments,\n validateAccountsDatabaseAddAccountArguments,\n validateAccountsDatabaseGetAccountsArguments,\n validateAccountsDatabaseAccountNames,\n validateUseCommentArguments,\n validateUseCommentsArguments,\n validateUseCommunityArguments,\n validateUseCommunityStatsArguments,\n validateUseCommunitiesArguments,\n validateUseCommunitiesStatesArguments,\n validateFeedSortType,\n validateUseFeedArguments,\n validateUseBufferedFeedsArguments,\n validateRepliesSortType,\n validateUseRepliesArguments,\n};\n\nexport default validator;\n"]}
1
+ {"version":3,"file":"validator.js","sourceRoot":"","sources":["../../src/lib/validator.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,UAAU,CAAC;AAC9B,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAErD,MAAM,QAAQ,GAAG,CAAC,KAAU,EAAE,EAAE;IAC9B,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,OAAO,KAAK,CAAC;IACf,CAAC;IACD,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;QACrC,OAAO,MAAM,CAAC;IAChB,CAAC;IAAC,WAAM,CAAC,CAAA,CAAC;IACV,OAAO,KAAK,CAAC;AACf,CAAC,CAAC;AAEF,MAAM,8BAA8B,GAAG,CAAC,OAAY,EAAE,EAAE,CACtD,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,gBAAgB,MAAI,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,gBAAgB,CAAA,CAAC;AACzD,MAAM,wBAAwB,GAAG,CAAC,OAAY,EAA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AAM,CAAC,OAAO,IAAI,KAAK,SAAS,EAAE,6BAA6B,IAAI,iBAAiB,CAAC,CAAC;IACxF,CAAC;IACD,IAAI,eAAe,KAAK,SAAS,IAAI,eAAe,KAAK,IAAI,EAAE,CAAC;QAC9D,MAAM,CACJ,OAAO,eAAe,CAAC,SAAS,KAAK,QAAQ,EAC7C,kDAAkD,eAAe,CAAC,SAAS,gBAAgB,CAC5F,CAAC;QACF,MAAM,CACJ,CAAC,eAAe,CAAC,MAAM,IAAI,OAAO,eAAe,CAAC,MAAM,KAAK,SAAS,EACtE,+CAA+C,eAAe,CAAC,MAAM,iBAAiB,CACvF,CAAC;IACJ,CAAC;IACD,IAAI,MAAM,EAAE,CAAC;QACX,MAAM,CACJ,OAAO,MAAM,CAAC,MAAM,KAAK,UAAU,EACnC,sCAAsC,MAAM,CAAC,MAAM,yHAAyH,CAC7K,CAAC;QACF,MAAM,CACJ,OAAO,MAAM,CAAC,GAAG,KAAK,QAAQ,EAC9B,mCAAmC,MAAM,CAAC,GAAG,yEAAyE,CACvH,CAAC;IACJ,CAAC;AACH,CAAC,CAAC;AAEF,MAAM,SAAS,GAAG;IAChB,8CAA8C;IAC9C,kDAAkD;IAClD,wDAAwD;IACxD,oDAAoD;IACpD,2CAA2C;IAC3C,6CAA6C;IAC7C,gDAAgD;IAChD,0CAA0C;IAC1C,gDAAgD;IAChD,2CAA2C;IAC3C,4CAA4C;IAC5C,oCAAoC;IACpC,2BAA2B;IAC3B,4BAA4B;IAC5B,6BAA6B;IAC7B,kCAAkC;IAClC,+BAA+B;IAC/B,qCAAqC;IACrC,oBAAoB;IACpB,wBAAwB;IACxB,iCAAiC;IACjC,uBAAuB;IACvB,2BAA2B;CAC5B,CAAC;AAEF,eAAe,SAAS,CAAC","sourcesContent":["import assert from \"./assert\";\nimport { assertCommunityRef } from \"./community-ref\";\n\nconst toString = (value: any) => {\n if (typeof value === \"string\") {\n return value;\n }\n try {\n const string = JSON.stringify(value);\n return string;\n } catch {}\n return value;\n};\n\nconst getPublicationCommunityAddress = (options: any) =>\n options?.communityAddress || options?.communityAddress;\nconst getAccountProtocolClient = (account: any) => account?.pkc || account?.pkc;\n\nconst validateAccountsActionsPublishCommentArguments = ({\n publishCommentOptions,\n accountName,\n account,\n}: any) => {\n assert(\n !accountName || typeof accountName === \"string\",\n `publishComment accountName '${accountName}' not a string`,\n );\n assert(accountName !== \"\", `publishComment accountName argument is empty string`);\n assert(\n !accountName || account,\n `publishComment no account with name '${accountName}' in accountsStore`,\n );\n assert(\n publishCommentOptions && typeof publishCommentOptions === \"object\",\n \"publishComment publishCommentOptions not an object\",\n );\n assert(\n typeof publishCommentOptions.onChallenge === \"function\",\n \"publishComment publishCommentOptions.onChallenge not a function\",\n );\n assert(\n typeof publishCommentOptions.onChallengeVerification === \"function\",\n \"publishComment publishCommentOptions.onChallengeVerification not a function\",\n );\n assert(\n !publishCommentOptions.onError || typeof publishCommentOptions.onError === \"function\",\n \"publishComment publishCommentOptions.onError not a function\",\n );\n assert(\n publishCommentOptions.onPendingComment == null ||\n typeof publishCommentOptions.onPendingComment === \"function\",\n \"publishComment publishCommentOptions.onPendingComment not a function\",\n );\n assert(\n typeof getPublicationCommunityAddress(publishCommentOptions) === \"string\",\n \"publishComment publishCommentOptions.communityAddress/communityAddress not a string\",\n );\n assert(\n !publishCommentOptions.parentCid || typeof publishCommentOptions.parentCid === \"string\",\n \"publishComment publishCommentOptions.parentCid not a string\",\n );\n assert(\n !publishCommentOptions.timestamp || typeof publishCommentOptions.timestamp === \"number\",\n \"publishComment publishCommentOptions.timestamp is not a number\",\n );\n\n // validate content\n assert(\n !publishCommentOptions.content || typeof publishCommentOptions.content === \"string\",\n \"publishComment publishCommentOptions.content not a string\",\n );\n assert(\n publishCommentOptions.content !== \"\",\n \"publishComment publishCommentOptions.content is an empty string\",\n );\n assert(\n !publishCommentOptions.link || typeof publishCommentOptions.link === \"string\",\n \"publishComment publishCommentOptions.link not a string\",\n );\n assert(\n publishCommentOptions.link !== \"\",\n \"publishComment publishCommentOptions.link is an empty string\",\n );\n assert(\n !publishCommentOptions.title || typeof publishCommentOptions.title === \"string\",\n \"publishComment publishCommentOptions.title not a string\",\n );\n assert(\n publishCommentOptions.title !== \"\",\n \"publishComment publishCommentOptions.title is an empty string\",\n );\n};\n\nconst validateAccountsActionsPublishVoteArguments = ({\n publishVoteOptions,\n accountName,\n account,\n}: any) => {\n assert(\n !accountName || typeof accountName === \"string\",\n `publishVote accountName '${accountName}' not a string`,\n );\n assert(accountName !== \"\", `publishVote accountName argument is empty string`);\n assert(\n !accountName || account,\n `publishVote no account with name '${accountName}' in accountsStore`,\n );\n assert(\n publishVoteOptions && typeof publishVoteOptions === \"object\",\n \"publishVote publishVoteOptions not an object\",\n );\n assert(\n typeof publishVoteOptions.onChallenge === \"function\",\n \"publishVote publishVoteOptions.onChallenge not a function\",\n );\n assert(\n typeof publishVoteOptions.onChallengeVerification === \"function\",\n \"publishVote publishVoteOptions.onChallengeVerification not a function\",\n );\n assert(\n !publishVoteOptions.onError || typeof publishVoteOptions.onError === \"function\",\n \"publishVote publishVoteOptions.onError not a function\",\n );\n assert(\n typeof getPublicationCommunityAddress(publishVoteOptions) === \"string\",\n \"publishVote publishVoteOptions.communityAddress/communityAddress not a string\",\n );\n assert(\n typeof publishVoteOptions.commentCid === \"string\",\n \"publishVote publishVoteOptions.commentCid not a string\",\n );\n assert(\n publishVoteOptions.vote === 1 ||\n publishVoteOptions.vote === 0 ||\n publishVoteOptions.vote === -1,\n \"publishVote publishVoteOptions.vote not 1, 0 or -1\",\n );\n assert(\n !publishVoteOptions.timestamp || typeof publishVoteOptions.timestamp === \"number\",\n \"publishVote publishVoteOptions.timestamp is not a number\",\n );\n};\n\nconst validateAccountsActionsPublishCommentEditArguments = ({\n publishCommentEditOptions,\n accountName,\n account,\n}: any) => {\n assert(\n !accountName || typeof accountName === \"string\",\n `publishCommentEdit accountName '${accountName}' not a string`,\n );\n assert(accountName !== \"\", `publishCommentEdit accountName argument is empty string`);\n assert(\n !accountName || account,\n `publishCommentEdit no account with name '${accountName}' in accountsStore`,\n );\n assert(\n publishCommentEditOptions && typeof publishCommentEditOptions === \"object\",\n \"publishCommentEdit publishCommentEditOptions not an object\",\n );\n assert(\n typeof publishCommentEditOptions.onChallenge === \"function\",\n \"publishCommentEdit publishCommentEditOptions.onChallenge not a function\",\n );\n assert(\n typeof publishCommentEditOptions.onChallengeVerification === \"function\",\n \"publishCommentEdit publishCommentEditOptions.onChallengeVerification not a function\",\n );\n assert(\n !publishCommentEditOptions.onError || typeof publishCommentEditOptions.onError === \"function\",\n \"publishCommentEditOptions publishCommentEditOptions.onError not a function\",\n );\n assert(\n typeof getPublicationCommunityAddress(publishCommentEditOptions) === \"string\",\n \"publishCommentEdit publishCommentEditOptions.communityAddress/communityAddress not a string\",\n );\n assert(\n typeof publishCommentEditOptions.commentCid === \"string\",\n \"publishCommentEdit publishCommentEditOptions.commentCid not a string\",\n );\n assert(\n !publishCommentEditOptions.timestamp || typeof publishCommentEditOptions.timestamp === \"number\",\n \"publishCommentEdit publishCommentEditOptions.timestamp is not a number\",\n );\n};\n\nconst validateAccountsActionsPublishCommentModerationArguments = ({\n publishCommentModerationOptions,\n accountName,\n account,\n}: any) => {\n assert(\n !accountName || typeof accountName === \"string\",\n `publishCommentModeration accountName '${accountName}' not a string`,\n );\n assert(accountName !== \"\", `publishCommentModeration accountName argument is empty string`);\n assert(\n !accountName || account,\n `publishCommentModeration no account with name '${accountName}' in accountsStore`,\n );\n assert(\n publishCommentModerationOptions && typeof publishCommentModerationOptions === \"object\",\n \"publishCommentModeration publishCommentModerationOptions not an object\",\n );\n assert(\n typeof publishCommentModerationOptions.onChallenge === \"function\",\n \"publishCommentModeration publishCommentModerationOptions.onChallenge not a function\",\n );\n assert(\n typeof publishCommentModerationOptions.onChallengeVerification === \"function\",\n \"publishCommentModeration publishCommentModerationOptions.onChallengeVerification not a function\",\n );\n assert(\n !publishCommentModerationOptions.onError ||\n typeof publishCommentModerationOptions.onError === \"function\",\n \"publishCommentModerationOptions publishCommentModerationOptions.onError not a function\",\n );\n assert(\n typeof getPublicationCommunityAddress(publishCommentModerationOptions) === \"string\",\n \"publishCommentModeration publishCommentModerationOptions.communityAddress/communityAddress not a string\",\n );\n assert(\n typeof publishCommentModerationOptions.commentCid === \"string\",\n \"publishCommentModeration publishCommentModerationOptions.commentCid not a string\",\n );\n assert(\n !publishCommentModerationOptions.timestamp ||\n typeof publishCommentModerationOptions.timestamp === \"number\",\n \"publishCommentModeration publishCommentModerationOptions.timestamp is not a number\",\n );\n assert(\n publishCommentModerationOptions.commentModeration &&\n typeof publishCommentModerationOptions.commentModeration === \"object\",\n \"publishCommentModeration publishCommentModerationOptions.commentModeration is not an object\",\n );\n};\n\nconst validateAccountsActionsPublishCommunityEditArguments = ({\n communityAddress,\n publishCommunityEditOptions,\n accountName,\n account,\n}: any) => {\n assert(\n !accountName || typeof accountName === \"string\",\n `publishCommunityEdit accountName '${accountName}' not a string`,\n );\n assert(accountName !== \"\", `publishCommunityEdit accountName argument is empty string`);\n assert(\n !accountName || account,\n `publishCommunityEdit no account with name '${accountName}' in accountsStore`,\n );\n assert(\n publishCommunityEditOptions && typeof publishCommunityEditOptions === \"object\",\n \"publishCommunityEdit publishCommunityEditOptions not an object\",\n );\n assert(\n typeof publishCommunityEditOptions.onChallenge === \"function\",\n \"publishCommunityEdit publishCommunityEditOptions.onChallenge not a function\",\n );\n assert(\n typeof publishCommunityEditOptions.onChallengeVerification === \"function\",\n \"publishCommunityEdit publishCommunityEditOptions.onChallengeVerification not a function\",\n );\n assert(\n !publishCommunityEditOptions.onError ||\n typeof publishCommunityEditOptions.onError === \"function\",\n \"publishCommunityEdit publishCommunityEditOptions.onError not a function\",\n );\n assert(communityAddress !== \"\", `publishCommunityEdit communityAddress argument is empty string`);\n assert(\n typeof communityAddress === \"string\",\n \"publishCommunityEdit communityAddress not a string\",\n );\n assert(\n !publishCommunityEditOptions.timestamp ||\n typeof publishCommunityEditOptions.timestamp === \"number\",\n \"publishCommunityEdit publishCommunityEditOptions.timestamp is not a number\",\n );\n};\n\nconst validateAccountsActionsExportAccountArguments = (accountName: any) => {\n assert(\n typeof accountName === \"string\",\n `exportAccount accountName '${accountName}' not a string`,\n );\n assert(accountName !== \"\", `exportAccount accountName argument is empty string`);\n};\n\nconst validateAccountsActionsSetAccountsOrderArguments = (\n newOrderedAccountNames: any,\n accountNames: any,\n) => {\n assert(\n JSON.stringify([...accountNames].sort()) === JSON.stringify([...newOrderedAccountNames].sort()),\n `previous account names '${accountNames} contain different account names than argument newOrderedAccountNames '${newOrderedAccountNames}'`,\n );\n};\n\nconst validateAccountsActionsSetAccountArguments = (account: any) => {\n assert(account && typeof account === \"object\", `setAccount account '${account}' not an object`);\n assert(\n typeof account.name === \"string\",\n `setAccount account.name '${account.name}' not a string`,\n );\n assert(account.name !== \"\", `setAccount account.name is empty string`);\n assert(typeof account.id === \"string\", `setAccount account.id '${account.id}' not a string`);\n assert(account.id !== \"\", `setAccount account.id is empty string`);\n};\n\nconst validateAccountsActionsSetActiveAccountArguments = (accountName: any) => {\n assert(\n typeof accountName === \"string\",\n `setActiveAccountName accountName '${accountName}' not a string`,\n );\n assert(accountName !== \"\", `setActiveAccountName accountName argument is empty string`);\n};\n\nconst validateAccountsDatabaseGetAccountsArguments = (accountIds: any) => {\n assert(\n Array.isArray(accountIds),\n `accountsDatabase.getAccounts accountIds '${accountIds}' not an array`,\n );\n assert(accountIds.length > 0, `accountsDatabase.getAccounts accountIds array is empty`);\n for (const accountId of accountIds) {\n assert(\n typeof accountId === \"string\",\n `accountsDatabase.getAccountsaccountIds '${accountIds}' accountId '${accountId}' not a string`,\n );\n assert(\n accountId !== \"\",\n `accountsDatabase.getAccounts accountIds '${accountIds}' an accountId argument is empty string`,\n );\n }\n};\n\nconst validateAccountsDatabaseAccountNames = (accountNames: any) => {\n assert(\n Array.isArray(accountNames),\n `accountsDatabase accountNames '${accountNames}' not an array`,\n );\n for (const accountName of accountNames) {\n assert(\n typeof accountName === \"string\",\n `accountsDatabase accountNames '${accountNames}' accountName '${accountName}' not a string`,\n );\n }\n};\n\nconst validateAccountsDatabaseAddAccountArguments = (account: any) => {\n assert(\n account && typeof account === \"object\",\n `accountsDatabase.addAccount '${account}' not an object`,\n );\n assert(\n typeof account.name === \"string\",\n `accountsDatabase.addAccount account.name '${account.name}' not a string`,\n );\n assert(account.name !== \"\", `accountsDatabase.addAccount account.name is empty string`);\n assert(\n typeof account.id === \"string\",\n `accountsDatabase.addAccount account.id '${account.id}' not a string`,\n );\n assert(account.id !== \"\", `accountsDatabase.addAccount account.id is empty string`);\n};\n\nconst validateUseCommentArguments = (commentCid: any, account: any) => {\n assert(typeof commentCid === \"string\", `useComment commentCid '${commentCid}' not a string`);\n assert(\n getAccountProtocolClient(account) && typeof getAccountProtocolClient(account) === \"object\",\n `useComment account.pkc/account.pkc '${getAccountProtocolClient(account)}' not an object`,\n );\n};\n\nconst validateUseCommentsArguments = (commentCids: any, account: any) => {\n assert(\n Array.isArray(commentCids),\n `useComment commentCids '${toString(commentCids)}' not an array`,\n );\n for (const commentCid of commentCids) {\n assert(\n typeof commentCid === \"string\",\n `useComments commentCids '${toString(commentCids)}' commentCid '${toString(commentCid)}' not a string`,\n );\n }\n assert(\n getAccountProtocolClient(account) && typeof getAccountProtocolClient(account) === \"object\",\n `useComments account.pkc/account.pkc '${getAccountProtocolClient(account)}' not an object`,\n );\n};\n\nconst validateCommunityIdentifierArguments = (\n community: any,\n legacyCommunityAddress: any,\n scope: string,\n) => {\n assert(\n legacyCommunityAddress === undefined,\n `${scope} communityAddress has been removed, pass { community: { name, publicKey } }`,\n );\n if (community === undefined) {\n return;\n }\n assertCommunityRef(community, `${scope} community`);\n};\n\nconst validateUseCommunityArguments = ({ community, communityAddress, account }: any) => {\n validateCommunityIdentifierArguments(community, communityAddress, \"useCommunity\");\n if (account !== undefined && account !== null) {\n assert(\n getAccountProtocolClient(account) && typeof getAccountProtocolClient(account) === \"object\",\n `useCommunity account.pkc/account.pkc '${getAccountProtocolClient(account)}' not an object`,\n );\n }\n};\n\nconst validateUseCommunityStatsArguments = ({ community, communityAddress }: any) => {\n validateCommunityIdentifierArguments(community, communityAddress, \"useCommunityStats\");\n};\n\nconst validateCommunitiesArguments = (\n communities: any,\n communityRefs: any,\n communityAddresses: any,\n scope: string,\n) => {\n assert(\n communityRefs === undefined,\n `${scope} communityRefs has been removed, pass communities instead`,\n );\n assert(\n communityAddresses === undefined,\n `${scope} communityAddresses has been removed, pass communities instead`,\n );\n if (communities !== undefined) {\n assert(\n Array.isArray(communities),\n `${scope} communities '${toString(communities)}' not an array`,\n );\n for (const community of communities) {\n assertCommunityRef(\n community,\n `${scope} communities '${toString(communities)}' community '${toString(community)}'`,\n );\n }\n }\n};\n\nconst validateUseCommunitiesArguments = ({\n communities,\n communityRefs,\n communityAddresses,\n account,\n}: any) => {\n validateCommunitiesArguments(communities, communityRefs, communityAddresses, \"useCommunities\");\n if (account !== undefined && account !== null) {\n assert(\n getAccountProtocolClient(account) && typeof getAccountProtocolClient(account) === \"object\",\n `useCommunity account.pkc/account.pkc '${getAccountProtocolClient(account)}' not an object`,\n );\n }\n};\n\nconst validateFeedSortType = (sortType: any) => {\n assert(\n sortType === undefined || (typeof sortType === \"string\" && sortType.length > 0),\n `invalid feed sort type '${sortType}'`,\n );\n};\nconst validateUseFeedArguments = ({\n communities,\n communityRefs,\n communityAddresses,\n sortType,\n accountName,\n postsPerPage,\n filter,\n newerThan,\n accountComments,\n}: any) => {\n validateCommunitiesArguments(communities, communityRefs, communityAddresses, \"useFeed\");\n assert(\n sortType === undefined || (typeof sortType === \"string\" && sortType.length > 0),\n `useFeed sortType argument '${sortType}' invalid`,\n );\n if (accountName) {\n assert(\n typeof accountName === \"string\",\n `useFeed accountName argument '${accountName}' not a string`,\n );\n }\n if (postsPerPage !== undefined && postsPerPage !== null) {\n assert(\n typeof postsPerPage === \"number\",\n `useFeed postsPerPage argument '${postsPerPage}' not a number`,\n );\n }\n if (filter) {\n assert(\n typeof filter.filter === \"function\",\n `useFeed filter.filter argument '${filter.filter}' not a function, useFeedOptions.filter is now an object Filter {filter: (comment: Comment) => Boolean, key: string}`,\n );\n assert(\n typeof filter.key === \"string\",\n `useFeed filter.key argument '${filter.key}' not a string, a unique filter.key is now required to cache the filter`,\n );\n }\n if (newerThan !== undefined && newerThan !== null) {\n assert(typeof newerThan === \"number\", `useFeed newerThan argument '${newerThan}' not a number`);\n }\n if (accountComments) {\n assert(\n typeof accountComments === \"object\",\n `useFeed accountComments argument '${accountComments}' not an object`,\n );\n assert(\n typeof accountComments.newerThan === \"number\",\n `useFeed accountComments.newerThan argument '${accountComments}' not a number`,\n );\n }\n};\nconst validateUseBufferedFeedsArguments = ({\n feedsOptions,\n accountName,\n}: {\n feedsOptions?: any;\n accountName?: any;\n}) => {\n assert(\n Array.isArray(feedsOptions),\n `useBufferedFeeds feedsOptions argument '${toString(feedsOptions)}' not an array`,\n );\n for (const {\n communities,\n communityRefs,\n communityAddresses,\n sortType,\n postsPerPage,\n filter,\n newerThan,\n } of feedsOptions) {\n validateCommunitiesArguments(\n communities,\n communityRefs,\n communityAddresses,\n \"useBufferedFeeds feedOptions\",\n );\n assert(\n sortType === undefined || (typeof sortType === \"string\" && sortType.length > 0),\n `useBufferedFeeds feedOptions.sortType argument '${sortType}' invalid`,\n );\n if (postsPerPage !== undefined && postsPerPage !== null) {\n assert(\n typeof postsPerPage === \"number\",\n `useBufferedFeeds feedOptions.postsPerPage argument '${postsPerPage}' not a number`,\n );\n }\n if (filter) {\n assert(\n typeof filter.filter === \"function\",\n `useBufferedFeeds feedOptions.filter.filter argument '${filter.filter}' not a function, useFeedOptions.filter is now an object Filter {filter: (comment: Comment) => Boolean, key: string}`,\n );\n assert(\n typeof filter.key === \"string\",\n `useBufferedFeeds feedOptions.filter.key argument '${filter.key}' not a string, a unique filter.key is now required to cache the filter`,\n );\n }\n if (newerThan !== undefined && newerThan !== null) {\n assert(\n typeof newerThan === \"number\",\n `useBufferedFeeds feedOptions.newerThan argument '${newerThan}' not a number`,\n );\n }\n }\n if (accountName) {\n assert(\n typeof accountName === \"string\",\n `useBufferedFeeds accountName argument '${accountName}' not a string`,\n );\n }\n};\n\nconst validateUseCommunitiesStatesArguments = ({\n communities,\n communityRefs,\n communityAddresses,\n}: any) => {\n validateCommunitiesArguments(\n communities,\n communityRefs,\n communityAddresses,\n \"useCommunitiesStates\",\n );\n};\n\nconst validateRepliesSortType = (sortType: any) => {\n assert(\n sortType === undefined || (typeof sortType === \"string\" && sortType.length > 0),\n `invalid replies sort type '${sortType}'`,\n );\n};\nconst validateUseRepliesArguments = (\n comment?: any,\n sortType?: any,\n accountName?: any,\n onlyIfCached?: any,\n flat?: any,\n accountComments?: any,\n postsPerPage?: any,\n filter?: any,\n) => {\n assert(\n !comment || typeof comment === \"object\",\n `useReplies comment argument '${comment}' not an object`,\n );\n assert(\n !comment?.cid || typeof comment.cid === \"string\",\n `useReplies comment.cid argument '${comment?.cid}' not a string`,\n );\n assert(\n sortType === undefined || (typeof sortType === \"string\" && sortType.length > 0),\n `useReplies sortType argument '${sortType}' invalid`,\n );\n if (accountName) {\n assert(\n typeof accountName === \"string\",\n `useReplies accountName argument '${accountName}' not a string`,\n );\n }\n if (onlyIfCached !== undefined && onlyIfCached !== null) {\n assert(\n typeof onlyIfCached === \"boolean\",\n `useReplies onlyIfCached argument '${onlyIfCached}' not a boolean`,\n );\n }\n if (postsPerPage !== undefined && postsPerPage !== null) {\n assert(\n typeof postsPerPage === \"number\",\n `useReplies postsPerPage argument '${postsPerPage}' not a number`,\n );\n }\n if (flat !== undefined && flat !== null) {\n assert(typeof flat === \"boolean\", `useReplies flat argument '${flat}' not a boolean`);\n }\n if (accountComments !== undefined && accountComments !== null) {\n assert(\n typeof accountComments.newerThan === \"number\",\n `useReplies accountComments.newerThan argument '${accountComments.newerThan}' not a number`,\n );\n assert(\n !accountComments.append || typeof accountComments.append === \"boolean\",\n `useReplies accountComments.append argument '${accountComments.append}' not a boolean`,\n );\n }\n if (filter) {\n assert(\n typeof filter.filter === \"function\",\n `useReplies filter.filter argument '${filter.filter}' not a function, useRepliesOptions.filter is now an object Filter {filter: (comment: Comment) => Boolean, key: string}`,\n );\n assert(\n typeof filter.key === \"string\",\n `useReplies filter.key argument '${filter.key}' not a string, a unique filter.key is now required to cache the filter`,\n );\n }\n};\n\nconst validator = {\n validateAccountsActionsPublishCommentArguments,\n validateAccountsActionsPublishCommentEditArguments,\n validateAccountsActionsPublishCommentModerationArguments,\n validateAccountsActionsPublishCommunityEditArguments,\n validateAccountsActionsPublishVoteArguments,\n validateAccountsActionsExportAccountArguments,\n validateAccountsActionsSetAccountsOrderArguments,\n validateAccountsActionsSetAccountArguments,\n validateAccountsActionsSetActiveAccountArguments,\n validateAccountsDatabaseAddAccountArguments,\n validateAccountsDatabaseGetAccountsArguments,\n validateAccountsDatabaseAccountNames,\n validateUseCommentArguments,\n validateUseCommentsArguments,\n validateUseCommunityArguments,\n validateUseCommunityStatsArguments,\n validateUseCommunitiesArguments,\n validateUseCommunitiesStatesArguments,\n validateFeedSortType,\n validateUseFeedArguments,\n validateUseBufferedFeedsArguments,\n validateRepliesSortType,\n validateUseRepliesArguments,\n};\n\nexport default validator;\n"]}
@@ -11,8 +11,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
11
11
  import accountsStore, { listeners } from "./accounts-store.js";
12
12
  import accountsDatabase from "./accounts-database.js";
13
13
  import Logger from "@pkcprotocol/pkc-logger";
14
- import assert from "assert";
15
- import isEqual from "lodash.isequal";
14
+ import assert from "../../lib/assert.js";
15
+ import isEqual from "../../lib/is-equal.js";
16
16
  const log = Logger("bitsocial-react-hooks:accounts:stores");
17
17
  import utils from "../../lib/utils/index.js";
18
18
  import { backfillPublicationCommunityAddress, getCommentCommunityAddress, normalizePublicationOptionsForPkc, normalizePublicationOptionsForStore, } from "../../lib/pkc-compat.js";
@@ -1 +1 @@
1
- {"version":3,"file":"accounts-actions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AAC,CAAC;AACL,CAAC,CAAA,CAAC","sourcesContent":["// internal accounts actions that are not called by the user\n\nimport accountsStore, { listeners } from \"./accounts-store\";\nimport accountsDatabase from \"./accounts-database\";\nimport Logger from \"@pkcprotocol/pkc-logger\";\nimport assert from \"assert\";\nimport isEqual from \"lodash.isequal\";\nconst log = Logger(\"bitsocial-react-hooks:accounts:stores\");\nimport {\n Account,\n AccountCommentReply,\n Comment,\n AccountsComments,\n AccountCommentsReplies,\n Community,\n} from \"../../types\";\nimport utils from \"../../lib/utils\";\nimport {\n backfillPublicationCommunityAddress,\n getCommentCommunityAddress,\n normalizePublicationOptionsForPkc,\n normalizePublicationOptionsForStore,\n} from \"../../lib/pkc-compat\";\nimport {\n addShortAddressesToAccountComment,\n getAccountsCommentsIndexes,\n sanitizeStoredAccountComment,\n} from \"./utils\";\n\nconst accountEditsLoadPromises = new Map<string, Promise<void>>();\n\nconst doesStoredAccountEditMatch = (storedAccountEdit: any, targetStoredAccountEdit: any) =>\n storedAccountEdit?.clientId && targetStoredAccountEdit?.clientId\n ? storedAccountEdit.clientId === targetStoredAccountEdit.clientId\n : isEqual(storedAccountEdit, targetStoredAccountEdit);\n\nconst mergeLoadedAccountEdits = (\n loadedAccountEdits: Record<string, any[]> | undefined,\n currentAccountEdits: Record<string, any[]> | undefined,\n) => {\n const mergedAccountEdits: Record<string, any[]> = { ...(loadedAccountEdits || {}) };\n const editTargets = new Set([\n ...Object.keys(loadedAccountEdits || {}),\n ...Object.keys(currentAccountEdits || {}),\n ]);\n\n for (const editTarget of editTargets) {\n const mergedTargetEdits = [...(loadedAccountEdits?.[editTarget] || [])];\n for (const currentAccountEdit of currentAccountEdits?.[editTarget] || []) {\n const alreadyLoaded = mergedTargetEdits.some((loadedAccountEdit) =>\n doesStoredAccountEditMatch(loadedAccountEdit, currentAccountEdit),\n );\n if (!alreadyLoaded) {\n mergedTargetEdits.push(currentAccountEdit);\n }\n }\n if (mergedTargetEdits.length > 0) {\n mergedAccountEdits[editTarget] = mergedTargetEdits.sort(\n (a, b) => (a?.timestamp || 0) - (b?.timestamp || 0),\n );\n }\n }\n\n return mergedAccountEdits;\n};\n\nconst backfillLiveCommentCommunityAddress = (\n comment: Comment | undefined,\n communityAddress: string | undefined,\n) => {\n if (!comment || comment.communityAddress || !communityAddress) {\n return;\n }\n\n try {\n Object.defineProperty(comment, \"communityAddress\", {\n value: communityAddress,\n writable: true,\n configurable: true,\n enumerable: false,\n });\n } catch (error) {\n try {\n comment.communityAddress = communityAddress;\n } catch (assignmentError) {\n log.trace(\"backfillLiveCommentCommunityAddress failed\", {\n cid: comment.cid,\n error,\n assignmentError,\n });\n }\n }\n};\n\n// TODO: we currently subscribe to updates for every single comment\n// in the user's account history. This probably does not scale, we\n// need to eventually schedule and queue older comments to look\n// for updates at a lower priority.\nexport const startUpdatingAccountCommentOnCommentUpdateEvents = async (\n comment: Comment,\n account: Account,\n accountCommentIndex: number,\n) => {\n assert(\n typeof accountCommentIndex === \"number\",\n `startUpdatingAccountCommentOnCommentUpdateEvents accountCommentIndex '${accountCommentIndex}' not a number`,\n );\n assert(\n typeof account?.id === \"string\",\n `startUpdatingAccountCommentOnCommentUpdateEvents account '${account}' account.id '${account?.id}' not a string`,\n );\n const commentArgument = comment;\n\n // comment doesn't have a cid yet, so can't receive updates\n if (!comment.cid) {\n return;\n }\n\n // account comment already updating\n if (accountsStore.getState().accountsCommentsUpdating[comment.cid]) {\n return;\n }\n accountsStore.setState(({ accountsCommentsUpdating }) => ({\n accountsCommentsUpdating: { ...accountsCommentsUpdating, [comment.cid]: true },\n }));\n\n // comment is not a `Comment` instance\n if (!comment.on) {\n comment = backfillPublicationCommunityAddress(\n await account.pkc.createComment(normalizePublicationOptionsForPkc(account.pkc, comment)),\n comment,\n );\n }\n\n const initialStoredComment =\n accountsStore.getState().accountsComments[account.id]?.[accountCommentIndex];\n backfillLiveCommentCommunityAddress(\n comment,\n getCommentCommunityAddress(commentArgument) ||\n initialStoredComment?.communityAddress ||\n initialStoredComment?.communityAddress,\n );\n\n comment.on(\"update\", async (updatedComment: Comment) => {\n const mapping =\n accountsStore.getState().commentCidsToAccountsComments[updatedComment.cid || \"\"];\n if (!mapping || mapping.accountId !== account.id) {\n accountsStore.setState(({ accountsCommentsUpdating }) => {\n const next = { ...accountsCommentsUpdating };\n delete next[updatedComment.cid || \"\"];\n return { accountsCommentsUpdating: next };\n });\n try {\n if (typeof comment.removeAllListeners === \"function\") comment.removeAllListeners();\n if (typeof (comment as any).stop === \"function\") (comment as any).stop();\n } catch (e) {\n log.trace(\"startUpdatingAccountCommentOnCommentUpdateEvents stop/removeAllListeners\", {\n cid: updatedComment.cid,\n error: e,\n });\n }\n return;\n }\n const currentIndex = mapping.accountCommentIndex;\n\n // merge should not be needed if pkc-js is implemented properly, but no harm in fixing potential errors\n const storedComment = accountsStore.getState().accountsComments[account.id]?.[currentIndex];\n updatedComment = utils.merge(commentArgument, comment, updatedComment);\n updatedComment.communityAddress =\n getCommentCommunityAddress(updatedComment) ||\n getCommentCommunityAddress(comment) ||\n getCommentCommunityAddress(commentArgument) ||\n storedComment?.communityAddress ||\n storedComment?.communityAddress;\n const normalizedUpdatedComment = addShortAddressesToAccountComment(\n normalizePublicationOptionsForStore(updatedComment) as Comment,\n ) as Comment;\n const storedUpdatedComment = sanitizeStoredAccountComment(normalizedUpdatedComment) as Comment;\n await accountsDatabase.addAccountComment(account.id, storedUpdatedComment, currentIndex);\n log(\"startUpdatingAccountCommentOnCommentUpdateEvents comment update\", {\n commentCid: comment.cid,\n accountCommentIndex: currentIndex,\n updatedComment: storedUpdatedComment,\n account,\n });\n accountsStore.setState(({ accountsComments, accountsCommentsIndexes }) => {\n // account no longer exists\n if (!accountsComments[account.id]) {\n log.error(\n `startUpdatingAccountCommentOnCommentUpdateEvents comment.on('update') invalid accountsStore.accountsComments['${account.id}'] '${\n accountsComments[account.id]\n }', account may have been deleted`,\n );\n return {};\n }\n\n const updatedAccountComments = [...accountsComments[account.id]];\n const previousComment = updatedAccountComments[currentIndex];\n const updatedAccountComment = utils.clone({\n ...storedUpdatedComment,\n index: currentIndex,\n accountId: account.id,\n });\n updatedAccountComments[currentIndex] = updatedAccountComment;\n const nextAccountsComments = {\n ...accountsComments,\n [account.id]: updatedAccountComments,\n };\n return {\n accountsComments: nextAccountsComments,\n accountsCommentsIndexes: {\n ...accountsCommentsIndexes,\n [account.id]: getAccountsCommentsIndexes({\n [account.id]: updatedAccountComments,\n } as AccountsComments)[account.id],\n },\n };\n });\n\n // update AccountCommentsReplies with new replies if has any new replies\n const replyPageArray: any[] = Object.values(normalizedUpdatedComment.replies?.pages || {});\n const getReplyCount = (replyPage: any) => replyPage?.comments?.length ?? 0;\n const replyCount =\n replyPageArray.length > 0\n ? replyPageArray.map(getReplyCount).reduce((prev, curr) => prev + curr)\n : 0;\n const hasReplies = replyCount > 0;\n const repliesAreValid = await utils.repliesAreValid(\n normalizedUpdatedComment,\n { validateReplies: false, blockCommunity: true },\n account.pkc,\n );\n\n if (hasReplies && repliesAreValid) {\n accountsStore.setState(({ accountsCommentsReplies }) => {\n // account no longer exists\n if (!accountsCommentsReplies[account.id]) {\n log.error(\n `startUpdatingAccountCommentOnCommentUpdateEvents comment.on('update') invalid accountsStore.accountsCommentsReplies['${account.id}'] '${\n accountsCommentsReplies[account.id]\n }', account may have been deleted`,\n );\n return {};\n }\n\n // check which replies are read or not\n const updatedAccountCommentsReplies: { [replyCid: string]: AccountCommentReply } = {};\n for (const replyPage of replyPageArray) {\n for (const reply of replyPage?.comments || []) {\n const normalizedReply = normalizePublicationOptionsForStore(reply) as Comment;\n normalizedReply.communityAddress =\n getCommentCommunityAddress(normalizedReply) ||\n normalizedUpdatedComment.communityAddress ||\n storedUpdatedComment.communityAddress;\n const markedAsRead =\n accountsCommentsReplies[account.id]?.[reply.cid]?.markedAsRead === true\n ? true\n : false;\n updatedAccountCommentsReplies[normalizedReply.cid] = {\n ...normalizedReply,\n markedAsRead,\n };\n }\n }\n\n // add all to database\n const promises = [];\n for (const replyCid in updatedAccountCommentsReplies) {\n promises.push(\n accountsDatabase.addAccountCommentReply(\n account.id,\n updatedAccountCommentsReplies[replyCid],\n ),\n );\n }\n Promise.all(promises);\n\n // set new store\n const newAccountCommentsReplies = {\n ...accountsCommentsReplies[account.id],\n ...updatedAccountCommentsReplies,\n };\n return {\n accountsCommentsReplies: {\n ...accountsCommentsReplies,\n [account.id]: newAccountCommentsReplies,\n },\n };\n });\n }\n });\n listeners.push(comment);\n comment.update().catch((error: unknown) => log.trace(\"comment.update error\", { comment, error }));\n};\n\n// internal accounts action: the comment CID is not known at the time of publishing, so every time\n// we fetch a new comment, check if its our own, and attempt to add the CID\nexport const addCidToAccountComment = async (comment: Comment) => {\n const { accounts } = accountsStore.getState();\n assert(accounts, `can't use accountsStore.accountActions before initialized`);\n const accountCommentsWithoutCids = getAccountsCommentsWithoutCids()[comment?.author?.address];\n if (!accountCommentsWithoutCids) {\n return;\n }\n for (const accountComment of accountCommentsWithoutCids) {\n // if author address and timestamp is the same, we assume it's the right comment\n if (accountComment.timestamp && accountComment.timestamp === comment.timestamp) {\n const commentWithCid = utils.merge(accountComment, comment);\n await accountsDatabase.addAccountComment(\n accountComment.accountId,\n commentWithCid,\n accountComment.index,\n );\n log(\"accountsActions.addCidToAccountComment\", {\n commentCid: comment.cid,\n accountCommentIndex: accountComment.index,\n accountComment: commentWithCid,\n });\n accountsStore.setState(\n ({ accountsComments, accountsCommentsIndexes, commentCidsToAccountsComments }) => {\n const updatedAccountComments = [...accountsComments[accountComment.accountId]];\n updatedAccountComments[accountComment.index] = commentWithCid;\n const newAccountsComments = {\n ...accountsComments,\n [accountComment.accountId]: updatedAccountComments,\n };\n return {\n accountsComments: newAccountsComments,\n accountsCommentsIndexes: {\n ...accountsCommentsIndexes,\n [accountComment.accountId]: getAccountsCommentsIndexes({\n [accountComment.accountId]: updatedAccountComments,\n } as AccountsComments)[accountComment.accountId],\n },\n commentCidsToAccountsComments: {\n ...commentCidsToAccountsComments,\n [comment.cid]: {\n accountId: accountComment.accountId,\n accountCommentIndex: accountComment.index,\n },\n },\n };\n },\n );\n\n startUpdatingAccountCommentOnCommentUpdateEvents(\n comment,\n accounts[accountComment.accountId],\n accountComment.index,\n ).catch((error: unknown) =>\n log.error(\n \"accountsActions.addCidToAccountComment startUpdatingAccountCommentOnCommentUpdateEvents error\",\n {\n comment,\n account: accounts[accountComment.accountId],\n accountCommentIndex: accountComment.index,\n error,\n },\n ),\n );\n break;\n }\n }\n};\n\n// cache the last result of this function\nlet previousAccountsCommentsJson: string;\nlet previousAccountsCommentsWithoutCids: any = {};\nconst getAccountsCommentsWithoutCids = () => {\n const { accounts, accountsComments } = accountsStore.getState();\n\n // same accounts comments as last time, return cached value\n const accountsCommentsJson = JSON.stringify(accountsComments);\n if (accountsCommentsJson === previousAccountsCommentsJson) {\n return previousAccountsCommentsWithoutCids;\n }\n previousAccountsCommentsJson = accountsCommentsJson;\n\n const accountsCommentsWithoutCids: AccountsComments = {};\n if (!accounts || !accountsComments) {\n return accountsCommentsWithoutCids;\n }\n for (const accountId in accountsComments) {\n const accountComments = accountsComments[accountId];\n const account = accounts[accountId];\n for (const accountCommentIndex in accountComments) {\n const accountComment = accountComments[accountCommentIndex];\n if (!accountComment.cid) {\n const authorAddress = account?.author?.address;\n if (!authorAddress) {\n continue;\n }\n if (!accountsCommentsWithoutCids[authorAddress]) {\n accountsCommentsWithoutCids[authorAddress] = [];\n }\n accountsCommentsWithoutCids[authorAddress].push(accountComment);\n }\n }\n }\n previousAccountsCommentsWithoutCids = accountsCommentsWithoutCids;\n return accountsCommentsWithoutCids;\n};\n\nexport const ensureAccountEditsLoaded = async (accountId: string) => {\n assert(\n accountId && typeof accountId === \"string\",\n `ensureAccountEditsLoaded invalid '${accountId}'`,\n );\n\n if (accountsStore.getState().accountsEditsLoaded[accountId]) {\n return;\n }\n const existingPromise = accountEditsLoadPromises.get(accountId);\n if (existingPromise) {\n return existingPromise;\n }\n\n const loadPromise = accountsDatabase\n .getAccountEdits(accountId)\n .then((loadedAccountEdits) => {\n accountsStore.setState(({ accountsEdits, accountsEditsLoaded }) => ({\n accountsEdits: {\n ...accountsEdits,\n [accountId]: mergeLoadedAccountEdits(loadedAccountEdits, accountsEdits[accountId]),\n },\n accountsEditsLoaded: { ...accountsEditsLoaded, [accountId]: true },\n }));\n })\n .finally(() => {\n accountEditsLoadPromises.delete(accountId);\n });\n accountEditsLoadPromises.set(accountId, loadPromise);\n return loadPromise;\n};\n\nexport const resetLazyAccountHistoryLoaders = () => {\n accountEditsLoadPromises.clear();\n};\n\n// internal accounts action: mark an account's notifications as read\nexport const markNotificationsAsRead = async (account: Account) => {\n const { accountsCommentsReplies } = accountsStore.getState();\n assert(\n typeof account?.id === \"string\",\n `accountsStore.markNotificationsAsRead invalid account argument '${account}'`,\n );\n\n // find all unread replies\n const repliesToMarkAsRead: AccountCommentsReplies = {};\n for (const replyCid in accountsCommentsReplies[account.id]) {\n if (!accountsCommentsReplies[account.id][replyCid].markedAsRead) {\n repliesToMarkAsRead[replyCid] = {\n ...accountsCommentsReplies[account.id][replyCid],\n markedAsRead: true,\n };\n }\n }\n\n // add all to database\n const promises = [];\n for (const replyCid in repliesToMarkAsRead) {\n promises.push(\n accountsDatabase.addAccountCommentReply(account.id, repliesToMarkAsRead[replyCid]),\n );\n }\n await Promise.all(promises);\n\n // add all to react store\n log(\"accountsActions.markNotificationsAsRead\", { account, repliesToMarkAsRead });\n accountsStore.setState(({ accountsCommentsReplies }) => {\n const updatedAccountCommentsReplies = {\n ...accountsCommentsReplies[account.id],\n ...repliesToMarkAsRead,\n };\n return {\n accountsCommentsReplies: {\n ...accountsCommentsReplies,\n [account.id]: updatedAccountCommentsReplies,\n },\n };\n });\n};\n\n// internal accounts action: if a community has a role with an account's address\n// add it to the account.communities database\nexport const addCommunityRoleToAccountsCommunities = async (community: Community) => {\n if (!community) {\n return;\n }\n const { accounts } = accountsStore.getState();\n assert(accounts, `can't use accountsStore.accountActions before initialized`);\n\n // find community roles to add and remove\n const getRole = (community: any, authorAddress: string) =>\n community.roles && community.roles[authorAddress];\n const getChange = (accounts: any, community: any) => {\n const toUpsert: string[] = [];\n const toRemove: string[] = [];\n for (const accountId in accounts) {\n const account = accounts[accountId];\n const role = getRole(community, account.author.address);\n if (!role) {\n if (account.communities[community.address]) {\n toRemove.push(accountId);\n }\n } else {\n const currentRole = account.communities[community.address]?.role;\n if (!currentRole || currentRole.role !== role.role) {\n toUpsert.push(accountId);\n }\n }\n }\n return {\n toUpsert,\n toRemove,\n hasChange: toUpsert.length !== 0 || toRemove.length !== 0,\n };\n };\n\n const { hasChange } = getChange(accounts, community);\n if (!hasChange) {\n return;\n }\n\n accountsStore.setState(({ accounts }) => {\n const { toUpsert, toRemove } = getChange(accounts, community);\n const nextAccounts = { ...accounts };\n\n // edit databases and build next accounts (toUpsert implies role exists from getChange)\n for (const accountId of toUpsert) {\n const account = { ...nextAccounts[accountId] };\n const role = community.roles![account.author.address];\n account.communities = {\n ...account.communities,\n [community.address]: { ...account.communities[community.address], role },\n };\n nextAccounts[accountId] = account;\n accountsDatabase.addAccount(account);\n }\n for (const accountId of toRemove) {\n const account = { ...nextAccounts[accountId] };\n account.communities = { ...account.communities };\n delete account.communities[community.address];\n nextAccounts[accountId] = account;\n accountsDatabase.addAccount(account);\n }\n\n log(\"accountsActions.addCommunityRoleToAccountsCommunities\", {\n community,\n toUpsert,\n toRemove,\n });\n return { accounts: nextAccounts };\n });\n};\n"]}
1
+ {"version":3,"file":"accounts-actions-internal.js","sourceRoot":"","sources":["../../../src/stores/accounts/accounts-actions-internal.ts"],"names":[],"mappings":"AAAA,4DAA4D;;;;;;;;;;AAE5D,OAAO,aAAa,EAAE,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC5D,OAAO,gBAAgB,MAAM,qBAAqB,CAAC;AACnD,OAAO,MAAM,MAAM,yBAAyB,CAAC;AAC7C,OAAO,MAAM,MAAM,kBAAkB,CAAC;AACtC,OAAO,OAAO,MAAM,oB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C;YACjC,MAAM,OAAO,qBAAQ,YAAY,CAAC,SAAS,CAAC,CAAE,CAAC;YAC/C,MAAM,IAAI,GAAG,SAAS,CAAC,KAAM,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;YACtD,OAAO,CAAC,WAAW,mCACd,OAAO,CAAC,WAAW,KACtB,CAAC,SAAS,CAAC,OAAO,CAAC,kCAAO,OAAO,CAAC,WAAW,CAAC,SAAS,CAAC,OAAO,CAAC,KAAE,IAAI,MACvE,CAAC;YACF,YAAY,CAAC,SAAS,CAAC,GAAG,OAAO,CAAC;YAClC,gBAAgB,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;QACvC,CAAC;QACD,KAAK,MAAM,SAAS,IAAI,QAAQ,EAAE,CAAC;YACjC,MAAM,OAAO,qBAAQ,YAAY,CAAC,SAAS,CAAC,CAAE,CAAC;YAC/C,OAAO,CAAC,WAAW,qBAAQ,OAAO,CAAC,WAAW,CAAE,CAAC;YACjD,OAAO,OAAO,CAAC,WAAW,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;YAC9C,YAAY,CAAC,SAAS,CAAC,GAAG,OAAO,CAAC;YAClC,gBAAgB,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;QACvC,CAAC;QAED,GAAG,CAAC,uDAAuD,EAAE;YAC3D,SAAS;YACT,QAAQ;YACR,QAAQ;SACT,CAAC,CAAC;QACH,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,CAAC;IACpC,CAAC,CAAC,CAAC;AACL,CAAC,CAAA,CAAC","sourcesContent":["// internal accounts actions that are not called by the user\n\nimport accountsStore, { listeners } from \"./accounts-store\";\nimport accountsDatabase from \"./accounts-database\";\nimport Logger from \"@pkcprotocol/pkc-logger\";\nimport assert from \"../../lib/assert\";\nimport isEqual from \"../../lib/is-equal\";\nconst log = Logger(\"bitsocial-react-hooks:accounts:stores\");\nimport {\n Account,\n AccountCommentReply,\n Comment,\n AccountsComments,\n AccountCommentsReplies,\n Community,\n} from \"../../types\";\nimport utils from \"../../lib/utils\";\nimport {\n backfillPublicationCommunityAddress,\n getCommentCommunityAddress,\n normalizePublicationOptionsForPkc,\n normalizePublicationOptionsForStore,\n} from \"../../lib/pkc-compat\";\nimport {\n addShortAddressesToAccountComment,\n getAccountsCommentsIndexes,\n sanitizeStoredAccountComment,\n} from \"./utils\";\n\nconst accountEditsLoadPromises = new Map<string, Promise<void>>();\n\nconst doesStoredAccountEditMatch = (storedAccountEdit: any, targetStoredAccountEdit: any) =>\n storedAccountEdit?.clientId && targetStoredAccountEdit?.clientId\n ? storedAccountEdit.clientId === targetStoredAccountEdit.clientId\n : isEqual(storedAccountEdit, targetStoredAccountEdit);\n\nconst mergeLoadedAccountEdits = (\n loadedAccountEdits: Record<string, any[]> | undefined,\n currentAccountEdits: Record<string, any[]> | undefined,\n) => {\n const mergedAccountEdits: Record<string, any[]> = { ...(loadedAccountEdits || {}) };\n const editTargets = new Set([\n ...Object.keys(loadedAccountEdits || {}),\n ...Object.keys(currentAccountEdits || {}),\n ]);\n\n for (const editTarget of editTargets) {\n const mergedTargetEdits = [...(loadedAccountEdits?.[editTarget] || [])];\n for (const currentAccountEdit of currentAccountEdits?.[editTarget] || []) {\n const alreadyLoaded = mergedTargetEdits.some((loadedAccountEdit) =>\n doesStoredAccountEditMatch(loadedAccountEdit, currentAccountEdit),\n );\n if (!alreadyLoaded) {\n mergedTargetEdits.push(currentAccountEdit);\n }\n }\n if (mergedTargetEdits.length > 0) {\n mergedAccountEdits[editTarget] = mergedTargetEdits.sort(\n (a, b) => (a?.timestamp || 0) - (b?.timestamp || 0),\n );\n }\n }\n\n return mergedAccountEdits;\n};\n\nconst backfillLiveCommentCommunityAddress = (\n comment: Comment | undefined,\n communityAddress: string | undefined,\n) => {\n if (!comment || comment.communityAddress || !communityAddress) {\n return;\n }\n\n try {\n Object.defineProperty(comment, \"communityAddress\", {\n value: communityAddress,\n writable: true,\n configurable: true,\n enumerable: false,\n });\n } catch (error) {\n try {\n comment.communityAddress = communityAddress;\n } catch (assignmentError) {\n log.trace(\"backfillLiveCommentCommunityAddress failed\", {\n cid: comment.cid,\n error,\n assignmentError,\n });\n }\n }\n};\n\n// TODO: we currently subscribe to updates for every single comment\n// in the user's account history. This probably does not scale, we\n// need to eventually schedule and queue older comments to look\n// for updates at a lower priority.\nexport const startUpdatingAccountCommentOnCommentUpdateEvents = async (\n comment: Comment,\n account: Account,\n accountCommentIndex: number,\n) => {\n assert(\n typeof accountCommentIndex === \"number\",\n `startUpdatingAccountCommentOnCommentUpdateEvents accountCommentIndex '${accountCommentIndex}' not a number`,\n );\n assert(\n typeof account?.id === \"string\",\n `startUpdatingAccountCommentOnCommentUpdateEvents account '${account}' account.id '${account?.id}' not a string`,\n );\n const commentArgument = comment;\n\n // comment doesn't have a cid yet, so can't receive updates\n if (!comment.cid) {\n return;\n }\n\n // account comment already updating\n if (accountsStore.getState().accountsCommentsUpdating[comment.cid]) {\n return;\n }\n accountsStore.setState(({ accountsCommentsUpdating }) => ({\n accountsCommentsUpdating: { ...accountsCommentsUpdating, [comment.cid]: true },\n }));\n\n // comment is not a `Comment` instance\n if (!comment.on) {\n comment = backfillPublicationCommunityAddress(\n await account.pkc.createComment(normalizePublicationOptionsForPkc(account.pkc, comment)),\n comment,\n );\n }\n\n const initialStoredComment =\n accountsStore.getState().accountsComments[account.id]?.[accountCommentIndex];\n backfillLiveCommentCommunityAddress(\n comment,\n getCommentCommunityAddress(commentArgument) ||\n initialStoredComment?.communityAddress ||\n initialStoredComment?.communityAddress,\n );\n\n comment.on(\"update\", async (updatedComment: Comment) => {\n const mapping =\n accountsStore.getState().commentCidsToAccountsComments[updatedComment.cid || \"\"];\n if (!mapping || mapping.accountId !== account.id) {\n accountsStore.setState(({ accountsCommentsUpdating }) => {\n const next = { ...accountsCommentsUpdating };\n delete next[updatedComment.cid || \"\"];\n return { accountsCommentsUpdating: next };\n });\n try {\n if (typeof comment.removeAllListeners === \"function\") comment.removeAllListeners();\n if (typeof (comment as any).stop === \"function\") (comment as any).stop();\n } catch (e) {\n log.trace(\"startUpdatingAccountCommentOnCommentUpdateEvents stop/removeAllListeners\", {\n cid: updatedComment.cid,\n error: e,\n });\n }\n return;\n }\n const currentIndex = mapping.accountCommentIndex;\n\n // merge should not be needed if pkc-js is implemented properly, but no harm in fixing potential errors\n const storedComment = accountsStore.getState().accountsComments[account.id]?.[currentIndex];\n updatedComment = utils.merge(commentArgument, comment, updatedComment);\n updatedComment.communityAddress =\n getCommentCommunityAddress(updatedComment) ||\n getCommentCommunityAddress(comment) ||\n getCommentCommunityAddress(commentArgument) ||\n storedComment?.communityAddress ||\n storedComment?.communityAddress;\n const normalizedUpdatedComment = addShortAddressesToAccountComment(\n normalizePublicationOptionsForStore(updatedComment) as Comment,\n ) as Comment;\n const storedUpdatedComment = sanitizeStoredAccountComment(normalizedUpdatedComment) as Comment;\n await accountsDatabase.addAccountComment(account.id, storedUpdatedComment, currentIndex);\n log(\"startUpdatingAccountCommentOnCommentUpdateEvents comment update\", {\n commentCid: comment.cid,\n accountCommentIndex: currentIndex,\n updatedComment: storedUpdatedComment,\n account,\n });\n accountsStore.setState(({ accountsComments, accountsCommentsIndexes }) => {\n // account no longer exists\n if (!accountsComments[account.id]) {\n log.error(\n `startUpdatingAccountCommentOnCommentUpdateEvents comment.on('update') invalid accountsStore.accountsComments['${account.id}'] '${\n accountsComments[account.id]\n }', account may have been deleted`,\n );\n return {};\n }\n\n const updatedAccountComments = [...accountsComments[account.id]];\n const previousComment = updatedAccountComments[currentIndex];\n const updatedAccountComment = utils.clone({\n ...storedUpdatedComment,\n index: currentIndex,\n accountId: account.id,\n });\n updatedAccountComments[currentIndex] = updatedAccountComment;\n const nextAccountsComments = {\n ...accountsComments,\n [account.id]: updatedAccountComments,\n };\n return {\n accountsComments: nextAccountsComments,\n accountsCommentsIndexes: {\n ...accountsCommentsIndexes,\n [account.id]: getAccountsCommentsIndexes({\n [account.id]: updatedAccountComments,\n } as AccountsComments)[account.id],\n },\n };\n });\n\n // update AccountCommentsReplies with new replies if has any new replies\n const replyPageArray: any[] = Object.values(normalizedUpdatedComment.replies?.pages || {});\n const getReplyCount = (replyPage: any) => replyPage?.comments?.length ?? 0;\n const replyCount =\n replyPageArray.length > 0\n ? replyPageArray.map(getReplyCount).reduce((prev, curr) => prev + curr)\n : 0;\n const hasReplies = replyCount > 0;\n const repliesAreValid = await utils.repliesAreValid(\n normalizedUpdatedComment,\n { validateReplies: false, blockCommunity: true },\n account.pkc,\n );\n\n if (hasReplies && repliesAreValid) {\n accountsStore.setState(({ accountsCommentsReplies }) => {\n // account no longer exists\n if (!accountsCommentsReplies[account.id]) {\n log.error(\n `startUpdatingAccountCommentOnCommentUpdateEvents comment.on('update') invalid accountsStore.accountsCommentsReplies['${account.id}'] '${\n accountsCommentsReplies[account.id]\n }', account may have been deleted`,\n );\n return {};\n }\n\n // check which replies are read or not\n const updatedAccountCommentsReplies: { [replyCid: string]: AccountCommentReply } = {};\n for (const replyPage of replyPageArray) {\n for (const reply of replyPage?.comments || []) {\n const normalizedReply = normalizePublicationOptionsForStore(reply) as Comment;\n normalizedReply.communityAddress =\n getCommentCommunityAddress(normalizedReply) ||\n normalizedUpdatedComment.communityAddress ||\n storedUpdatedComment.communityAddress;\n const markedAsRead =\n accountsCommentsReplies[account.id]?.[reply.cid]?.markedAsRead === true\n ? true\n : false;\n updatedAccountCommentsReplies[normalizedReply.cid] = {\n ...normalizedReply,\n markedAsRead,\n };\n }\n }\n\n // add all to database\n const promises = [];\n for (const replyCid in updatedAccountCommentsReplies) {\n promises.push(\n accountsDatabase.addAccountCommentReply(\n account.id,\n updatedAccountCommentsReplies[replyCid],\n ),\n );\n }\n Promise.all(promises);\n\n // set new store\n const newAccountCommentsReplies = {\n ...accountsCommentsReplies[account.id],\n ...updatedAccountCommentsReplies,\n };\n return {\n accountsCommentsReplies: {\n ...accountsCommentsReplies,\n [account.id]: newAccountCommentsReplies,\n },\n };\n });\n }\n });\n listeners.push(comment);\n comment.update().catch((error: unknown) => log.trace(\"comment.update error\", { comment, error }));\n};\n\n// internal accounts action: the comment CID is not known at the time of publishing, so every time\n// we fetch a new comment, check if its our own, and attempt to add the CID\nexport const addCidToAccountComment = async (comment: Comment) => {\n const { accounts } = accountsStore.getState();\n assert(accounts, `can't use accountsStore.accountActions before initialized`);\n const accountCommentsWithoutCids = getAccountsCommentsWithoutCids()[comment?.author?.address];\n if (!accountCommentsWithoutCids) {\n return;\n }\n for (const accountComment of accountCommentsWithoutCids) {\n // if author address and timestamp is the same, we assume it's the right comment\n if (accountComment.timestamp && accountComment.timestamp === comment.timestamp) {\n const commentWithCid = utils.merge(accountComment, comment);\n await accountsDatabase.addAccountComment(\n accountComment.accountId,\n commentWithCid,\n accountComment.index,\n );\n log(\"accountsActions.addCidToAccountComment\", {\n commentCid: comment.cid,\n accountCommentIndex: accountComment.index,\n accountComment: commentWithCid,\n });\n accountsStore.setState(\n ({ accountsComments, accountsCommentsIndexes, commentCidsToAccountsComments }) => {\n const updatedAccountComments = [...accountsComments[accountComment.accountId]];\n updatedAccountComments[accountComment.index] = commentWithCid;\n const newAccountsComments = {\n ...accountsComments,\n [accountComment.accountId]: updatedAccountComments,\n };\n return {\n accountsComments: newAccountsComments,\n accountsCommentsIndexes: {\n ...accountsCommentsIndexes,\n [accountComment.accountId]: getAccountsCommentsIndexes({\n [accountComment.accountId]: updatedAccountComments,\n } as AccountsComments)[accountComment.accountId],\n },\n commentCidsToAccountsComments: {\n ...commentCidsToAccountsComments,\n [comment.cid]: {\n accountId: accountComment.accountId,\n accountCommentIndex: accountComment.index,\n },\n },\n };\n },\n );\n\n startUpdatingAccountCommentOnCommentUpdateEvents(\n comment,\n accounts[accountComment.accountId],\n accountComment.index,\n ).catch((error: unknown) =>\n log.error(\n \"accountsActions.addCidToAccountComment startUpdatingAccountCommentOnCommentUpdateEvents error\",\n {\n comment,\n account: accounts[accountComment.accountId],\n accountCommentIndex: accountComment.index,\n error,\n },\n ),\n );\n break;\n }\n }\n};\n\n// cache the last result of this function\nlet previousAccountsCommentsJson: string;\nlet previousAccountsCommentsWithoutCids: any = {};\nconst getAccountsCommentsWithoutCids = () => {\n const { accounts, accountsComments } = accountsStore.getState();\n\n // same accounts comments as last time, return cached value\n const accountsCommentsJson = JSON.stringify(accountsComments);\n if (accountsCommentsJson === previousAccountsCommentsJson) {\n return previousAccountsCommentsWithoutCids;\n }\n previousAccountsCommentsJson = accountsCommentsJson;\n\n const accountsCommentsWithoutCids: AccountsComments = {};\n if (!accounts || !accountsComments) {\n return accountsCommentsWithoutCids;\n }\n for (const accountId in accountsComments) {\n const accountComments = accountsComments[accountId];\n const account = accounts[accountId];\n for (const accountCommentIndex in accountComments) {\n const accountComment = accountComments[accountCommentIndex];\n if (!accountComment.cid) {\n const authorAddress = account?.author?.address;\n if (!authorAddress) {\n continue;\n }\n if (!accountsCommentsWithoutCids[authorAddress]) {\n accountsCommentsWithoutCids[authorAddress] = [];\n }\n accountsCommentsWithoutCids[authorAddress].push(accountComment);\n }\n }\n }\n previousAccountsCommentsWithoutCids = accountsCommentsWithoutCids;\n return accountsCommentsWithoutCids;\n};\n\nexport const ensureAccountEditsLoaded = async (accountId: string) => {\n assert(\n accountId && typeof accountId === \"string\",\n `ensureAccountEditsLoaded invalid '${accountId}'`,\n );\n\n if (accountsStore.getState().accountsEditsLoaded[accountId]) {\n return;\n }\n const existingPromise = accountEditsLoadPromises.get(accountId);\n if (existingPromise) {\n return existingPromise;\n }\n\n const loadPromise = accountsDatabase\n .getAccountEdits(accountId)\n .then((loadedAccountEdits) => {\n accountsStore.setState(({ accountsEdits, accountsEditsLoaded }) => ({\n accountsEdits: {\n ...accountsEdits,\n [accountId]: mergeLoadedAccountEdits(loadedAccountEdits, accountsEdits[accountId]),\n },\n accountsEditsLoaded: { ...accountsEditsLoaded, [accountId]: true },\n }));\n })\n .finally(() => {\n accountEditsLoadPromises.delete(accountId);\n });\n accountEditsLoadPromises.set(accountId, loadPromise);\n return loadPromise;\n};\n\nexport const resetLazyAccountHistoryLoaders = () => {\n accountEditsLoadPromises.clear();\n};\n\n// internal accounts action: mark an account's notifications as read\nexport const markNotificationsAsRead = async (account: Account) => {\n const { accountsCommentsReplies } = accountsStore.getState();\n assert(\n typeof account?.id === \"string\",\n `accountsStore.markNotificationsAsRead invalid account argument '${account}'`,\n );\n\n // find all unread replies\n const repliesToMarkAsRead: AccountCommentsReplies = {};\n for (const replyCid in accountsCommentsReplies[account.id]) {\n if (!accountsCommentsReplies[account.id][replyCid].markedAsRead) {\n repliesToMarkAsRead[replyCid] = {\n ...accountsCommentsReplies[account.id][replyCid],\n markedAsRead: true,\n };\n }\n }\n\n // add all to database\n const promises = [];\n for (const replyCid in repliesToMarkAsRead) {\n promises.push(\n accountsDatabase.addAccountCommentReply(account.id, repliesToMarkAsRead[replyCid]),\n );\n }\n await Promise.all(promises);\n\n // add all to react store\n log(\"accountsActions.markNotificationsAsRead\", { account, repliesToMarkAsRead });\n accountsStore.setState(({ accountsCommentsReplies }) => {\n const updatedAccountCommentsReplies = {\n ...accountsCommentsReplies[account.id],\n ...repliesToMarkAsRead,\n };\n return {\n accountsCommentsReplies: {\n ...accountsCommentsReplies,\n [account.id]: updatedAccountCommentsReplies,\n },\n };\n });\n};\n\n// internal accounts action: if a community has a role with an account's address\n// add it to the account.communities database\nexport const addCommunityRoleToAccountsCommunities = async (community: Community) => {\n if (!community) {\n return;\n }\n const { accounts } = accountsStore.getState();\n assert(accounts, `can't use accountsStore.accountActions before initialized`);\n\n // find community roles to add and remove\n const getRole = (community: any, authorAddress: string) =>\n community.roles && community.roles[authorAddress];\n const getChange = (accounts: any, community: any) => {\n const toUpsert: string[] = [];\n const toRemove: string[] = [];\n for (const accountId in accounts) {\n const account = accounts[accountId];\n const role = getRole(community, account.author.address);\n if (!role) {\n if (account.communities[community.address]) {\n toRemove.push(accountId);\n }\n } else {\n const currentRole = account.communities[community.address]?.role;\n if (!currentRole || currentRole.role !== role.role) {\n toUpsert.push(accountId);\n }\n }\n }\n return {\n toUpsert,\n toRemove,\n hasChange: toUpsert.length !== 0 || toRemove.length !== 0,\n };\n };\n\n const { hasChange } = getChange(accounts, community);\n if (!hasChange) {\n return;\n }\n\n accountsStore.setState(({ accounts }) => {\n const { toUpsert, toRemove } = getChange(accounts, community);\n const nextAccounts = { ...accounts };\n\n // edit databases and build next accounts (toUpsert implies role exists from getChange)\n for (const accountId of toUpsert) {\n const account = { ...nextAccounts[accountId] };\n const role = community.roles![account.author.address];\n account.communities = {\n ...account.communities,\n [community.address]: { ...account.communities[community.address], role },\n };\n nextAccounts[accountId] = account;\n accountsDatabase.addAccount(account);\n }\n for (const accountId of toRemove) {\n const account = { ...nextAccounts[accountId] };\n account.communities = { ...account.communities };\n delete account.communities[community.address];\n nextAccounts[accountId] = account;\n accountsDatabase.addAccount(account);\n }\n\n log(\"accountsActions.addCommunityRoleToAccountsCommunities\", {\n community,\n toUpsert,\n toRemove,\n });\n return { accounts: nextAccounts };\n });\n};\n"]}
@@ -26,12 +26,12 @@ import accountGenerator from "./account-generator.js";
26
26
  import Logger from "@pkcprotocol/pkc-logger";
27
27
  import validator from "../../lib/validator.js";
28
28
  import chain from "../../lib/chain/index.js";
29
- import assert from "assert";
29
+ import assert from "../../lib/assert.js";
30
30
  const log = Logger("bitsocial-react-hooks:accounts:stores");
31
31
  import * as accountsActionsInternal from "./accounts-actions-internal.js";
32
32
  import { backfillPublicationCommunityAddress, createPkcCommunity, createPkcCommunityEdit, getPkcCommunityAddresses, normalizeCommunityEditOptionsForPkc, normalizePublicationOptionsForStore, normalizePublicationOptionsForPkc, withPublishChallengeAnswersCompat, } from "../../lib/pkc-compat.js";
33
33
  import { getAccountCommentsIndex, getAccountCommunities, getCommentCidsToAccountsComments, COMMENT_MODERATION_AUTHOR_SUMMARY_KEY, getAccountEditPropertySummary, fetchCommentLinkDimensions, getAccountCommentDepth, addShortAddressesToAccountComment, sanitizeAccountCommentForState, sanitizeStoredAccountComment, getFreshestLoadedComment, getInitAccountCommentsToUpdate, } from "./utils.js";
34
- import isEqual from "lodash.isequal";
34
+ import isEqual from "../../lib/is-equal.js";
35
35
  import { v4 as uuid } from "uuid";
36
36
  import utils from "../../lib/utils/index.js";
37
37
  import { addOptimisticVoteMetadata } from "../../lib/utils/optimistic-vote-counts.js";