@topgunbuild/client 0.8.0 → 0.9.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/LICENSE +97 -0
- package/dist/index.d.mts +223 -1
- package/dist/index.d.ts +223 -1
- package/dist/index.js +419 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +418 -0
- package/dist/index.mjs.map +1 -1
- package/package.json +10 -10
package/LICENSE
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
Business Source License 1.1
|
|
2
|
+
|
|
3
|
+
Parameters
|
|
4
|
+
|
|
5
|
+
Licensor: TopGun Contributors
|
|
6
|
+
Licensed Work: TopGun
|
|
7
|
+
The Licensed Work is (c) 2024 TopGun Contributors.
|
|
8
|
+
Additional Use Grant: You may make production use of the Licensed Work,
|
|
9
|
+
provided Your use does not include offering the
|
|
10
|
+
Licensed Work to third parties as a commercial
|
|
11
|
+
managed database service, database-as-a-service,
|
|
12
|
+
or similar hosted database offering that competes
|
|
13
|
+
with TopGun products or services.
|
|
14
|
+
|
|
15
|
+
For purposes of this license:
|
|
16
|
+
- "Managed database service" means a service that
|
|
17
|
+
allows third parties to create, manage, or operate
|
|
18
|
+
databases using TopGun as the underlying technology.
|
|
19
|
+
- Internal use within your organization is permitted.
|
|
20
|
+
- Using TopGun as part of your application's backend
|
|
21
|
+
(not exposed as a database service) is permitted.
|
|
22
|
+
- Consulting and professional services around TopGun
|
|
23
|
+
are permitted.
|
|
24
|
+
|
|
25
|
+
Change Date: Four years from the date of each version release
|
|
26
|
+
Change License: Apache License, Version 2.0
|
|
27
|
+
|
|
28
|
+
For information about alternative licensing arrangements for the Licensed Work,
|
|
29
|
+
please contact the Licensor.
|
|
30
|
+
|
|
31
|
+
Notice
|
|
32
|
+
|
|
33
|
+
Business Source License 1.1
|
|
34
|
+
|
|
35
|
+
Terms
|
|
36
|
+
|
|
37
|
+
The Licensor hereby grants you the right to copy, modify, create derivative
|
|
38
|
+
works, redistribute, and make non-production use of the Licensed Work. The
|
|
39
|
+
Licensor may make an Additional Use Grant, above, permitting limited production use.
|
|
40
|
+
|
|
41
|
+
Effective on the Change Date, or the fourth anniversary of the first publicly
|
|
42
|
+
available distribution of a specific version of the Licensed Work under this
|
|
43
|
+
License, whichever comes first, the Licensor hereby grants you rights under
|
|
44
|
+
the terms of the Change License, and the rights granted in the paragraph
|
|
45
|
+
above terminate.
|
|
46
|
+
|
|
47
|
+
If your use of the Licensed Work does not comply with the requirements
|
|
48
|
+
currently in effect as described in this License, you must purchase a
|
|
49
|
+
commercial license from the Licensor, its affiliated entities, or authorized
|
|
50
|
+
resellers, or you must refrain from using the Licensed Work.
|
|
51
|
+
|
|
52
|
+
All copies of the original and modified Licensed Work, and derivative works
|
|
53
|
+
of the Licensed Work, are subject to this License. This License applies
|
|
54
|
+
separately for each version of the Licensed Work and the Change Date may vary
|
|
55
|
+
for each version of the Licensed Work released by Licensor.
|
|
56
|
+
|
|
57
|
+
You must conspicuously display this License on each original or modified copy
|
|
58
|
+
of the Licensed Work. If you receive the Licensed Work in original or
|
|
59
|
+
modified form from a third party, the terms and conditions set forth in this
|
|
60
|
+
License apply to your use of that work.
|
|
61
|
+
|
|
62
|
+
Any use of the Licensed Work in violation of this License will automatically
|
|
63
|
+
terminate your rights under this License for the current and all other
|
|
64
|
+
versions of the Licensed Work.
|
|
65
|
+
|
|
66
|
+
This License does not grant you any right in any trademark or logo of
|
|
67
|
+
Licensor or its affiliates (provided that you may use a trademark or logo of
|
|
68
|
+
Licensor as expressly required by this License).
|
|
69
|
+
|
|
70
|
+
TO THE EXTENT PERMITTED BY APPLICABLE LAW, THE LICENSED WORK IS PROVIDED ON
|
|
71
|
+
AN "AS IS" BASIS. LICENSOR HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS,
|
|
72
|
+
EXPRESS OR IMPLIED, INCLUDING (WITHOUT LIMITATION) WARRANTIES OF
|
|
73
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, AND
|
|
74
|
+
TITLE.
|
|
75
|
+
|
|
76
|
+
MariaDB hereby grants you permission to use this License's text to license
|
|
77
|
+
your works, and to refer to it using the trademark "Business Source License",
|
|
78
|
+
as long as you comply with the Covenants of Licensor below.
|
|
79
|
+
|
|
80
|
+
Covenants of Licensor
|
|
81
|
+
|
|
82
|
+
In consideration of the right to use this License's text and the "Business
|
|
83
|
+
Source License" name and trademark, Licensor covenants to MariaDB, and to all
|
|
84
|
+
other recipients of the licensed work to be provided by Licensor:
|
|
85
|
+
|
|
86
|
+
1. To specify as the Change License the GPL Version 2.0 or any later version,
|
|
87
|
+
or a license that is compatible with GPL Version 2.0 or a later version,
|
|
88
|
+
where "compatible" means that software provided under the Change License can
|
|
89
|
+
be included in a program with software provided under GPL Version 2.0 or a
|
|
90
|
+
later version. Licensor may specify additional Change Licenses without
|
|
91
|
+
limitation.
|
|
92
|
+
|
|
93
|
+
2. To either: (a) specify an Additional Use Grant (above) that does not impose
|
|
94
|
+
any additional restriction on the right granted in this License, as the
|
|
95
|
+
Additional Use Grant; or (b) insert the text "None" to specify a Change Date.
|
|
96
|
+
|
|
97
|
+
3. Not to modify this License in any other way.
|
package/dist/index.d.mts
CHANGED
|
@@ -188,6 +188,148 @@ declare class QueryHandle<T> {
|
|
|
188
188
|
getMapName(): string;
|
|
189
189
|
}
|
|
190
190
|
|
|
191
|
+
/**
|
|
192
|
+
* HybridQueryHandle - Query handle for hybrid FTS + filter queries
|
|
193
|
+
*
|
|
194
|
+
* Extends QueryHandle functionality to support:
|
|
195
|
+
* - FTS predicates (match, matchPhrase, matchPrefix)
|
|
196
|
+
* - Score-based sorting (_score field)
|
|
197
|
+
* - Hybrid queries combining FTS with traditional filters
|
|
198
|
+
*
|
|
199
|
+
* Part of Phase 12: Unified Search
|
|
200
|
+
*
|
|
201
|
+
* @module HybridQueryHandle
|
|
202
|
+
*/
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* Filter options for hybrid queries.
|
|
206
|
+
*/
|
|
207
|
+
interface HybridQueryFilter {
|
|
208
|
+
/** Traditional where clause filters */
|
|
209
|
+
where?: Record<string, any>;
|
|
210
|
+
/** Predicate tree (can include FTS predicates) */
|
|
211
|
+
predicate?: PredicateNode;
|
|
212
|
+
/** Sort configuration - use '_score' for FTS relevance sorting */
|
|
213
|
+
sort?: Record<string, 'asc' | 'desc'>;
|
|
214
|
+
/** Maximum results */
|
|
215
|
+
limit?: number;
|
|
216
|
+
/** Skip N results */
|
|
217
|
+
offset?: number;
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* Result item with score for hybrid queries.
|
|
221
|
+
*/
|
|
222
|
+
interface HybridResultItem<T> {
|
|
223
|
+
/** The document */
|
|
224
|
+
value: T;
|
|
225
|
+
/** Unique key */
|
|
226
|
+
_key: string;
|
|
227
|
+
/** Relevance score (only for FTS queries) */
|
|
228
|
+
_score?: number;
|
|
229
|
+
/** Matched terms (only for FTS queries) */
|
|
230
|
+
_matchedTerms?: string[];
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Source of query results.
|
|
234
|
+
*/
|
|
235
|
+
type HybridResultSource = 'local' | 'server';
|
|
236
|
+
/**
|
|
237
|
+
* HybridQueryHandle manages hybrid queries that combine FTS with filters.
|
|
238
|
+
*
|
|
239
|
+
* @example
|
|
240
|
+
* ```typescript
|
|
241
|
+
* // Create hybrid query: FTS + filter
|
|
242
|
+
* const handle = new HybridQueryHandle(syncEngine, 'articles', {
|
|
243
|
+
* predicate: Predicates.and(
|
|
244
|
+
* Predicates.match('body', 'machine learning'),
|
|
245
|
+
* Predicates.equal('category', 'tech')
|
|
246
|
+
* ),
|
|
247
|
+
* sort: { _score: 'desc' },
|
|
248
|
+
* limit: 20
|
|
249
|
+
* });
|
|
250
|
+
*
|
|
251
|
+
* // Subscribe to results
|
|
252
|
+
* handle.subscribe((results) => {
|
|
253
|
+
* results.forEach(r => console.log(`${r._key}: ${r._score}`));
|
|
254
|
+
* });
|
|
255
|
+
* ```
|
|
256
|
+
*/
|
|
257
|
+
declare class HybridQueryHandle<T> {
|
|
258
|
+
readonly id: string;
|
|
259
|
+
private syncEngine;
|
|
260
|
+
private mapName;
|
|
261
|
+
private filter;
|
|
262
|
+
private listeners;
|
|
263
|
+
private currentResults;
|
|
264
|
+
private changeTracker;
|
|
265
|
+
private pendingChanges;
|
|
266
|
+
private changeListeners;
|
|
267
|
+
private hasReceivedServerData;
|
|
268
|
+
constructor(syncEngine: SyncEngine, mapName: string, filter?: HybridQueryFilter);
|
|
269
|
+
/**
|
|
270
|
+
* Subscribe to query results.
|
|
271
|
+
*/
|
|
272
|
+
subscribe(callback: (results: HybridResultItem<T>[]) => void): () => void;
|
|
273
|
+
private loadInitialLocalData;
|
|
274
|
+
/**
|
|
275
|
+
* Called by SyncEngine with query results.
|
|
276
|
+
*/
|
|
277
|
+
onResult(items: Array<{
|
|
278
|
+
key: string;
|
|
279
|
+
value: T;
|
|
280
|
+
score?: number;
|
|
281
|
+
matchedTerms?: string[];
|
|
282
|
+
}>, source?: HybridResultSource): void;
|
|
283
|
+
/**
|
|
284
|
+
* Called by SyncEngine on live update.
|
|
285
|
+
*/
|
|
286
|
+
onUpdate(key: string, value: T | null, score?: number, matchedTerms?: string[]): void;
|
|
287
|
+
/**
|
|
288
|
+
* Subscribe to change events.
|
|
289
|
+
*/
|
|
290
|
+
onChanges(listener: (changes: ChangeEvent<T>[]) => void): () => void;
|
|
291
|
+
/**
|
|
292
|
+
* Get and clear pending changes.
|
|
293
|
+
*/
|
|
294
|
+
consumeChanges(): ChangeEvent<T>[];
|
|
295
|
+
/**
|
|
296
|
+
* Get last change without consuming.
|
|
297
|
+
*/
|
|
298
|
+
getLastChange(): ChangeEvent<T> | null;
|
|
299
|
+
/**
|
|
300
|
+
* Get all pending changes without consuming.
|
|
301
|
+
*/
|
|
302
|
+
getPendingChanges(): ChangeEvent<T>[];
|
|
303
|
+
/**
|
|
304
|
+
* Clear all pending changes.
|
|
305
|
+
*/
|
|
306
|
+
clearChanges(): void;
|
|
307
|
+
/**
|
|
308
|
+
* Reset change tracker.
|
|
309
|
+
*/
|
|
310
|
+
resetChangeTracker(): void;
|
|
311
|
+
private computeAndNotifyChanges;
|
|
312
|
+
private notifyChangeListeners;
|
|
313
|
+
private notify;
|
|
314
|
+
/**
|
|
315
|
+
* Get sorted results with _key and _score.
|
|
316
|
+
*/
|
|
317
|
+
private getSortedResults;
|
|
318
|
+
/**
|
|
319
|
+
* Get the filter configuration.
|
|
320
|
+
*/
|
|
321
|
+
getFilter(): HybridQueryFilter;
|
|
322
|
+
/**
|
|
323
|
+
* Get the map name.
|
|
324
|
+
*/
|
|
325
|
+
getMapName(): string;
|
|
326
|
+
/**
|
|
327
|
+
* Check if this query contains FTS predicates.
|
|
328
|
+
*/
|
|
329
|
+
hasFTSPredicate(): boolean;
|
|
330
|
+
private containsFTS;
|
|
331
|
+
}
|
|
332
|
+
|
|
191
333
|
type TopicCallback = (data: any, context: {
|
|
192
334
|
timestamp: number;
|
|
193
335
|
publisherId?: string;
|
|
@@ -1057,6 +1199,54 @@ declare class SyncEngine {
|
|
|
1057
1199
|
* and subscribing to merge rejection events.
|
|
1058
1200
|
*/
|
|
1059
1201
|
getConflictResolverClient(): ConflictResolverClient;
|
|
1202
|
+
/** Active hybrid query subscriptions */
|
|
1203
|
+
private hybridQueries;
|
|
1204
|
+
/**
|
|
1205
|
+
* Subscribe to a hybrid query (FTS + filter combination).
|
|
1206
|
+
*/
|
|
1207
|
+
subscribeToHybridQuery<T>(query: HybridQueryHandle<T>): void;
|
|
1208
|
+
/**
|
|
1209
|
+
* Unsubscribe from a hybrid query.
|
|
1210
|
+
*/
|
|
1211
|
+
unsubscribeFromHybridQuery(queryId: string): void;
|
|
1212
|
+
/**
|
|
1213
|
+
* Send hybrid query subscription to server.
|
|
1214
|
+
*/
|
|
1215
|
+
private sendHybridQuerySubscription;
|
|
1216
|
+
/**
|
|
1217
|
+
* Run a local hybrid query (FTS + filter combination).
|
|
1218
|
+
* For FTS predicates, returns results with score = 0 (local-only mode).
|
|
1219
|
+
* Server provides actual FTS scoring.
|
|
1220
|
+
*/
|
|
1221
|
+
runLocalHybridQuery<T>(mapName: string, filter: HybridQueryFilter): Promise<Array<{
|
|
1222
|
+
key: string;
|
|
1223
|
+
value: T;
|
|
1224
|
+
score?: number;
|
|
1225
|
+
matchedTerms?: string[];
|
|
1226
|
+
}>>;
|
|
1227
|
+
/**
|
|
1228
|
+
* Handle hybrid query response from server.
|
|
1229
|
+
*/
|
|
1230
|
+
handleHybridQueryResponse(payload: {
|
|
1231
|
+
subscriptionId: string;
|
|
1232
|
+
results: Array<{
|
|
1233
|
+
key: string;
|
|
1234
|
+
value: unknown;
|
|
1235
|
+
score: number;
|
|
1236
|
+
matchedTerms: string[];
|
|
1237
|
+
}>;
|
|
1238
|
+
}): void;
|
|
1239
|
+
/**
|
|
1240
|
+
* Handle hybrid query delta update from server.
|
|
1241
|
+
*/
|
|
1242
|
+
handleHybridQueryDelta(payload: {
|
|
1243
|
+
subscriptionId: string;
|
|
1244
|
+
key: string;
|
|
1245
|
+
value: unknown | null;
|
|
1246
|
+
score?: number;
|
|
1247
|
+
matchedTerms?: string[];
|
|
1248
|
+
type: 'ENTER' | 'UPDATE' | 'LEAVE';
|
|
1249
|
+
}): void;
|
|
1060
1250
|
}
|
|
1061
1251
|
|
|
1062
1252
|
interface ILock {
|
|
@@ -1647,6 +1837,38 @@ declare class TopGunClient {
|
|
|
1647
1837
|
* ```
|
|
1648
1838
|
*/
|
|
1649
1839
|
searchSubscribe<T>(mapName: string, query: string, options?: SearchOptions): SearchHandle<T>;
|
|
1840
|
+
/**
|
|
1841
|
+
* Create a hybrid query combining FTS with traditional filters.
|
|
1842
|
+
*
|
|
1843
|
+
* Hybrid queries allow combining full-text search predicates (match, matchPhrase, matchPrefix)
|
|
1844
|
+
* with traditional filter predicates (eq, gt, lt, contains, etc.) in a single query.
|
|
1845
|
+
* Results include relevance scores for FTS ranking.
|
|
1846
|
+
*
|
|
1847
|
+
* @param mapName Name of the map to query
|
|
1848
|
+
* @param filter Hybrid query filter with predicate, where, sort, limit, offset
|
|
1849
|
+
* @returns HybridQueryHandle for managing the subscription
|
|
1850
|
+
*
|
|
1851
|
+
* @example
|
|
1852
|
+
* ```typescript
|
|
1853
|
+
* import { Predicates } from '@topgunbuild/core';
|
|
1854
|
+
*
|
|
1855
|
+
* // Hybrid query: FTS + filter
|
|
1856
|
+
* const handle = client.hybridQuery<Article>('articles', {
|
|
1857
|
+
* predicate: Predicates.and(
|
|
1858
|
+
* Predicates.match('body', 'machine learning'),
|
|
1859
|
+
* Predicates.equal('category', 'tech')
|
|
1860
|
+
* ),
|
|
1861
|
+
* sort: { _score: 'desc' },
|
|
1862
|
+
* limit: 20
|
|
1863
|
+
* });
|
|
1864
|
+
*
|
|
1865
|
+
* // Subscribe to results
|
|
1866
|
+
* handle.subscribe((results) => {
|
|
1867
|
+
* results.forEach(r => console.log(`${r._key}: score=${r._score}`));
|
|
1868
|
+
* });
|
|
1869
|
+
* ```
|
|
1870
|
+
*/
|
|
1871
|
+
hybridQuery<T>(mapName: string, filter?: HybridQueryFilter): HybridQueryHandle<T>;
|
|
1650
1872
|
/**
|
|
1651
1873
|
* Execute an entry processor on a single key atomically.
|
|
1652
1874
|
*
|
|
@@ -2483,4 +2705,4 @@ declare class SingleServerProvider implements IConnectionProvider {
|
|
|
2483
2705
|
|
|
2484
2706
|
declare const logger: pino.Logger<never, boolean>;
|
|
2485
2707
|
|
|
2486
|
-
export { type BackoffConfig, type BackpressureConfig, BackpressureError, type BackpressureStatus, type BackpressureStrategy, type BackpressureThresholdEvent, type ChangeEvent, ChangeTracker, type CircuitState, ClusterClient, type ClusterClientEvents, type ClusterRoutingMode, ConflictResolverClient, type ConnectionEventHandler, ConnectionPool, type ConnectionPoolEvents, type ConnectionProviderEvent, DEFAULT_BACKPRESSURE_CONFIG, DEFAULT_CLUSTER_CONFIG, EncryptedStorageAdapter, EventJournalReader, type HeartbeatConfig, type IConnectionProvider, IDBAdapter, type IStorageAdapter, type JournalEventData, type JournalSubscribeOptions, type OpLogEntry, type OperationDroppedEvent, PNCounterHandle, PartitionRouter, type PartitionRouterEvents, type QueryFilter, QueryHandle, type QueryResultItem, type QueryResultSource, type RegisterResult, type ResolverInfo, type RoutingMetrics, type RoutingResult, SearchHandle, type SearchResult, type SearchResultsCallback, SingleServerProvider, type SingleServerProviderConfig, type StateChangeEvent, type StateChangeListener, SyncEngine, type SyncEngineConfig, SyncState, SyncStateMachine, type SyncStateMachineConfig, TopGun, TopGunClient, type TopGunClientConfig, type TopGunClusterConfig, type TopicCallback, TopicHandle, VALID_TRANSITIONS, isValidTransition, logger };
|
|
2708
|
+
export { type BackoffConfig, type BackpressureConfig, BackpressureError, type BackpressureStatus, type BackpressureStrategy, type BackpressureThresholdEvent, type ChangeEvent, ChangeTracker, type CircuitState, ClusterClient, type ClusterClientEvents, type ClusterRoutingMode, ConflictResolverClient, type ConnectionEventHandler, ConnectionPool, type ConnectionPoolEvents, type ConnectionProviderEvent, DEFAULT_BACKPRESSURE_CONFIG, DEFAULT_CLUSTER_CONFIG, EncryptedStorageAdapter, EventJournalReader, type HeartbeatConfig, type HybridQueryFilter, HybridQueryHandle, type HybridResultItem, type HybridResultSource, type IConnectionProvider, IDBAdapter, type IStorageAdapter, type JournalEventData, type JournalSubscribeOptions, type OpLogEntry, type OperationDroppedEvent, PNCounterHandle, PartitionRouter, type PartitionRouterEvents, type QueryFilter, QueryHandle, type QueryResultItem, type QueryResultSource, type RegisterResult, type ResolverInfo, type RoutingMetrics, type RoutingResult, SearchHandle, type SearchResult, type SearchResultsCallback, SingleServerProvider, type SingleServerProviderConfig, type StateChangeEvent, type StateChangeListener, SyncEngine, type SyncEngineConfig, SyncState, SyncStateMachine, type SyncStateMachineConfig, TopGun, TopGunClient, type TopGunClientConfig, type TopGunClusterConfig, type TopicCallback, TopicHandle, VALID_TRANSITIONS, isValidTransition, logger };
|
package/dist/index.d.ts
CHANGED
|
@@ -188,6 +188,148 @@ declare class QueryHandle<T> {
|
|
|
188
188
|
getMapName(): string;
|
|
189
189
|
}
|
|
190
190
|
|
|
191
|
+
/**
|
|
192
|
+
* HybridQueryHandle - Query handle for hybrid FTS + filter queries
|
|
193
|
+
*
|
|
194
|
+
* Extends QueryHandle functionality to support:
|
|
195
|
+
* - FTS predicates (match, matchPhrase, matchPrefix)
|
|
196
|
+
* - Score-based sorting (_score field)
|
|
197
|
+
* - Hybrid queries combining FTS with traditional filters
|
|
198
|
+
*
|
|
199
|
+
* Part of Phase 12: Unified Search
|
|
200
|
+
*
|
|
201
|
+
* @module HybridQueryHandle
|
|
202
|
+
*/
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* Filter options for hybrid queries.
|
|
206
|
+
*/
|
|
207
|
+
interface HybridQueryFilter {
|
|
208
|
+
/** Traditional where clause filters */
|
|
209
|
+
where?: Record<string, any>;
|
|
210
|
+
/** Predicate tree (can include FTS predicates) */
|
|
211
|
+
predicate?: PredicateNode;
|
|
212
|
+
/** Sort configuration - use '_score' for FTS relevance sorting */
|
|
213
|
+
sort?: Record<string, 'asc' | 'desc'>;
|
|
214
|
+
/** Maximum results */
|
|
215
|
+
limit?: number;
|
|
216
|
+
/** Skip N results */
|
|
217
|
+
offset?: number;
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* Result item with score for hybrid queries.
|
|
221
|
+
*/
|
|
222
|
+
interface HybridResultItem<T> {
|
|
223
|
+
/** The document */
|
|
224
|
+
value: T;
|
|
225
|
+
/** Unique key */
|
|
226
|
+
_key: string;
|
|
227
|
+
/** Relevance score (only for FTS queries) */
|
|
228
|
+
_score?: number;
|
|
229
|
+
/** Matched terms (only for FTS queries) */
|
|
230
|
+
_matchedTerms?: string[];
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Source of query results.
|
|
234
|
+
*/
|
|
235
|
+
type HybridResultSource = 'local' | 'server';
|
|
236
|
+
/**
|
|
237
|
+
* HybridQueryHandle manages hybrid queries that combine FTS with filters.
|
|
238
|
+
*
|
|
239
|
+
* @example
|
|
240
|
+
* ```typescript
|
|
241
|
+
* // Create hybrid query: FTS + filter
|
|
242
|
+
* const handle = new HybridQueryHandle(syncEngine, 'articles', {
|
|
243
|
+
* predicate: Predicates.and(
|
|
244
|
+
* Predicates.match('body', 'machine learning'),
|
|
245
|
+
* Predicates.equal('category', 'tech')
|
|
246
|
+
* ),
|
|
247
|
+
* sort: { _score: 'desc' },
|
|
248
|
+
* limit: 20
|
|
249
|
+
* });
|
|
250
|
+
*
|
|
251
|
+
* // Subscribe to results
|
|
252
|
+
* handle.subscribe((results) => {
|
|
253
|
+
* results.forEach(r => console.log(`${r._key}: ${r._score}`));
|
|
254
|
+
* });
|
|
255
|
+
* ```
|
|
256
|
+
*/
|
|
257
|
+
declare class HybridQueryHandle<T> {
|
|
258
|
+
readonly id: string;
|
|
259
|
+
private syncEngine;
|
|
260
|
+
private mapName;
|
|
261
|
+
private filter;
|
|
262
|
+
private listeners;
|
|
263
|
+
private currentResults;
|
|
264
|
+
private changeTracker;
|
|
265
|
+
private pendingChanges;
|
|
266
|
+
private changeListeners;
|
|
267
|
+
private hasReceivedServerData;
|
|
268
|
+
constructor(syncEngine: SyncEngine, mapName: string, filter?: HybridQueryFilter);
|
|
269
|
+
/**
|
|
270
|
+
* Subscribe to query results.
|
|
271
|
+
*/
|
|
272
|
+
subscribe(callback: (results: HybridResultItem<T>[]) => void): () => void;
|
|
273
|
+
private loadInitialLocalData;
|
|
274
|
+
/**
|
|
275
|
+
* Called by SyncEngine with query results.
|
|
276
|
+
*/
|
|
277
|
+
onResult(items: Array<{
|
|
278
|
+
key: string;
|
|
279
|
+
value: T;
|
|
280
|
+
score?: number;
|
|
281
|
+
matchedTerms?: string[];
|
|
282
|
+
}>, source?: HybridResultSource): void;
|
|
283
|
+
/**
|
|
284
|
+
* Called by SyncEngine on live update.
|
|
285
|
+
*/
|
|
286
|
+
onUpdate(key: string, value: T | null, score?: number, matchedTerms?: string[]): void;
|
|
287
|
+
/**
|
|
288
|
+
* Subscribe to change events.
|
|
289
|
+
*/
|
|
290
|
+
onChanges(listener: (changes: ChangeEvent<T>[]) => void): () => void;
|
|
291
|
+
/**
|
|
292
|
+
* Get and clear pending changes.
|
|
293
|
+
*/
|
|
294
|
+
consumeChanges(): ChangeEvent<T>[];
|
|
295
|
+
/**
|
|
296
|
+
* Get last change without consuming.
|
|
297
|
+
*/
|
|
298
|
+
getLastChange(): ChangeEvent<T> | null;
|
|
299
|
+
/**
|
|
300
|
+
* Get all pending changes without consuming.
|
|
301
|
+
*/
|
|
302
|
+
getPendingChanges(): ChangeEvent<T>[];
|
|
303
|
+
/**
|
|
304
|
+
* Clear all pending changes.
|
|
305
|
+
*/
|
|
306
|
+
clearChanges(): void;
|
|
307
|
+
/**
|
|
308
|
+
* Reset change tracker.
|
|
309
|
+
*/
|
|
310
|
+
resetChangeTracker(): void;
|
|
311
|
+
private computeAndNotifyChanges;
|
|
312
|
+
private notifyChangeListeners;
|
|
313
|
+
private notify;
|
|
314
|
+
/**
|
|
315
|
+
* Get sorted results with _key and _score.
|
|
316
|
+
*/
|
|
317
|
+
private getSortedResults;
|
|
318
|
+
/**
|
|
319
|
+
* Get the filter configuration.
|
|
320
|
+
*/
|
|
321
|
+
getFilter(): HybridQueryFilter;
|
|
322
|
+
/**
|
|
323
|
+
* Get the map name.
|
|
324
|
+
*/
|
|
325
|
+
getMapName(): string;
|
|
326
|
+
/**
|
|
327
|
+
* Check if this query contains FTS predicates.
|
|
328
|
+
*/
|
|
329
|
+
hasFTSPredicate(): boolean;
|
|
330
|
+
private containsFTS;
|
|
331
|
+
}
|
|
332
|
+
|
|
191
333
|
type TopicCallback = (data: any, context: {
|
|
192
334
|
timestamp: number;
|
|
193
335
|
publisherId?: string;
|
|
@@ -1057,6 +1199,54 @@ declare class SyncEngine {
|
|
|
1057
1199
|
* and subscribing to merge rejection events.
|
|
1058
1200
|
*/
|
|
1059
1201
|
getConflictResolverClient(): ConflictResolverClient;
|
|
1202
|
+
/** Active hybrid query subscriptions */
|
|
1203
|
+
private hybridQueries;
|
|
1204
|
+
/**
|
|
1205
|
+
* Subscribe to a hybrid query (FTS + filter combination).
|
|
1206
|
+
*/
|
|
1207
|
+
subscribeToHybridQuery<T>(query: HybridQueryHandle<T>): void;
|
|
1208
|
+
/**
|
|
1209
|
+
* Unsubscribe from a hybrid query.
|
|
1210
|
+
*/
|
|
1211
|
+
unsubscribeFromHybridQuery(queryId: string): void;
|
|
1212
|
+
/**
|
|
1213
|
+
* Send hybrid query subscription to server.
|
|
1214
|
+
*/
|
|
1215
|
+
private sendHybridQuerySubscription;
|
|
1216
|
+
/**
|
|
1217
|
+
* Run a local hybrid query (FTS + filter combination).
|
|
1218
|
+
* For FTS predicates, returns results with score = 0 (local-only mode).
|
|
1219
|
+
* Server provides actual FTS scoring.
|
|
1220
|
+
*/
|
|
1221
|
+
runLocalHybridQuery<T>(mapName: string, filter: HybridQueryFilter): Promise<Array<{
|
|
1222
|
+
key: string;
|
|
1223
|
+
value: T;
|
|
1224
|
+
score?: number;
|
|
1225
|
+
matchedTerms?: string[];
|
|
1226
|
+
}>>;
|
|
1227
|
+
/**
|
|
1228
|
+
* Handle hybrid query response from server.
|
|
1229
|
+
*/
|
|
1230
|
+
handleHybridQueryResponse(payload: {
|
|
1231
|
+
subscriptionId: string;
|
|
1232
|
+
results: Array<{
|
|
1233
|
+
key: string;
|
|
1234
|
+
value: unknown;
|
|
1235
|
+
score: number;
|
|
1236
|
+
matchedTerms: string[];
|
|
1237
|
+
}>;
|
|
1238
|
+
}): void;
|
|
1239
|
+
/**
|
|
1240
|
+
* Handle hybrid query delta update from server.
|
|
1241
|
+
*/
|
|
1242
|
+
handleHybridQueryDelta(payload: {
|
|
1243
|
+
subscriptionId: string;
|
|
1244
|
+
key: string;
|
|
1245
|
+
value: unknown | null;
|
|
1246
|
+
score?: number;
|
|
1247
|
+
matchedTerms?: string[];
|
|
1248
|
+
type: 'ENTER' | 'UPDATE' | 'LEAVE';
|
|
1249
|
+
}): void;
|
|
1060
1250
|
}
|
|
1061
1251
|
|
|
1062
1252
|
interface ILock {
|
|
@@ -1647,6 +1837,38 @@ declare class TopGunClient {
|
|
|
1647
1837
|
* ```
|
|
1648
1838
|
*/
|
|
1649
1839
|
searchSubscribe<T>(mapName: string, query: string, options?: SearchOptions): SearchHandle<T>;
|
|
1840
|
+
/**
|
|
1841
|
+
* Create a hybrid query combining FTS with traditional filters.
|
|
1842
|
+
*
|
|
1843
|
+
* Hybrid queries allow combining full-text search predicates (match, matchPhrase, matchPrefix)
|
|
1844
|
+
* with traditional filter predicates (eq, gt, lt, contains, etc.) in a single query.
|
|
1845
|
+
* Results include relevance scores for FTS ranking.
|
|
1846
|
+
*
|
|
1847
|
+
* @param mapName Name of the map to query
|
|
1848
|
+
* @param filter Hybrid query filter with predicate, where, sort, limit, offset
|
|
1849
|
+
* @returns HybridQueryHandle for managing the subscription
|
|
1850
|
+
*
|
|
1851
|
+
* @example
|
|
1852
|
+
* ```typescript
|
|
1853
|
+
* import { Predicates } from '@topgunbuild/core';
|
|
1854
|
+
*
|
|
1855
|
+
* // Hybrid query: FTS + filter
|
|
1856
|
+
* const handle = client.hybridQuery<Article>('articles', {
|
|
1857
|
+
* predicate: Predicates.and(
|
|
1858
|
+
* Predicates.match('body', 'machine learning'),
|
|
1859
|
+
* Predicates.equal('category', 'tech')
|
|
1860
|
+
* ),
|
|
1861
|
+
* sort: { _score: 'desc' },
|
|
1862
|
+
* limit: 20
|
|
1863
|
+
* });
|
|
1864
|
+
*
|
|
1865
|
+
* // Subscribe to results
|
|
1866
|
+
* handle.subscribe((results) => {
|
|
1867
|
+
* results.forEach(r => console.log(`${r._key}: score=${r._score}`));
|
|
1868
|
+
* });
|
|
1869
|
+
* ```
|
|
1870
|
+
*/
|
|
1871
|
+
hybridQuery<T>(mapName: string, filter?: HybridQueryFilter): HybridQueryHandle<T>;
|
|
1650
1872
|
/**
|
|
1651
1873
|
* Execute an entry processor on a single key atomically.
|
|
1652
1874
|
*
|
|
@@ -2483,4 +2705,4 @@ declare class SingleServerProvider implements IConnectionProvider {
|
|
|
2483
2705
|
|
|
2484
2706
|
declare const logger: pino.Logger<never, boolean>;
|
|
2485
2707
|
|
|
2486
|
-
export { type BackoffConfig, type BackpressureConfig, BackpressureError, type BackpressureStatus, type BackpressureStrategy, type BackpressureThresholdEvent, type ChangeEvent, ChangeTracker, type CircuitState, ClusterClient, type ClusterClientEvents, type ClusterRoutingMode, ConflictResolverClient, type ConnectionEventHandler, ConnectionPool, type ConnectionPoolEvents, type ConnectionProviderEvent, DEFAULT_BACKPRESSURE_CONFIG, DEFAULT_CLUSTER_CONFIG, EncryptedStorageAdapter, EventJournalReader, type HeartbeatConfig, type IConnectionProvider, IDBAdapter, type IStorageAdapter, type JournalEventData, type JournalSubscribeOptions, type OpLogEntry, type OperationDroppedEvent, PNCounterHandle, PartitionRouter, type PartitionRouterEvents, type QueryFilter, QueryHandle, type QueryResultItem, type QueryResultSource, type RegisterResult, type ResolverInfo, type RoutingMetrics, type RoutingResult, SearchHandle, type SearchResult, type SearchResultsCallback, SingleServerProvider, type SingleServerProviderConfig, type StateChangeEvent, type StateChangeListener, SyncEngine, type SyncEngineConfig, SyncState, SyncStateMachine, type SyncStateMachineConfig, TopGun, TopGunClient, type TopGunClientConfig, type TopGunClusterConfig, type TopicCallback, TopicHandle, VALID_TRANSITIONS, isValidTransition, logger };
|
|
2708
|
+
export { type BackoffConfig, type BackpressureConfig, BackpressureError, type BackpressureStatus, type BackpressureStrategy, type BackpressureThresholdEvent, type ChangeEvent, ChangeTracker, type CircuitState, ClusterClient, type ClusterClientEvents, type ClusterRoutingMode, ConflictResolverClient, type ConnectionEventHandler, ConnectionPool, type ConnectionPoolEvents, type ConnectionProviderEvent, DEFAULT_BACKPRESSURE_CONFIG, DEFAULT_CLUSTER_CONFIG, EncryptedStorageAdapter, EventJournalReader, type HeartbeatConfig, type HybridQueryFilter, HybridQueryHandle, type HybridResultItem, type HybridResultSource, type IConnectionProvider, IDBAdapter, type IStorageAdapter, type JournalEventData, type JournalSubscribeOptions, type OpLogEntry, type OperationDroppedEvent, PNCounterHandle, PartitionRouter, type PartitionRouterEvents, type QueryFilter, QueryHandle, type QueryResultItem, type QueryResultSource, type RegisterResult, type ResolverInfo, type RoutingMetrics, type RoutingResult, SearchHandle, type SearchResult, type SearchResultsCallback, SingleServerProvider, type SingleServerProviderConfig, type StateChangeEvent, type StateChangeListener, SyncEngine, type SyncEngineConfig, SyncState, SyncStateMachine, type SyncStateMachineConfig, TopGun, TopGunClient, type TopGunClientConfig, type TopGunClusterConfig, type TopicCallback, TopicHandle, VALID_TRANSITIONS, isValidTransition, logger };
|