cry-search 1.0.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.
- package/CLAUDE.md +285 -0
- package/LICENSE.md +67 -0
- package/README.md +283 -0
- package/UNIVERSE.md +818 -0
- package/dist/common/SearchUniverse.d.ts +210 -0
- package/dist/common/SearchUniverse.d.ts.map +1 -0
- package/dist/common/findInArray.d.ts +37 -0
- package/dist/common/findInArray.d.ts.map +1 -0
- package/dist/common/findInArrayReturnDataAndMeta.d.ts +52 -0
- package/dist/common/findInArrayReturnDataAndMeta.d.ts.map +1 -0
- package/dist/common/findInLinkedArrays.d.ts +66 -0
- package/dist/common/findInLinkedArrays.d.ts.map +1 -0
- package/dist/common/numeric/createSearchArrayMetadata.d.ts +65 -0
- package/dist/common/numeric/createSearchArrayMetadata.d.ts.map +1 -0
- package/dist/common/numeric/createSearchLinkedMetadata.d.ts +46 -0
- package/dist/common/numeric/createSearchLinkedMetadata.d.ts.map +1 -0
- package/dist/common/numeric/findInLinkedArrays.d.ts +32 -0
- package/dist/common/numeric/findInLinkedArrays.d.ts.map +1 -0
- package/dist/common/numeric/index.d.ts +9 -0
- package/dist/common/numeric/index.d.ts.map +1 -0
- package/dist/common/numeric/searchInData.d.ts +31 -0
- package/dist/common/numeric/searchInData.d.ts.map +1 -0
- package/dist/common/numeric/updateSearchMetadata.d.ts +60 -0
- package/dist/common/numeric/updateSearchMetadata.d.ts.map +1 -0
- package/dist/common/string/createSearchArrayMetadata.d.ts +117 -0
- package/dist/common/string/createSearchArrayMetadata.d.ts.map +1 -0
- package/dist/common/string/createSearchLinkedMetadata.d.ts +36 -0
- package/dist/common/string/createSearchLinkedMetadata.d.ts.map +1 -0
- package/dist/common/string/index.d.ts +10 -0
- package/dist/common/string/index.d.ts.map +1 -0
- package/dist/common/string/updateSearchMetadata.d.ts +103 -0
- package/dist/common/string/updateSearchMetadata.d.ts.map +1 -0
- package/dist/common/syncSearchArrayMetadata.d.ts +64 -0
- package/dist/common/syncSearchArrayMetadata.d.ts.map +1 -0
- package/dist/common/updateSearchLinkedMetadata.d.ts +129 -0
- package/dist/common/updateSearchLinkedMetadata.d.ts.map +1 -0
- package/dist/index.cjs +1827 -0
- package/dist/index.d.cts +32 -0
- package/dist/index.d.ts +32 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1795 -0
- package/dist/types/index.d.ts +300 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types.d.ts +6 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/utils/matchToken.d.ts +65 -0
- package/dist/utils/matchToken.d.ts.map +1 -0
- package/dist/utils/matchTokenNumeric.d.ts +94 -0
- package/dist/utils/matchTokenNumeric.d.ts.map +1 -0
- package/dist/utils/normalizeDates.d.ts +39 -0
- package/dist/utils/normalizeDates.d.ts.map +1 -0
- package/dist/utils/prepareStringForSearch.d.ts +28 -0
- package/dist/utils/prepareStringForSearch.d.ts.map +1 -0
- package/dist/utils/prepareStringForSearchNumeric.d.ts +42 -0
- package/dist/utils/prepareStringForSearchNumeric.d.ts.map +1 -0
- package/dist/utils/preprocessString.d.ts +26 -0
- package/dist/utils/preprocessString.d.ts.map +1 -0
- package/dist/utils/sanitiseString.d.ts +26 -0
- package/dist/utils/sanitiseString.d.ts.map +1 -0
- package/dist/utils/tokenRegistry.d.ts +70 -0
- package/dist/utils/tokenRegistry.d.ts.map +1 -0
- package/dist/utils/tokenize.d.ts +46 -0
- package/dist/utils/tokenize.d.ts.map +1 -0
- package/package.json +67 -0
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core types for cry-search library
|
|
3
|
+
*/
|
|
4
|
+
/** Unique identifier for searchable objects */
|
|
5
|
+
export type Id = string;
|
|
6
|
+
/** A single search token (preprocessed and sanitized) */
|
|
7
|
+
export type SearchToken = string;
|
|
8
|
+
/** Sorted array of search tokens for efficient matching */
|
|
9
|
+
export type SearchTokenSortedList = SearchToken[];
|
|
10
|
+
/** Numeric token ID (index into global tokens array) */
|
|
11
|
+
export type NumericToken = number;
|
|
12
|
+
/** Sorted Uint32Array of numeric token IDs for memory-efficient storage */
|
|
13
|
+
export type NumericTokenSortedList = Uint32Array;
|
|
14
|
+
/** Metadata mapping object IDs to their sorted token lists (string-based) */
|
|
15
|
+
export type SearchMetadata = Map<Id, SearchTokenSortedList>;
|
|
16
|
+
/** Metadata mapping object IDs to their sorted numeric token lists */
|
|
17
|
+
export type NumericSearchMetadata = Map<Id, NumericTokenSortedList>;
|
|
18
|
+
/** Map of objects by their ID for efficient lookup */
|
|
19
|
+
export type SearchableData<T extends SearchableObject> = Map<Id, T>;
|
|
20
|
+
/** Base interface for searchable objects - must have unique _id */
|
|
21
|
+
export interface SearchableObject {
|
|
22
|
+
_id: Id;
|
|
23
|
+
_deleted?: Date;
|
|
24
|
+
_blocked?: Date;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Match mode for search tokens
|
|
28
|
+
* - 'start': match from beginning only - "rex" matches "rexona" but not "ceporex"
|
|
29
|
+
* - 'end': match from end only - "rex" matches "ceporex" but not "rexona"
|
|
30
|
+
* - 'startEnd': match from start OR end - "rex" matches both "rexona" and "ceporex" but not "unrexy"
|
|
31
|
+
* - 'anywhere': match anywhere - "rex" matches "unrexy", "ceporex", "rexona"
|
|
32
|
+
* - 'whole': exact match only - "rex" matches "rex" but not "rexona" or "ceporex"
|
|
33
|
+
*/
|
|
34
|
+
export type MatchMode = 'start' | 'end' | 'startEnd' | 'anywhere' | 'whole';
|
|
35
|
+
/**
|
|
36
|
+
* Specification for how to extract searchable text from objects
|
|
37
|
+
*/
|
|
38
|
+
export interface SearchableObjectSpec<T extends SearchableObject, C = unknown> {
|
|
39
|
+
/** Fields to include in search (if not specified, all string fields are used) */
|
|
40
|
+
searchInFields?: (keyof T)[];
|
|
41
|
+
/** Fields to exclude from search */
|
|
42
|
+
dontSearchInFields?: (keyof T)[];
|
|
43
|
+
/** Optional context passed to enrichSearchObjectFn */
|
|
44
|
+
searchContext?: C;
|
|
45
|
+
/** Custom function to extract searchable string from object */
|
|
46
|
+
extractSearchableStringFn?: (obj: T) => string | undefined;
|
|
47
|
+
/** Function to enrich object with additional searchable fields before extraction */
|
|
48
|
+
enrichSearchObjectFn?: (obj: T, searchContext: C) => void;
|
|
49
|
+
/**
|
|
50
|
+
* Per-field match mode overrides. Tokens from these fields will have a prefix
|
|
51
|
+
* that forces the specified match mode, ignoring global SearchOpts.
|
|
52
|
+
* Prefixes: < (start), > (end), + (startEnd), * (anywhere), ! (whole)
|
|
53
|
+
*/
|
|
54
|
+
fieldMatchModes?: Partial<Record<keyof T, MatchMode>>;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Options for controlling how search matching works
|
|
58
|
+
*/
|
|
59
|
+
export interface SearchOpts {
|
|
60
|
+
/**
|
|
61
|
+
* How to match words (non-numeric tokens)
|
|
62
|
+
* @default 'start'
|
|
63
|
+
*/
|
|
64
|
+
matchWords?: MatchMode;
|
|
65
|
+
/**
|
|
66
|
+
* How to match numbers (numeric tokens)
|
|
67
|
+
* @default 'startEnd'
|
|
68
|
+
*/
|
|
69
|
+
matchNumbers?: MatchMode;
|
|
70
|
+
}
|
|
71
|
+
/** Default search options */
|
|
72
|
+
export declare const DEFAULT_SEARCH_OPTS: Required<SearchOpts>;
|
|
73
|
+
/** Linked search metadata for searching across related arrays */
|
|
74
|
+
export interface LinkedSearchMetadata {
|
|
75
|
+
/** Metadata for primary items */
|
|
76
|
+
primaryMeta: SearchMetadata;
|
|
77
|
+
/** Metadata for linked/secondary items */
|
|
78
|
+
linkedMeta: SearchMetadata;
|
|
79
|
+
/** Index: primary._id -> linked._id[] */
|
|
80
|
+
primaryToLinked: Map<Id, Id[]>;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Extended linked search metadata that includes data references for convenient access during search.
|
|
84
|
+
*
|
|
85
|
+
* Extends {@link LinkedSearchMetadata} with direct references to the primary and linked data maps,
|
|
86
|
+
* so search functions don't need to pass them separately.
|
|
87
|
+
*
|
|
88
|
+
* @typeParam TPrimary - Type of primary items (e.g., Stranka)
|
|
89
|
+
* @typeParam TLinked - Type of linked items (e.g., Pacient)
|
|
90
|
+
*/
|
|
91
|
+
export interface SearchLinkedMetadataWithData<TPrimary extends SearchableObject, TLinked extends SearchableObject> extends LinkedSearchMetadata {
|
|
92
|
+
/** Reference to primary data map */
|
|
93
|
+
primaryData: SearchableData<TPrimary>;
|
|
94
|
+
/** Reference to linked data map */
|
|
95
|
+
linkedData: SearchableData<TLinked>;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Specification for linked search across two related arrays
|
|
99
|
+
*/
|
|
100
|
+
export interface SearchableLinkedObjectsSpec<TPrimary extends SearchableObject, TLinked extends SearchableObject, CPrimary = unknown, CLinked = unknown> {
|
|
101
|
+
/** Spec for primary items */
|
|
102
|
+
primarySpec?: SearchableObjectSpec<TPrimary, CPrimary>;
|
|
103
|
+
/** Spec for linked items */
|
|
104
|
+
linkedSpec?: SearchableObjectSpec<TLinked, CLinked>;
|
|
105
|
+
/** Function to get primary ID from linked item (foreign key) */
|
|
106
|
+
foreignKeyGetter: (linked: TLinked) => Id | undefined;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Result of a linked search operation.
|
|
110
|
+
*
|
|
111
|
+
* Contains the primary item and the linked items that contributed to the match,
|
|
112
|
+
* along with information about where the match was found.
|
|
113
|
+
*
|
|
114
|
+
* @typeParam TPrimary - Type of primary items (e.g., Stranka)
|
|
115
|
+
* @typeParam TLinked - Type of linked items (e.g., Pacient)
|
|
116
|
+
*/
|
|
117
|
+
export interface LinkedSearchResult<TPrimary, TLinked> {
|
|
118
|
+
/** The primary item (e.g., stranka) */
|
|
119
|
+
primary: TPrimary;
|
|
120
|
+
/** Linked items that contributed to the match (not all linked items) */
|
|
121
|
+
linked: TLinked[];
|
|
122
|
+
/** Where the match was found: primary only, linked only, or both */
|
|
123
|
+
matchedIn: 'primary' | 'linked' | 'both';
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Result of a linked search with query metadata.
|
|
127
|
+
*
|
|
128
|
+
* Includes the tokenized query for debugging/highlighting purposes.
|
|
129
|
+
*
|
|
130
|
+
* @typeParam TPrimary - Type of primary items (e.g., Stranka)
|
|
131
|
+
* @typeParam TLinked - Type of linked items (e.g., Pacient)
|
|
132
|
+
*/
|
|
133
|
+
export interface LinkedSearchResultWithMeta<TPrimary, TLinked> {
|
|
134
|
+
/** The search query tokens (after preprocessing) */
|
|
135
|
+
queryTokens: SearchTokenSortedList;
|
|
136
|
+
/** Array of matching results */
|
|
137
|
+
results: LinkedSearchResult<TPrimary, TLinked>[];
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Result of a search operation with metadata included.
|
|
141
|
+
*
|
|
142
|
+
* Contains the tokenized query and matching items along with their
|
|
143
|
+
* pre-computed tokens. Useful for debugging, highlighting, or
|
|
144
|
+
* understanding why items matched.
|
|
145
|
+
*
|
|
146
|
+
* @typeParam T - Type of items being searched
|
|
147
|
+
*/
|
|
148
|
+
export interface SearchResultWithMeta<T extends SearchableObject> {
|
|
149
|
+
/** The search query tokens (after preprocessing) */
|
|
150
|
+
queryTokens: SearchTokenSortedList;
|
|
151
|
+
/** Array of matching items with their token metadata */
|
|
152
|
+
results: Array<{
|
|
153
|
+
/** The matched item */
|
|
154
|
+
item: T;
|
|
155
|
+
/** Pre-computed tokens for this item */
|
|
156
|
+
tokens: SearchTokenSortedList;
|
|
157
|
+
}>;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Result of a sync operation.
|
|
161
|
+
*
|
|
162
|
+
* Contains counts and IDs of items that were added, updated, or removed
|
|
163
|
+
* during the sync process.
|
|
164
|
+
*/
|
|
165
|
+
export interface SyncResult {
|
|
166
|
+
/** Number of items added */
|
|
167
|
+
added: number;
|
|
168
|
+
/** Number of items updated (tokens changed) */
|
|
169
|
+
updated: number;
|
|
170
|
+
/** Number of items removed */
|
|
171
|
+
removed: number;
|
|
172
|
+
/** IDs of added items */
|
|
173
|
+
addedIds: Id[];
|
|
174
|
+
/** IDs of updated items */
|
|
175
|
+
updatedIds: Id[];
|
|
176
|
+
/** IDs of removed items */
|
|
177
|
+
removedIds: Id[];
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Options for sync operations.
|
|
181
|
+
*/
|
|
182
|
+
export interface SyncOptions {
|
|
183
|
+
/**
|
|
184
|
+
* If true, skips checking if existing items have changed.
|
|
185
|
+
* Useful when you know items haven't changed to save processing time.
|
|
186
|
+
* @default false
|
|
187
|
+
*/
|
|
188
|
+
skipUpdateCheck?: boolean;
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Result of syncing linked items for a primary.
|
|
192
|
+
*/
|
|
193
|
+
export interface SyncLinkedResult {
|
|
194
|
+
/** Number of new linked items added */
|
|
195
|
+
added: number;
|
|
196
|
+
/** Number of existing linked items updated */
|
|
197
|
+
updated: number;
|
|
198
|
+
/** Number of linked items removed */
|
|
199
|
+
removed: number;
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Result of upserting an item to linked metadata.
|
|
203
|
+
*/
|
|
204
|
+
export interface UpsertResult {
|
|
205
|
+
/** True if the item was newly added, false if it was updated */
|
|
206
|
+
added: boolean;
|
|
207
|
+
/** Previous primary ID if the foreign key changed (only for linked items) */
|
|
208
|
+
previousPrimaryId?: Id | undefined;
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Batch item for updating search metadata.
|
|
212
|
+
*
|
|
213
|
+
* @typeParam T - Type of the searchable object
|
|
214
|
+
*/
|
|
215
|
+
export interface UpdateSearchMetadataBatchItem<T extends SearchableObject> {
|
|
216
|
+
/** The ID of the object to update */
|
|
217
|
+
objectId: Id;
|
|
218
|
+
/** The object to update (may be null, undefined, deleted, or blocked - null/undefined removes from search) */
|
|
219
|
+
obj: T | null | undefined;
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Extended search options for the {@link SearchUniverse.searchUniversally} method.
|
|
223
|
+
*
|
|
224
|
+
* Inherits all options from {@link SearchOpts} and adds collection filtering.
|
|
225
|
+
*/
|
|
226
|
+
export interface UniversalSearchOpts extends SearchOpts {
|
|
227
|
+
/**
|
|
228
|
+
* If specified, only search in these collections.
|
|
229
|
+
* Use collection name for standalone collections (e.g., "artikli")
|
|
230
|
+
* Use "linked-primary" format for linked collections (e.g., "pacienti-stranke", "racuni-pacienti")
|
|
231
|
+
*/
|
|
232
|
+
inCollections?: string[];
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* Configuration for a collection in SearchUniverse.
|
|
236
|
+
*
|
|
237
|
+
* @typeParam T - Type of items in this collection
|
|
238
|
+
* @typeParam C - Type of the search context
|
|
239
|
+
*/
|
|
240
|
+
export interface CollectionConfig<T extends SearchableObject, C = unknown> {
|
|
241
|
+
/** Specification for how to extract searchable text */
|
|
242
|
+
spec?: SearchableObjectSpec<T, C>;
|
|
243
|
+
/** Links to other collections (this collection is the "linked" side) */
|
|
244
|
+
linkedTo?: {
|
|
245
|
+
/** Name of the primary collection */
|
|
246
|
+
collectionName: string;
|
|
247
|
+
/** Function to get primary ID from this item (foreign key) */
|
|
248
|
+
foreignKeyGetter: (item: T) => Id | undefined;
|
|
249
|
+
};
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* Result of an update operation via {@link SearchUniverse.updateSearchMetadata}.
|
|
253
|
+
*/
|
|
254
|
+
export interface UpdateResult {
|
|
255
|
+
/** true if item was added, false if updated */
|
|
256
|
+
added: boolean;
|
|
257
|
+
/** Previous foreign key value (only for linked items that changed FK) */
|
|
258
|
+
previousPrimaryId?: Id | undefined;
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* Result of a batch update operation via {@link SearchUniverse.updateSearchMetadataBatch}.
|
|
262
|
+
*/
|
|
263
|
+
export interface BatchUpdateResult {
|
|
264
|
+
/** Number of items added */
|
|
265
|
+
added: number;
|
|
266
|
+
/** Number of items updated */
|
|
267
|
+
updated: number;
|
|
268
|
+
/** Number of items removed (due to _deleted/_blocked) */
|
|
269
|
+
removed: number;
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
* Helper to convert an array to SearchableData Map
|
|
273
|
+
*/
|
|
274
|
+
export declare function arrayToSearchableData<T extends SearchableObject>(items: T[]): SearchableData<T>;
|
|
275
|
+
/**
|
|
276
|
+
* Helper to convert SearchableData Map back to array
|
|
277
|
+
*/
|
|
278
|
+
export declare function searchableDataToArray<T extends SearchableObject>(data: SearchableData<T>): T[];
|
|
279
|
+
/**
|
|
280
|
+
* Legacy type alias for backwards compatibility.
|
|
281
|
+
* @deprecated Use SearchMetadata directly instead
|
|
282
|
+
*/
|
|
283
|
+
export type SearchArrayMetadata = {
|
|
284
|
+
items: SearchMetadata;
|
|
285
|
+
};
|
|
286
|
+
/**
|
|
287
|
+
* Legacy type alias for backwards compatibility.
|
|
288
|
+
* @deprecated Use SearchableObject directly instead
|
|
289
|
+
*/
|
|
290
|
+
export interface SearchableItem extends SearchableObject {
|
|
291
|
+
searchableText?: string;
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* Legacy type alias for backwards compatibility.
|
|
295
|
+
* @deprecated Use SearchTokenSortedList directly instead
|
|
296
|
+
*/
|
|
297
|
+
export interface SearchItemMetadata {
|
|
298
|
+
tokens: SearchTokenSortedList;
|
|
299
|
+
}
|
|
300
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAMH,+CAA+C;AAC/C,MAAM,MAAM,EAAE,GAAG,MAAM,CAAC;AAExB,yDAAyD;AACzD,MAAM,MAAM,WAAW,GAAG,MAAM,CAAC;AAEjC,2DAA2D;AAC3D,MAAM,MAAM,qBAAqB,GAAG,WAAW,EAAE,CA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AC,SAAS,gBAAgB,EAAE,KAAK,EAAE,CAAC,EAAE,GAAG,cAAc,CAAC,CAAC,CAAC,CAM/F;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,CAAC,SAAS,gBAAgB,EAAE,IAAI,EAAE,cAAc,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,CAE9F;AAMD;;;GAGG;AACH,MAAM,MAAM,mBAAmB,GAAG;IAChC,KAAK,EAAE,cAAc,CAAC;CACvB,CAAC;AAEF;;;GAGG;AACH,MAAM,WAAW,cAAe,SAAQ,gBAAgB;IACtD,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED;;;GAGG;AACH,MAAM,WAAW,kBAAkB;IACjC,MAAM,EAAE,qBAAqB,CAAC;CAC/B"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,cAAc,eAAe,CAAC"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import type { SearchOpts, SearchTokenSortedList } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Checks if a search token matches a target token.
|
|
4
|
+
*
|
|
5
|
+
* If target token has a prefix (<, >, +, *, !), that prefix determines the match mode
|
|
6
|
+
* and global SearchOpts are ignored for that token.
|
|
7
|
+
*
|
|
8
|
+
* Otherwise, matching rules depend on SearchOpts:
|
|
9
|
+
* - For words (non-numeric): uses matchWords option (default: 'start')
|
|
10
|
+
* - For numbers: uses matchNumbers option (default: 'startEnd')
|
|
11
|
+
*
|
|
12
|
+
* @param searchToken - The token to search for
|
|
13
|
+
* @param targetToken - The token to match against (may have a prefix)
|
|
14
|
+
* @param opts - Optional search options for match mode
|
|
15
|
+
* @returns True if the search token matches the target token
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* // Default word matching (start)
|
|
20
|
+
* matchToken('rex', 'rexona') // true
|
|
21
|
+
* matchToken('rex', 'ceporex') // false
|
|
22
|
+
*
|
|
23
|
+
* // Default number matching (startEnd)
|
|
24
|
+
* matchToken('123', '12345') // true
|
|
25
|
+
* matchToken('123', '45123') // true
|
|
26
|
+
*
|
|
27
|
+
* // With prefix (overrides opts)
|
|
28
|
+
* matchToken('rex', '!rex') // true (whole match)
|
|
29
|
+
* matchToken('rex', '!rexona') // false (whole match)
|
|
30
|
+
* matchToken('rex', '*unrexy') // true (anywhere match)
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export declare function matchToken(searchToken: string, targetToken: string, opts?: SearchOpts): boolean;
|
|
34
|
+
/**
|
|
35
|
+
* Checks if a search token matches any token in a sorted list.
|
|
36
|
+
* Leverages sorted order for early exit when using 'start' match mode.
|
|
37
|
+
*
|
|
38
|
+
* @param searchToken - The token to search for
|
|
39
|
+
* @param targetTokens - Sorted list of tokens to search in
|
|
40
|
+
* @param opts - Optional search options for match mode
|
|
41
|
+
* @returns True if any target token matches the search token
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```typescript
|
|
45
|
+
* matchTokenInSortedList('rex', ['labrador', 'rexona']) // true
|
|
46
|
+
* matchTokenInSortedList('cat', ['labrador', 'rexona']) // false
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
export declare function matchTokenInSortedList(searchToken: string, targetTokens: SearchTokenSortedList, opts?: SearchOpts): boolean;
|
|
50
|
+
/**
|
|
51
|
+
* Checks if all search tokens match at least one token in the target sorted list.
|
|
52
|
+
*
|
|
53
|
+
* @param searchTokens - Array of tokens to search for
|
|
54
|
+
* @param targetTokens - Sorted list of tokens to search in
|
|
55
|
+
* @param opts - Optional search options for match mode
|
|
56
|
+
* @returns True only if every search token has at least one match
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* ```typescript
|
|
60
|
+
* allTokensMatch(['rex', 'lab'], ['labrador', 'rexona']) // true
|
|
61
|
+
* allTokensMatch(['rex', 'cat'], ['labrador', 'rexona']) // false
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
export declare function allTokensMatch(searchTokens: SearchTokenSortedList, targetTokens: SearchTokenSortedList, opts?: SearchOpts): boolean;
|
|
65
|
+
//# sourceMappingURL=matchToken.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"matchToken.d.ts","sourceRoot":"","sources":["../../src/utils/matchToken.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAa,UAAU,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AAuC7E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,wBAAgB,UAAU,CACxB,WAAW,EAAE,MAAM,EACnB,WAAW,EAAE,MAAM,EACnB,IAAI,CAAC,EAAE,UAAU,GAChB,OAAO,CAmBT;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,sBAAsB,CACpC,WAAW,EAAE,MAAM,EACnB,YAAY,EAAE,qBAAqB,EACnC,IAAI,CAAC,EAAE,UAAU,GAChB,OAAO,CA0CT;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,cAAc,CAC5B,YAAY,EAAE,qBAAqB,EACnC,YAAY,EAAE,qBAAqB,EACnC,IAAI,CAAC,EAAE,UAAU,GAChB,OAAO,CAOT"}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import type { MatchMode, NumericTokenSortedList, SearchOpts } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* A prepared query token with pre-computed ID and numeric flag.
|
|
4
|
+
* Used to avoid repeated findTokenId calls during search.
|
|
5
|
+
*/
|
|
6
|
+
export interface PreparedQueryToken {
|
|
7
|
+
str: string;
|
|
8
|
+
id: number;
|
|
9
|
+
isNumeric: boolean;
|
|
10
|
+
/** Optional override mode from query prefix (e.g., !word for whole match) */
|
|
11
|
+
overrideMode?: MatchMode;
|
|
12
|
+
/** If true, this token must NOT appear in the target (negation with -- or ~ prefix) */
|
|
13
|
+
negated?: boolean;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Prepares query tokens by pre-computing their IDs.
|
|
17
|
+
* Call this ONCE at the start of a search to avoid repeated findTokenId calls.
|
|
18
|
+
*
|
|
19
|
+
* Supports query prefixes/suffixes to override match modes:
|
|
20
|
+
* - `!word` or `=word` = whole (exact match)
|
|
21
|
+
* - `<word` = start (prefix match)
|
|
22
|
+
* - `>word` or `..word` = end (suffix match)
|
|
23
|
+
* - `+word` = startEnd (prefix or suffix)
|
|
24
|
+
* - `*word` or `?word` = anywhere (substring match)
|
|
25
|
+
* - `word..` = start (prefix match, suffix notation)
|
|
26
|
+
* - `--word` or `~word` = negation (token must NOT appear)
|
|
27
|
+
*
|
|
28
|
+
* @param queryTokenStrs - Array of query token strings
|
|
29
|
+
* @returns Array of prepared tokens with pre-computed IDs
|
|
30
|
+
*/
|
|
31
|
+
export declare function prepareQueryTokens(queryTokenStrs: string[]): PreparedQueryToken[];
|
|
32
|
+
/**
|
|
33
|
+
* Binary search to find if a token ID exists in a sorted Uint32Array.
|
|
34
|
+
*
|
|
35
|
+
* @param arr - Sorted Uint32Array of token IDs
|
|
36
|
+
* @param target - Token ID to find
|
|
37
|
+
* @returns True if found, false otherwise
|
|
38
|
+
*/
|
|
39
|
+
export declare function binarySearchUint32(arr: Uint32Array, target: number): boolean;
|
|
40
|
+
/**
|
|
41
|
+
* Checks if a prepared search token matches any token in a sorted numeric list.
|
|
42
|
+
* Uses pre-computed token ID for efficiency.
|
|
43
|
+
*
|
|
44
|
+
* @param preparedToken - The prepared token with pre-computed ID
|
|
45
|
+
* @param targetTokens - Sorted Uint32Array of target token IDs
|
|
46
|
+
* @param opts - Optional search options for match mode
|
|
47
|
+
* @returns True if any target token matches the search token
|
|
48
|
+
*/
|
|
49
|
+
export declare function matchPreparedTokenInSortedList(preparedToken: PreparedQueryToken, targetTokens: NumericTokenSortedList, opts?: SearchOpts): boolean;
|
|
50
|
+
/**
|
|
51
|
+
* Checks if a search token (string) matches any token in a sorted numeric list.
|
|
52
|
+
* Note: For better performance when searching multiple items, use prepareQueryTokens
|
|
53
|
+
* and matchPreparedTokenInSortedList instead.
|
|
54
|
+
*
|
|
55
|
+
* Supports query prefixes/suffixes to override match modes:
|
|
56
|
+
* - `!word` or `=word` = whole
|
|
57
|
+
* - `<word` = start
|
|
58
|
+
* - `>word` or `..word` = end
|
|
59
|
+
* - `+word` = startEnd
|
|
60
|
+
* - `*word` or `?word` = anywhere
|
|
61
|
+
* - `word..` = start
|
|
62
|
+
* - `--word` or `~word` = negation (returns true if NOT found)
|
|
63
|
+
*
|
|
64
|
+
* @param searchTokenStr - The string token to search for (may include prefix/suffix)
|
|
65
|
+
* @param targetTokens - Sorted Uint32Array of target token IDs
|
|
66
|
+
* @param opts - Optional search options for match mode
|
|
67
|
+
* @returns True if any target token matches the search token (or no match for negated tokens)
|
|
68
|
+
*/
|
|
69
|
+
export declare function matchTokenInSortedListNumeric(searchTokenStr: string, targetTokens: NumericTokenSortedList, opts?: SearchOpts): boolean;
|
|
70
|
+
/**
|
|
71
|
+
* Checks if all prepared search tokens match at least one token in the target sorted list.
|
|
72
|
+
* Uses pre-computed token IDs for efficiency.
|
|
73
|
+
*
|
|
74
|
+
* For negated tokens (--word or ~word), the logic is inverted:
|
|
75
|
+
* the token must NOT match any target token.
|
|
76
|
+
*
|
|
77
|
+
* @param preparedTokens - Array of prepared tokens with pre-computed IDs
|
|
78
|
+
* @param targetTokens - Sorted Uint32Array of target token IDs
|
|
79
|
+
* @param opts - Optional search options for match mode
|
|
80
|
+
* @returns True only if every search token has at least one match (or no match for negated tokens)
|
|
81
|
+
*/
|
|
82
|
+
export declare function allPreparedTokensMatch(preparedTokens: PreparedQueryToken[], targetTokens: NumericTokenSortedList, opts?: SearchOpts): boolean;
|
|
83
|
+
/**
|
|
84
|
+
* Checks if all search tokens match at least one token in the target sorted list.
|
|
85
|
+
* Note: For better performance when searching multiple items, use prepareQueryTokens
|
|
86
|
+
* and allPreparedTokensMatch instead.
|
|
87
|
+
*
|
|
88
|
+
* @param searchTokenStrs - Array of string tokens to search for
|
|
89
|
+
* @param targetTokens - Sorted Uint32Array of target token IDs
|
|
90
|
+
* @param opts - Optional search options for match mode
|
|
91
|
+
* @returns True only if every search token has at least one match
|
|
92
|
+
*/
|
|
93
|
+
export declare function allTokensMatchNumeric(searchTokenStrs: string[], targetTokens: NumericTokenSortedList, opts?: SearchOpts): boolean;
|
|
94
|
+
//# sourceMappingURL=matchTokenNumeric.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"matchTokenNumeric.d.ts","sourceRoot":"","sources":["../../src/utils/matchTokenNumeric.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,sBAAsB,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAS9E;;;GAGG;AACH,MAAM,WAAW,kBAAkB;IACjC,GAAG,EAAE,MAAM,CAAC;IACZ,EAAE,EAAE,MAAM,CAAC;IACX,SAAS,EAAE,OAAO,CAAC;IACnB,6EAA6E;IAC7E,YAAY,CAAC,EAAE,SAAS,CAAC;IACzB,uFAAuF;IACvF,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,kBAAkB,CAAC,cAAc,EAAE,MAAM,EAAE,GAAG,kBAAkB,EAAE,CAoDjF;AAmED;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAiB5E;AAED;;;;;;;;GAQG;AACH,wBAAgB,8BAA8B,CAC5C,aAAa,EAAE,kBAAkB,EACjC,YAAY,EAAE,sBAAsB,EACpC,IAAI,CAAC,EAAE,UAAU,GAChB,OAAO,CAmCT;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,6BAA6B,CAC3C,cAAc,EAAE,MAAM,EACtB,YAAY,EAAE,sBAAsB,EACpC,IAAI,CAAC,EAAE,UAAU,GAChB,OAAO,CAsDT;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,sBAAsB,CACpC,cAAc,EAAE,kBAAkB,EAAE,EACpC,YAAY,EAAE,sBAAsB,EACpC,IAAI,CAAC,EAAE,UAAU,GAChB,OAAO,CAYT;AAED;;;;;;;;;GASG;AACH,wBAAgB,qBAAqB,CACnC,eAAe,EAAE,MAAM,EAAE,EACzB,YAAY,EAAE,sBAAsB,EACpC,IAAI,CAAC,EAAE,UAAU,GAChB,OAAO,CAGT"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Normalizes date patterns in a string to YYYYMMDD or YYYYMM format for searchability.
|
|
3
|
+
*
|
|
4
|
+
* This is the first step in the search preparation pipeline. Date normalization allows
|
|
5
|
+
* users to search for dates using partial prefixes (e.g., "202503" finds all March 2025 dates).
|
|
6
|
+
*
|
|
7
|
+
* Patterns recognized:
|
|
8
|
+
* | Input Format | Example | Normalized |
|
|
9
|
+
* |--------------|---------|------------|
|
|
10
|
+
* | ISO 8601 | `2025-12-27T11:35:25.814Z` | `20251227` |
|
|
11
|
+
* | ISO date only | `2025-12-27` | `20251227` |
|
|
12
|
+
* | ISO year-month | `2025-12` | `202512` |
|
|
13
|
+
* | d.m.yyyy | `1.3.2025` or `01.03.2025` | `20250301` |
|
|
14
|
+
* | d.m.yy | `27.12.25` | `20251227` (2-digit year assumes 2000s) |
|
|
15
|
+
* | m.yyyy | `3.2025` or `03.2025` | `202503` |
|
|
16
|
+
* | MM-YYYY | `11-2025` | `202511` (year must be 2001-2099) |
|
|
17
|
+
* | MM/YYYY | `11/2025` | `202511` (year must be 2001-2099) |
|
|
18
|
+
* | MM/YY | `11/25` | `202511` (2-digit year assumes 2000s) |
|
|
19
|
+
* | DDMMYYYY | `22112025` | `20251122` (DD 01-31, MM 01-12, year 20xx) |
|
|
20
|
+
* | MMYYYY | `112025` | `202511` (MM must be 01-12, year 20xx) |
|
|
21
|
+
* | month name + year | `mar 2025`, `march 2025`, `marec 2025` | `202503` |
|
|
22
|
+
*
|
|
23
|
+
* @param input - The string potentially containing date patterns
|
|
24
|
+
* @returns String with date patterns normalized to YYYYMMDD/YYYYMM format
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```typescript
|
|
28
|
+
* normalizeDates('2025-12-27T11:35:25.814Z')
|
|
29
|
+
* // Returns: '20251227'
|
|
30
|
+
*
|
|
31
|
+
* normalizeDates('Datum: 1.3.2025 je pomemben')
|
|
32
|
+
* // Returns: 'Datum: 20250301 je pomemben'
|
|
33
|
+
*
|
|
34
|
+
* normalizeDates('v mar 2025 smo')
|
|
35
|
+
* // Returns: 'v 202503 smo'
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
export declare function normalizeDates(input: string): string;
|
|
39
|
+
//# sourceMappingURL=normalizeDates.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"normalizeDates.d.ts","sourceRoot":"","sources":["../../src/utils/normalizeDates.ts"],"names":[],"mappings":"AA8EA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAkEpD"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { SearchTokenSortedList } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Prepares a string for search by applying the full transformation pipeline.
|
|
4
|
+
*
|
|
5
|
+
* Processing pipeline:
|
|
6
|
+
* 1. **Date normalization** - Convert date patterns to YYYYMMDD/YYYYMM format
|
|
7
|
+
* 2. **Preprocessing** - Handle decimal commas, leading zeros, letter-digit boundaries
|
|
8
|
+
* 3. **Sanitation** - Lowercase, remove diacritics, keep only allowed characters
|
|
9
|
+
* 4. **Tokenization** - Split on spaces, trim, filter empty strings
|
|
10
|
+
* 5. **Sorting** - Sort alphabetically for efficient matching
|
|
11
|
+
*
|
|
12
|
+
* @param input - The raw input string to prepare for search
|
|
13
|
+
* @returns Sorted array of tokens ready for matching
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* prepareStringForSearch('Čokolada 100g SI123')
|
|
18
|
+
* // Returns: ['100', '123', 'cokolada', 'g', 'si']
|
|
19
|
+
*
|
|
20
|
+
* prepareStringForSearch('1.3.2025')
|
|
21
|
+
* // Returns: ['20250301']
|
|
22
|
+
*
|
|
23
|
+
* prepareStringForSearch('John Doe')
|
|
24
|
+
* // Returns: ['doe', 'john']
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export declare function prepareStringForSearch(input: string): SearchTokenSortedList;
|
|
28
|
+
//# sourceMappingURL=prepareStringForSearch.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prepareStringForSearch.d.ts","sourceRoot":"","sources":["../../src/utils/prepareStringForSearch.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AAMtD;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,MAAM,GAAG,qBAAqB,CAO3E"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { NumericTokenSortedList } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Prepares a string for search, returning numeric token IDs.
|
|
4
|
+
*
|
|
5
|
+
* Processing pipeline:
|
|
6
|
+
* 1. **Date normalization** - Convert date patterns to YYYYMMDD/YYYYMM format
|
|
7
|
+
* 2. **Preprocessing** - Handle decimal commas, leading zeros, letter-digit boundaries
|
|
8
|
+
* 3. **Sanitation** - Lowercase, remove diacritics, keep only allowed characters
|
|
9
|
+
* 4. **Tokenization** - Split on spaces, trim, filter empty strings
|
|
10
|
+
* 5. **Numeric conversion** - Convert strings to numeric IDs via tokensMap
|
|
11
|
+
* 6. **Sorting** - Sort numerically for efficient matching
|
|
12
|
+
*
|
|
13
|
+
* @param input - The raw input string to prepare for search
|
|
14
|
+
* @param tokensMap - Map for string->number conversion (required for metadata creation)
|
|
15
|
+
* @returns Sorted Uint32Array of numeric token IDs
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* const tokensMap = createTokensMap();
|
|
20
|
+
* prepareStringForSearchNumeric('Čokolada 100g', tokensMap)
|
|
21
|
+
* // Returns: Uint32Array of numeric IDs, sorted
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export declare function prepareStringForSearchNumeric(input: string, tokensMap: Map<string, number>): NumericTokenSortedList;
|
|
25
|
+
/**
|
|
26
|
+
* Prepares a search query string, returning numeric token IDs.
|
|
27
|
+
*
|
|
28
|
+
* Unlike prepareStringForSearchNumeric, this uses findTokenId for lookups
|
|
29
|
+
* since search queries should only match existing tokens.
|
|
30
|
+
* Tokens not in the registry are returned as -1.
|
|
31
|
+
*
|
|
32
|
+
* @param input - The raw search query string
|
|
33
|
+
* @returns Sorted array of numeric token IDs (-1 for unknown tokens)
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```typescript
|
|
37
|
+
* prepareQueryForSearchNumeric('čokolada 100g')
|
|
38
|
+
* // Returns: sorted number[] of IDs (-1 for tokens not in registry)
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
export declare function prepareQueryForSearchNumeric(input: string): number[];
|
|
42
|
+
//# sourceMappingURL=prepareStringForSearchNumeric.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prepareStringForSearchNumeric.d.ts","sourceRoot":"","sources":["../../src/utils/prepareStringForSearchNumeric.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,UAAU,CAAC;AAOvD;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,6BAA6B,CAC3C,KAAK,EAAE,MAAM,EACb,SAAS,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,GAC7B,sBAAsB,CAgBxB;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,4BAA4B,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,CAgBpE"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Preprocesses a string for search by normalizing number formats and splitting mixed alphanumeric tokens.
|
|
3
|
+
*
|
|
4
|
+
* Processing steps:
|
|
5
|
+
* 1. Replaces decimal commas with periods (e.g., "12,3" → "12.3")
|
|
6
|
+
* 2. Drops leading zeros from numbers (e.g., "007" → "7", "0,3" → ".3")
|
|
7
|
+
* 3. Removes spaces in digit-dash-digit patterns (e.g., "12 - 25" → "12-25")
|
|
8
|
+
* 4. Inserts spaces at letter-to-digit boundaries (e.g., "SI123" → "SI 123", "123SI" → "123 SI")
|
|
9
|
+
*
|
|
10
|
+
* @param input - The raw input string to preprocess
|
|
11
|
+
* @returns Preprocessed string ready for sanitization
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* preprocessString('SI123 Čokolada 0,5kg')
|
|
16
|
+
* // Returns: 'SI 123 Čokolada .5kg'
|
|
17
|
+
*
|
|
18
|
+
* preprocessString('007')
|
|
19
|
+
* // Returns: '7'
|
|
20
|
+
*
|
|
21
|
+
* preprocessString('12 - 25')
|
|
22
|
+
* // Returns: '12-25'
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export declare function preprocessString(input: string): string;
|
|
26
|
+
//# sourceMappingURL=preprocessString.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"preprocessString.d.ts","sourceRoot":"","sources":["../../src/utils/preprocessString.ts"],"names":[],"mappings":"AASA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAqBtD"}
|