stream-chat 9.50.3 → 10.0.0-rc.2
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.
- package/dist/cjs/index.browser.js +19798 -14472
- package/dist/cjs/index.browser.js.map +4 -4
- package/dist/cjs/index.node.js +19817 -14482
- package/dist/cjs/index.node.js.map +4 -4
- package/dist/esm/index.mjs +19795 -14469
- package/dist/esm/index.mjs.map +4 -4
- package/dist/types/ChannelManager.d.ts +221 -0
- package/dist/types/EventHandlerPipeline.d.ts +104 -0
- package/dist/types/api-client.d.ts +26 -0
- package/dist/types/campaign.d.ts +0 -44
- package/dist/types/channel.d.ts +454 -479
- package/dist/types/channel_batch_updater.d.ts +0 -93
- package/dist/types/channel_state.d.ts +53 -201
- package/dist/types/client.d.ts +451 -1920
- package/dist/types/client_state.d.ts +4 -4
- package/dist/types/configuration/InstanceConfigurationService.d.ts +26 -0
- package/dist/types/configuration/index.d.ts +1 -0
- package/dist/types/configuration/types.d.ts +53 -0
- package/dist/types/connection.d.ts +49 -41
- package/dist/types/connection_fallback.d.ts +6 -4
- package/dist/types/constants.d.ts +0 -4
- package/dist/types/custom_types.d.ts +2 -0
- package/dist/types/entityStore/EntityStore.d.ts +111 -0
- package/dist/types/entityStore/StoreBackedItemIndex.d.ts +60 -0
- package/dist/types/entityStore/applyReactionLocally.d.ts +26 -0
- package/dist/types/entityStore/index.d.ts +2 -0
- package/dist/types/errors.d.ts +10 -2
- package/dist/types/gen/chat/ChannelApi.d.ts +45 -0
- package/dist/types/gen/chat/ChatApi.d.ts +334 -0
- package/dist/types/gen/model-decoders/decoders.d.ts +3 -0
- package/dist/types/gen/model-decoders/event-decoder-mapping.d.ts +6 -0
- package/dist/types/gen/models/index.d.ts +8836 -0
- package/dist/types/gen/moderation/ModerationApi.d.ts +50 -0
- package/dist/types/gen-imports.d.ts +3 -0
- package/dist/types/index.d.ts +8 -7
- package/dist/types/insights.d.ts +9 -8
- package/dist/types/logger.d.ts +9 -0
- package/dist/types/messageComposer/LocationComposer.d.ts +7 -4
- package/dist/types/messageComposer/attachmentIdentity.d.ts +2 -2
- package/dist/types/messageComposer/attachmentManager.d.ts +8 -4
- package/dist/types/messageComposer/configuration/types.d.ts +11 -11
- package/dist/types/messageComposer/linkPreviewsManager.d.ts +25 -13
- package/dist/types/messageComposer/messageComposer.d.ts +10 -10
- package/dist/types/messageComposer/middleware/messageComposer/types.d.ts +3 -3
- package/dist/types/messageComposer/middleware/pollComposer/types.d.ts +4 -7
- package/dist/types/messageComposer/middleware/textComposer/commandUtils.d.ts +3 -3
- package/dist/types/messageComposer/middleware/textComposer/commands.d.ts +7 -7
- package/dist/types/messageComposer/middleware/textComposer/mentions.d.ts +218 -4
- package/dist/types/messageComposer/middleware/textComposer/types.d.ts +9 -4
- package/dist/types/messageComposer/pollComposer.d.ts +5 -4
- package/dist/types/messageComposer/textComposer.d.ts +8 -3
- package/dist/types/messageComposer/types.d.ts +6 -28
- package/dist/types/messageDelivery/MessageDeliveryReporter.d.ts +40 -25
- package/dist/types/messageDelivery/MessageReceiptsTracker.d.ts +53 -12
- package/dist/types/messageOperations/MessageOperationStatePolicy.d.ts +19 -0
- package/dist/types/messageOperations/MessageOperations.d.ts +17 -0
- package/dist/types/messageOperations/index.d.ts +3 -0
- package/dist/types/messageOperations/types.d.ts +49 -0
- package/dist/types/moderation.d.ts +21 -203
- package/dist/types/notifications/types.d.ts +8 -7
- package/dist/types/offline-support/offline_support_api.d.ts +111 -87
- package/dist/types/offline-support/offline_sync_manager.d.ts +0 -7
- package/dist/types/offline-support/types.d.ts +19 -23
- package/dist/types/offline-support/util.d.ts +4 -2
- package/dist/types/pagination/FilterBuilder.d.ts +1 -1
- package/dist/types/pagination/ItemIndex.d.ts +25 -0
- package/dist/types/pagination/cursorDerivation/createdAtAroundPaginationFlags.d.ts +9 -0
- package/dist/types/pagination/cursorDerivation/idAroundPaginationFlags.d.ts +6 -0
- package/dist/types/pagination/cursorDerivation/index.d.ts +1 -0
- package/dist/types/pagination/cursorDerivation/linearPaginationFlags.d.ts +6 -0
- package/dist/types/pagination/filterCompiler.d.ts +7 -0
- package/dist/types/pagination/index.d.ts +1 -3
- package/dist/types/pagination/paginators/BasePaginator.d.ts +848 -0
- package/dist/types/pagination/paginators/ChannelPaginator.d.ts +212 -0
- package/dist/types/pagination/paginators/MessageIntervalPaginator.d.ts +282 -0
- package/dist/types/pagination/paginators/MessagePaginator.d.ts +208 -0
- package/dist/types/pagination/paginators/PinnedMessagePaginator.d.ts +39 -0
- package/dist/types/pagination/paginators/ReminderPaginator.d.ts +19 -0
- package/dist/types/pagination/paginators/UserGroupPaginator.d.ts +24 -0
- package/dist/types/pagination/paginators/index.d.ts +7 -0
- package/dist/types/pagination/paginators/stateThrottling.d.ts +2 -0
- package/dist/types/pagination/sortCompiler.d.ts +49 -0
- package/dist/types/pagination/types.normalization.d.ts +11 -0
- package/dist/types/pagination/utility.normalization.d.ts +18 -0
- package/dist/types/pagination/utility.queryChannel.d.ts +26 -0
- package/dist/types/pagination/utility.search.d.ts +13 -0
- package/dist/types/permissions.d.ts +1 -1
- package/dist/types/poll.d.ts +29 -32
- package/dist/types/poll_manager.d.ts +2 -2
- package/dist/types/reminders/Reminder.d.ts +2 -5
- package/dist/types/reminders/ReminderManager.d.ts +2 -9
- package/dist/types/search/MessageSearchSource.d.ts +4 -4
- package/dist/types/search/UserSearchSource.d.ts +1 -1
- package/dist/types/search/types.d.ts +3 -3
- package/dist/types/segment.d.ts +0 -34
- package/dist/types/signing.d.ts +105 -65
- package/dist/types/store.d.ts +1 -0
- package/dist/types/thread.d.ts +70 -34
- package/dist/types/thread_manager.d.ts +3 -3
- package/dist/types/token_manager.d.ts +15 -10
- package/dist/types/types.d.ts +197 -3404
- package/dist/types/utils/FixedSizeQueueCache.d.ts +12 -6
- package/dist/types/utils/WithSubscriptions.d.ts +2 -1
- package/dist/types/utils/concurrency.d.ts +4 -4
- package/dist/types/utils/mergeWith/mergeWith.d.ts +3 -3
- package/dist/types/utils/mergeWith/mergeWithCore.d.ts +8 -3
- package/dist/types/utils/retryable.d.ts +34 -0
- package/dist/types/utils/throttling/throttle.d.ts +36 -0
- package/dist/types/utils.d.ts +100 -194
- package/package.json +7 -3
- package/src/ChannelManager.ts +724 -0
- package/src/CooldownTimer.ts +2 -2
- package/src/EventHandlerPipeline.ts +228 -0
- package/src/LiveLocationManager.ts +12 -11
- package/src/api-client.ts +275 -0
- package/src/campaign.ts +1 -77
- package/src/channel.ts +1344 -1282
- package/src/channel_batch_updater.ts +1 -211
- package/src/channel_state.ts +144 -1013
- package/src/client.ts +936 -3995
- package/src/client_state.ts +4 -4
- package/src/configuration/InstanceConfigurationService.ts +73 -0
- package/src/configuration/index.ts +1 -0
- package/src/configuration/types.ts +81 -0
- package/src/connection.ts +145 -94
- package/src/connection_fallback.ts +29 -27
- package/src/constants.ts +1 -5
- package/src/custom_types.ts +4 -1
- package/src/entityStore/EntityStore.ts +208 -0
- package/src/entityStore/StoreBackedItemIndex.ts +115 -0
- package/src/entityStore/applyReactionLocally.ts +113 -0
- package/src/entityStore/index.ts +2 -0
- package/src/errors.ts +14 -2
- package/src/gen/chat/ChannelApi.ts +275 -0
- package/src/gen/chat/ChatApi.ts +2554 -0
- package/src/gen/model-decoders/decoders.ts +2680 -0
- package/src/gen/model-decoders/event-decoder-mapping.ts +198 -0
- package/src/gen/models/index.ts +12673 -0
- package/src/gen/moderation/ModerationApi.ts +607 -0
- package/src/gen-imports.ts +3 -0
- package/src/index.ts +11 -12
- package/src/insights.ts +6 -5
- package/src/logger.ts +28 -0
- package/src/messageComposer/LocationComposer.ts +9 -5
- package/src/messageComposer/MessageComposerEffectHandlers.ts +1 -0
- package/src/messageComposer/attachmentIdentity.ts +16 -9
- package/src/messageComposer/attachmentManager.ts +13 -8
- package/src/messageComposer/configuration/types.ts +11 -11
- package/src/messageComposer/linkPreviewsManager.ts +9 -10
- package/src/messageComposer/messageComposer.ts +57 -53
- package/src/messageComposer/middleware/messageComposer/attachments.ts +1 -2
- package/src/messageComposer/middleware/messageComposer/cleanData.ts +1 -1
- package/src/messageComposer/middleware/messageComposer/compositionValidation.ts +2 -2
- package/src/messageComposer/middleware/messageComposer/messageComposerState.ts +2 -2
- package/src/messageComposer/middleware/messageComposer/sharedLocation.ts +4 -3
- package/src/messageComposer/middleware/messageComposer/textComposer.ts +2 -2
- package/src/messageComposer/middleware/messageComposer/types.ts +3 -4
- package/src/messageComposer/middleware/messageComposer/userDataInjection.ts +9 -5
- package/src/messageComposer/middleware/pollComposer/state.ts +0 -2
- package/src/messageComposer/middleware/pollComposer/types.ts +4 -7
- package/src/messageComposer/middleware/textComposer/TextComposerMiddlewareExecutor.ts +10 -1
- package/src/messageComposer/middleware/textComposer/commandEffects.ts +4 -4
- package/src/messageComposer/middleware/textComposer/commandUtils.ts +3 -6
- package/src/messageComposer/middleware/textComposer/commands.ts +3 -3
- package/src/messageComposer/middleware/textComposer/mentionUtils.ts +1 -1
- package/src/messageComposer/middleware/textComposer/mentions.ts +31 -15
- package/src/messageComposer/middleware/textComposer/types.ts +9 -4
- package/src/messageComposer/pollComposer.ts +6 -8
- package/src/messageComposer/textComposer.ts +27 -2
- package/src/messageComposer/types.ts +6 -28
- package/src/messageDelivery/MessageDeliveryReporter.ts +101 -45
- package/src/messageDelivery/MessageReceiptsTracker.ts +294 -21
- package/src/messageOperations/MessageOperationStatePolicy.ts +77 -0
- package/src/messageOperations/MessageOperations.ts +212 -0
- package/src/messageOperations/index.ts +10 -0
- package/src/messageOperations/types.ts +64 -0
- package/src/moderation.ts +38 -431
- package/src/notifications/types.ts +8 -7
- package/src/offline-support/offline_support_api.ts +200 -133
- package/src/offline-support/offline_sync_manager.ts +23 -44
- package/src/offline-support/types.ts +23 -26
- package/src/offline-support/util.ts +5 -4
- package/src/pagination/FilterBuilder.ts +4 -1
- package/src/pagination/ItemIndex.ts +25 -0
- package/src/pagination/cursorDerivation/createdAtAroundPaginationFlags.ts +73 -0
- package/src/pagination/cursorDerivation/idAroundPaginationFlags.ts +53 -0
- package/src/pagination/cursorDerivation/index.ts +1 -0
- package/src/pagination/cursorDerivation/linearPaginationFlags.ts +86 -0
- package/src/pagination/filterCompiler.ts +196 -0
- package/src/pagination/index.ts +1 -3
- package/src/pagination/paginators/BasePaginator.ts +2859 -0
- package/src/pagination/paginators/ChannelPaginator.ts +729 -0
- package/src/pagination/paginators/MessageIntervalPaginator.ts +1116 -0
- package/src/pagination/paginators/MessagePaginator.ts +508 -0
- package/src/pagination/paginators/PinnedMessagePaginator.ts +108 -0
- package/src/pagination/paginators/ReminderPaginator.ts +107 -0
- package/src/pagination/paginators/UserGroupPaginator.ts +127 -0
- package/src/pagination/paginators/index.ts +7 -0
- package/src/pagination/paginators/stateThrottling.ts +31 -0
- package/src/pagination/sortCompiler.ts +193 -0
- package/src/pagination/types.normalization.ts +14 -0
- package/src/pagination/utility.normalization.ts +106 -0
- package/src/pagination/utility.queryChannel.ts +84 -0
- package/src/pagination/utility.search.ts +80 -0
- package/src/permissions.ts +7 -8
- package/src/poll.ts +101 -110
- package/src/poll_manager.ts +14 -8
- package/src/reminders/Reminder.ts +2 -5
- package/src/reminders/ReminderManager.ts +19 -21
- package/src/search/BaseSearchSource.ts +0 -3
- package/src/search/ChannelMemberSearchSource.ts +7 -1
- package/src/search/ChannelSearchSource.ts +10 -3
- package/src/search/MessageSearchSource.ts +29 -30
- package/src/search/UserSearchSource.ts +12 -8
- package/src/search/types.ts +3 -4
- package/src/segment.ts +1 -95
- package/src/signing.ts +107 -67
- package/src/store.ts +2 -1
- package/src/thread.ts +562 -238
- package/src/thread_manager.ts +37 -16
- package/src/token_manager.ts +21 -10
- package/src/types.ts +364 -4533
- package/src/uploadManager.ts +8 -0
- package/src/utils/FixedSizeQueueCache.ts +12 -6
- package/src/utils/WithSubscriptions.ts +2 -1
- package/src/utils/concurrency.ts +4 -4
- package/src/utils/mergeWith/mergeWith.ts +3 -3
- package/src/utils/mergeWith/mergeWithCore.ts +140 -164
- package/src/utils/mergeWith/mergeWithDiff.ts +3 -3
- package/src/utils/retryable.ts +117 -0
- package/src/utils/throttling/throttle.ts +130 -0
- package/src/utils.ts +208 -754
- package/dist/types/channel_manager.d.ts +0 -122
- package/dist/types/events.d.ts +0 -72
- package/dist/types/pagination/BasePaginator.d.ts +0 -69
- package/dist/types/pagination/ReminderPaginator.d.ts +0 -16
- package/dist/types/pagination/UserGroupPaginator.d.ts +0 -21
- package/src/channel_manager.ts +0 -830
- package/src/events.ts +0 -75
- package/src/pagination/BasePaginator.ts +0 -184
- package/src/pagination/ReminderPaginator.ts +0 -56
- package/src/pagination/UserGroupPaginator.ts +0 -93
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
import {
|
|
2
|
+
arraysEqualAsSets,
|
|
3
|
+
asArray,
|
|
4
|
+
compare,
|
|
5
|
+
isIterableButNotString,
|
|
6
|
+
normalizeComparedValues,
|
|
7
|
+
resolveDotPathValue,
|
|
8
|
+
toIterableArray,
|
|
9
|
+
tokenize,
|
|
10
|
+
} from './utility.normalization';
|
|
11
|
+
import type { FieldToDataResolver } from './types.normalization';
|
|
12
|
+
import type { QueryFilters } from '../types';
|
|
13
|
+
|
|
14
|
+
export type ItemMatchesFilterOptions<DataSource> = {
|
|
15
|
+
/** Custom resolvers to extract values from an item given a path */
|
|
16
|
+
resolvers?: ReadonlyArray<FieldToDataResolver<DataSource>>;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export function itemMatchesFilter<T>(
|
|
20
|
+
item: T,
|
|
21
|
+
filter: QueryFilters<any>,
|
|
22
|
+
options: ItemMatchesFilterOptions<T>,
|
|
23
|
+
): boolean {
|
|
24
|
+
const resolvers = options.resolvers ?? [];
|
|
25
|
+
const resolverValueCache = new Map<string, unknown>();
|
|
26
|
+
|
|
27
|
+
const resolveOnce = (field: string) => {
|
|
28
|
+
if (resolverValueCache.has(field)) return resolverValueCache.get(field);
|
|
29
|
+
const resolver = resolvers?.find((resolver) => resolver.matchesField(field)) ?? {
|
|
30
|
+
resolve: resolveDotPathValue,
|
|
31
|
+
};
|
|
32
|
+
const value = resolver.resolve(item, field);
|
|
33
|
+
resolverValueCache.set(field, value);
|
|
34
|
+
return value;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const matches = (filterNode: QueryFilters<any>): boolean => {
|
|
38
|
+
if (!filterNode || typeof filterNode !== 'object') return true;
|
|
39
|
+
|
|
40
|
+
// Logical operators are ANDed with each other AND with any sibling field conditions on the
|
|
41
|
+
// same node (MongoDB / Stream server semantics: `{ $or: [...], field: value }` means
|
|
42
|
+
// `(field == value) AND ($or ...)`). They must not short-circuit past the field loop below.
|
|
43
|
+
if (filterNode.$and && !filterNode.$and.every((n) => matches(n))) return false;
|
|
44
|
+
if (filterNode.$or && !filterNode.$or.some((n) => matches(n))) return false;
|
|
45
|
+
if (filterNode.$nor && filterNode.$nor.some((n) => matches(n))) return false;
|
|
46
|
+
|
|
47
|
+
for (const [field, condition] of Object.entries(filterNode)) {
|
|
48
|
+
if (field === '$and' || field === '$or' || field === '$nor') continue;
|
|
49
|
+
const itemPropertyValue = resolveOnce(field);
|
|
50
|
+
|
|
51
|
+
if (
|
|
52
|
+
typeof condition !== 'object' ||
|
|
53
|
+
condition === null ||
|
|
54
|
+
Array.isArray(condition)
|
|
55
|
+
) {
|
|
56
|
+
if (!equalsOp(itemPropertyValue, condition)) return false;
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
for (const [op, filterValue] of Object.entries(condition)) {
|
|
61
|
+
switch (op) {
|
|
62
|
+
case '$eq':
|
|
63
|
+
if (!equalsOp(itemPropertyValue, filterValue)) return false;
|
|
64
|
+
break;
|
|
65
|
+
case '$ne':
|
|
66
|
+
if (equalsOp(itemPropertyValue, filterValue)) return false;
|
|
67
|
+
break;
|
|
68
|
+
|
|
69
|
+
case '$in':
|
|
70
|
+
if (!inSetOp(itemPropertyValue, asArray(filterValue))) return false;
|
|
71
|
+
break;
|
|
72
|
+
case '$nin':
|
|
73
|
+
if (inSetOp(itemPropertyValue, asArray(filterValue))) return false;
|
|
74
|
+
break;
|
|
75
|
+
|
|
76
|
+
case '$gt':
|
|
77
|
+
if (!orderedCompareOp(itemPropertyValue, filterValue, (c) => c > 0))
|
|
78
|
+
return false;
|
|
79
|
+
break;
|
|
80
|
+
case '$gte':
|
|
81
|
+
if (!orderedCompareOp(itemPropertyValue, filterValue, (c) => c >= 0))
|
|
82
|
+
return false;
|
|
83
|
+
break;
|
|
84
|
+
case '$lt':
|
|
85
|
+
if (!orderedCompareOp(itemPropertyValue, filterValue, (c) => c < 0))
|
|
86
|
+
return false;
|
|
87
|
+
break;
|
|
88
|
+
case '$lte':
|
|
89
|
+
if (!orderedCompareOp(itemPropertyValue, filterValue, (c) => c <= 0))
|
|
90
|
+
return false;
|
|
91
|
+
break;
|
|
92
|
+
|
|
93
|
+
case '$exists':
|
|
94
|
+
if (!!itemPropertyValue !== !!filterValue) return false;
|
|
95
|
+
break;
|
|
96
|
+
case '$contains':
|
|
97
|
+
if (!containsOp(itemPropertyValue, filterValue)) return false;
|
|
98
|
+
break;
|
|
99
|
+
case '$autocomplete':
|
|
100
|
+
if (!autoCompleteOp(itemPropertyValue, filterValue)) return false;
|
|
101
|
+
break;
|
|
102
|
+
default:
|
|
103
|
+
return false;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return true;
|
|
108
|
+
};
|
|
109
|
+
return matches(filter);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Duplicates ignored for array–array equality: ['a','a','b'] equals ['b','a'].
|
|
114
|
+
*
|
|
115
|
+
* Empty arrays: [] equals []; a scalar never equals [].
|
|
116
|
+
*
|
|
117
|
+
* This reuses your normalizeComparedValues so '1' equals 1, ISO dates compare correctly, etc.
|
|
118
|
+
*
|
|
119
|
+
* $gt/$gte/$lt/$lte remain scalar-only (return false if either side is iterable), as you wanted.
|
|
120
|
+
*
|
|
121
|
+
* $in/$nin left may be scalar or iterable; the right is a list.
|
|
122
|
+
*
|
|
123
|
+
* @param a - Left-hand operand.
|
|
124
|
+
* @param b - Right-hand operand.
|
|
125
|
+
* @param ok - Predicate applied to the result of comparing `a` and `b`.
|
|
126
|
+
*/
|
|
127
|
+
function orderedCompareOp(a: any, b: any, ok: (c: number) => boolean): boolean {
|
|
128
|
+
if (isIterableButNotString(a) || isIterableButNotString(b)) return false;
|
|
129
|
+
const n = normalizeComparedValues(a, b);
|
|
130
|
+
if (n.kind === 'incomparable') return false;
|
|
131
|
+
return ok(compare(n.a, n.b));
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function equalsOp(left: any, right: any): boolean {
|
|
135
|
+
const leftIsIter = isIterableButNotString(left);
|
|
136
|
+
const rightIsIter = isIterableButNotString(right);
|
|
137
|
+
|
|
138
|
+
if (!leftIsIter && !rightIsIter) {
|
|
139
|
+
// scalar vs scalar
|
|
140
|
+
const n = normalizeComparedValues(left, right);
|
|
141
|
+
if (n.kind === 'incomparable') return Object.is(left, right);
|
|
142
|
+
return n.a === n.b;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
if (leftIsIter && rightIsIter) {
|
|
146
|
+
// array vs array → set equality (order-insensitive)
|
|
147
|
+
const a = toIterableArray(left);
|
|
148
|
+
const b = toIterableArray(right);
|
|
149
|
+
return arraysEqualAsSets(a, b);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// one side scalar, the other iterable → membership
|
|
153
|
+
if (leftIsIter) {
|
|
154
|
+
const a = toIterableArray(left);
|
|
155
|
+
return a.some((elem) => equalsOp(elem, right));
|
|
156
|
+
} else {
|
|
157
|
+
const b = toIterableArray(right);
|
|
158
|
+
return b.some((elem) => equalsOp(left, elem));
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
function inSetOp(a: any, arr: any[]): boolean {
|
|
163
|
+
return arr.some((b) => equalsOp(a, b));
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
function containsOp(value: any, needle: any): boolean {
|
|
167
|
+
if (Array.isArray(value)) return value.includes(needle);
|
|
168
|
+
if (typeof value === 'string' && typeof needle === 'string')
|
|
169
|
+
return value.includes(needle);
|
|
170
|
+
return false;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* A value matches an autocomplete query if:
|
|
175
|
+
* - value is string: every query token is a prefix of some token in the value
|
|
176
|
+
* - value is string[]: any element matches as above
|
|
177
|
+
* - query can be string (tokenized) or string[]
|
|
178
|
+
*/
|
|
179
|
+
function autoCompleteOp(value: any, query: any): boolean {
|
|
180
|
+
if (value == null || query == null) return false;
|
|
181
|
+
|
|
182
|
+
const queryTokens: string[] = Array.isArray(query)
|
|
183
|
+
? query.map(String).flatMap(tokenize)
|
|
184
|
+
: tokenize(String(query));
|
|
185
|
+
if (queryTokens.length === 0) return false;
|
|
186
|
+
|
|
187
|
+
const matchOneString = (s: string): boolean => {
|
|
188
|
+
const valTokens = tokenize(s);
|
|
189
|
+
return queryTokens.every((qt) => valTokens.some((vt) => vt.includes(qt)));
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
if (typeof value === 'string') return matchOneString(value);
|
|
193
|
+
if (Array.isArray(value))
|
|
194
|
+
return value.some((v) => typeof v === 'string' && matchOneString(v));
|
|
195
|
+
return false;
|
|
196
|
+
}
|
package/src/pagination/index.ts
CHANGED