cry-search 1.0.1 → 1.0.4
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 +110 -4
- package/README.md +86 -2
- package/dist/common/numeric/AugmentedMetadata.d.ts +111 -0
- package/dist/common/numeric/AugmentedMetadata.d.ts.map +1 -0
- package/dist/common/numeric/index.d.ts +3 -0
- package/dist/common/numeric/index.d.ts.map +1 -1
- package/dist/common/numeric/syncSearchArrayMetadata.d.ts +64 -0
- package/dist/common/numeric/syncSearchArrayMetadata.d.ts.map +1 -0
- package/dist/common/numeric/updateSearchLinkedMetadata.d.ts +130 -0
- package/dist/common/numeric/updateSearchLinkedMetadata.d.ts.map +1 -0
- package/dist/common/syncSearchArrayMetadata.d.ts +12 -8
- package/dist/common/syncSearchArrayMetadata.d.ts.map +1 -1
- package/dist/common/updateSearchLinkedMetadata.d.ts +26 -16
- package/dist/common/updateSearchLinkedMetadata.d.ts.map +1 -1
- package/dist/index.cjs +192 -427
- package/dist/index.d.cts +3 -9
- package/dist/index.d.ts +3 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +192 -427
- package/dist/string.cjs +924 -0
- package/dist/string.d.cts +26 -0
- package/dist/string.d.ts +26 -0
- package/dist/string.d.ts.map +1 -0
- package/dist/string.js +892 -0
- package/dist/utils/preprocessString.d.ts +6 -2
- package/dist/utils/preprocessString.d.ts.map +1 -1
- package/package.json +14 -4
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import type { SearchMetadata, SearchableData, SearchableObject, SearchableObjectSpec, SyncResult, SyncOptions } from '../types';
|
|
2
2
|
export type { SyncResult, SyncOptions } from '../types';
|
|
3
3
|
/**
|
|
4
|
-
* Syncs search metadata with new data.
|
|
4
|
+
* Syncs string-based search metadata with new data.
|
|
5
|
+
*
|
|
6
|
+
* LEGACY: Use syncSearchArrayMetadataNumeric for new code.
|
|
5
7
|
*
|
|
6
8
|
* This function performs a full sync of metadata against the provided data:
|
|
7
9
|
* - Adds metadata for new items
|
|
@@ -9,7 +11,7 @@ export type { SyncResult, SyncOptions } from '../types';
|
|
|
9
11
|
* - Updates metadata for items whose tokens have changed
|
|
10
12
|
*
|
|
11
13
|
* Use this when you have completely new data to sync with. If you have both
|
|
12
|
-
* previous and new data available, use {@link
|
|
14
|
+
* previous and new data available, use {@link syncSearchArrayMetadataStringWithPrevious}
|
|
13
15
|
* for more efficient diffing.
|
|
14
16
|
*
|
|
15
17
|
* @typeParam T - Type of the searchable objects
|
|
@@ -23,16 +25,18 @@ export type { SyncResult, SyncOptions } from '../types';
|
|
|
23
25
|
* @example
|
|
24
26
|
* ```typescript
|
|
25
27
|
* const newProducts = arrayToSearchableData(freshProductsFromServer);
|
|
26
|
-
* const result =
|
|
28
|
+
* const result = syncSearchArrayMetadataString(metadata, newProducts, spec);
|
|
27
29
|
*
|
|
28
30
|
* console.log(`Added: ${result.added}, Updated: ${result.updated}, Removed: ${result.removed}`);
|
|
29
31
|
* ```
|
|
30
32
|
*/
|
|
31
|
-
export declare function
|
|
33
|
+
export declare function syncSearchArrayMetadataString<T extends SearchableObject, C = unknown>(metadata: SearchMetadata, newData: SearchableData<T>, spec?: SearchableObjectSpec<T, C>): SyncResult;
|
|
32
34
|
/**
|
|
33
|
-
* Syncs search metadata using previous and new data for efficient diffing.
|
|
35
|
+
* Syncs string-based search metadata using previous and new data for efficient diffing.
|
|
36
|
+
*
|
|
37
|
+
* LEGACY: Use syncSearchArrayMetadataNumericWithPrevious for new code.
|
|
34
38
|
*
|
|
35
|
-
* More efficient than {@link
|
|
39
|
+
* More efficient than {@link syncSearchArrayMetadataString} when you have both the
|
|
36
40
|
* previous and new data available. Uses the previous data to determine
|
|
37
41
|
* what was removed without iterating through all metadata keys.
|
|
38
42
|
*
|
|
@@ -51,7 +55,7 @@ export declare function syncSearchArrayMetadata<T extends SearchableObject, C =
|
|
|
51
55
|
* const previousProducts = currentData;
|
|
52
56
|
* const newProducts = arrayToSearchableData(freshProductsFromServer);
|
|
53
57
|
*
|
|
54
|
-
* const result =
|
|
58
|
+
* const result = syncSearchArrayMetadataStringWithPrevious(
|
|
55
59
|
* metadata,
|
|
56
60
|
* previousProducts,
|
|
57
61
|
* newProducts,
|
|
@@ -60,5 +64,5 @@ export declare function syncSearchArrayMetadata<T extends SearchableObject, C =
|
|
|
60
64
|
* );
|
|
61
65
|
* ```
|
|
62
66
|
*/
|
|
63
|
-
export declare function
|
|
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;
|
|
64
68
|
//# sourceMappingURL=syncSearchArrayMetadata.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
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
|
|
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,7 +1,9 @@
|
|
|
1
1
|
import type { Id, SearchableData, SearchableObject, SearchableObjectSpec, SearchLinkedMetadataWithData, UpsertResult, SyncLinkedResult } from '../types';
|
|
2
2
|
export type { UpsertResult, SyncLinkedResult } from '../types';
|
|
3
3
|
/**
|
|
4
|
-
* Upserts a primary item into the linked metadata.
|
|
4
|
+
* Upserts a primary item into the linked metadata (string-based).
|
|
5
|
+
*
|
|
6
|
+
* LEGACY: Use upsertPrimaryItemNumeric for new code.
|
|
5
7
|
*
|
|
6
8
|
* - If the item doesn't exist, adds it to data, metadata, and initializes primaryToLinked index
|
|
7
9
|
* - If the item exists, updates data and metadata
|
|
@@ -19,17 +21,19 @@ export type { UpsertResult, SyncLinkedResult } from '../types';
|
|
|
19
21
|
* @example
|
|
20
22
|
* ```typescript
|
|
21
23
|
* const stranka = { _id: 's1', ime: 'Janez', priimek: 'Novak' };
|
|
22
|
-
* const result =
|
|
24
|
+
* const result = upsertPrimaryItemString(linkedMeta, stranka, spec);
|
|
23
25
|
* // result.added === true if stranka was new
|
|
24
26
|
* ```
|
|
25
27
|
*/
|
|
26
|
-
export declare function
|
|
28
|
+
export declare function upsertPrimaryItemString<TPrimary extends SearchableObject, TLinked extends SearchableObject, C = unknown>(linked: SearchLinkedMetadataWithData<TPrimary, TLinked>, item: TPrimary, spec?: SearchableObjectSpec<TPrimary, C>): UpsertResult;
|
|
27
29
|
/**
|
|
28
|
-
* Removes a primary item from the linked metadata.
|
|
30
|
+
* Removes a primary item from the linked metadata (string-based).
|
|
31
|
+
*
|
|
32
|
+
* LEGACY: Use removePrimaryItemNumeric for new code.
|
|
29
33
|
*
|
|
30
34
|
* Removes the item from data, metadata, and the primaryToLinked index.
|
|
31
35
|
* Note: This does NOT automatically remove linked items - they will become orphans.
|
|
32
|
-
* If you want to also remove linked items, call {@link
|
|
36
|
+
* If you want to also remove linked items, call {@link removeLinkedItemString} for each.
|
|
33
37
|
*
|
|
34
38
|
* @typeParam TPrimary - Type of primary items
|
|
35
39
|
* @typeParam TLinked - Type of linked items
|
|
@@ -38,9 +42,11 @@ export declare function upsertPrimaryItem<TPrimary extends SearchableObject, TLi
|
|
|
38
42
|
* @param primaryId - The ID of the primary item to remove
|
|
39
43
|
* @returns true if item was found and removed, false if not found
|
|
40
44
|
*/
|
|
41
|
-
export declare function
|
|
45
|
+
export declare function removePrimaryItemString<TPrimary extends SearchableObject, TLinked extends SearchableObject>(linked: SearchLinkedMetadataWithData<TPrimary, TLinked>, primaryId: Id): boolean;
|
|
42
46
|
/**
|
|
43
|
-
* Upserts a linked item into the linked metadata.
|
|
47
|
+
* Upserts a linked item into the linked metadata (string-based).
|
|
48
|
+
*
|
|
49
|
+
* LEGACY: Use upsertLinkedItemNumeric for new code.
|
|
44
50
|
*
|
|
45
51
|
* - If the item doesn't exist, adds it
|
|
46
52
|
* - If the item exists, updates it
|
|
@@ -61,17 +67,19 @@ export declare function removePrimaryItem<TPrimary extends SearchableObject, TLi
|
|
|
61
67
|
* @example
|
|
62
68
|
* ```typescript
|
|
63
69
|
* const pacient = { _id: 'p1', ime: 'Rex', stranka_id: 's1' };
|
|
64
|
-
* const result =
|
|
70
|
+
* const result = upsertLinkedItemString(linkedMeta, pacient, (p) => p.stranka_id, spec);
|
|
65
71
|
*
|
|
66
72
|
* // If the pacient moved to a different stranka:
|
|
67
73
|
* pacient.stranka_id = 's2';
|
|
68
|
-
* const result2 =
|
|
74
|
+
* const result2 = upsertLinkedItemString(linkedMeta, pacient, (p) => p.stranka_id, spec);
|
|
69
75
|
* // result2.previousPrimaryId === 's1'
|
|
70
76
|
* ```
|
|
71
77
|
*/
|
|
72
|
-
export declare function
|
|
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;
|
|
73
79
|
/**
|
|
74
|
-
* Removes a linked item from the linked metadata.
|
|
80
|
+
* Removes a linked item from the linked metadata (string-based).
|
|
81
|
+
*
|
|
82
|
+
* LEGACY: Use removeLinkedItemNumeric for new code.
|
|
75
83
|
*
|
|
76
84
|
* Removes the item from data, metadata, and the primaryToLinked index.
|
|
77
85
|
*
|
|
@@ -85,12 +93,14 @@ export declare function upsertLinkedItem<TPrimary extends SearchableObject, TLin
|
|
|
85
93
|
*
|
|
86
94
|
* @example
|
|
87
95
|
* ```typescript
|
|
88
|
-
*
|
|
96
|
+
* removeLinkedItemString(linkedMeta, 'pacient-id', (p) => p.stranka_id);
|
|
89
97
|
* ```
|
|
90
98
|
*/
|
|
91
|
-
export declare function
|
|
99
|
+
export declare function removeLinkedItemString<TPrimary extends SearchableObject, TLinked extends SearchableObject>(linked: SearchLinkedMetadataWithData<TPrimary, TLinked>, linkedId: Id, foreignKeyGetter: (item: TLinked) => Id | undefined): boolean;
|
|
92
100
|
/**
|
|
93
|
-
* Syncs all linked items for a specific primary item.
|
|
101
|
+
* Syncs all linked items for a specific primary item (string-based).
|
|
102
|
+
*
|
|
103
|
+
* LEGACY: Use syncLinkedItemsForPrimaryNumeric for new code.
|
|
94
104
|
*
|
|
95
105
|
* This function performs a full sync of linked items belonging to a single primary:
|
|
96
106
|
* - Removes linked items that are no longer in the new data
|
|
@@ -115,7 +125,7 @@ export declare function removeLinkedItem<TPrimary extends SearchableObject, TLin
|
|
|
115
125
|
* @example
|
|
116
126
|
* ```typescript
|
|
117
127
|
* const newPacienti = arrayToSearchableData(freshPacientiFromServer);
|
|
118
|
-
* const result =
|
|
128
|
+
* const result = syncLinkedItemsForPrimaryString(
|
|
119
129
|
* linkedMeta,
|
|
120
130
|
* 'stranka-1',
|
|
121
131
|
* newPacienti,
|
|
@@ -125,5 +135,5 @@ export declare function removeLinkedItem<TPrimary extends SearchableObject, TLin
|
|
|
125
135
|
* console.log(`Added: ${result.added}, Updated: ${result.updated}, Removed: ${result.removed}`);
|
|
126
136
|
* ```
|
|
127
137
|
*/
|
|
128
|
-
export declare function
|
|
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;
|
|
129
139
|
//# sourceMappingURL=updateSearchLinkedMetadata.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"updateSearchLinkedMetadata.d.ts","sourceRoot":"","sources":["../../src/common/updateSearchLinkedMetadata.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,EAAE,EACF,cAAc,EACd,gBAAgB,EAChB,oBAAoB,EACpB,4BAA4B,EAC5B,YAAY,EACZ,gBAAgB,EACjB,MAAM,UAAU,CAAC;AAIlB,YAAY,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAkB/D
|
|
1
|
+
{"version":3,"file":"updateSearchLinkedMetadata.d.ts","sourceRoot":"","sources":["../../src/common/updateSearchLinkedMetadata.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,EAAE,E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