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