stream-chat 9.45.5 → 9.46.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.
@@ -47,6 +47,7 @@ __export(index_exports, {
47
47
  Channel: () => Channel,
48
48
  ChannelBatchUpdater: () => ChannelBatchUpdater,
49
49
  ChannelManager: () => ChannelManager,
50
+ ChannelMemberSearchSource: () => ChannelMemberSearchSource,
50
51
  ChannelSearchSource: () => ChannelSearchSource,
51
52
  ChannelState: () => ChannelState,
52
53
  CheckSignature: () => CheckSignature,
@@ -4578,110 +4579,6 @@ var BaseSearchSourceSync = class extends BaseSearchSourceBase {
4578
4579
  }
4579
4580
  };
4580
4581
 
4581
- // src/search/SearchController.ts
4582
- var SearchController = class {
4583
- constructor({ config, sources } = {}) {
4584
- this.addSource = (source) => {
4585
- this.state.partialNext({
4586
- sources: [...this.sources, source]
4587
- });
4588
- };
4589
- this.getSource = (sourceType) => this.sources.find((s) => s.type === sourceType);
4590
- this.removeSource = (sourceType) => {
4591
- const newSources = this.sources.filter((s) => s.type !== sourceType);
4592
- if (newSources.length === this.sources.length) return;
4593
- this.state.partialNext({ sources: newSources });
4594
- };
4595
- this.activateSource = (sourceType) => {
4596
- const source = this.getSource(sourceType);
4597
- if (!source || source.isActive) return;
4598
- if (this.config.keepSingleActiveSource) {
4599
- this.sources.forEach((s) => {
4600
- if (s.type !== sourceType) {
4601
- s.deactivate();
4602
- }
4603
- });
4604
- }
4605
- source.activate();
4606
- this.state.partialNext({ sources: [...this.sources] });
4607
- };
4608
- this.deactivateSource = (sourceType) => {
4609
- const source = this.getSource(sourceType);
4610
- if (!source?.isActive) return;
4611
- if (this.activeSources.length === 1) return;
4612
- source.deactivate();
4613
- this.state.partialNext({ sources: [...this.sources] });
4614
- };
4615
- this.activate = () => {
4616
- if (!this.activeSources.length) {
4617
- const sourcesToActivate = this.config.keepSingleActiveSource ? this.sources.slice(0, 1) : this.sources;
4618
- sourcesToActivate.forEach((s) => s.activate());
4619
- }
4620
- if (this.isActive) return;
4621
- this.state.partialNext({ isActive: true });
4622
- };
4623
- this.search = async (searchQuery) => {
4624
- const searchedSources = this.activeSources;
4625
- this.state.partialNext({
4626
- searchQuery
4627
- });
4628
- await Promise.all(searchedSources.map((source) => source.search(searchQuery)));
4629
- };
4630
- this.cancelSearchQueries = () => {
4631
- this.activeSources.forEach((s) => s.cancelScheduledQuery());
4632
- };
4633
- this.clear = () => {
4634
- this.cancelSearchQueries();
4635
- this.sources.forEach(
4636
- (source) => source.state.next({ ...source.initialState, isActive: source.isActive })
4637
- );
4638
- this.state.next((current) => ({
4639
- ...current,
4640
- isActive: true,
4641
- queriesInProgress: [],
4642
- searchQuery: ""
4643
- }));
4644
- };
4645
- this.exit = () => {
4646
- this.cancelSearchQueries();
4647
- this.sources.forEach(
4648
- (source) => source.state.next({ ...source.initialState, isActive: source.isActive })
4649
- );
4650
- this.state.next((current) => ({
4651
- ...current,
4652
- isActive: false,
4653
- queriesInProgress: [],
4654
- searchQuery: ""
4655
- }));
4656
- };
4657
- this.state = new StateStore({
4658
- isActive: false,
4659
- searchQuery: "",
4660
- sources: sources ?? []
4661
- });
4662
- this._internalState = new StateStore({});
4663
- this.config = { keepSingleActiveSource: true, ...config };
4664
- }
4665
- get hasNext() {
4666
- return this.sources.some((source) => source.hasNext);
4667
- }
4668
- get sources() {
4669
- return this.state.getLatestValue().sources;
4670
- }
4671
- get activeSources() {
4672
- return this.state.getLatestValue().sources.filter((s) => s.isActive);
4673
- }
4674
- get isActive() {
4675
- return this.state.getLatestValue().isActive;
4676
- }
4677
- get searchQuery() {
4678
- return this.state.getLatestValue().searchQuery;
4679
- }
4680
- get searchSourceTypes() {
4681
- return this.sources.map((s) => s.type);
4682
- }
4683
- };
4684
-
4685
4582
  // src/pagination/BasePaginator.ts
4686
4583
  var DEFAULT_PAGINATION_OPTIONS = {
4687
4584
  debounceMs: 300,
@@ -4950,6 +4847,152 @@ var UserGroupPaginator = class extends BasePaginator {
4950
4847
  }
4951
4848
  };
4952
4849
 
4850
+ // src/search/ChannelMemberSearchSource.ts
4851
+ var ChannelMemberSearchSource = class extends BaseSearchSource {
4852
+ constructor(channel, options, filterBuilderOptions = {}) {
4853
+ super(options);
4854
+ this.type = "members";
4855
+ this.canExecuteQuery = (newSearchString) => {
4856
+ const hasNewSearchQuery = typeof newSearchString !== "undefined";
4857
+ return this.isActive && !this.isLoading && (this.hasNext || hasNewSearchQuery);
4858
+ };
4859
+ this.channel = channel;
4860
+ this.filterBuilder = new FilterBuilder({
4861
+ initialFilterConfig: {
4862
+ default: {
4863
+ enabled: true,
4864
+ generate: ({ searchQuery }) => searchQuery ? {
4865
+ $or: [
4866
+ { name: { $autocomplete: searchQuery } },
4867
+ { id: { $eq: searchQuery } }
4868
+ ]
4869
+ } : null
4870
+ }
4871
+ },
4872
+ ...filterBuilderOptions
4873
+ });
4874
+ }
4875
+ async query(searchQuery) {
4876
+ const filters = this.filterBuilder.buildFilters({
4877
+ baseFilters: this.filters,
4878
+ context: {
4879
+ searchQuery
4880
+ }
4881
+ });
4882
+ const sort = this.sort ?? [];
4883
+ const options = { ...this.searchOptions, limit: this.pageSize, offset: this.offset };
4884
+ const { members } = await this.channel.queryMembers(filters ?? {}, sort, options);
4885
+ return { items: members };
4886
+ }
4887
+ filterQueryResults(items) {
4888
+ return items;
4889
+ }
4890
+ };
4891
+
4892
+ // src/search/SearchController.ts
4893
+ var SearchController = class {
4894
+ constructor({ config, sources } = {}) {
4895
+ this.addSource = (source) => {
4896
+ this.state.partialNext({
4897
+ sources: [...this.sources, source]
4898
+ });
4899
+ };
4900
+ this.getSource = (sourceType) => this.sources.find((s) => s.type === sourceType);
4901
+ this.removeSource = (sourceType) => {
4902
+ const newSources = this.sources.filter((s) => s.type !== sourceType);
4903
+ if (newSources.length === this.sources.length) return;
4904
+ this.state.partialNext({ sources: newSources });
4905
+ };
4906
+ this.activateSource = (sourceType) => {
4907
+ const source = this.getSource(sourceType);
4908
+ if (!source || source.isActive) return;
4909
+ if (this.config.keepSingleActiveSource) {
4910
+ this.sources.forEach((s) => {
4911
+ if (s.type !== sourceType) {
4912
+ s.deactivate();
4913
+ }
4914
+ });
4915
+ }
4916
+ source.activate();
4917
+ this.state.partialNext({ sources: [...this.sources] });
4918
+ };
4919
+ this.deactivateSource = (sourceType) => {
4920
+ const source = this.getSource(sourceType);
4921
+ if (!source?.isActive) return;
4922
+ if (this.activeSources.length === 1) return;
4923
+ source.deactivate();
4924
+ this.state.partialNext({ sources: [...this.sources] });
4925
+ };
4926
+ this.activate = () => {
4927
+ if (!this.activeSources.length) {
4928
+ const sourcesToActivate = this.config.keepSingleActiveSource ? this.sources.slice(0, 1) : this.sources;
4929
+ sourcesToActivate.forEach((s) => s.activate());
4930
+ }
4931
+ if (this.isActive) return;
4932
+ this.state.partialNext({ isActive: true });
4933
+ };
4934
+ this.search = async (searchQuery) => {
4935
+ const searchedSources = this.activeSources;
4936
+ this.state.partialNext({
4937
+ searchQuery
4938
+ });
4939
+ await Promise.all(searchedSources.map((source) => source.search(searchQuery)));
4940
+ };
4941
+ this.cancelSearchQueries = () => {
4942
+ this.activeSources.forEach((s) => s.cancelScheduledQuery());
4943
+ };
4944
+ this.clear = () => {
4945
+ this.cancelSearchQueries();
4946
+ this.sources.forEach(
4947
+ (source) => source.state.next({ ...source.initialState, isActive: source.isActive })
4948
+ );
4949
+ this.state.next((current) => ({
4950
+ ...current,
4951
+ isActive: true,
4952
+ queriesInProgress: [],
4953
+ searchQuery: ""
4954
+ }));
4955
+ };
4956
+ this.exit = () => {
4957
+ this.cancelSearchQueries();
4958
+ this.sources.forEach(
4959
+ (source) => source.state.next({ ...source.initialState, isActive: source.isActive })
4960
+ );
4961
+ this.state.next((current) => ({
4962
+ ...current,
4963
+ isActive: false,
4964
+ queriesInProgress: [],
4965
+ searchQuery: ""
4966
+ }));
4967
+ };
4968
+ this.state = new StateStore({
4969
+ isActive: false,
4970
+ searchQuery: "",
4971
+ sources: sources ?? []
4972
+ });
4973
+ this._internalState = new StateStore({});
4974
+ this.config = { keepSingleActiveSource: true, ...config };
4975
+ }
4976
+ get hasNext() {
4977
+ return this.sources.some((source) => source.hasNext);
4978
+ }
4979
+ get sources() {
4980
+ return this.state.getLatestValue().sources;
4981
+ }
4982
+ get activeSources() {
4983
+ return this.state.getLatestValue().sources.filter((s) => s.isActive);
4984
+ }
4985
+ get isActive() {
4986
+ return this.state.getLatestValue().isActive;
4987
+ }
4988
+ get searchQuery() {
4989
+ return this.state.getLatestValue().searchQuery;
4990
+ }
4991
+ get searchSourceTypes() {
4992
+ return this.sources.map((s) => s.type);
4993
+ }
4994
+ };
4995
+
4953
4996
  // src/search/UserSearchSource.ts
4954
4997
  var UserSearchSource = class extends BaseSearchSource {
4955
4998
  constructor(client, options, filterBuilderOptions = {}) {
@@ -5056,7 +5099,7 @@ var MessageSearchSource = class extends BaseSearchSource {
5056
5099
  });
5057
5100
  }
5058
5101
  async query(searchQuery) {
5059
- if (!this.client.userID || !searchQuery || this.next === null) return { items: [] };
5102
+ if (!this.client.userID || this.next === null) return { items: [] };
5060
5103
  const channelFilters = this.messageSearchChannelFilterBuilder.buildFilters({
5061
5104
  baseFilters: {
5062
5105
  ...this.client.userID ? { members: { $in: [this.client.userID] } } : {},
@@ -14085,6 +14128,69 @@ var getPendingTaskChannelData = (cid) => {
14085
14128
  };
14086
14129
  };
14087
14130
 
14131
+ // src/utils/FixedSizeQueueCache.ts
14132
+ var FixedSizeQueueCache = class {
14133
+ constructor(size, options) {
14134
+ if (!size) throw new Error("Size must be greater than 0");
14135
+ this.keys = [];
14136
+ this.size = size;
14137
+ this.map = /* @__PURE__ */ new Map();
14138
+ this.dispose = options?.dispose ?? null;
14139
+ }
14140
+ /**
14141
+ * Adds a new or moves the existing reference to the front of the queue
14142
+ * @param key
14143
+ * @param value
14144
+ */
14145
+ add(key, value) {
14146
+ const index = this.keys.indexOf(key);
14147
+ if (index > -1) {
14148
+ this.keys.splice(this.keys.indexOf(key), 1);
14149
+ } else if (this.keys.length >= this.size) {
14150
+ const itemKey = this.keys.shift();
14151
+ if (itemKey) {
14152
+ const item = this.peek(itemKey);
14153
+ if (item) {
14154
+ this.dispose?.(itemKey, item);
14155
+ }
14156
+ this.map.delete(itemKey);
14157
+ }
14158
+ }
14159
+ this.keys.push(key);
14160
+ this.map.set(key, value);
14161
+ }
14162
+ /**
14163
+ * Retrieves the value by key.
14164
+ * @param key
14165
+ */
14166
+ peek(key) {
14167
+ const value = this.map.get(key);
14168
+ return value;
14169
+ }
14170
+ /**
14171
+ * Retrieves the value and moves it to the front of the queue.
14172
+ * @param key
14173
+ */
14174
+ get(key) {
14175
+ const foundItem = this.peek(key);
14176
+ if (foundItem && this.keys.indexOf(key) !== this.size - 1) {
14177
+ this.keys.splice(this.keys.indexOf(key), 1);
14178
+ this.keys.push(key);
14179
+ }
14180
+ return foundItem;
14181
+ }
14182
+ /**
14183
+ * Clears queue entirely and disposes of each item individually.
14184
+ */
14185
+ clear() {
14186
+ if (this.dispose) {
14187
+ this.map.forEach((entry, key) => this.dispose?.(key, entry));
14188
+ }
14189
+ this.map.clear();
14190
+ this.keys = [];
14191
+ }
14192
+ };
14193
+
14088
14194
  // src/client.ts
14089
14195
  function isString2(x) {
14090
14196
  return typeof x === "string" || x instanceof String;
@@ -14291,6 +14397,7 @@ var StreamChat = class _StreamChat {
14291
14397
  this.state = new ClientState({ client: this });
14292
14398
  this.threads.resetState();
14293
14399
  this.uploadManager.reset();
14400
+ this.messageComposerCache.clear();
14294
14401
  closePromise.finally(() => {
14295
14402
  this.tokenManager.reset();
14296
14403
  }).catch((err) => console.error(err));
@@ -14742,6 +14849,7 @@ var StreamChat = class _StreamChat {
14742
14849
  this.polls = new PollManager({ client: this });
14743
14850
  this.reminders = new ReminderManager({ client: this });
14744
14851
  this.messageDeliveryReporter = new MessageDeliveryReporter({ client: this });
14852
+ this.messageComposerCache = new FixedSizeQueueCache(64);
14745
14853
  }
14746
14854
  static getInstance(key, secretOrOptions, options) {
14747
14855
  if (!_StreamChat._instance) {
@@ -16614,7 +16722,7 @@ var StreamChat = class _StreamChat {
16614
16722
  if (this.userAgent) {
16615
16723
  return this.userAgent;
16616
16724
  }
16617
- const version = "9.45.5";
16725
+ const version = "9.46.0";
16618
16726
  const clientBundle = "node-cjs";
16619
16727
  let userAgentString = "";
16620
16728
  if (this.sdkIdentifier) {
@@ -19212,59 +19320,6 @@ var _LiveLocationManager = class _LiveLocationManager extends WithSubscriptions
19212
19320
  };
19213
19321
  _LiveLocationManager.symbol = Symbol(_LiveLocationManager.name);
19214
19322
  var LiveLocationManager = _LiveLocationManager;
19215
-
19216
- // src/utils/FixedSizeQueueCache.ts
19217
- var FixedSizeQueueCache = class {
19218
- constructor(size, options) {
19219
- if (!size) throw new Error("Size must be greater than 0");
19220
- this.keys = [];
19221
- this.size = size;
19222
- this.map = /* @__PURE__ */ new Map();
19223
- this.dispose = options?.dispose ?? null;
19224
- }
19225
- /**
19226
- * Adds a new or moves the existing reference to the front of the queue
19227
- * @param key
19228
- * @param value
19229
- */
19230
- add(key, value) {
19231
- const index = this.keys.indexOf(key);
19232
- if (index > -1) {
19233
- this.keys.splice(this.keys.indexOf(key), 1);
19234
- } else if (this.keys.length >= this.size) {
19235
- const itemKey = this.keys.shift();
19236
- if (itemKey) {
19237
- const item = this.peek(itemKey);
19238
- if (item) {
19239
- this.dispose?.(itemKey, item);
19240
- }
19241
- this.map.delete(itemKey);
19242
- }
19243
- }
19244
- this.keys.push(key);
19245
- this.map.set(key, value);
19246
- }
19247
- /**
19248
- * Retrieves the value by key.
19249
- * @param key
19250
- */
19251
- peek(key) {
19252
- const value = this.map.get(key);
19253
- return value;
19254
- }
19255
- /**
19256
- * Retrieves the value and moves it to the front of the queue.
19257
- * @param key
19258
- */
19259
- get(key) {
19260
- const foundItem = this.peek(key);
19261
- if (foundItem && this.keys.indexOf(key) !== this.size - 1) {
19262
- this.keys.splice(this.keys.indexOf(key), 1);
19263
- this.keys.push(key);
19264
- }
19265
- return foundItem;
19266
- }
19267
- };
19268
19323
  // Annotate the CommonJS export names for ESM import in node:
19269
19324
  0 && (module.exports = {
19270
19325
  AbstractOfflineDB,
@@ -19284,6 +19339,7 @@ var FixedSizeQueueCache = class {
19284
19339
  Channel,
19285
19340
  ChannelBatchUpdater,
19286
19341
  ChannelManager,
19342
+ ChannelMemberSearchSource,
19287
19343
  ChannelSearchSource,
19288
19344
  ChannelState,
19289
19345
  CheckSignature,