@amityco/ts-sdk 7.8.1-1b0200c.0 → 7.8.1-2caef95.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (111) hide show
  1. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/@types/domains/client.d.ts +4 -0
  2. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/@types/domains/client.d.ts.map +1 -1
  3. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/@types/domains/client.js.map +1 -1
  4. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/@types/domains/content.d.ts +1 -0
  5. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/@types/domains/content.d.ts.map +1 -1
  6. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/@types/domains/content.js.map +1 -1
  7. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/@types/domains/hashtag.d.ts +11 -0
  8. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/@types/domains/hashtag.d.ts.map +1 -0
  9. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/@types/domains/hashtag.js +2 -0
  10. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/@types/domains/hashtag.js.map +1 -0
  11. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/@types/domains/poll.d.ts +3 -1
  12. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/@types/domains/poll.d.ts.map +1 -1
  13. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/@types/domains/poll.js.map +1 -1
  14. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/@types/domains/post.d.ts +14 -1
  15. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/@types/domains/post.d.ts.map +1 -1
  16. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/@types/domains/post.js.map +1 -1
  17. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/@types/index.d.ts +1 -0
  18. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/@types/index.d.ts.map +1 -1
  19. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/@types/index.js +1 -0
  20. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/@types/index.js.map +1 -1
  21. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/client/api/getShareableLinkConfiguration.d.ts +16 -0
  22. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/client/api/getShareableLinkConfiguration.d.ts.map +1 -0
  23. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/client/api/getShareableLinkConfiguration.js +21 -0
  24. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/client/api/getShareableLinkConfiguration.js.map +1 -0
  25. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/client/api/index.d.ts +1 -0
  26. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/client/api/index.d.ts.map +1 -1
  27. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/client/api/index.js +1 -0
  28. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/client/api/index.js.map +1 -1
  29. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/pollRepository/api/createPoll.d.ts +3 -3
  30. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/pollRepository/api/createPoll.d.ts.map +1 -1
  31. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/pollRepository/api/createPoll.js +2 -2
  32. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/pollRepository/api/createPoll.js.map +1 -1
  33. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/api/createPost.d.ts +1 -1
  34. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/api/createPost.js.map +1 -1
  35. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/api/editPost.d.ts +1 -1
  36. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/api/editPost.js.map +1 -1
  37. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/api/queryPosts.js +2 -2
  38. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/api/queryPosts.js.map +1 -1
  39. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/getPostsByHashtag/SearchPostLiveCollectionController.d.ts +14 -0
  40. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/getPostsByHashtag/SearchPostLiveCollectionController.d.ts.map +1 -0
  41. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/getPostsByHashtag/SearchPostLiveCollectionController.js +126 -0
  42. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/getPostsByHashtag/SearchPostLiveCollectionController.js.map +1 -0
  43. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/getPostsByHashtag/SearchPostPaginationController.d.ts +5 -0
  44. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/getPostsByHashtag/SearchPostPaginationController.d.ts.map +1 -0
  45. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/getPostsByHashtag/SearchPostPaginationController.js +27 -0
  46. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/getPostsByHashtag/SearchPostPaginationController.js.map +1 -0
  47. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/getPostsByHashtag/SearchPostQueryStreamController.d.ts +15 -0
  48. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/getPostsByHashtag/SearchPostQueryStreamController.d.ts.map +1 -0
  49. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/getPostsByHashtag/SearchPostQueryStreamController.js +65 -0
  50. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/getPostsByHashtag/SearchPostQueryStreamController.js.map +1 -0
  51. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/index.d.ts +1 -0
  52. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/index.d.ts.map +1 -1
  53. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/index.js +1 -0
  54. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/index.js.map +1 -1
  55. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/searchPostsByHashtag.d.ts +22 -0
  56. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/searchPostsByHashtag.d.ts.map +1 -0
  57. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/searchPostsByHashtag.js +45 -0
  58. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/searchPostsByHashtag.js.map +1 -0
  59. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/tsconfig.tsbuildinfo +1 -1
  60. package/dist/@types/domains/client.d.ts +4 -0
  61. package/dist/@types/domains/client.d.ts.map +1 -1
  62. package/dist/@types/domains/content.d.ts +1 -0
  63. package/dist/@types/domains/content.d.ts.map +1 -1
  64. package/dist/@types/domains/hashtag.d.ts +11 -0
  65. package/dist/@types/domains/hashtag.d.ts.map +1 -0
  66. package/dist/@types/domains/poll.d.ts +3 -1
  67. package/dist/@types/domains/poll.d.ts.map +1 -1
  68. package/dist/@types/domains/post.d.ts +14 -1
  69. package/dist/@types/domains/post.d.ts.map +1 -1
  70. package/dist/@types/index.d.ts +1 -0
  71. package/dist/@types/index.d.ts.map +1 -1
  72. package/dist/client/api/getShareableLinkConfiguration.d.ts +16 -0
  73. package/dist/client/api/getShareableLinkConfiguration.d.ts.map +1 -0
  74. package/dist/client/api/index.d.ts +1 -0
  75. package/dist/client/api/index.d.ts.map +1 -1
  76. package/dist/index.cjs.js +257 -3
  77. package/dist/index.esm.js +257 -3
  78. package/dist/index.umd.js +4 -4
  79. package/dist/pollRepository/api/createPoll.d.ts +3 -3
  80. package/dist/pollRepository/api/createPoll.d.ts.map +1 -1
  81. package/dist/postRepository/api/createPost.d.ts +1 -1
  82. package/dist/postRepository/api/editPost.d.ts +1 -1
  83. package/dist/postRepository/observers/getPostsByHashtag/SearchPostLiveCollectionController.d.ts +14 -0
  84. package/dist/postRepository/observers/getPostsByHashtag/SearchPostLiveCollectionController.d.ts.map +1 -0
  85. package/dist/postRepository/observers/getPostsByHashtag/SearchPostPaginationController.d.ts +5 -0
  86. package/dist/postRepository/observers/getPostsByHashtag/SearchPostPaginationController.d.ts.map +1 -0
  87. package/dist/postRepository/observers/getPostsByHashtag/SearchPostQueryStreamController.d.ts +15 -0
  88. package/dist/postRepository/observers/getPostsByHashtag/SearchPostQueryStreamController.d.ts.map +1 -0
  89. package/dist/postRepository/observers/index.d.ts +1 -0
  90. package/dist/postRepository/observers/index.d.ts.map +1 -1
  91. package/dist/postRepository/observers/searchPostsByHashtag.d.ts +22 -0
  92. package/dist/postRepository/observers/searchPostsByHashtag.d.ts.map +1 -0
  93. package/package.json +1 -1
  94. package/src/@types/domains/client.ts +5 -0
  95. package/src/@types/domains/content.ts +1 -0
  96. package/src/@types/domains/hashtag.ts +11 -0
  97. package/src/@types/domains/poll.ts +3 -1
  98. package/src/@types/domains/post.ts +18 -1
  99. package/src/@types/index.ts +1 -0
  100. package/src/client/api/getShareableLinkConfiguration.ts +26 -0
  101. package/src/client/api/index.ts +2 -0
  102. package/src/pollRepository/api/createPoll.ts +3 -3
  103. package/src/postRepository/api/createPost.ts +1 -1
  104. package/src/postRepository/api/editPost.ts +1 -1
  105. package/src/postRepository/api/queryPosts.ts +2 -2
  106. package/src/postRepository/observers/getPostsByHashtag/SearchPostLiveCollectionController.ts +183 -0
  107. package/src/postRepository/observers/getPostsByHashtag/SearchPostPaginationController.ts +49 -0
  108. package/src/postRepository/observers/getPostsByHashtag/SearchPostQueryStreamController.ts +99 -0
  109. package/src/postRepository/observers/index.ts +1 -0
  110. package/src/postRepository/observers/searchPostsByHashtag.ts +56 -0
  111. package/tsconfig.tsbuildinfo +1 -1
