@stream-io/feeds-client 1.1.0 → 1.3.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 (38) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/dist/cjs/index.js +477 -466
  3. package/dist/cjs/index.js.map +1 -1
  4. package/dist/cjs/react-bindings.js +454 -449
  5. package/dist/cjs/react-bindings.js.map +1 -1
  6. package/dist/es/index.mjs +440 -466
  7. package/dist/es/index.mjs.map +1 -1
  8. package/dist/es/react-bindings.mjs +447 -479
  9. package/dist/es/react-bindings.mjs.map +1 -1
  10. package/dist/feeds-client-CqD2zQW0.mjs +8791 -0
  11. package/dist/feeds-client-CqD2zQW0.mjs.map +1 -0
  12. package/dist/feeds-client-DXci2Pbn.js +8957 -0
  13. package/dist/feeds-client-DXci2Pbn.js.map +1 -0
  14. package/dist/tsconfig.lib.tsbuildinfo +1 -1
  15. package/dist/types/common/real-time/StableWSConnection.d.ts +3 -3
  16. package/dist/types/common/real-time/StableWSConnection.d.ts.map +1 -1
  17. package/dist/types/feed/event-handlers/notification-feed/handle-notification-feed-updated.d.ts.map +1 -1
  18. package/dist/types/feed/feed.d.ts +2 -2
  19. package/dist/types/feed/feed.d.ts.map +1 -1
  20. package/dist/types/feeds-client/feeds-client.d.ts +3 -2
  21. package/dist/types/feeds-client/feeds-client.d.ts.map +1 -1
  22. package/dist/types/gen/feeds/FeedsApi.d.ts +4 -1
  23. package/dist/types/gen/feeds/FeedsApi.d.ts.map +1 -1
  24. package/dist/types/gen/model-decoders/event-decoder-mapping.d.ts.map +1 -1
  25. package/dist/types/gen/models/index.d.ts +63 -1
  26. package/dist/types/gen/models/index.d.ts.map +1 -1
  27. package/package.json +15 -15
  28. package/src/feed/event-handlers/notification-feed/handle-notification-feed-updated.ts +1 -5
  29. package/src/feed/feed.ts +1 -0
  30. package/src/feeds-client/feeds-client.ts +104 -45
  31. package/src/gen/feeds/FeedsApi.ts +26 -0
  32. package/src/gen/model-decoders/decoders.ts +20 -0
  33. package/src/gen/model-decoders/event-decoder-mapping.ts +3 -0
  34. package/src/gen/models/index.ts +105 -1
  35. package/dist/feeds-client-C1c6lcS3.js +0 -8799
  36. package/dist/feeds-client-C1c6lcS3.js.map +0 -1
  37. package/dist/feeds-client-jtUTE4AC.mjs +0 -8783
  38. package/dist/feeds-client-jtUTE4AC.mjs.map +0 -1
package/dist/es/index.mjs CHANGED
@@ -1,472 +1,446 @@
1
+ import { C as LogLevelEnum, S as debounce, _ as uniqueArrayMerge, a as ownFeedFields, b as isVoteAnswer, c as shouldUpdateState, d as isFollowResponse, f as isImageFile, g as replaceUniqueArrayMerge, h as Constants, i as activityFilter, l as ensureExhausted, m as isVideoFile, n as ActivityWithStateUpdates, o as updateEntityInArray, p as isReactionResponse, r as Feed, s as getStateUpdateQueueId, t as FeedsClient, u as isCommentResponse, v as checkHasAnotherPage, w as feedsLoggerSystem, x as StreamApiError, y as StreamPoll } from "../feeds-client-CqD2zQW0.mjs";
1
2
  import { StateStore } from "@stream-io/state-store";
2
3
  export * from "@stream-io/state-store";
