@goatlab/typesense 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/dist/TypesenseApi.d.ts +229 -0
- package/dist/TypesenseApi.js +423 -0
- package/dist/TypesenseApi.js.map +1 -0
- package/dist/actions/admin/getCollectionStats.d.ts +3 -0
- package/dist/actions/admin/getCollectionStats.js +8 -0
- package/dist/actions/admin/getCollectionStats.js.map +1 -0
- package/dist/actions/admin/health.d.ts +4 -0
- package/dist/actions/admin/health.js +22 -0
- package/dist/actions/admin/health.js.map +1 -0
- package/dist/actions/admin/metrics.d.ts +4 -0
- package/dist/actions/admin/metrics.js +11 -0
- package/dist/actions/admin/metrics.js.map +1 -0
- package/dist/actions/aliases/createOrUpdateAlias.d.ts +3 -0
- package/dist/actions/aliases/createOrUpdateAlias.js +10 -0
- package/dist/actions/aliases/createOrUpdateAlias.js.map +1 -0
- package/dist/actions/aliases/deleteAlias.d.ts +3 -0
- package/dist/actions/aliases/deleteAlias.js +7 -0
- package/dist/actions/aliases/deleteAlias.js.map +1 -0
- package/dist/actions/aliases/getAlias.d.ts +3 -0
- package/dist/actions/aliases/getAlias.js +7 -0
- package/dist/actions/aliases/getAlias.js.map +1 -0
- package/dist/actions/aliases/listAliases.d.ts +3 -0
- package/dist/actions/aliases/listAliases.js +7 -0
- package/dist/actions/aliases/listAliases.js.map +1 -0
- package/dist/actions/collections/createCollection.d.ts +3 -0
- package/dist/actions/collections/createCollection.js +18 -0
- package/dist/actions/collections/createCollection.js.map +1 -0
- package/dist/actions/collections/deleteCollection.d.ts +3 -0
- package/dist/actions/collections/deleteCollection.js +13 -0
- package/dist/actions/collections/deleteCollection.js.map +1 -0
- package/dist/actions/collections/getCollection.d.ts +3 -0
- package/dist/actions/collections/getCollection.js +11 -0
- package/dist/actions/collections/getCollection.js.map +1 -0
- package/dist/actions/collections/getOrCreateCollection.d.ts +3 -0
- package/dist/actions/collections/getOrCreateCollection.js +19 -0
- package/dist/actions/collections/getOrCreateCollection.js.map +1 -0
- package/dist/actions/collections/listCollections.d.ts +3 -0
- package/dist/actions/collections/listCollections.js +7 -0
- package/dist/actions/collections/listCollections.js.map +1 -0
- package/dist/actions/collections/updateCollection.d.ts +3 -0
- package/dist/actions/collections/updateCollection.js +14 -0
- package/dist/actions/collections/updateCollection.js.map +1 -0
- package/dist/actions/documents/clearCollection.d.ts +5 -0
- package/dist/actions/documents/clearCollection.js +11 -0
- package/dist/actions/documents/clearCollection.js.map +1 -0
- package/dist/actions/documents/deleteByFilter.d.ts +5 -0
- package/dist/actions/documents/deleteByFilter.js +15 -0
- package/dist/actions/documents/deleteByFilter.js.map +1 -0
- package/dist/actions/documents/deleteDocument.d.ts +3 -0
- package/dist/actions/documents/deleteDocument.js +14 -0
- package/dist/actions/documents/deleteDocument.js.map +1 -0
- package/dist/actions/documents/exportDocuments.d.ts +5 -0
- package/dist/actions/documents/exportDocuments.js +51 -0
- package/dist/actions/documents/exportDocuments.js.map +1 -0
- package/dist/actions/documents/getDocumentById.d.ts +3 -0
- package/dist/actions/documents/getDocumentById.js +12 -0
- package/dist/actions/documents/getDocumentById.js.map +1 -0
- package/dist/actions/documents/importDocuments.d.ts +4 -0
- package/dist/actions/documents/importDocuments.js +58 -0
- package/dist/actions/documents/importDocuments.js.map +1 -0
- package/dist/actions/documents/insertDocument.d.ts +3 -0
- package/dist/actions/documents/insertDocument.js +38 -0
- package/dist/actions/documents/insertDocument.js.map +1 -0
- package/dist/actions/documents/updateDocument.d.ts +5 -0
- package/dist/actions/documents/updateDocument.js +15 -0
- package/dist/actions/documents/updateDocument.js.map +1 -0
- package/dist/actions/documents/upsertDocument.d.ts +3 -0
- package/dist/actions/documents/upsertDocument.js +16 -0
- package/dist/actions/documents/upsertDocument.js.map +1 -0
- package/dist/actions/overrides/deleteOverride.d.ts +3 -0
- package/dist/actions/overrides/deleteOverride.js +8 -0
- package/dist/actions/overrides/deleteOverride.js.map +1 -0
- package/dist/actions/overrides/getOverride.d.ts +3 -0
- package/dist/actions/overrides/getOverride.js +8 -0
- package/dist/actions/overrides/getOverride.js.map +1 -0
- package/dist/actions/overrides/listOverrides.d.ts +5 -0
- package/dist/actions/overrides/listOverrides.js +8 -0
- package/dist/actions/overrides/listOverrides.js.map +1 -0
- package/dist/actions/overrides/upsertOverride.d.ts +3 -0
- package/dist/actions/overrides/upsertOverride.js +11 -0
- package/dist/actions/overrides/upsertOverride.js.map +1 -0
- package/dist/actions/presets/deletePreset.d.ts +3 -0
- package/dist/actions/presets/deletePreset.js +7 -0
- package/dist/actions/presets/deletePreset.js.map +1 -0
- package/dist/actions/presets/getPreset.d.ts +3 -0
- package/dist/actions/presets/getPreset.js +7 -0
- package/dist/actions/presets/getPreset.js.map +1 -0
- package/dist/actions/presets/listPresets.d.ts +5 -0
- package/dist/actions/presets/listPresets.js +7 -0
- package/dist/actions/presets/listPresets.js.map +1 -0
- package/dist/actions/presets/upsertPreset.d.ts +3 -0
- package/dist/actions/presets/upsertPreset.js +10 -0
- package/dist/actions/presets/upsertPreset.js.map +1 -0
- package/dist/actions/search/multiSearch.d.ts +3 -0
- package/dist/actions/search/multiSearch.js +10 -0
- package/dist/actions/search/multiSearch.js.map +1 -0
- package/dist/actions/search/search.d.ts +5 -0
- package/dist/actions/search/search.js +19 -0
- package/dist/actions/search/search.js.map +1 -0
- package/dist/actions/synonyms/deleteSynonym.d.ts +3 -0
- package/dist/actions/synonyms/deleteSynonym.js +8 -0
- package/dist/actions/synonyms/deleteSynonym.js.map +1 -0
- package/dist/actions/synonyms/getSynonym.d.ts +3 -0
- package/dist/actions/synonyms/getSynonym.js +8 -0
- package/dist/actions/synonyms/getSynonym.js.map +1 -0
- package/dist/actions/synonyms/listSynonyms.d.ts +5 -0
- package/dist/actions/synonyms/listSynonyms.js +8 -0
- package/dist/actions/synonyms/listSynonyms.js.map +1 -0
- package/dist/actions/synonyms/upsertSynonym.d.ts +3 -0
- package/dist/actions/synonyms/upsertSynonym.js +11 -0
- package/dist/actions/synonyms/upsertSynonym.js.map +1 -0
- package/dist/components/export-formatter.d.ts +16 -0
- package/dist/components/export-formatter.js +226 -0
- package/dist/components/export-formatter.js.map +1 -0
- package/dist/components/http-client.d.ts +50 -0
- package/dist/components/http-client.js +149 -0
- package/dist/components/http-client.js.map +1 -0
- package/dist/components/resilience-policy.d.ts +33 -0
- package/dist/components/resilience-policy.js +115 -0
- package/dist/components/resilience-policy.js.map +1 -0
- package/dist/components/schema-manager.d.ts +30 -0
- package/dist/components/schema-manager.js +227 -0
- package/dist/components/schema-manager.js.map +1 -0
- package/dist/components/typesense.filter-builder.d.ts +127 -0
- package/dist/components/typesense.filter-builder.js +216 -0
- package/dist/components/typesense.filter-builder.js.map +1 -0
- package/dist/examples/multitenancy-example.d.ts +4 -0
- package/dist/examples/multitenancy-example.js +182 -0
- package/dist/examples/multitenancy-example.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +23 -0
- package/dist/index.js.map +1 -0
- package/dist/tests/const.d.ts +6 -0
- package/dist/tests/const.js +22 -0
- package/dist/tests/const.js.map +1 -0
- package/dist/tests/typesense.d.ts +2 -0
- package/dist/tests/typesense.js +24 -0
- package/dist/tests/typesense.js.map +1 -0
- package/dist/types.d.ts +16 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/dist/typesense.model.d.ts +455 -0
- package/dist/typesense.model.js +98 -0
- package/dist/typesense.model.js.map +1 -0
- package/dist/utils/tenant.d.ts +48 -0
- package/dist/utils/tenant.js +89 -0
- package/dist/utils/tenant.js.map +1 -0
- package/package.json +60 -0
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { TypesenseHttpClient } from './components/http-client';
|
|
2
|
+
import type { ResiliencePolicy } from './components/resilience-policy';
|
|
3
|
+
import type { CollectionSchemaManager } from './components/schema-manager';
|
|
4
|
+
export interface TypesenseContext {
|
|
5
|
+
httpClient: TypesenseHttpClient;
|
|
6
|
+
resilience: ResiliencePolicy;
|
|
7
|
+
schemaManager: CollectionSchemaManager;
|
|
8
|
+
tenantId?: string;
|
|
9
|
+
collectionName: string;
|
|
10
|
+
typesenseVersion?: string;
|
|
11
|
+
autoCreateCollection?: boolean;
|
|
12
|
+
suppressLogs?: boolean;
|
|
13
|
+
fqcn: (baseCollectionName?: string) => string;
|
|
14
|
+
}
|
|
15
|
+
export type Rest<Ctx, A> = Omit<A, keyof Ctx>;
|
|
16
|
+
export type Callable<F extends (a: any) => any, Ctx> = Rest<Ctx, Parameters<F>[0]> extends Record<string, never> ? () => ReturnType<F> : (arg: Rest<Ctx, Parameters<F>[0]>) => ReturnType<F>;
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,455 @@
|
|
|
1
|
+
import type { Primitive } from '@goatlab/js-utils';
|
|
2
|
+
/**
|
|
3
|
+
* Enhanced error class for Typesense API errors with rate limit and response details
|
|
4
|
+
*/
|
|
5
|
+
export declare class TypesenseError extends Error {
|
|
6
|
+
readonly status: number;
|
|
7
|
+
readonly statusText: string;
|
|
8
|
+
readonly response?: any;
|
|
9
|
+
readonly rateLimitRemaining?: number;
|
|
10
|
+
readonly rateLimitReset?: Date;
|
|
11
|
+
readonly retryAfter?: number;
|
|
12
|
+
readonly rateLimitLimit?: number;
|
|
13
|
+
constructor(message: string, status: number, response?: any, headers?: Record<string, string>);
|
|
14
|
+
/**
|
|
15
|
+
* Check if this error is due to rate limiting
|
|
16
|
+
*/
|
|
17
|
+
isRateLimited(): boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Get the time until rate limit reset (in milliseconds)
|
|
20
|
+
*/
|
|
21
|
+
getTimeUntilReset(): number | null;
|
|
22
|
+
}
|
|
23
|
+
export type TypesenseFieldType = 'string' | 'string[]' | 'int32' | 'int32[]' | 'int64' | 'int64[]' | 'float' | 'float[]' | 'bool' | 'bool[]' | 'geopoint' | 'geopoint[]' | 'string*' | 'auto' | 'object' | 'object[]';
|
|
24
|
+
export interface TypesenseCollectionField {
|
|
25
|
+
name: string;
|
|
26
|
+
type: TypesenseFieldType;
|
|
27
|
+
optional?: boolean;
|
|
28
|
+
facet?: boolean;
|
|
29
|
+
infix?: boolean;
|
|
30
|
+
sort?: boolean;
|
|
31
|
+
num_dim?: number;
|
|
32
|
+
vec_dist?: 'cosine' | 'ip' | 'l2';
|
|
33
|
+
store?: boolean;
|
|
34
|
+
}
|
|
35
|
+
export interface TypesenseCollection {
|
|
36
|
+
name: string;
|
|
37
|
+
alias?: string;
|
|
38
|
+
fields: TypesenseCollectionField[];
|
|
39
|
+
default_sorting_field?: string;
|
|
40
|
+
symbols_to_index?: string[];
|
|
41
|
+
enable_nested_fields?: boolean;
|
|
42
|
+
}
|
|
43
|
+
export type TypesenseCollectionOutput = TypesenseCollection & {
|
|
44
|
+
num_documents: number;
|
|
45
|
+
};
|
|
46
|
+
export type TypesenseDocument<T extends Record<string, any> = Record<string, any>> = {
|
|
47
|
+
id: string | number;
|
|
48
|
+
} & T;
|
|
49
|
+
/**
|
|
50
|
+
* Constraint to ensure documents have required id field
|
|
51
|
+
*/
|
|
52
|
+
export type WithRequiredId<T> = T & {
|
|
53
|
+
id: string | number;
|
|
54
|
+
};
|
|
55
|
+
export interface TypesenseDocumentGeneric {
|
|
56
|
+
[key: string]: Primitive | Primitive[];
|
|
57
|
+
id: string | number;
|
|
58
|
+
}
|
|
59
|
+
export interface TypesenseQuery {
|
|
60
|
+
q: string;
|
|
61
|
+
/**
|
|
62
|
+
* String[] should be separated by comma
|
|
63
|
+
*/
|
|
64
|
+
query_by: string;
|
|
65
|
+
filter_by?: string;
|
|
66
|
+
prefix?: string;
|
|
67
|
+
infix?: string;
|
|
68
|
+
split_join_tokens?: string;
|
|
69
|
+
pre_segmented_query?: string;
|
|
70
|
+
facet_by?: string;
|
|
71
|
+
max_facet_values?: number;
|
|
72
|
+
facet_query?: string;
|
|
73
|
+
facet_query_num_typos?: number;
|
|
74
|
+
/**
|
|
75
|
+
* Pagination - NOTE: Cannot be used with vector_query
|
|
76
|
+
*/
|
|
77
|
+
page?: number;
|
|
78
|
+
per_page?: number;
|
|
79
|
+
group_by?: string;
|
|
80
|
+
group_limit?: number;
|
|
81
|
+
/**
|
|
82
|
+
* Results
|
|
83
|
+
*/
|
|
84
|
+
include_fields?: string;
|
|
85
|
+
exclude_fields?: string;
|
|
86
|
+
highlight_fields?: string;
|
|
87
|
+
highlight_full_fields?: string;
|
|
88
|
+
highlight_affix_num_tokens?: number;
|
|
89
|
+
highlight_start_tag?: string;
|
|
90
|
+
highlight_end_tag?: string;
|
|
91
|
+
vector_query?: string;
|
|
92
|
+
text_matches?: number;
|
|
93
|
+
vector_weight?: number;
|
|
94
|
+
preset?: string;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Type-safe vector search query (cannot use pagination)
|
|
98
|
+
*/
|
|
99
|
+
export interface TypesenseVectorQuery extends Omit<TypesenseQuery, 'page' | 'per_page'> {
|
|
100
|
+
vector_query: string;
|
|
101
|
+
vector_weight?: number;
|
|
102
|
+
text_matches?: number;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Type-safe text search query (can use pagination)
|
|
106
|
+
*/
|
|
107
|
+
export interface TypesenseTextQuery extends TypesenseQuery {
|
|
108
|
+
vector_query?: never;
|
|
109
|
+
vector_weight?: never;
|
|
110
|
+
}
|
|
111
|
+
export interface TypesenseQueryResults<T> {
|
|
112
|
+
facet_counts: [];
|
|
113
|
+
found: number;
|
|
114
|
+
out_of: number;
|
|
115
|
+
page: number;
|
|
116
|
+
request_params: {
|
|
117
|
+
collection_name: string;
|
|
118
|
+
per_page: number;
|
|
119
|
+
q: string;
|
|
120
|
+
};
|
|
121
|
+
search_time_ms: number;
|
|
122
|
+
hits: {
|
|
123
|
+
document: TypesenseDocument<T>;
|
|
124
|
+
text_match: number;
|
|
125
|
+
highlights: {
|
|
126
|
+
field: string;
|
|
127
|
+
snippet: string;
|
|
128
|
+
matched_tokens: string[];
|
|
129
|
+
}[];
|
|
130
|
+
}[];
|
|
131
|
+
}
|
|
132
|
+
export interface TypesenseImportOptions {
|
|
133
|
+
/**
|
|
134
|
+
* The import operation to perform
|
|
135
|
+
* - create: Fails if a document with the same id already exists
|
|
136
|
+
* - upsert: Creates a new document or updates an existing document if one with the same id already exists
|
|
137
|
+
* - update: Updates an existing document. Fails if the document doesn't exist
|
|
138
|
+
* - emplace: Creates a new document if one with the same id doesn't exist. Does nothing if the document already exists
|
|
139
|
+
* @default 'create'
|
|
140
|
+
*/
|
|
141
|
+
action?: 'create' | 'upsert' | 'update' | 'emplace';
|
|
142
|
+
/**
|
|
143
|
+
* Number of documents to send in each batch
|
|
144
|
+
* @default 40
|
|
145
|
+
*/
|
|
146
|
+
batch_size?: number;
|
|
147
|
+
/**
|
|
148
|
+
* If set to true, the response will contain the id of the imported documents
|
|
149
|
+
* @default false
|
|
150
|
+
*/
|
|
151
|
+
return_id?: boolean;
|
|
152
|
+
/**
|
|
153
|
+
* If set to true, the response will contain the actual imported documents
|
|
154
|
+
* @default false
|
|
155
|
+
*/
|
|
156
|
+
return_doc?: boolean;
|
|
157
|
+
/**
|
|
158
|
+
* If set to true, skips indexing and stores the documents directly on disk. Indexing is done in background.
|
|
159
|
+
* Useful when you have a large number of documents to import and want to reduce memory usage during import.
|
|
160
|
+
* @default false
|
|
161
|
+
*/
|
|
162
|
+
dirty_values?: 'coerce_or_reject' | 'coerce_or_drop' | 'drop' | 'reject';
|
|
163
|
+
/**
|
|
164
|
+
* The format of the import data
|
|
165
|
+
* @default 'jsonl'
|
|
166
|
+
*/
|
|
167
|
+
format?: TypesenseImportFormat;
|
|
168
|
+
}
|
|
169
|
+
export interface TypesenseImportResult {
|
|
170
|
+
success: boolean;
|
|
171
|
+
error?: string;
|
|
172
|
+
document?: any;
|
|
173
|
+
id?: string | number;
|
|
174
|
+
}
|
|
175
|
+
export interface TypesenseExportOptions {
|
|
176
|
+
/**
|
|
177
|
+
* Filter documents by a condition. Uses the same syntax as search filter_by
|
|
178
|
+
*/
|
|
179
|
+
filter_by?: string;
|
|
180
|
+
/**
|
|
181
|
+
* List of fields to include in the exported documents
|
|
182
|
+
*/
|
|
183
|
+
include_fields?: string;
|
|
184
|
+
/**
|
|
185
|
+
* List of fields to exclude from the exported documents
|
|
186
|
+
*/
|
|
187
|
+
exclude_fields?: string;
|
|
188
|
+
/**
|
|
189
|
+
* Compression format for the export
|
|
190
|
+
*/
|
|
191
|
+
compression?: 'gzip' | 'none';
|
|
192
|
+
/**
|
|
193
|
+
* Collection override for multi-tenancy
|
|
194
|
+
*/
|
|
195
|
+
collection?: string;
|
|
196
|
+
}
|
|
197
|
+
export type TypesenseImportFormat = 'jsonl' | 'json' | 'csv';
|
|
198
|
+
export type TypesenseExportFormat = 'jsonl' | 'json' | 'csv';
|
|
199
|
+
/**
|
|
200
|
+
* Health check response from Typesense
|
|
201
|
+
*/
|
|
202
|
+
export interface TypesenseHealthResponse {
|
|
203
|
+
ok: boolean;
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Generic response wrapper for Typesense operations with metadata
|
|
207
|
+
*/
|
|
208
|
+
export interface TypesenseResponse<T> {
|
|
209
|
+
/**
|
|
210
|
+
* The actual data returned by the operation
|
|
211
|
+
*/
|
|
212
|
+
data: T;
|
|
213
|
+
/**
|
|
214
|
+
* Operation metadata
|
|
215
|
+
*/
|
|
216
|
+
metadata: {
|
|
217
|
+
/**
|
|
218
|
+
* Time taken for the operation in milliseconds
|
|
219
|
+
*/
|
|
220
|
+
operation_time_ms?: number;
|
|
221
|
+
/**
|
|
222
|
+
* Number of documents found (for search operations)
|
|
223
|
+
*/
|
|
224
|
+
found?: number;
|
|
225
|
+
/**
|
|
226
|
+
* Total documents that match without pagination (for search operations)
|
|
227
|
+
*/
|
|
228
|
+
out_of?: number;
|
|
229
|
+
/**
|
|
230
|
+
* Search time in milliseconds (for search operations)
|
|
231
|
+
*/
|
|
232
|
+
search_time_ms?: number;
|
|
233
|
+
/**
|
|
234
|
+
* Facet counts (for search operations with facets)
|
|
235
|
+
*/
|
|
236
|
+
facet_counts?: any[];
|
|
237
|
+
/**
|
|
238
|
+
* Number of documents in collection (for collection operations)
|
|
239
|
+
*/
|
|
240
|
+
num_documents?: number;
|
|
241
|
+
/**
|
|
242
|
+
* Request parameters used (for search operations)
|
|
243
|
+
*/
|
|
244
|
+
request_params?: Record<string, any>;
|
|
245
|
+
/**
|
|
246
|
+
* Operation type for clarity
|
|
247
|
+
*/
|
|
248
|
+
operation: 'create' | 'update' | 'delete' | 'upsert' | 'get' | 'search' | 'import' | 'export';
|
|
249
|
+
};
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* Type guard to check if a value is a valid document ID
|
|
253
|
+
*/
|
|
254
|
+
export declare function isValidDocumentId(id: any): id is string | number;
|
|
255
|
+
/**
|
|
256
|
+
* Validates text_matches parameter against per_page
|
|
257
|
+
*/
|
|
258
|
+
export declare function validateTextMatches(textMatches: number, perPage: number): boolean;
|
|
259
|
+
/**
|
|
260
|
+
* Validates vector search parameters
|
|
261
|
+
*/
|
|
262
|
+
export declare function validateVectorQuery(query: TypesenseQuery): {
|
|
263
|
+
valid: boolean;
|
|
264
|
+
errors: string[];
|
|
265
|
+
};
|
|
266
|
+
/**
|
|
267
|
+
* Error thrown when client is destroyed
|
|
268
|
+
*/
|
|
269
|
+
export declare class ClientDestroyedError extends Error {
|
|
270
|
+
constructor();
|
|
271
|
+
}
|
|
272
|
+
export interface TypesenseMultiSearchQuery {
|
|
273
|
+
collection?: string;
|
|
274
|
+
q: string;
|
|
275
|
+
query_by: string;
|
|
276
|
+
filter_by?: string;
|
|
277
|
+
prefix?: string;
|
|
278
|
+
infix?: string;
|
|
279
|
+
split_join_tokens?: string;
|
|
280
|
+
pre_segmented_query?: string;
|
|
281
|
+
facet_by?: string;
|
|
282
|
+
max_facet_values?: number;
|
|
283
|
+
facet_query?: string;
|
|
284
|
+
facet_query_num_typos?: number;
|
|
285
|
+
page?: number;
|
|
286
|
+
per_page?: number;
|
|
287
|
+
group_by?: string;
|
|
288
|
+
group_limit?: number;
|
|
289
|
+
include_fields?: string;
|
|
290
|
+
exclude_fields?: string;
|
|
291
|
+
highlight_fields?: string;
|
|
292
|
+
highlight_full_fields?: string;
|
|
293
|
+
highlight_affix_num_tokens?: number;
|
|
294
|
+
highlight_start_tag?: string;
|
|
295
|
+
highlight_end_tag?: string;
|
|
296
|
+
}
|
|
297
|
+
export interface TypesenseMultiSearchRequest {
|
|
298
|
+
searches: TypesenseMultiSearchQuery[];
|
|
299
|
+
}
|
|
300
|
+
export interface TypesenseMultiSearchResult<T> {
|
|
301
|
+
results: Array<TypesenseQueryResults<T> & {
|
|
302
|
+
request_params: any;
|
|
303
|
+
}>;
|
|
304
|
+
}
|
|
305
|
+
export interface TypesenseDeleteByFilterOptions {
|
|
306
|
+
filter_by: string;
|
|
307
|
+
batch_size?: number;
|
|
308
|
+
}
|
|
309
|
+
export interface TypesenseAlias {
|
|
310
|
+
name: string;
|
|
311
|
+
collection_name: string;
|
|
312
|
+
}
|
|
313
|
+
export interface TypesenseAliasCreateRequest {
|
|
314
|
+
collection_name: string;
|
|
315
|
+
}
|
|
316
|
+
export interface TypesenseAliasResponse extends TypesenseAlias {
|
|
317
|
+
}
|
|
318
|
+
export interface TypesenseAliasListResponse {
|
|
319
|
+
aliases: TypesenseAliasResponse[];
|
|
320
|
+
}
|
|
321
|
+
export interface TypesenseCollectionStats {
|
|
322
|
+
collection_name: string;
|
|
323
|
+
num_documents: number;
|
|
324
|
+
created_at: number;
|
|
325
|
+
num_memory_shards: number;
|
|
326
|
+
num_documents_indexed: number;
|
|
327
|
+
num_documents_queued: number;
|
|
328
|
+
field_stats?: {
|
|
329
|
+
[fieldName: string]: {
|
|
330
|
+
num_values: number;
|
|
331
|
+
avg_length?: number;
|
|
332
|
+
min?: number;
|
|
333
|
+
max?: number;
|
|
334
|
+
};
|
|
335
|
+
};
|
|
336
|
+
}
|
|
337
|
+
export interface TypesenseClusterNode {
|
|
338
|
+
id: string;
|
|
339
|
+
name: string;
|
|
340
|
+
state: 'ALIVE' | 'UNAVAILABLE' | 'INACTIVE';
|
|
341
|
+
last_contact: number;
|
|
342
|
+
}
|
|
343
|
+
export interface TypesenseClusterStatus {
|
|
344
|
+
state: 'HEALTHY' | 'DEGRADED' | 'UNAVAILABLE';
|
|
345
|
+
nodes: TypesenseClusterNode[];
|
|
346
|
+
}
|
|
347
|
+
export interface TypesenseSynonym {
|
|
348
|
+
id?: string;
|
|
349
|
+
synonyms: string[];
|
|
350
|
+
root?: string;
|
|
351
|
+
}
|
|
352
|
+
export interface TypesenseSynonymResponse extends TypesenseSynonym {
|
|
353
|
+
id: string;
|
|
354
|
+
}
|
|
355
|
+
export interface TypesenseOverride {
|
|
356
|
+
id?: string;
|
|
357
|
+
rule: {
|
|
358
|
+
query: string;
|
|
359
|
+
match: 'exact' | 'contains';
|
|
360
|
+
};
|
|
361
|
+
includes?: Array<{
|
|
362
|
+
id: string;
|
|
363
|
+
position: number;
|
|
364
|
+
}>;
|
|
365
|
+
excludes?: Array<{
|
|
366
|
+
id: string;
|
|
367
|
+
}>;
|
|
368
|
+
filter_by?: string;
|
|
369
|
+
remove_matched_tokens?: boolean;
|
|
370
|
+
stop_processing?: boolean;
|
|
371
|
+
}
|
|
372
|
+
export interface TypesenseOverrideResponse extends TypesenseOverride {
|
|
373
|
+
id: string;
|
|
374
|
+
}
|
|
375
|
+
export interface TypesensePreset {
|
|
376
|
+
name: string;
|
|
377
|
+
value: {
|
|
378
|
+
filter_by?: string;
|
|
379
|
+
sort_by?: string;
|
|
380
|
+
facet_by?: string;
|
|
381
|
+
max_facet_values?: number;
|
|
382
|
+
group_by?: string;
|
|
383
|
+
group_limit?: number;
|
|
384
|
+
include_fields?: string;
|
|
385
|
+
exclude_fields?: string;
|
|
386
|
+
highlight_fields?: string;
|
|
387
|
+
};
|
|
388
|
+
}
|
|
389
|
+
export interface TypesensePresetResponse extends TypesensePreset {
|
|
390
|
+
}
|
|
391
|
+
export interface TypesenseHealth {
|
|
392
|
+
ok: boolean;
|
|
393
|
+
}
|
|
394
|
+
export interface TypesenseMetrics {
|
|
395
|
+
system_cpu_active_percentage: string;
|
|
396
|
+
system_disk_total_bytes: string;
|
|
397
|
+
system_disk_used_bytes: string;
|
|
398
|
+
system_memory_total_bytes: string;
|
|
399
|
+
system_memory_used_bytes: string;
|
|
400
|
+
system_network_received_bytes: string;
|
|
401
|
+
system_network_sent_bytes: string;
|
|
402
|
+
typesense_memory_active_bytes: string;
|
|
403
|
+
typesense_memory_allocated_bytes: string;
|
|
404
|
+
typesense_memory_fragmentation_ratio: string;
|
|
405
|
+
typesense_memory_mapped_bytes: string;
|
|
406
|
+
typesense_memory_metadata_bytes: string;
|
|
407
|
+
typesense_memory_resident_bytes: string;
|
|
408
|
+
typesense_memory_retained_bytes: string;
|
|
409
|
+
latency_ms?: Record<string, Record<string, number>>;
|
|
410
|
+
requests_per_second?: Record<string, number>;
|
|
411
|
+
}
|
|
412
|
+
export interface TypesenseOperation {
|
|
413
|
+
id: number;
|
|
414
|
+
name: string;
|
|
415
|
+
status: 'success' | 'failure' | 'processing';
|
|
416
|
+
resource_id?: string;
|
|
417
|
+
resource_type?: string;
|
|
418
|
+
started_at: number;
|
|
419
|
+
completed_at?: number;
|
|
420
|
+
details?: Record<string, any>;
|
|
421
|
+
}
|
|
422
|
+
export interface TypesenseApiKey {
|
|
423
|
+
id?: number;
|
|
424
|
+
value?: string;
|
|
425
|
+
description: string;
|
|
426
|
+
actions: string[];
|
|
427
|
+
collections: string[];
|
|
428
|
+
expires_at?: number;
|
|
429
|
+
}
|
|
430
|
+
export interface TypesenseApiKeyResponse extends TypesenseApiKey {
|
|
431
|
+
id: number;
|
|
432
|
+
value_prefix: string;
|
|
433
|
+
}
|
|
434
|
+
export interface TypesenseRateLimitInfo {
|
|
435
|
+
limit?: number;
|
|
436
|
+
remaining?: number;
|
|
437
|
+
resetMs?: number;
|
|
438
|
+
retryAfter?: number;
|
|
439
|
+
}
|
|
440
|
+
export interface TypesenseVectorSearchOptions {
|
|
441
|
+
vector_query: string;
|
|
442
|
+
vector_weight?: number;
|
|
443
|
+
text_matches?: number;
|
|
444
|
+
}
|
|
445
|
+
export interface TypesenseHybridSearchOptions {
|
|
446
|
+
vector_weight: number;
|
|
447
|
+
text_matches?: number;
|
|
448
|
+
}
|
|
449
|
+
export interface TypesenseCollectionOptions {
|
|
450
|
+
collection?: string;
|
|
451
|
+
}
|
|
452
|
+
export interface TypesenseSchemaCacheEntry {
|
|
453
|
+
schema: TypesenseCollection;
|
|
454
|
+
timestamp: number;
|
|
455
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ClientDestroyedError = exports.TypesenseError = void 0;
|
|
4
|
+
exports.isValidDocumentId = isValidDocumentId;
|
|
5
|
+
exports.validateTextMatches = validateTextMatches;
|
|
6
|
+
exports.validateVectorQuery = validateVectorQuery;
|
|
7
|
+
/**
|
|
8
|
+
* Enhanced error class for Typesense API errors with rate limit and response details
|
|
9
|
+
*/
|
|
10
|
+
class TypesenseError extends Error {
|
|
11
|
+
status;
|
|
12
|
+
statusText;
|
|
13
|
+
response;
|
|
14
|
+
rateLimitRemaining;
|
|
15
|
+
rateLimitReset;
|
|
16
|
+
retryAfter;
|
|
17
|
+
rateLimitLimit;
|
|
18
|
+
constructor(message, status, response, headers) {
|
|
19
|
+
super(message);
|
|
20
|
+
this.name = 'TypesenseError';
|
|
21
|
+
this.status = status;
|
|
22
|
+
this.statusText = status.toString();
|
|
23
|
+
this.response = response;
|
|
24
|
+
// Extract rate limit information from headers (Typesense format)
|
|
25
|
+
if (headers) {
|
|
26
|
+
const remaining = headers['X-RateLimit-Remaining'];
|
|
27
|
+
const resetMs = headers['X-RateLimit-ResetMs']; // Typesense uses milliseconds
|
|
28
|
+
const retryAfter = headers['Retry-After'];
|
|
29
|
+
const limit = headers['X-RateLimit-Limit'];
|
|
30
|
+
if (remaining)
|
|
31
|
+
this.rateLimitRemaining = parseInt(remaining, 10);
|
|
32
|
+
if (resetMs)
|
|
33
|
+
this.rateLimitReset = new Date(parseInt(resetMs, 10));
|
|
34
|
+
if (retryAfter)
|
|
35
|
+
this.retryAfter = parseInt(retryAfter, 10);
|
|
36
|
+
if (limit)
|
|
37
|
+
this.rateLimitLimit = parseInt(limit, 10);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Check if this error is due to rate limiting
|
|
42
|
+
*/
|
|
43
|
+
isRateLimited() {
|
|
44
|
+
return this.status === 429;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Get the time until rate limit reset (in milliseconds)
|
|
48
|
+
*/
|
|
49
|
+
getTimeUntilReset() {
|
|
50
|
+
if (!this.rateLimitReset)
|
|
51
|
+
return null;
|
|
52
|
+
return Math.max(0, this.rateLimitReset.getTime() - Date.now());
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
exports.TypesenseError = TypesenseError;
|
|
56
|
+
/**
|
|
57
|
+
* Type guard to check if a value is a valid document ID
|
|
58
|
+
*/
|
|
59
|
+
function isValidDocumentId(id) {
|
|
60
|
+
return (typeof id === 'string' && id.length > 0) || (typeof id === 'number' && !isNaN(id));
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Validates text_matches parameter against per_page
|
|
64
|
+
*/
|
|
65
|
+
function validateTextMatches(textMatches, perPage) {
|
|
66
|
+
return textMatches <= perPage;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Validates vector search parameters
|
|
70
|
+
*/
|
|
71
|
+
function validateVectorQuery(query) {
|
|
72
|
+
const errors = [];
|
|
73
|
+
if (query.vector_query) {
|
|
74
|
+
// Vector queries cannot use pagination
|
|
75
|
+
if (query.page !== undefined || query.per_page !== undefined) {
|
|
76
|
+
errors.push('vector_query cannot be used with page or per_page parameters');
|
|
77
|
+
}
|
|
78
|
+
// Validate text_matches if present
|
|
79
|
+
if (query.text_matches && query.per_page && query.text_matches > query.per_page) {
|
|
80
|
+
errors.push('text_matches must be less than or equal to per_page');
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return {
|
|
84
|
+
valid: errors.length === 0,
|
|
85
|
+
errors
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Error thrown when client is destroyed
|
|
90
|
+
*/
|
|
91
|
+
class ClientDestroyedError extends Error {
|
|
92
|
+
constructor() {
|
|
93
|
+
super('TypesenseApi has been destroyed and cannot be used');
|
|
94
|
+
this.name = 'ClientDestroyedError';
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
exports.ClientDestroyedError = ClientDestroyedError;
|
|
98
|
+
//# sourceMappingURL=typesense.model.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"typesense.model.js","sourceRoot":"","sources":["../src/typesense.model.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tenant utility functions for multitenancy support
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Validates and sanitizes a tenant ID for use in collection names
|
|
6
|
+
* - Enforces allowed characters: a-zA-Z0-9_-
|
|
7
|
+
* - Converts to lowercase to avoid case-sensitivity issues
|
|
8
|
+
* - Enforces max length of 128 characters
|
|
9
|
+
*
|
|
10
|
+
* @param tenantId - Raw tenant ID to validate
|
|
11
|
+
* @returns Sanitized tenant ID
|
|
12
|
+
* @throws Error if tenant ID is invalid
|
|
13
|
+
*/
|
|
14
|
+
export declare function sanitizeTenantId(tenantId: string): string;
|
|
15
|
+
/**
|
|
16
|
+
* Creates a fully qualified collection name by prepending tenant ID
|
|
17
|
+
* Format: <tenantId>__<baseCollectionName>
|
|
18
|
+
*
|
|
19
|
+
* @param tenantId - Sanitized tenant ID
|
|
20
|
+
* @param baseCollectionName - Base collection name without tenant prefix
|
|
21
|
+
* @returns Fully qualified collection name
|
|
22
|
+
*/
|
|
23
|
+
export declare function createFQCN(tenantId: string, baseCollectionName: string): string;
|
|
24
|
+
/**
|
|
25
|
+
* Extracts tenant ID and base collection name from a fully qualified collection name
|
|
26
|
+
*
|
|
27
|
+
* @param fqcn - Fully qualified collection name
|
|
28
|
+
* @returns Object with tenantId and baseCollectionName, or null if not a tenant collection
|
|
29
|
+
*/
|
|
30
|
+
export declare function parseFQCN(fqcn: string): {
|
|
31
|
+
tenantId: string;
|
|
32
|
+
baseCollectionName: string;
|
|
33
|
+
} | null;
|
|
34
|
+
/**
|
|
35
|
+
* Checks if a collection name is tenant-prefixed
|
|
36
|
+
*
|
|
37
|
+
* @param collectionName - Collection name to check
|
|
38
|
+
* @returns True if the collection has a tenant prefix
|
|
39
|
+
*/
|
|
40
|
+
export declare function isTenantCollection(collectionName: string): boolean;
|
|
41
|
+
/**
|
|
42
|
+
* Filters collections by tenant ID
|
|
43
|
+
*
|
|
44
|
+
* @param collections - Array of collection names
|
|
45
|
+
* @param tenantId - Tenant ID to filter by
|
|
46
|
+
* @returns Collections belonging to the specified tenant
|
|
47
|
+
*/
|
|
48
|
+
export declare function filterCollectionsByTenant(collections: string[], tenantId: string): string[];
|