@@ -0,0 +1,99 @@
1
+ import { QueryStreamController } from '~/core/liveCollection/QueryStreamController';
2
+ import { pullFromCache, pushToCache } from '~/cache/api';
3
+ import { ingestInCache } from '~/cache/api/ingestInCache';
4
+ import { getResolver } from '~/core/model';
5
+ import { getActiveClient } from '~/client';
6
+ import { EnumPostActions } from '../enums';
7
+
8
+ export class SearchPostQueryStreamController extends QueryStreamController<
9
+ Amity.PostPayload,
10
+ Amity.SearchPostWithHashtagLiveCollection
11
+ > {
12
+ private notifyChange: (params: Amity.LiveCollectionNotifyParams) => void;
13
+
14
+ private preparePayload: (response: Amity.PostPayload) => Amity.ProcessedPostPayload;
15
+
16
+ constructor(
17
+ query: Amity.SearchPostWithHashtagLiveCollection,
18
+ cacheKey: string[],
19
+ notifyChange: (params: Amity.LiveCollectionNotifyParams) => void,
20
+ preparePayload: (response: Amity.PostPayload) => Amity.ProcessedPostPayload,
21
+ ) {
22
+ super(query, cacheKey);
23
+ this.notifyChange = notifyChange;
24
+ this.preparePayload = preparePayload;
25
+ }
26
+
27
+ async saveToMainDB(response: Amity.PostPayload) {
28
+ const processedPayload = await this.preparePayload(response);
29
+
30
+ const client = getActiveClient();
31
+ const cachedAt = client.cache && Date.now();
32
+
33
+ if (client.cache) {
34
+ ingestInCache(processedPayload, { cachedAt });
35
+ }
36
+ }
37
+
38
+ appendToQueryStream(
39
+ response: Amity.PostPayload & Partial<Amity.Pagination>,
40
+ direction: Amity.LiveCollectionPageDirection,
41
+ refresh = false,
42
+ ) {
43
+ if (refresh) {
44
+ pushToCache(this.cacheKey, {
45
+ data: response.posts.map(getResolver('post')),
46
+ });
47
+ } else {
48
+ const collection = pullFromCache<Amity.PostLiveCollectionCache>(this.cacheKey)?.data;
49
+
50
+ const posts = collection?.data ?? [];
51
+
52
+ pushToCache(this.cacheKey, {
53
+ ...collection,
54
+ data: [...new Set([...posts, ...response.posts.map(getResolver('post'))])],
55
+ });
56
+ }
57
+ }
58
+
59
+ reactor(action: EnumPostActions) {
60
+ return (post: Amity.InternalPost) => {
61
+ const collection = pullFromCache<Amity.PostLiveCollectionCache>(this.cacheKey)?.data;
62
+
63
+ if (!collection) return;
64
+
65
+ if (post.parentPostId && post.isDeleted) {
66
+ const parentPost = pullFromCache<Amity.InternalPost>([
67
+ 'post',
68
+ 'get',
69
+ post.parentPostId,
70
+ ])?.data;
71
+
72
+ if (!parentPost) return;
73
+
74
+ parentPost.children = parentPost.children.filter(childId => childId !== post.postId);
75
+ pushToCache(['post', 'get', parentPost.postId], parentPost);
76
+ }
77
+
78
+ if (action === EnumPostActions.OnPostDeclined) {
79
+ collection.data = collection.data.filter(postId => postId !== post.postId);
80
+ }
81
+
82
+ if (action === EnumPostActions.OnPostCreated || action === EnumPostActions.OnPostApproved) {
83
+ collection.data = [...new Set([post.postId, ...collection.data])];
84
+ }
85
+
86
+ pushToCache(this.cacheKey, collection);
87
+ this.notifyChange({ origin: Amity.LiveDataOrigin.EVENT, loading: false });
88
+ };
89
+ }
90
+
91
+ subscribeRTE(
92
+ createSubscriber: {
93
+ fn: (reactor: (post: Amity.InternalPost) => void) => Amity.Unsubscriber;
94
+ action: EnumPostActions;
95
+ }[],
96
+ ) {
97
+ return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
98
+ }
99
+ }
@@ -3,3 +3,4 @@ export * from './getPosts';
3
3
  export * from './getPinnedPosts';