3
- import { d as debounce } from "../feeds-client-jtUTE4AC.mjs";
4
- import { A, C, b, F, S, c, a, e, o, n, l, h, f, j, g, k, i, r, s, u, m } from "../feeds-client-jtUTE4AC.mjs";
5
- import { LogLevelEnum } from "@stream-io/logger";
6
- const ownFeedFields = ["own_capabilities", "own_follows", "own_membership"];
7
- const ChannelOwnCapability = {
8
- BAN_CHANNEL_MEMBERS: "ban-channel-members",
9
- CAST_POLL_VOTE: "cast-poll-vote",
10
- CONNECT_EVENTS: "connect-events",
11
- CREATE_ATTACHMENT: "create-attachment",
12
- DELETE_ANY_MESSAGE: "delete-any-message",
13
- DELETE_CHANNEL: "delete-channel",
14
- DELETE_OWN_MESSAGE: "delete-own-message",
15
- DELIVERY_EVENTS: "delivery-events",
16
- FLAG_MESSAGE: "flag-message",
17
- FREEZE_CHANNEL: "freeze-channel",
18
- JOIN_CHANNEL: "join-channel",
19
- LEAVE_CHANNEL: "leave-channel",
20
- MUTE_CHANNEL: "mute-channel",
21
- PIN_MESSAGE: "pin-message",
22
- QUERY_POLL_VOTES: "query-poll-votes",
23
- QUOTE_MESSAGE: "quote-message",
24
- READ_EVENTS: "read-events",
25
- SEARCH_MESSAGES: "search-messages",
26
- SEND_CUSTOM_EVENTS: "send-custom-events",
27
- SEND_LINKS: "send-links",
28
- SEND_MESSAGE: "send-message",
29
- SEND_POLL: "send-poll",
30
- SEND_REACTION: "send-reaction",
31
- SEND_REPLY: "send-reply",
32
- SEND_RESTRICTED_VISIBILITY_MESSAGE: "send-restricted-visibility-message",
33
- SEND_TYPING_EVENTS: "send-typing-events",
34
- SET_CHANNEL_COOLDOWN: "set-channel-cooldown",
35
- SHARE_LOCATION: "share-location",
36
- SKIP_SLOW_MODE: "skip-slow-mode",
37
- SLOW_MODE: "slow-mode",
38
- TYPING_EVENTS: "typing-events",
39
- UPDATE_ANY_MESSAGE: "update-any-message",
40
- UPDATE_CHANNEL: "update-channel",
41
- UPDATE_CHANNEL_MEMBERS: "update-channel-members",
42
- UPDATE_OWN_MESSAGE: "update-own-message",
43
- UPDATE_THREAD: "update-thread",
44
- UPLOAD_FILE: "upload-file"
4
+ //#region src/gen/models/index.ts
5
+ var ChannelOwnCapability = {
6
+ BAN_CHANNEL_MEMBERS: "ban-channel-members",
7
+ CAST_POLL_VOTE: "cast-poll-vote",
8
+ CONNECT_EVENTS: "connect-events",
9
+ CREATE_ATTACHMENT: "create-attachment",
10
+ DELETE_ANY_MESSAGE: "delete-any-message",
11
+ DELETE_CHANNEL: "delete-channel",
12
+ DELETE_OWN_MESSAGE: "delete-own-message",
13
+ DELIVERY_EVENTS: "delivery-events",
14
+ FLAG_MESSAGE: "flag-message",
15
+ FREEZE_CHANNEL: "freeze-channel",
16
+ JOIN_CHANNEL: "join-channel",
17
+ LEAVE_CHANNEL: "leave-channel",
18
+ MUTE_CHANNEL: "mute-channel",
19
+ PIN_MESSAGE: "pin-message",
20
+ QUERY_POLL_VOTES: "query-poll-votes",
21
+ QUOTE_MESSAGE: "quote-message",
22
+ READ_EVENTS: "read-events",
23
+ SEARCH_MESSAGES: "search-messages",
24
+ SEND_CUSTOM_EVENTS: "send-custom-events",
25
+ SEND_LINKS: "send-links",
26
+ SEND_MESSAGE: "send-message",
27
+ SEND_POLL: "send-poll",
28
+ SEND_REACTION: "send-reaction",
29
+ SEND_REPLY: "send-reply",
30
+ SEND_RESTRICTED_VISIBILITY_MESSAGE: "send-restricted-visibility-message",
31
+ SEND_TYPING_EVENTS: "send-typing-events",
32
+ SET_CHANNEL_COOLDOWN: "set-channel-cooldown",
33
+ SHARE_LOCATION: "share-location",
34
+ SKIP_SLOW_MODE: "skip-slow-mode",
35
+ SLOW_MODE: "slow-mode",
36
+ TYPING_EVENTS: "typing-events",
37
+ UPDATE_ANY_MESSAGE: "update-any-message",
38
+ UPDATE_CHANNEL: "update-channel",
39
+ UPDATE_CHANNEL_MEMBERS: "update-channel-members",
40
+ UPDATE_OWN_MESSAGE: "update-own-message",
41
+ UPDATE_THREAD: "update-thread",
42
+ UPLOAD_FILE: "upload-file"
45
43
  };
46
- const FeedOwnCapability = {
47
- ADD_ACTIVITY: "add-activity",
48
- ADD_ACTIVITY_BOOKMARK: "add-activity-bookmark",
49
- ADD_ACTIVITY_REACTION: "add-activity-reaction",
50
- ADD_COMMENT: "add-comment",
51
- ADD_COMMENT_REACTION: "add-comment-reaction",
52
- CREATE_FEED: "create-feed",
53
- DELETE_ANY_ACTIVITY: "delete-any-activity",
54
- DELETE_ANY_COMMENT: "delete-any-comment",
55
- DELETE_FEED: "delete-feed",
56
- DELETE_OWN_ACTIVITY: "delete-own-activity",
57
- DELETE_OWN_ACTIVITY_BOOKMARK: "delete-own-activity-bookmark",
58
- DELETE_OWN_ACTIVITY_REACTION: "delete-own-activity-reaction",
59
- DELETE_OWN_COMMENT: "delete-own-comment",
60
- DELETE_OWN_COMMENT_REACTION: "delete-own-comment-reaction",
61
- FOLLOW: "follow",
62
- PIN_ACTIVITY: "pin-activity",
63
- QUERY_FEED_MEMBERS: "query-feed-members",
64
- QUERY_FOLLOWS: "query-follows",
65
- READ_ACTIVITIES: "read-activities",
66
- READ_FEED: "read-feed",
67
- UNFOLLOW: "unfollow",
68
- UPDATE_ANY_ACTIVITY: "update-any-activity",
69
- UPDATE_ANY_COMMENT: "update-any-comment",
70
- UPDATE_FEED: "update-feed",
71
- UPDATE_FEED_FOLLOWERS: "update-feed-followers",
72
- UPDATE_FEED_MEMBERS: "update-feed-members",
73
- UPDATE_OWN_ACTIVITY: "update-own-activity",
74
- UPDATE_OWN_ACTIVITY_BOOKMARK: "update-own-activity-bookmark",
75
- UPDATE_OWN_COMMENT: "update-own-comment"
44
+ var FeedOwnCapability = {
45
+ ADD_ACTIVITY: "add-activity",
46
+ ADD_ACTIVITY_BOOKMARK: "add-activity-bookmark",
47
+ ADD_ACTIVITY_REACTION: "add-activity-reaction",
48
+ ADD_COMMENT: "add-comment",
49
+ ADD_COMMENT_REACTION: "add-comment-reaction",
50
+ CREATE_FEED: "create-feed",
51
+ DELETE_ANY_ACTIVITY: "delete-any-activity",
52
+ DELETE_ANY_COMMENT: "delete-any-comment",
53
+ DELETE_FEED: "delete-feed",
54
+ DELETE_OWN_ACTIVITY: "delete-own-activity",
55
+ DELETE_OWN_ACTIVITY_BOOKMARK: "delete-own-activity-bookmark",
56
+ DELETE_OWN_ACTIVITY_REACTION: "delete-own-activity-reaction",
57
+ DELETE_OWN_COMMENT: "delete-own-comment",
58
+ DELETE_OWN_COMMENT_REACTION: "delete-own-comment-reaction",
59
+ FOLLOW: "follow",
60
+ PIN_ACTIVITY: "pin-activity",
61
+ QUERY_FEED_MEMBERS: "query-feed-members",
62
+ QUERY_FOLLOWS: "query-follows",
63
+ READ_ACTIVITIES: "read-activities",
64
+ READ_FEED: "read-feed",
65
+ UNFOLLOW: "unfollow",
66
+ UPDATE_ANY_ACTIVITY: "update-any-activity",
67
+ UPDATE_ANY_COMMENT: "update-any-comment",
68
+ UPDATE_FEED: "update-feed",
69
+ UPDATE_FEED_FOLLOWERS: "update-feed-followers",
70
+ UPDATE_FEED_MEMBERS: "update-feed-members",
71
+ UPDATE_OWN_ACTIVITY: "update-own-activity",
72
+ UPDATE_OWN_ACTIVITY_BOOKMARK: "update-own-activity-bookmark",
73
+ UPDATE_OWN_COMMENT: "update-own-comment"
76
74
  };
77
- class SearchController {
78
- constructor({ config, sources } = {}) {
79
- this.addSource = (source) => {
80
- this.state.partialNext({
81
- sources: [...this.sources, source]
82
- });
83
- };
84
- this.getSource = (sourceType) => this.sources.find((s2) => s2.type === sourceType);
85
- this.removeSource = (sourceType) => {
86
- const newSources = this.sources.filter((s2) => s2.type !== sourceType);
87
- if (newSources.length === this.sources.length) return;
88
- this.state.partialNext({ sources: newSources });
89
- };
90
- this.activateSource = (sourceType) => {
91
- const source = this.getSource(sourceType);
92
- if (!source || source.isActive) return;
93
- if (this.config.keepSingleActiveSource) {
94
- this.sources.forEach((s2) => {
95
- if (s2.type !== sourceType) {
96
- s2.deactivate();
97
- }
98
- });
99
- }
100
- source.activate();
101
- this.state.partialNext({ sources: [...this.sources] });
102
- };
103
- this.deactivateSource = (sourceType) => {
104
- const source = this.getSource(sourceType);
105
- if (!source?.isActive) return;
106
- if (this.activeSources.length === 1) return;
107
- source.deactivate();
108
- this.state.partialNext({ sources: [...this.sources] });
109
- };
110
- this.activate = () => {
111
- if (!this.activeSources.length) {
112
- const sourcesToActivate = this.config.keepSingleActiveSource ? this.sources.slice(0, 1) : this.sources;
113
- sourcesToActivate.forEach((s2) => s2.activate());
114
- }
115
- if (this.isActive) return;
116
- this.state.partialNext({ isActive: true });
117
- };
118
- this.search = async (searchQuery) => {
119
- const searchedSources = this.activeSources;
120
- this.state.partialNext({
121
- searchQuery
122
- });
123
- await Promise.all(
124
- searchedSources.map((source) => source.search(searchQuery))
125
- );
126
- };
127
- this.cancelSearchQueries = () => {
128
- this.activeSources.forEach((s2) => s2.cancelScheduledQuery());
129
- };
130
- this.clear = () => {
131
- this.cancelSearchQueries();
132
- this.sources.forEach(
133
- (source) => source.state.next({ ...source.initialState, isActive: source.isActive })
134
- );
135
- this.state.next((current) => ({
136
- ...current,
137
- isActive: true,
138
- queriesInProgress: [],
139
- searchQuery: ""
140
- }));
141
- };
142
- this.exit = () => {
143
- this.cancelSearchQueries();
144
- this.sources.forEach(
145
- (source) => source.state.next({ ...source.initialState, isActive: source.isActive })
146
- );
147
- this.state.next((current) => ({
148
- ...current,
149
- isActive: false,
150
- queriesInProgress: [],
151
- searchQuery: ""
152
- }));
153
- };
154
- this.state = new StateStore({
155
- isActive: false,
156
- searchQuery: "",
157
- sources: sources ?? []
158
- });
159
- this._internalState = new StateStore({});
160
- this.config = { keepSingleActiveSource: true, ...config };
161
- }
162
- get hasNext() {
163
- return this.sources.some((source) => source.hasNext);
164
- }
165
- get sources() {
166
- return this.state.getLatestValue().sources;
167
- }
168
- get activeSources() {
169
- return this.state.getLatestValue().sources.filter((s2) => s2.isActive);
170
- }
171
- get isActive() {
172
- return this.state.getLatestValue().isActive;
173
- }
174
- get searchQuery() {
175
- return this.state.getLatestValue().searchQuery;
176
- }
177
- get searchSourceTypes() {
178
- return this.sources.map((s2) => s2.type);
179
- }
180
- }
181
- const DEFAULT_SEARCH_SOURCE_OPTIONS = {
182
- debounceMs: 300,
183
- pageSize: 10,
184
- allowEmptySearchString: false,
185
- resetOnNewSearchQuery: true
75
+ //#endregion
76
+ //#region src/common/search/SearchController.ts
77
+ var SearchController = class {
78
+ constructor({ config, sources } = {}) {
79
+ this.addSource = (source) => {
80
+ this.state.partialNext({ sources: [...this.sources, source] });
81
+ };
82
+ this.getSource = (sourceType) => this.sources.find((s) => s.type === sourceType);
83
+ this.removeSource = (sourceType) => {
84
+ const newSources = this.sources.filter((s) => s.type !== sourceType);
85
+ if (newSources.length === this.sources.length) return;
86
+ this.state.partialNext({ sources: newSources });
87
+ };
88
+ this.activateSource = (sourceType) => {
89
+ const source = this.getSource(sourceType);
90
+ if (!source || source.isActive) return;
91
+ if (this.config.keepSingleActiveSource) this.sources.forEach((s) => {
92
+ if (s.type !== sourceType) s.deactivate();
93
+ });
94
+ source.activate();
95
+ this.state.partialNext({ sources: [...this.sources] });
96
+ };
97
+ this.deactivateSource = (sourceType) => {
98
+ const source = this.getSource(sourceType);
99
+ if (!source?.isActive) return;
100
+ if (this.activeSources.length === 1) return;
101
+ source.deactivate();
102
+ this.state.partialNext({ sources: [...this.sources] });
103
+ };
104
+ this.activate = () => {
105
+ if (!this.activeSources.length) (this.config.keepSingleActiveSource ? this.sources.slice(0, 1) : this.sources).forEach((s) => s.activate());
106
+ if (this.isActive) return;
107
+ this.state.partialNext({ isActive: true });
108
+ };
109
+ this.search = async (searchQuery) => {
110
+ const searchedSources = this.activeSources;
111
+ this.state.partialNext({ searchQuery });
112
+ await Promise.all(searchedSources.map((source) => source.search(searchQuery)));
113
+ };
114
+ this.cancelSearchQueries = () => {
115
+ this.activeSources.forEach((s) => s.cancelScheduledQuery());
116
+ };
117
+ this.clear = () => {
118
+ this.cancelSearchQueries();
119
+ this.sources.forEach((source) => source.state.next({
120
+ ...source.initialState,
121
+ isActive: source.isActive
122
+ }));
123
+ this.state.next((current) => ({
124
+ ...current,
125
+ isActive: true,
126
+ queriesInProgress: [],
127
+ searchQuery: ""
128
+ }));
129
+ };
130
+ this.exit = () => {
131
+ this.cancelSearchQueries();
132
+ this.sources.forEach((source) => source.state.next({
133
+ ...source.initialState,
134
+ isActive: source.isActive
135
+ }));
136
+ this.state.next((current) => ({
137
+ ...current,
138
+ isActive: false,
139
+ queriesInProgress: [],
140
+ searchQuery: ""
141
+ }));
142
+ };
143
+ this.state = new StateStore({
144
+ isActive: false,
145
+ searchQuery: "",
146
+ sources: sources ?? []
147
+ });
148
+ this._internalState = new StateStore({});
149
+ this.config = {
150
+ keepSingleActiveSource: true,
151
+ ...config
152
+ };
153
+ }
154
+ get hasNext() {
155
+ return this.sources.some((source) => source.hasNext);
156
+ }
157
+ get sources() {
158
+ return this.state.getLatestValue().sources;
159
+ }
160
+ get activeSources() {
161
+ return this.state.getLatestValue().sources.filter((s) => s.isActive);
162
+ }
163
+ get isActive() {
164
+ return this.state.getLatestValue().isActive;
165
+ }
166
+ get searchQuery() {
167
+ return this.state.getLatestValue().searchQuery;
168
+ }
169
+ get searchSourceTypes() {
170
+ return this.sources.map((s) => s.type);
171
+ }
186
172
  };
187
- class BaseSearchSourceBase {
188
- constructor(options) {
189
- this.activate = () => {
190
- if (this.isActive) return;
191
- this.state.partialNext({ isActive: true });
192
- };
193
- this.deactivate = () => {
194
- if (!this.isActive) return;
195
- this.state.partialNext({ isActive: false });
196
- };
197
- this.canExecuteQuery = (newSearchString) => {
198
- const hasNewSearchQuery = typeof newSearchString !== "undefined";
199
- const searchString = newSearchString ?? this.searchQuery;
200
- return !!(this.isActive && !this.isLoading && (this.hasNext || hasNewSearchQuery) && (this.allowEmptySearchString || searchString));
201
- };
202
- const { pageSize, allowEmptySearchString, resetOnNewSearchQuery } = {
203
- ...DEFAULT_SEARCH_SOURCE_OPTIONS,
204
- ...options
205
- };
206
- this.pageSize = pageSize;
207
- this.allowEmptySearchString = allowEmptySearchString;
208
- this.resetOnNewSearchQuery = resetOnNewSearchQuery;
209
- this.state = new StateStore(this.initialState);
210
- }
211
- get lastQueryError() {
212
- return this.state.getLatestValue().lastQueryError;
213
- }
214
- get hasNext() {
215
- return this.state.getLatestValue().hasNext;
216
- }
217
- get hasResults() {
218
- return Array.isArray(this.state.getLatestValue().items);
219
- }
220
- get isActive() {
221
- return this.state.getLatestValue().isActive;
222
- }
223
- get isLoading() {
224
- return this.state.getLatestValue().isLoading;
225
- }
226
- get initialState() {
227
- return {
228
- hasNext: true,
229
- isActive: false,
230
- isLoading: false,
231
- items: void 0,
232
- lastQueryError: void 0,
233
- next: void 0,
234
- offset: 0,
235
- searchQuery: ""
236
- };
237
- }
238
- get items() {
239
- return this.state.getLatestValue().items;
240
- }
241
- get next() {
242
- return this.state.getLatestValue().next;
243
- }
244
- get offset() {
245
- return this.state.getLatestValue().offset;
246
- }
247
- get searchQuery() {
248
- return this.state.getLatestValue().searchQuery;
249
- }
250
- getStateBeforeFirstQuery(newSearchString) {
251
- const initialState = this.initialState;
252
- const oldItems = this.items;
253
- const items = this.resetOnNewSearchQuery ? initialState.items : oldItems;
254
- return {
255
- ...this.initialState,
256
- items,
257
- isActive: this.isActive,
258
- isLoading: this.resetOnNewSearchQuery ? true : !oldItems,
259
- searchQuery: newSearchString
260
- };
261
- }
262
- getStateAfterQuery(stateUpdate, isFirstPage) {
263
- const current = this.state.getLatestValue();
264
- return {
265
- ...current,
266
- lastQueryError: void 0,
267
- // reset lastQueryError that can be overridden by the stateUpdate
268
- ...stateUpdate,
269
- isLoading: false,
270
- items: isFirstPage ? stateUpdate.items : [...this.items ?? [], ...stateUpdate.items || []]
271
- };
272
- }
273
- prepareStateForQuery(newSearchString) {
274
- const hasNewSearchQuery = typeof newSearchString !== "undefined";
275
- const searchString = newSearchString ?? this.searchQuery;
276
- if (hasNewSearchQuery) {
277
- this.state.next(this.getStateBeforeFirstQuery(newSearchString ?? ""));
278
- } else {
279
- this.state.partialNext({ isLoading: true });
280
- }
281
- return { searchString, hasNewSearchQuery };
282
- }
283
- updatePaginationStateFromQuery(result) {
284
- const { items, next } = result;
285
- const stateUpdate = {};
286
- if (Object.prototype.hasOwnProperty.call(result, "next")) {
287
- stateUpdate.next = next;
288
- stateUpdate.hasNext = !!next;
289
- } else {
290
- stateUpdate.offset = (this.offset ?? 0) + items.length;
291
- stateUpdate.hasNext = items.length === this.pageSize;
292
- }
293
- return stateUpdate;
294
- }
295
- resetState() {
296
- this.state.next(this.initialState);
297
- }
298
- resetStateAndActivate() {
299
- this.resetState();
300
- this.activate();
301
- }
302
- }
303
- class BaseSearchSource extends BaseSearchSourceBase {
304
- constructor(options) {
305
- const { debounceMs } = { ...DEFAULT_SEARCH_SOURCE_OPTIONS, ...options };
306
- super(options);
307
- this.setDebounceOptions = ({ debounceMs: debounceMs2 }) => {
308
- this.searchDebounced = debounce(this.executeQuery.bind(this), debounceMs2);
309
- };
310
- this.search = (searchQuery) => this.searchDebounced(searchQuery);
311
- this.setDebounceOptions({ debounceMs });
312
- }
313
- async executeQuery(newSearchString) {
314
- if (!this.canExecuteQuery(newSearchString)) return;
315
- const { hasNewSearchQuery, searchString } = this.prepareStateForQuery(newSearchString);
316
- let stateUpdate = {};
317
- try {
318
- const results = await this.query(searchString);
319
- if (!results) return;
320
- const { items } = results;
321
- stateUpdate = this.updatePaginationStateFromQuery(results);
322
- stateUpdate.items = await this.filterQueryResults(items);
323
- } catch (e2) {
324
- stateUpdate.lastQueryError = e2;
325
- } finally {
326
- this.state.next(this.getStateAfterQuery(stateUpdate, hasNewSearchQuery));
327
- }
328
- }
329
- cancelScheduledQuery() {
330
- this.searchDebounced.cancel();
331
- }
332
- }
333
- class BaseSearchSourceSync extends BaseSearchSourceBase {
334
- constructor(options) {
335
- const { debounceMs } = { ...DEFAULT_SEARCH_SOURCE_OPTIONS, ...options };
336
- super(options);
337
- this.setDebounceOptions = ({ debounceMs: debounceMs2 }) => {
338
- this.searchDebounced = debounce(this.executeQuery.bind(this), debounceMs2);
339
- };
340
- this.search = (searchQuery) => this.searchDebounced(searchQuery);
341
- this.setDebounceOptions({ debounceMs });
342
- }
343
- executeQuery(newSearchString) {
344
- if (!this.canExecuteQuery(newSearchString)) return;
345
- const { hasNewSearchQuery, searchString } = this.prepareStateForQuery(newSearchString);
346
- let stateUpdate = {};
347
- try {
348
- const results = this.query(searchString);
349
- if (!results) return;
350
- const { items } = results;
351
- stateUpdate = this.updatePaginationStateFromQuery(results);
352
- stateUpdate.items = this.filterQueryResults(items);
353
- } catch (e2) {
354
- stateUpdate.lastQueryError = e2;
355
- } finally {
356
- this.state.next(this.getStateAfterQuery(stateUpdate, hasNewSearchQuery));
357
- }
358
- }
359
- cancelScheduledQuery() {
360
- this.searchDebounced.cancel();
361
- }
362
- }
363
- class ActivitySearchSource extends BaseSearchSource {
364
- constructor(client, options) {
365
- super(options);
366
- this.type = "activity";
367
- this.client = client;
368
- }
369
- async query(searchQuery) {
370
- const { connected_user: connectedUser } = this.client.state.getLatestValue();
371
- if (!connectedUser) return { items: [] };
372
- const { activities: items, next } = await this.client.queryActivities({
373
- sort: [{ direction: -1, field: "created_at" }],
374
- ...!this.allowEmptySearchString || searchQuery.length > 0 ? { filter: { text: { $autocomplete: searchQuery } } } : {},
375
- limit: 10,
376
- next: this.next ?? void 0
377
- });
378
- return { items, next };
379
- }
380
- filterQueryResults(items) {
381
- return items;
382
- }
383
- }
384
- class FeedSearchSource extends BaseSearchSource {
385
- constructor(client, options) {
386
- super(options);
387
- this.client = client;
388
- this.feedGroupId = options?.groupId;
389
- this.type = `${this.feedGroupId}-feed`;
390
- }
391
- async query(searchQuery) {
392
- const { connected_user: connectedUser } = this.client.state.getLatestValue();
393
- if (!connectedUser) return { items: [] };
394
- const { feeds: items, next } = await this.client.queryFeeds({
395
- filter: {
396
- ...this.feedGroupId ? { group_id: this.feedGroupId } : {},
397
- ...!this.allowEmptySearchString || searchQuery.length > 0 ? {
398
- $or: [
399
- { name: { $autocomplete: searchQuery } },
400
- { description: { $autocomplete: searchQuery } },
401
- { "created_by.name": { $autocomplete: searchQuery } }
402
- ]
403
- } : {}
404
- },
405
- next: this.next ?? void 0
406
- });
407
- return { items, next };
408
- }
409
- filterQueryResults(items) {
410
- return items;
411
- }
412
- }
413
- class UserSearchSource extends BaseSearchSource {
414
- constructor(client, options) {
415
- super(options);
416
- this.type = "user";
417
- this.client = client;
418
- }
419
- async query(searchQuery) {
420
- const { connected_user: connectedUser } = this.client.state.getLatestValue();
421
- if (!connectedUser) return { items: [] };
422
- const { users: items } = await this.client.queryUsers({
423
- payload: {
424
- filter_conditions: {
425
- ...!this.allowEmptySearchString || searchQuery.length > 0 ? {
426
- name: {
427
- $autocomplete: searchQuery
428
- }
429
- } : {}
430
- }
431
- }
432
- });
433
- return { items, next: void 0 };
434
- }
435
- filterQueryResults(items) {
436
- return items;
437
- }
438
- }
439
- export {
440
- ActivitySearchSource,
441
- A as ActivityWithStateUpdates,
442
- BaseSearchSource,
443
- BaseSearchSourceSync,
444
- ChannelOwnCapability,
445
- C as Constants,
446
- b as Feed,
447
- FeedOwnCapability,
448
- FeedSearchSource,
449
- F as FeedsClient,
450
- LogLevelEnum,
451
- SearchController,
452
- S as StreamApiError,
453
- c as StreamPoll,
454
- UserSearchSource,
455
- a as activityFilter,
456
- e as checkHasAnotherPage,
457
- o as ensureExhausted,
458
- n as feedsLoggerSystem,
459
- l as getStateUpdateQueueId,
460
- h as isCommentResponse,
461
- f as isFollowResponse,
462
- j as isImageFile,
463
- g as isReactionResponse,
464
- k as isVideoFile,
465
- i as isVoteAnswer,
466
- ownFeedFields,
467
- r as replaceUniqueArrayMerge,
468
- s as shouldUpdateState,
469
- u as uniqueArrayMerge,
470
- m as updateEntityInArray
173
+ //#endregion
174
+ //#region src/common/search/BaseSearchSource.ts
175
+ var DEFAULT_SEARCH_SOURCE_OPTIONS = {
176
+ debounceMs: 300,
177
+ pageSize: 10,
178
+ allowEmptySearchString: false,
179
+ resetOnNewSearchQuery: true
471
180
  };
472
- //# sourceMappingURL=index.mjs.map
181
+ var BaseSearchSourceBase = class {
182
+ constructor(options) {
183
+ this.activate = () => {
184
+ if (this.isActive) return;
185
+ this.state.partialNext({ isActive: true });
186
+ };
187
+ this.deactivate = () => {
188
+ if (!this.isActive) return;
189
+ this.state.partialNext({ isActive: false });
190
+ };
191
+ this.canExecuteQuery = (newSearchString) => {
192
+ const hasNewSearchQuery = typeof newSearchString !== "undefined";
193
+ const searchString = newSearchString ?? this.searchQuery;
194
+ return !!(this.isActive && !this.isLoading && (this.hasNext || hasNewSearchQuery) && (this.allowEmptySearchString || searchString));
195
+ };
196
+ const { pageSize, allowEmptySearchString, resetOnNewSearchQuery } = {
197
+ ...DEFAULT_SEARCH_SOURCE_OPTIONS,
198
+ ...options
199
+ };
200
+ this.pageSize = pageSize;
201
+ this.allowEmptySearchString = allowEmptySearchString;
202
+ this.resetOnNewSearchQuery = resetOnNewSearchQuery;
203
+ this.state = new StateStore(this.initialState);
204
+ }
205
+ get lastQueryError() {
206
+ return this.state.getLatestValue().lastQueryError;
207
+ }
208
+ get hasNext() {
209
+ return this.state.getLatestValue().hasNext;
210
+ }
211
+ get hasResults() {
212
+ return Array.isArray(this.state.getLatestValue().items);
213
+ }
214
+ get isActive() {
215
+ return this.state.getLatestValue().isActive;
216
+ }
217
+ get isLoading() {
218
+ return this.state.getLatestValue().isLoading;
219
+ }
220
+ get initialState() {
221
+ return {
222
+ hasNext: true,
223
+ isActive: false,
224
+ isLoading: false,
225
+ items: void 0,
226
+ lastQueryError: void 0,
227
+ next: void 0,
228
+ offset: 0,
229
+ searchQuery: ""
230
+ };
231
+ }
232
+ get items() {
233
+ return this.state.getLatestValue().items;
234
+ }
235
+ get next() {
236
+ return this.state.getLatestValue().next;
237
+ }
238
+ get offset() {
239
+ return this.state.getLatestValue().offset;
240
+ }
241
+ get searchQuery() {
242
+ return this.state.getLatestValue().searchQuery;
243
+ }
244
+ getStateBeforeFirstQuery(newSearchString) {
245
+ const initialState = this.initialState;
246
+ const oldItems = this.items;
247
+ const items = this.resetOnNewSearchQuery ? initialState.items : oldItems;
248
+ return {
249
+ ...this.initialState,
250
+ items,
251
+ isActive: this.isActive,
252
+ isLoading: this.resetOnNewSearchQuery ? true : !oldItems,
253
+ searchQuery: newSearchString
254
+ };
255
+ }
256
+ getStateAfterQuery(stateUpdate, isFirstPage) {
257
+ return {
258
+ ...this.state.getLatestValue(),
259
+ lastQueryError: void 0,
260
+ ...stateUpdate,
261
+ isLoading: false,
262
+ items: isFirstPage ? stateUpdate.items : [...this.items ?? [], ...stateUpdate.items || []]
263
+ };
264
+ }
265
+ prepareStateForQuery(newSearchString) {
266
+ const hasNewSearchQuery = typeof newSearchString !== "undefined";
267
+ const searchString = newSearchString ?? this.searchQuery;
268
+ if (hasNewSearchQuery) this.state.next(this.getStateBeforeFirstQuery(newSearchString ?? ""));
269
+ else this.state.partialNext({ isLoading: true });
270
+ return {
271
+ searchString,
272
+ hasNewSearchQuery
273
+ };
274
+ }
275
+ updatePaginationStateFromQuery(result) {
276
+ const { items, next } = result;
277
+ const stateUpdate = {};
278
+ if (Object.prototype.hasOwnProperty.call(result, "next")) {
279
+ stateUpdate.next = next;
280
+ stateUpdate.hasNext = !!next;
281
+ } else {
282
+ stateUpdate.offset = (this.offset ?? 0) + items.length;
283
+ stateUpdate.hasNext = items.length === this.pageSize;
284
+ }
285
+ return stateUpdate;
286
+ }
287
+ resetState() {
288
+ this.state.next(this.initialState);
289
+ }
290
+ resetStateAndActivate() {
291
+ this.resetState();
292
+ this.activate();
293
+ }
294
+ };
295
+ var BaseSearchSource = class extends BaseSearchSourceBase {
296
+ constructor(options) {
297
+ const { debounceMs } = {
298
+ ...DEFAULT_SEARCH_SOURCE_OPTIONS,
299
+ ...options
300
+ };
301
+ super(options);
302
+ this.setDebounceOptions = ({ debounceMs }) => {
303
+ this.searchDebounced = debounce(this.executeQuery.bind(this), debounceMs);
304
+ };
305
+ this.search = (searchQuery) => this.searchDebounced(searchQuery);
306
+ this.setDebounceOptions({ debounceMs });
307
+ }
308
+ async executeQuery(newSearchString) {
309
+ if (!this.canExecuteQuery(newSearchString)) return;
310
+ const { hasNewSearchQuery, searchString } = this.prepareStateForQuery(newSearchString);
311
+ let stateUpdate = {};
312
+ try {
313
+ const results = await this.query(searchString);
314
+ if (!results) return;
315
+ const { items } = results;
316
+ stateUpdate = this.updatePaginationStateFromQuery(results);
317
+ stateUpdate.items = await this.filterQueryResults(items);
318
+ } catch (e) {
319
+ stateUpdate.lastQueryError = e;
320
+ } finally {
321
+ this.state.next(this.getStateAfterQuery(stateUpdate, hasNewSearchQuery));
322
+ }
323
+ }
324
+ cancelScheduledQuery() {
325
+ this.searchDebounced.cancel();
326
+ }
327
+ };
328
+ var BaseSearchSourceSync = class extends BaseSearchSourceBase {
329
+ constructor(options) {
330
+ const { debounceMs } = {
331
+ ...DEFAULT_SEARCH_SOURCE_OPTIONS,
332
+ ...options
333
+ };
334
+ super(options);
335
+ this.setDebounceOptions = ({ debounceMs }) => {
336
+ this.searchDebounced = debounce(this.executeQuery.bind(this), debounceMs);
337
+ };
338
+ this.search = (searchQuery) => this.searchDebounced(searchQuery);
339
+ this.setDebounceOptions({ debounceMs });
340
+ }
341
+ executeQuery(newSearchString) {
342
+ if (!this.canExecuteQuery(newSearchString)) return;
343
+ const { hasNewSearchQuery, searchString } = this.prepareStateForQuery(newSearchString);
344
+ let stateUpdate = {};
345
+ try {
346
+ const results = this.query(searchString);
347
+ if (!results) return;
348
+ const { items } = results;
349
+ stateUpdate = this.updatePaginationStateFromQuery(results);
350
+ stateUpdate.items = this.filterQueryResults(items);
351
+ } catch (e) {
352
+ stateUpdate.lastQueryError = e;
353
+ } finally {
354
+ this.state.next(this.getStateAfterQuery(stateUpdate, hasNewSearchQuery));
355
+ }
356
+ }
357
+ cancelScheduledQuery() {
358
+ this.searchDebounced.cancel();
359
+ }
360
+ };
361
+ //#endregion
362
+ //#region src/common/search/ActivitySearchSource.ts
363
+ var ActivitySearchSource = class extends BaseSearchSource {
364
+ constructor(client, options) {
365
+ super(options);
366
+ this.type = "activity";
367
+ this.client = client;
368
+ }
369
+ async query(searchQuery) {
370
+ const { connected_user: connectedUser } = this.client.state.getLatestValue();
371
+ if (!connectedUser) return { items: [] };
372
+ const { activities: items, next } = await this.client.queryActivities({
373
+ sort: [{
374
+ direction: -1,
375
+ field: "created_at"
376
+ }],
377
+ ...!this.allowEmptySearchString || searchQuery.length > 0 ? { filter: { text: { $autocomplete: searchQuery } } } : {},
378
+ limit: 10,
379
+ next: this.next ?? void 0
380
+ });
381
+ return {
382
+ items,
383
+ next
384
+ };
385
+ }
386
+ filterQueryResults(items) {
387
+ return items;
388
+ }
389
+ };
390
+ //#endregion
391
+ //#region src/common/search/FeedSearchSource.ts
392
+ var FeedSearchSource = class extends BaseSearchSource {
393
+ constructor(client, options) {
394
+ super(options);
395
+ this.client = client;
396
+ this.feedGroupId = options?.groupId;
397
+ this.type = `${this.feedGroupId}-feed`;
398
+ }
399
+ async query(searchQuery) {
400
+ const { connected_user: connectedUser } = this.client.state.getLatestValue();
401
+ if (!connectedUser) return { items: [] };
402
+ const { feeds: items, next } = await this.client.queryFeeds({
403
+ filter: {
404
+ ...this.feedGroupId ? { group_id: this.feedGroupId } : {},
405
+ ...!this.allowEmptySearchString || searchQuery.length > 0 ? { $or: [
406
+ { name: { $autocomplete: searchQuery } },
407
+ { description: { $autocomplete: searchQuery } },
408
+ { "created_by.name": { $autocomplete: searchQuery } }
409
+ ] } : {}
410
+ },
411
+ next: this.next ?? void 0
412
+ });
413
+ return {
414
+ items,
415
+ next
416
+ };
417
+ }
418
+ filterQueryResults(items) {
419
+ return items;
420
+ }
421
+ };
422
+ //#endregion
423
+ //#region src/common/search/UserSearchSource.ts
424
+ var UserSearchSource = class extends BaseSearchSource {
425
+ constructor(client, options) {
426
+ super(options);
427
+ this.type = "user";
428
+ this.client = client;
429
+ }
430
+ async query(searchQuery) {
431
+ const { connected_user: connectedUser } = this.client.state.getLatestValue();
432
+ if (!connectedUser) return { items: [] };
433
+ const { users: items } = await this.client.queryUsers({ payload: { filter_conditions: { ...!this.allowEmptySearchString || searchQuery.length > 0 ? { name: { $autocomplete: searchQuery } } : {} } } });
434
+ return {
435
+ items,
436
+ next: void 0
437
+ };
438
+ }
439
+ filterQueryResults(items) {
440
+ return items;
441
+ }
442
+ };
443
+ //#endregion
444
+ export { ActivitySearchSource, ActivityWithStateUpdates, BaseSearchSource, BaseSearchSourceSync, ChannelOwnCapability, Constants, Feed, FeedOwnCapability, FeedSearchSource, FeedsClient, LogLevelEnum, SearchController, StreamApiError, StreamPoll, UserSearchSource, activityFilter, checkHasAnotherPage, ensureExhausted, feedsLoggerSystem, getStateUpdateQueueId, isCommentResponse, isFollowResponse, isImageFile, isReactionResponse, isVideoFile, isVoteAnswer, ownFeedFields, replaceUniqueArrayMerge, shouldUpdateState, uniqueArrayMerge, updateEntityInArray };
445
+
446
+ //# sourceMappingURL=index.mjs.map