cry-search 1.0.7 → 2.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 +73 -98
- package/README.md +39 -28
- package/UNIVERSE.md +11 -18
- package/dist/common/SearchUniverse.d.ts.map +1 -1
- package/dist/common/numeric/AugmentedMetadata.d.ts +27 -92
- package/dist/common/numeric/AugmentedMetadata.d.ts.map +1 -1
- package/dist/common/numeric/createSearchArrayMetadata.d.ts +47 -7
- package/dist/common/numeric/createSearchArrayMetadata.d.ts.map +1 -1
- package/dist/common/numeric/findInLinkedArrays.d.ts +7 -4
- package/dist/common/numeric/findInLinkedArrays.d.ts.map +1 -1
- package/dist/common/numeric/scoring.d.ts +95 -0
- package/dist/common/numeric/scoring.d.ts.map +1 -0
- package/dist/common/numeric/searchAndRank.d.ts +18 -60
- package/dist/common/numeric/searchAndRank.d.ts.map +1 -1
- package/dist/common/numeric/searchInData.d.ts +17 -9
- package/dist/common/numeric/searchInData.d.ts.map +1 -1
- package/dist/common/numeric/syncSearchArrayMetadata.d.ts +7 -50
- package/dist/common/numeric/syncSearchArrayMetadata.d.ts.map +1 -1
- package/dist/common/numeric/updateSearchLinkedMetadata.d.ts +11 -110
- package/dist/common/numeric/updateSearchLinkedMetadata.d.ts.map +1 -1
- package/dist/common/numeric/updateSearchMetadata.d.ts.map +1 -1
- package/dist/index.cjs +614 -360
- package/dist/index.d.cts +3 -4
- package/dist/index.d.ts +3 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +614 -360
- package/dist/types/index.d.ts +35 -50
- package/dist/types/index.d.ts.map +1 -1
- package/dist/utils/matchTokenNumeric.d.ts.map +1 -1
- package/dist/utils/prepareStringForSearchNumeric.d.ts +24 -29
- package/dist/utils/prepareStringForSearchNumeric.d.ts.map +1 -1
- package/package.json +4 -14
- package/dist/common/findInArray.d.ts +0 -37
- package/dist/common/findInArray.d.ts.map +0 -1
- package/dist/common/findInArrayReturnDataAndMeta.d.ts +0 -52
- package/dist/common/findInArrayReturnDataAndMeta.d.ts.map +0 -1
- package/dist/common/findInLinkedArrays.d.ts +0 -66
- package/dist/common/findInLinkedArrays.d.ts.map +0 -1
- package/dist/common/string/createSearchArrayMetadata.d.ts +0 -117
- package/dist/common/string/createSearchArrayMetadata.d.ts.map +0 -1
- package/dist/common/string/createSearchLinkedMetadata.d.ts +0 -36
- package/dist/common/string/createSearchLinkedMetadata.d.ts.map +0 -1
- package/dist/common/string/index.d.ts +0 -10
- package/dist/common/string/index.d.ts.map +0 -1
- package/dist/common/string/updateSearchMetadata.d.ts +0 -103
- package/dist/common/string/updateSearchMetadata.d.ts.map +0 -1
- package/dist/common/syncSearchArrayMetadata.d.ts +0 -68
- package/dist/common/syncSearchArrayMetadata.d.ts.map +0 -1
- package/dist/common/updateSearchLinkedMetadata.d.ts +0 -139
- package/dist/common/updateSearchLinkedMetadata.d.ts.map +0 -1
- package/dist/string.cjs +0 -930
- package/dist/string.d.cts +0 -26
- package/dist/string.d.ts +0 -26
- package/dist/string.d.ts.map +0 -1
- package/dist/string.js +0 -898
- package/dist/utils/matchToken.d.ts +0 -65
- package/dist/utils/matchToken.d.ts.map +0 -1
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
import type { Id, SearchMetadata, SearchableObject, SearchableObjectSpec, UpdateSearchMetadataBatchItem } from '../../types';
|
|
2
|
-
export type { UpdateSearchMetadataBatchItem } from '../../types';
|
|
3
|
-
/**
|
|
4
|
-
* Updates search metadata for a single object.
|
|
5
|
-
*
|
|
6
|
-
* This function handles updates, additions, and removals:
|
|
7
|
-
* - If the object is `null` or `undefined`, removes it from metadata
|
|
8
|
-
* - If the object is `_deleted` or `_blocked`, removes it from metadata
|
|
9
|
-
* - Otherwise, computes new tokens and updates/adds to metadata
|
|
10
|
-
*
|
|
11
|
-
* The metadata map is mutated in place for efficiency.
|
|
12
|
-
*
|
|
13
|
-
* @typeParam T - Type of the searchable object
|
|
14
|
-
* @typeParam C - Type of the search context
|
|
15
|
-
*
|
|
16
|
-
* @param metadata - The SearchMetadata map to update (mutated in place)
|
|
17
|
-
* @param objectId - The ID of the object to update
|
|
18
|
-
* @param obj - The object (may be null, undefined, deleted, or blocked)
|
|
19
|
-
* @param spec - Optional specification for how to extract searchable text
|
|
20
|
-
* @returns true if metadata was added/updated, false if removed
|
|
21
|
-
*
|
|
22
|
-
* @example
|
|
23
|
-
* ```typescript
|
|
24
|
-
* // Update an existing item
|
|
25
|
-
* const product = { _id: '1', name: 'Updated Product' };
|
|
26
|
-
* updateSearchMetadata(metadata, '1', product, spec);
|
|
27
|
-
*
|
|
28
|
-
* // Mark an item as deleted (removes from search)
|
|
29
|
-
* const deletedProduct = { _id: '1', name: 'Product', _deleted: new Date() };
|
|
30
|
-
* updateSearchMetadata(metadata, '1', deletedProduct, spec); // returns false
|
|
31
|
-
*
|
|
32
|
-
* // Remove by passing null/undefined
|
|
33
|
-
* updateSearchMetadata(metadata, '1', null, spec); // returns false
|
|
34
|
-
* ```
|
|
35
|
-
*/
|
|
36
|
-
export declare function updateSearchMetadata<T extends SearchableObject, C = unknown>(metadata: SearchMetadata, objectId: Id, obj: T | null | undefined, spec?: SearchableObjectSpec<T, C>): boolean;
|
|
37
|
-
/**
|
|
38
|
-
* Updates search metadata for multiple objects in a batch.
|
|
39
|
-
*
|
|
40
|
-
* More efficient than calling {@link updateSearchMetadata} repeatedly
|
|
41
|
-
* when you have multiple objects to update at once.
|
|
42
|
-
*
|
|
43
|
-
* - For objects that are `_deleted` or `_blocked`, removes them from metadata
|
|
44
|
-
* - For other objects, updates or adds their tokens to metadata
|
|
45
|
-
*
|
|
46
|
-
* @typeParam T - Type of the searchable objects
|
|
47
|
-
* @typeParam C - Type of the search context
|
|
48
|
-
*
|
|
49
|
-
* @param metadata - The SearchMetadata map to update (mutated in place)
|
|
50
|
-
* @param batch - Array of objects to update
|
|
51
|
-
* @param spec - Optional specification for how to extract searchable text
|
|
52
|
-
* @returns Object with counts of added/updated and removed items
|
|
53
|
-
*
|
|
54
|
-
* @example
|
|
55
|
-
* ```typescript
|
|
56
|
-
* const batch = [
|
|
57
|
-
* { objectId: '1', obj: { _id: '1', name: 'Product 1' } },
|
|
58
|
-
* { objectId: '2', obj: { _id: '2', name: 'Product 2', _deleted: new Date() } },
|
|
59
|
-
* ];
|
|
60
|
-
*
|
|
61
|
-
* const result = updateSearchMetadataBatch(metadata, batch, spec);
|
|
62
|
-
* // result: { updated: 1, removed: 1 }
|
|
63
|
-
* ```
|
|
64
|
-
*/
|
|
65
|
-
export declare function updateSearchMetadataBatch<T extends SearchableObject, C = unknown>(metadata: SearchMetadata, batch: UpdateSearchMetadataBatchItem<T>[], spec?: SearchableObjectSpec<T, C>): {
|
|
66
|
-
updated: number;
|
|
67
|
-
removed: number;
|
|
68
|
-
};
|
|
69
|
-
/**
|
|
70
|
-
* Removes an object from search metadata by ID.
|
|
71
|
-
*
|
|
72
|
-
* Use this when you want to explicitly remove an object without having the full object.
|
|
73
|
-
* For updates where you have the object (including deleting by setting `_deleted`),
|
|
74
|
-
* use {@link updateSearchMetadata} instead.
|
|
75
|
-
*
|
|
76
|
-
* @param metadata - The SearchMetadata map to update (mutated in place)
|
|
77
|
-
* @param objectId - The ID of the object to remove
|
|
78
|
-
* @returns true if the object was found and removed, false if it wasn't in metadata
|
|
79
|
-
*
|
|
80
|
-
* @example
|
|
81
|
-
* ```typescript
|
|
82
|
-
* removeFromSearchMetadata(metadata, 'object-id-to-remove');
|
|
83
|
-
* ```
|
|
84
|
-
*/
|
|
85
|
-
export declare function removeFromSearchMetadata(metadata: SearchMetadata, objectId: Id): boolean;
|
|
86
|
-
/**
|
|
87
|
-
* Removes multiple objects from search metadata by IDs.
|
|
88
|
-
*
|
|
89
|
-
* More efficient than calling {@link removeFromSearchMetadata} repeatedly
|
|
90
|
-
* when you have multiple IDs to remove.
|
|
91
|
-
*
|
|
92
|
-
* @param metadata - The SearchMetadata map to update (mutated in place)
|
|
93
|
-
* @param objectIds - Array of IDs to remove
|
|
94
|
-
* @returns Number of objects that were actually removed (may be less than objectIds.length)
|
|
95
|
-
*
|
|
96
|
-
* @example
|
|
97
|
-
* ```typescript
|
|
98
|
-
* const removed = removeFromSearchMetadataBatch(metadata, ['id1', 'id2', 'id3']);
|
|
99
|
-
* console.log(`Removed ${removed} items from metadata`);
|
|
100
|
-
* ```
|
|
101
|
-
*/
|
|
102
|
-
export declare function removeFromSearchMetadataBatch(metadata: SearchMetadata, objectIds: Id[]): number;
|
|
103
|
-
//# sourceMappingURL=updateSearchMetadata.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"updateSearchMetadata.d.ts","sourceRoot":"","sources":["../../../src/common/string/updateSearchMetadata.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,EAAE,EACF,cAAc,EACd,gBAAgB,EAChB,oBAAoB,EACpB,6BAA6B,EAC9B,MAAM,aAAa,CAAC;AAIrB,YAAY,EAAE,6BAA6B,EAAE,MAAM,aAAa,CAAC;AAEjE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,wBAAgB,oBAAoB,CAAC,CAAC,SAAS,gBAAgB,EAAE,CAAC,GAAG,OAAO,EAC1E,QAAQ,EAAE,cAAc,EACxB,QAAQ,EAAE,EAAE,EACZ,GAAG,EAAE,CAAC,GAAG,IAAI,GAAG,SAAS,EACzB,IAAI,CAAC,EAAE,oBAAoB,CAAC,CAAC,EAAE,CAAC,CAAC,GAChC,OAAO,CAYT;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAgB,yBAAyB,CAAC,CAAC,SAAS,gBAAgB,EAAE,CAAC,GAAG,OAAO,EAC/E,QAAQ,EAAE,cAAc,EACxB,KAAK,EAAE,6BAA6B,CAAC,CAAC,CAAC,EAAE,EACzC,IAAI,CAAC,EAAE,oBAAoB,CAAC,CAAC,EAAE,CAAC,CAAC,GAChC;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAkBtC;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,wBAAwB,CACtC,QAAQ,EAAE,cAAc,EACxB,QAAQ,EAAE,EAAE,GACX,OAAO,CAET;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,6BAA6B,CAC3C,QAAQ,EAAE,cAAc,EACxB,SAAS,EAAE,EAAE,EAAE,GACd,MAAM,CAYR"}
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import type { SearchMetadata, SearchableData, SearchableObject, SearchableObjectSpec, SyncResult, SyncOptions } from '../types';
|
|
2
|
-
export type { SyncResult, SyncOptions } from '../types';
|
|
3
|
-
/**
|
|
4
|
-
* Syncs string-based search metadata with new data.
|
|
5
|
-
*
|
|
6
|
-
* LEGACY: Use syncSearchArrayMetadataNumeric for new code.
|
|
7
|
-
*
|
|
8
|
-
* This function performs a full sync of metadata against the provided data:
|
|
9
|
-
* - Adds metadata for new items
|
|
10
|
-
* - Removes metadata for items no longer in data (or marked `_deleted`/`_blocked`)
|
|
11
|
-
* - Updates metadata for items whose tokens have changed
|
|
12
|
-
*
|
|
13
|
-
* Use this when you have completely new data to sync with. If you have both
|
|
14
|
-
* previous and new data available, use {@link syncSearchArrayMetadataStringWithPrevious}
|
|
15
|
-
* for more efficient diffing.
|
|
16
|
-
*
|
|
17
|
-
* @typeParam T - Type of the searchable objects
|
|
18
|
-
* @typeParam C - Type of the search context
|
|
19
|
-
*
|
|
20
|
-
* @param metadata - The SearchMetadata map to update (mutated in place)
|
|
21
|
-
* @param newData - The new data to sync with
|
|
22
|
-
* @param spec - Optional specification for how to extract searchable text
|
|
23
|
-
* @returns SyncResult with counts and IDs of added/updated/removed items
|
|
24
|
-
*
|
|
25
|
-
* @example
|
|
26
|
-
* ```typescript
|
|
27
|
-
* const newProducts = arrayToSearchableData(freshProductsFromServer);
|
|
28
|
-
* const result = syncSearchArrayMetadataString(metadata, newProducts, spec);
|
|
29
|
-
*
|
|
30
|
-
* console.log(`Added: ${result.added}, Updated: ${result.updated}, Removed: ${result.removed}`);
|
|
31
|
-
* ```
|
|
32
|
-
*/
|
|
33
|
-
export declare function syncSearchArrayMetadataString<T extends SearchableObject, C = unknown>(metadata: SearchMetadata, newData: SearchableData<T>, spec?: SearchableObjectSpec<T, C>): SyncResult;
|
|
34
|
-
/**
|
|
35
|
-
* Syncs string-based search metadata using previous and new data for efficient diffing.
|
|
36
|
-
*
|
|
37
|
-
* LEGACY: Use syncSearchArrayMetadataNumericWithPrevious for new code.
|
|
38
|
-
*
|
|
39
|
-
* More efficient than {@link syncSearchArrayMetadataString} when you have both the
|
|
40
|
-
* previous and new data available. Uses the previous data to determine
|
|
41
|
-
* what was removed without iterating through all metadata keys.
|
|
42
|
-
*
|
|
43
|
-
* @typeParam T - Type of the searchable objects
|
|
44
|
-
* @typeParam C - Type of the search context
|
|
45
|
-
*
|
|
46
|
-
* @param metadata - The SearchMetadata map to update (mutated in place)
|
|
47
|
-
* @param previousData - The previous data (used to determine what was removed)
|
|
48
|
-
* @param newData - The new data to sync with
|
|
49
|
-
* @param options - Optional sync options (e.g., skipUpdateCheck)
|
|
50
|
-
* @param spec - Optional specification for how to extract searchable text
|
|
51
|
-
* @returns SyncResult with counts and IDs of added/updated/removed items
|
|
52
|
-
*
|
|
53
|
-
* @example
|
|
54
|
-
* ```typescript
|
|
55
|
-
* const previousProducts = currentData;
|
|
56
|
-
* const newProducts = arrayToSearchableData(freshProductsFromServer);
|
|
57
|
-
*
|
|
58
|
-
* const result = syncSearchArrayMetadataStringWithPrevious(
|
|
59
|
-
* metadata,
|
|
60
|
-
* previousProducts,
|
|
61
|
-
* newProducts,
|
|
62
|
-
* { skipUpdateCheck: false },
|
|
63
|
-
* spec
|
|
64
|
-
* );
|
|
65
|
-
* ```
|
|
66
|
-
*/
|
|
67
|
-
export declare function syncSearchArrayMetadataStringWithPrevious<T extends SearchableObject, C = unknown>(metadata: SearchMetadata, previousData: SearchableData<T>, newData: SearchableData<T>, options?: SyncOptions, spec?: SearchableObjectSpec<T, C>): SyncResult;
|
|
68
|
-
//# sourceMappingURL=syncSearchArrayMetadata.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"syncSearchArrayMetadata.d.ts","sourceRoot":"","sources":["../../src/common/syncSearchArrayMetadata.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EACd,cAAc,EACd,gBAAgB,EAChB,oBAAoB,EAEpB,UAAU,EACV,WAAW,EACZ,MAAM,UAAU,CAAC;AAIlB,YAAY,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAkBxD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,wBAAgB,6BAA6B,CAAC,CAAC,SAAS,gBAAgB,EAAE,CAAC,GAAG,OAAO,EACnF,QAAQ,EAAE,cAAc,EACxB,OAAO,EAAE,cAAc,CAAC,CAAC,CAAC,EAC1B,IAAI,CAAC,EAAE,oBAAoB,CAAC,CAAC,EAAE,CAAC,CAAC,GAChC,UAAU,CAiDZ;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,wBAAgB,yCAAyC,CAAC,CAAC,SAAS,gBAAgB,EAAE,CAAC,GAAG,OAAO,EAC/F,QAAQ,EAAE,cAAc,EACxB,YAAY,EAAE,cAAc,CAAC,CAAC,CAAC,EAC/B,OAAO,EAAE,cAAc,CAAC,CAAC,CAAC,EAC1B,OAAO,CAAC,EAAE,WAAW,EACrB,IAAI,CAAC,EAAE,oBAAoB,CAAC,CAAC,EAAE,CAAC,CAAC,GAChC,UAAU,CAmDZ"}
|
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
import type { Id, SearchableData, SearchableObject, SearchableObjectSpec, SearchLinkedMetadataWithData, UpsertResult, SyncLinkedResult } from '../types';
|
|
2
|
-
export type { UpsertResult, SyncLinkedResult } from '../types';
|
|
3
|
-
/**
|
|
4
|
-
* Upserts a primary item into the linked metadata (string-based).
|
|
5
|
-
*
|
|
6
|
-
* LEGACY: Use upsertPrimaryItemNumeric for new code.
|
|
7
|
-
*
|
|
8
|
-
* - If the item doesn't exist, adds it to data, metadata, and initializes primaryToLinked index
|
|
9
|
-
* - If the item exists, updates data and metadata
|
|
10
|
-
* - Handles `_deleted`/`_blocked` items by removing their metadata
|
|
11
|
-
*
|
|
12
|
-
* @typeParam TPrimary - Type of primary items
|
|
13
|
-
* @typeParam TLinked - Type of linked items
|
|
14
|
-
* @typeParam C - Type of the search context
|
|
15
|
-
*
|
|
16
|
-
* @param linked - The linked metadata to update (mutated in place)
|
|
17
|
-
* @param item - The primary item to upsert
|
|
18
|
-
* @param spec - Optional specification for how to extract searchable text
|
|
19
|
-
* @returns UpsertResult indicating if item was added or updated
|
|
20
|
-
*
|
|
21
|
-
* @example
|
|
22
|
-
* ```typescript
|
|
23
|
-
* const stranka = { _id: 's1', ime: 'Janez', priimek: 'Novak' };
|
|
24
|
-
* const result = upsertPrimaryItemString(linkedMeta, stranka, spec);
|
|
25
|
-
* // result.added === true if stranka was new
|
|
26
|
-
* ```
|
|
27
|
-
*/
|
|
28
|
-
export declare function upsertPrimaryItemString<TPrimary extends SearchableObject, TLinked extends SearchableObject, C = unknown>(linked: SearchLinkedMetadataWithData<TPrimary, TLinked>, item: TPrimary, spec?: SearchableObjectSpec<TPrimary, C>): UpsertResult;
|
|
29
|
-
/**
|
|
30
|
-
* Removes a primary item from the linked metadata (string-based).
|
|
31
|
-
*
|
|
32
|
-
* LEGACY: Use removePrimaryItemNumeric for new code.
|
|
33
|
-
*
|
|
34
|
-
* Removes the item from data, metadata, and the primaryToLinked index.
|
|
35
|
-
* Note: This does NOT automatically remove linked items - they will become orphans.
|
|
36
|
-
* If you want to also remove linked items, call {@link removeLinkedItemString} for each.
|
|
37
|
-
*
|
|
38
|
-
* @typeParam TPrimary - Type of primary items
|
|
39
|
-
* @typeParam TLinked - Type of linked items
|
|
40
|
-
*
|
|
41
|
-
* @param linked - The linked metadata to update (mutated in place)
|
|
42
|
-
* @param primaryId - The ID of the primary item to remove
|
|
43
|
-
* @returns true if item was found and removed, false if not found
|
|
44
|
-
*/
|
|
45
|
-
export declare function removePrimaryItemString<TPrimary extends SearchableObject, TLinked extends SearchableObject>(linked: SearchLinkedMetadataWithData<TPrimary, TLinked>, primaryId: Id): boolean;
|
|
46
|
-
/**
|
|
47
|
-
* Upserts a linked item into the linked metadata (string-based).
|
|
48
|
-
*
|
|
49
|
-
* LEGACY: Use upsertLinkedItemNumeric for new code.
|
|
50
|
-
*
|
|
51
|
-
* - If the item doesn't exist, adds it
|
|
52
|
-
* - If the item exists, updates it
|
|
53
|
-
* - Handles foreign key changes by updating the primaryToLinked index
|
|
54
|
-
* (removes from old primary's list, adds to new primary's list)
|
|
55
|
-
* - Handles `_deleted`/`_blocked` items by removing their metadata
|
|
56
|
-
*
|
|
57
|
-
* @typeParam TPrimary - Type of primary items
|
|
58
|
-
* @typeParam TLinked - Type of linked items
|
|
59
|
-
* @typeParam C - Type of the search context
|
|
60
|
-
*
|
|
61
|
-
* @param linked - The linked metadata to update (mutated in place)
|
|
62
|
-
* @param item - The linked item to upsert
|
|
63
|
-
* @param foreignKeyGetter - Function to get the primary ID from a linked item
|
|
64
|
-
* @param spec - Optional specification for how to extract searchable text
|
|
65
|
-
* @returns UpsertResult indicating if item was added or updated, and previous primary ID if FK changed
|
|
66
|
-
*
|
|
67
|
-
* @example
|
|
68
|
-
* ```typescript
|
|
69
|
-
* const pacient = { _id: 'p1', ime: 'Rex', stranka_id: 's1' };
|
|
70
|
-
* const result = upsertLinkedItemString(linkedMeta, pacient, (p) => p.stranka_id, spec);
|
|
71
|
-
*
|
|
72
|
-
* // If the pacient moved to a different stranka:
|
|
73
|
-
* pacient.stranka_id = 's2';
|
|
74
|
-
* const result2 = upsertLinkedItemString(linkedMeta, pacient, (p) => p.stranka_id, spec);
|
|
75
|
-
* // result2.previousPrimaryId === 's1'
|
|
76
|
-
* ```
|
|
77
|
-
*/
|
|
78
|
-
export declare function upsertLinkedItemString<TPrimary extends SearchableObject, TLinked extends SearchableObject, C = unknown>(linked: SearchLinkedMetadataWithData<TPrimary, TLinked>, item: TLinked, foreignKeyGetter: (item: TLinked) => Id | undefined, spec?: SearchableObjectSpec<TLinked, C>): UpsertResult;
|
|
79
|
-
/**
|
|
80
|
-
* Removes a linked item from the linked metadata (string-based).
|
|
81
|
-
*
|
|
82
|
-
* LEGACY: Use removeLinkedItemNumeric for new code.
|
|
83
|
-
*
|
|
84
|
-
* Removes the item from data, metadata, and the primaryToLinked index.
|
|
85
|
-
*
|
|
86
|
-
* @typeParam TPrimary - Type of primary items
|
|
87
|
-
* @typeParam TLinked - Type of linked items
|
|
88
|
-
*
|
|
89
|
-
* @param linked - The linked metadata to update (mutated in place)
|
|
90
|
-
* @param linkedId - The ID of the linked item to remove
|
|
91
|
-
* @param foreignKeyGetter - Function to get the primary ID from a linked item
|
|
92
|
-
* @returns true if item was found and removed, false if not found
|
|
93
|
-
*
|
|
94
|
-
* @example
|
|
95
|
-
* ```typescript
|
|
96
|
-
* removeLinkedItemString(linkedMeta, 'pacient-id', (p) => p.stranka_id);
|
|
97
|
-
* ```
|
|
98
|
-
*/
|
|
99
|
-
export declare function removeLinkedItemString<TPrimary extends SearchableObject, TLinked extends SearchableObject>(linked: SearchLinkedMetadataWithData<TPrimary, TLinked>, linkedId: Id, foreignKeyGetter: (item: TLinked) => Id | undefined): boolean;
|
|
100
|
-
/**
|
|
101
|
-
* Syncs all linked items for a specific primary item (string-based).
|
|
102
|
-
*
|
|
103
|
-
* LEGACY: Use syncLinkedItemsForPrimaryNumeric for new code.
|
|
104
|
-
*
|
|
105
|
-
* This function performs a full sync of linked items belonging to a single primary:
|
|
106
|
-
* - Removes linked items that are no longer in the new data
|
|
107
|
-
* - Updates existing linked items if their tokens changed
|
|
108
|
-
* - Adds new linked items
|
|
109
|
-
* - Only processes items whose foreign key points to the given primary
|
|
110
|
-
*
|
|
111
|
-
* Use this when you have a complete new set of linked items for a primary
|
|
112
|
-
* and want to update the metadata to match.
|
|
113
|
-
*
|
|
114
|
-
* @typeParam TPrimary - Type of primary items
|
|
115
|
-
* @typeParam TLinked - Type of linked items
|
|
116
|
-
* @typeParam C - Type of the search context
|
|
117
|
-
*
|
|
118
|
-
* @param linked - The linked metadata to update (mutated in place)
|
|
119
|
-
* @param primaryId - The primary ID to sync linked items for
|
|
120
|
-
* @param newLinkedItems - The new linked items (only items with matching FK will be processed)
|
|
121
|
-
* @param foreignKeyGetter - Function to get the primary ID from a linked item
|
|
122
|
-
* @param spec - Optional specification for how to extract searchable text
|
|
123
|
-
* @returns SyncLinkedResult with counts of added/updated/removed items
|
|
124
|
-
*
|
|
125
|
-
* @example
|
|
126
|
-
* ```typescript
|
|
127
|
-
* const newPacienti = arrayToSearchableData(freshPacientiFromServer);
|
|
128
|
-
* const result = syncLinkedItemsForPrimaryString(
|
|
129
|
-
* linkedMeta,
|
|
130
|
-
* 'stranka-1',
|
|
131
|
-
* newPacienti,
|
|
132
|
-
* (p) => p.stranka_id,
|
|
133
|
-
* spec
|
|
134
|
-
* );
|
|
135
|
-
* console.log(`Added: ${result.added}, Updated: ${result.updated}, Removed: ${result.removed}`);
|
|
136
|
-
* ```
|
|
137
|
-
*/
|
|
138
|
-
export declare function syncLinkedItemsForPrimaryString<TPrimary extends SearchableObject, TLinked extends SearchableObject, C = unknown>(linked: SearchLinkedMetadataWithData<TPrimary, TLinked>, primaryId: Id, newLinkedItems: SearchableData<TLinked>, foreignKeyGetter: (item: TLinked) => Id | undefined, spec?: SearchableObjectSpec<TLinked, C>): SyncLinkedResult;
|
|
139
|
-
//# sourceMappingURL=updateSearchLinkedMetadata.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"updateSearchLinkedMetadata.d.ts","sourceRoot":"","sources":["../../src/common/updateSearchLinkedMetadata.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,EAAE,EACF,c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