4
4
  export * from './getGlobalPinnedPosts';
5
5
  export * from './semanticSearchPosts';
6
+ export * from './searchPostsByHashtag';
@@ -0,0 +1,56 @@
1
+ import { getActiveClient } from '~/client/api';
2
+ import { dropFromCache } from '~/cache/api';
3
+
4
+ import { ENABLE_CACHE_MESSAGE } from '~/utils/constants';
5
+ import { SearchPostLiveCollectionController } from './getPostsByHashtag/SearchPostLiveCollectionController';
6
+
7
+ /* begin_public_function
8
+ id: post.query
9
+ */
10
+ /**
11
+ * ```js
12
+ * import { PostRepository } from '@amityco/ts-sdk'
13
+ *
14
+ * let posts = []
15
+ * const unsub = PostRepository.searchPostsByHashtag({
16
+ * hashtags: ['amity'],
17
+ * limit: 10,
18
+ * }, response => merge(posts, response.data))
19
+ * ```
20
+ *
21
+ * Observe all mutations on a list of {@link Amity.Post} for a given target object
22
+ *
23
+ * @param params.hashtags the hashtags to search for
24
+ * @param callback the function to call when new data are available
25
+ * @param config
26
+ * @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the messages
27
+ *
28
+ * @category Posts Live Collection
29
+ */
30
+ export const searchPostsByHashtag = (
31
+ params: Amity.SearchPostWithHashtagLiveCollection,
32
+ callback: Amity.LiveCollectionCallback<Amity.Post>,
33
+ config?: Amity.LiveCollectionConfig,
34
+ ): Amity.Unsubscriber => {
35
+ const { log, cache } = getActiveClient();
36
+
37
+ if (!cache) {
38
+ console.log(ENABLE_CACHE_MESSAGE);
39
+ }
40
+
41
+ const timestamp = Date.now();
42
+ log(`searchPostsByHashtag(tmpid: ${timestamp}) > listen`);
43
+
44
+ const postsLiveCollection = new SearchPostLiveCollectionController(params, callback);
45
+ const disposers = postsLiveCollection.startSubscription();
46
+
47
+ const cacheKey = postsLiveCollection.getCacheKey();
48
+
49
+ disposers.push(() => dropFromCache(cacheKey));
50
+
51
+ return () => {
52
+ log(`searchPostsByHashtag(tmpid: ${timestamp}) > dispose`);
53
+ disposers.forEach(fn => fn());
54
+ };
55
+ };
56
+ /* end_public_function */