@goatlab/typesense 0.0.3 → 0.1.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/README.md +265 -1
- package/dist/TypesenseApi.d.ts +114 -70
- package/dist/TypesenseApi.js +101 -55
- package/dist/TypesenseApi.js.map +1 -1
- package/dist/actions/aliases/createOrUpdateAlias.js +7 -2
- package/dist/actions/aliases/createOrUpdateAlias.js.map +1 -1
- package/dist/actions/aliases/deleteAlias.js +3 -1
- package/dist/actions/aliases/deleteAlias.js.map +1 -1
- package/dist/actions/aliases/getAlias.js +3 -1
- package/dist/actions/aliases/getAlias.js.map +1 -1
- package/dist/actions/collections/getOrCreateCollection.js +1 -1
- package/dist/actions/collections/getOrCreateCollection.js.map +1 -1
- package/dist/actions/documents/exportDocuments.js.map +1 -1
- package/dist/actions/documents/insertDocument.d.ts +1 -1
- package/dist/actions/documents/insertDocument.js +1 -2
- package/dist/actions/documents/insertDocument.js.map +1 -1
- package/dist/actions/documents/updateDocument.d.ts +2 -2
- package/dist/actions/documents/updateDocument.js.map +1 -1
- package/dist/actions/documents/upsertDocument.d.ts +1 -1
- package/dist/actions/documents/upsertDocument.js.map +1 -1
- package/dist/actions/presets/deletePreset.js +4 -1
- package/dist/actions/presets/deletePreset.js.map +1 -1
- package/dist/actions/presets/getPreset.js +4 -1
- package/dist/actions/presets/getPreset.js.map +1 -1
- package/dist/actions/presets/listPresets.js +13 -1
- package/dist/actions/presets/listPresets.js.map +1 -1
- package/dist/actions/presets/upsertPreset.js +6 -2
- package/dist/actions/presets/upsertPreset.js.map +1 -1
- package/dist/components/resilience-policy.d.ts +4 -0
- package/dist/components/resilience-policy.js +21 -0
- package/dist/components/resilience-policy.js.map +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +6 -1
- package/dist/index.js.map +1 -1
- package/dist/tests/type-inference-example.d.ts +1 -0
- package/dist/tests/type-inference-example.js +91 -0
- package/dist/tests/type-inference-example.js.map +1 -0
- package/dist/types.d.ts +2 -1
- package/dist/typesense.model.d.ts +1 -0
- package/dist/typesense.model.js.map +1 -1
- package/dist/utils/schema-to-types.d.ts +46 -0
- package/dist/utils/schema-to-types.js +10 -0
- package/dist/utils/schema-to-types.js.map +1 -0
- package/dist/utils/schema-typed-api.d.ts +33 -0
- package/dist/utils/schema-typed-api.js +42 -0
- package/dist/utils/schema-typed-api.js.map +1 -0
- package/dist/utils/tenant.d.ts +9 -0
- package/dist/utils/tenant.js +12 -0
- package/dist/utils/tenant.js.map +1 -1
- package/package.json +6 -5
package/README.md
CHANGED
|
@@ -53,9 +53,9 @@ const results = await typesense.search.query({
|
|
|
53
53
|
## Key Features
|
|
54
54
|
|
|
55
55
|
- **Grouped API Interface**: Organized methods under logical namespaces (collections, documents, search, admin)
|
|
56
|
+
- **Full Type Safety**: Generic type support for document operations with compile-time checking
|
|
56
57
|
- **Multi-tenancy Support**: Built-in tenant isolation with automatic collection name prefixing
|
|
57
58
|
- **Resilience Features**: Circuit breaker pattern, rate limiting, and automatic retries
|
|
58
|
-
- **Type Safety**: Full TypeScript support with comprehensive type definitions
|
|
59
59
|
- **Schema Management**: Automatic schema caching and version compatibility checks
|
|
60
60
|
- **Stream Support**: Efficient document export with streaming capabilities
|
|
61
61
|
- **Advanced Search**: Support for text search, vector search, and multi-search operations
|
|
@@ -101,6 +101,270 @@ const results = await typesense.search.query({
|
|
|
101
101
|
- **Overrides**: Set up search result overrides
|
|
102
102
|
- **Presets**: Configure search presets
|
|
103
103
|
|
|
104
|
+
## Type Safety
|
|
105
|
+
|
|
106
|
+
The TypesenseApi supports full type safety for document operations:
|
|
107
|
+
|
|
108
|
+
### Basic Typed API
|
|
109
|
+
|
|
110
|
+
```typescript
|
|
111
|
+
import { createTypedApi } from '@goatlab/typesense'
|
|
112
|
+
|
|
113
|
+
// Define your document type
|
|
114
|
+
interface Product {
|
|
115
|
+
id: string
|
|
116
|
+
title: string
|
|
117
|
+
price: number
|
|
118
|
+
inStock: boolean
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// Create a typed API instance
|
|
122
|
+
const productApi = createTypedApi<Product>()({
|
|
123
|
+
prefixUrl: 'http://localhost:8108',
|
|
124
|
+
token: 'your-api-key',
|
|
125
|
+
collectionName: 'products'
|
|
126
|
+
})
|
|
127
|
+
|
|
128
|
+
// All document operations are now type-safe
|
|
129
|
+
await productApi.documents.insert({
|
|
130
|
+
id: '1',
|
|
131
|
+
title: 'Widget',
|
|
132
|
+
price: 99.99,
|
|
133
|
+
inStock: true
|
|
134
|
+
}) // ✅ Typed
|
|
135
|
+
|
|
136
|
+
// TypeScript will catch errors at compile time
|
|
137
|
+
// await productApi.documents.insert({ id: '2', title: 'Gadget' })
|
|
138
|
+
// ❌ Error: missing 'price' and 'inStock'
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
### Direct Generic Usage
|
|
142
|
+
|
|
143
|
+
```typescript
|
|
144
|
+
const api = new TypesenseApi<Product>({
|
|
145
|
+
prefixUrl: 'http://localhost:8108',
|
|
146
|
+
token: 'your-api-key',
|
|
147
|
+
collectionName: 'products'
|
|
148
|
+
})
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
## Multi-tenancy
|
|
152
|
+
|
|
153
|
+
The TypesenseApi provides built-in multi-tenancy support through collection-level isolation:
|
|
154
|
+
|
|
155
|
+
### Basic Tenant Setup
|
|
156
|
+
|
|
157
|
+
```typescript
|
|
158
|
+
// Create API instance with tenant ID
|
|
159
|
+
const api = new TypesenseApi({
|
|
160
|
+
prefixUrl: 'http://localhost:8108',
|
|
161
|
+
token: 'your-api-key',
|
|
162
|
+
tenantId: 'acme', // Tenant ID
|
|
163
|
+
collectionName: 'products'
|
|
164
|
+
})
|
|
165
|
+
|
|
166
|
+
// All operations use tenant-prefixed collections automatically
|
|
167
|
+
// Collection name becomes: 'acme__products'
|
|
168
|
+
await api.documents.insert({ id: '1', name: 'Product' })
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
### Type-Safe Tenant APIs
|
|
172
|
+
|
|
173
|
+
```typescript
|
|
174
|
+
import { forTenant } from '@goatlab/typesense'
|
|
175
|
+
|
|
176
|
+
interface Customer {
|
|
177
|
+
id: string
|
|
178
|
+
name: string
|
|
179
|
+
email: string
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
// Create tenant-specific APIs with compile-time safety
|
|
183
|
+
const tenant1Api = forTenant<Customer, 'tenant1'>('tenant1', {
|
|
184
|
+
prefixUrl: 'http://localhost:8108',
|
|
185
|
+
token: 'your-api-key',
|
|
186
|
+
collectionName: 'customers'
|
|
187
|
+
})
|
|
188
|
+
|
|
189
|
+
// Tenant ID is preserved in the type
|
|
190
|
+
const tenantId: 'tenant1' = tenant1Api.tenantId // ✅ Type-safe
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
### Tenant Admin Operations
|
|
194
|
+
|
|
195
|
+
```typescript
|
|
196
|
+
// List all collections for a tenant
|
|
197
|
+
const collections = await api.listTenantCollections()
|
|
198
|
+
// Returns: ['acme__products', 'acme__users', ...]
|
|
199
|
+
|
|
200
|
+
// Get base collection names (without prefix)
|
|
201
|
+
const baseNames = await api.listTenantBaseCollectionNames()
|
|
202
|
+
// Returns: ['products', 'users', ...]
|
|
203
|
+
|
|
204
|
+
// Check if a collection exists
|
|
205
|
+
const exists = await api.tenantCollectionExists('products')
|
|
206
|
+
|
|
207
|
+
// Delete all tenant collections (use with caution!)
|
|
208
|
+
await api.deleteAllTenantCollections()
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
### Collection Naming Convention
|
|
212
|
+
|
|
213
|
+
Tenant collections follow the pattern: `<tenantId>__<baseCollectionName>`
|
|
214
|
+
|
|
215
|
+
- Tenant IDs are automatically sanitized (lowercase, alphanumeric + hyphens/underscores)
|
|
216
|
+
- Maximum tenant ID length: 128 characters
|
|
217
|
+
- Examples: `acme__products`, `tenant-123__users`
|
|
218
|
+
|
|
219
|
+
## Schema-based Type Safety
|
|
220
|
+
|
|
221
|
+
The TypesenseApi provides compile-time type safety for your collections using TypeScript's advanced type system:
|
|
222
|
+
|
|
223
|
+
### Define Collections with Type Inference
|
|
224
|
+
|
|
225
|
+
```typescript
|
|
226
|
+
import { TypesenseApi } from '@goatlab/typesense'
|
|
227
|
+
|
|
228
|
+
// Define your collection schema with proper const assertions
|
|
229
|
+
const ProductCollection = TypesenseApi.defineCollection({
|
|
230
|
+
name: 'products',
|
|
231
|
+
fields: [
|
|
232
|
+
{ name: 'id', type: 'string' as const },
|
|
233
|
+
{ name: 'title', type: 'string' as const },
|
|
234
|
+
{ name: 'description', type: 'string' as const, optional: true },
|
|
235
|
+
{ name: 'price', type: 'float' as const },
|
|
236
|
+
{ name: 'inStock', type: 'bool' as const },
|
|
237
|
+
{ name: 'tags', type: 'string[]' as const, optional: true },
|
|
238
|
+
{ name: 'rating', type: 'int32' as const, optional: true }
|
|
239
|
+
] as const
|
|
240
|
+
} as const)
|
|
241
|
+
|
|
242
|
+
// Create a strongly-typed API instance
|
|
243
|
+
const api = TypesenseApi.createSchemaTypedApi(ProductCollection)({
|
|
244
|
+
prefixUrl: 'http://localhost:8108',
|
|
245
|
+
token: 'your-api-key'
|
|
246
|
+
})
|
|
247
|
+
|
|
248
|
+
// All operations are now fully typed with autocomplete
|
|
249
|
+
await api.documents.insert({
|
|
250
|
+
id: 'prod-001',
|
|
251
|
+
title: 'Laptop', // ✅ Required, must be string
|
|
252
|
+
price: 999.99, // ✅ Required, must be number
|
|
253
|
+
inStock: true, // ✅ Required, must be boolean
|
|
254
|
+
description: 'Gaming laptop', // ✅ Optional, can be omitted
|
|
255
|
+
tags: ['gaming', 'laptop'] // ✅ Optional, must be string[]
|
|
256
|
+
})
|
|
257
|
+
|
|
258
|
+
// TypeScript will catch these errors at compile time:
|
|
259
|
+
// ❌ Missing required field
|
|
260
|
+
// await api.documents.insert({
|
|
261
|
+
// id: 'prod-002',
|
|
262
|
+
// price: 99.99,
|
|
263
|
+
// inStock: true
|
|
264
|
+
// // Error: Property 'title' is missing
|
|
265
|
+
// })
|
|
266
|
+
|
|
267
|
+
// ❌ Wrong type
|
|
268
|
+
// await api.documents.insert({
|
|
269
|
+
// id: 'prod-003',
|
|
270
|
+
// title: 'Product',
|
|
271
|
+
// price: '99.99', // Error: Type 'string' is not assignable to type 'number'
|
|
272
|
+
// inStock: true
|
|
273
|
+
// })
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
### One-Step API Creation
|
|
277
|
+
|
|
278
|
+
For simpler cases, you can define and create the API in one step:
|
|
279
|
+
|
|
280
|
+
```typescript
|
|
281
|
+
const api = TypesenseApi.createFromSchema({
|
|
282
|
+
name: 'products',
|
|
283
|
+
fields: [
|
|
284
|
+
{ name: 'id', type: 'string' as const },
|
|
285
|
+
{ name: 'title', type: 'string' as const },
|
|
286
|
+
{ name: 'price', type: 'float' as const },
|
|
287
|
+
{ name: 'inStock', type: 'bool' as const }
|
|
288
|
+
] as const
|
|
289
|
+
} as const)({
|
|
290
|
+
prefixUrl: 'http://localhost:8108',
|
|
291
|
+
token: 'your-api-key'
|
|
292
|
+
})
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
### Complex Field Types
|
|
296
|
+
|
|
297
|
+
The type inference supports all Typesense field types:
|
|
298
|
+
|
|
299
|
+
```typescript
|
|
300
|
+
const EventCollection = TypesenseApi.defineCollection({
|
|
301
|
+
name: 'events',
|
|
302
|
+
fields: [
|
|
303
|
+
{ name: 'id', type: 'string' as const },
|
|
304
|
+
{ name: 'name', type: 'string' as const },
|
|
305
|
+
{ name: 'timestamp', type: 'int64' as const },
|
|
306
|
+
{ name: 'location', type: 'geopoint' as const }, // [lat, lon] tuple
|
|
307
|
+
{ name: 'attendees', type: 'int32[]' as const, optional: true },
|
|
308
|
+
{ name: 'metadata', type: 'object' as const, optional: true },
|
|
309
|
+
{ name: 'tags', type: 'auto' as const, optional: true } // string | string[]
|
|
310
|
+
] as const
|
|
311
|
+
} as const)
|
|
312
|
+
|
|
313
|
+
const api = TypesenseApi.createSchemaTypedApi(EventCollection)({
|
|
314
|
+
prefixUrl: 'http://localhost:8108',
|
|
315
|
+
token: 'your-api-key'
|
|
316
|
+
})
|
|
317
|
+
|
|
318
|
+
// Properly typed document
|
|
319
|
+
await api.documents.insert({
|
|
320
|
+
id: 'evt-001',
|
|
321
|
+
name: 'Tech Conference',
|
|
322
|
+
timestamp: Date.now(),
|
|
323
|
+
location: [37.7749, -122.4194], // Geopoint as [lat, lon]
|
|
324
|
+
attendees: [100, 200, 300], // Optional int32 array
|
|
325
|
+
metadata: { venue: 'Moscone Center' } // Optional object
|
|
326
|
+
})
|
|
327
|
+
```
|
|
328
|
+
|
|
329
|
+
### Key Features
|
|
330
|
+
|
|
331
|
+
- **Compile-time type checking** - No runtime overhead
|
|
332
|
+
- **Full autocomplete support** - Your IDE knows all field names and types
|
|
333
|
+
- **Optional field handling** - Correctly distinguishes between required and optional fields
|
|
334
|
+
- **All Typesense types supported** - Including arrays, objects, geopoints, and auto fields
|
|
335
|
+
- **Zero runtime validation** - Pure TypeScript type inference
|
|
336
|
+
|
|
337
|
+
### Alternative Import Methods
|
|
338
|
+
|
|
339
|
+
The utility functions are also available as direct imports:
|
|
340
|
+
|
|
341
|
+
```typescript
|
|
342
|
+
import { defineCollection, createSchemaTypedApi } from '@goatlab/typesense'
|
|
343
|
+
|
|
344
|
+
const collection = defineCollection({...})
|
|
345
|
+
const api = createSchemaTypedApi(collection)({...})
|
|
346
|
+
```
|
|
347
|
+
|
|
348
|
+
### Type Mapping Reference
|
|
349
|
+
|
|
350
|
+
| Typesense Type | TypeScript Type |
|
|
351
|
+
|----------------|----------------|
|
|
352
|
+
| `string` | `string` |
|
|
353
|
+
| `string[]` | `string[]` |
|
|
354
|
+
| `int32`, `int64` | `number` |
|
|
355
|
+
| `int32[]`, `int64[]` | `number[]` |
|
|
356
|
+
| `float` | `number` |
|
|
357
|
+
| `float[]` | `number[]` |
|
|
358
|
+
| `bool` | `boolean` |
|
|
359
|
+
| `bool[]` | `boolean[]` |
|
|
360
|
+
| `geopoint` | `[number, number]` |
|
|
361
|
+
| `geopoint[]` | `[number, number][]` |
|
|
362
|
+
| `object` | `Record<string, any>` |
|
|
363
|
+
| `object[]` | `Record<string, any>[]` |
|
|
364
|
+
| `auto` | `string \| string[]` |
|
|
365
|
+
|
|
366
|
+
**Note**: The `id` field is excluded from the document type for `insert()` operations, as it's handled separately by the TypesenseApi with `WithRequiredId<T>` type.
|
|
367
|
+
|
|
104
368
|
## Advanced Configuration
|
|
105
369
|
|
|
106
370
|
```typescript
|
package/dist/TypesenseApi.d.ts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
|
+
import type { TypesenseRateLimitInfo, WithRequiredId, TypesenseDocument, TypesenseCollectionOptions, TypesenseCollection } from './typesense.model';
|
|
2
|
+
import { defineCollection as defineCollectionUtil, type InferFromCollection } from './utils/schema-to-types';
|
|
3
|
+
import { createSchemaTypedApi as createSchemaTypedApiUtil } from './utils/schema-typed-api';
|
|
1
4
|
import { TypesenseHttpClient, type HttpClientOptions } from './components/http-client';
|
|
2
5
|
import { ResiliencePolicy, type ResiliencePolicyOptions } from './components/resilience-policy';
|
|
3
6
|
import { CollectionSchemaManager } from './components/schema-manager';
|
|
4
|
-
interface TypesenseApiOptions extends Omit<HttpClientOptions, 'prefixUrl' | 'token'> {
|
|
7
|
+
export interface TypesenseApiOptions extends Omit<HttpClientOptions, 'prefixUrl' | 'token'> {
|
|
5
8
|
prefixUrl: string;
|
|
6
9
|
token: string;
|
|
7
10
|
tenantId?: string;
|
|
@@ -15,6 +18,8 @@ interface TypesenseApiOptions extends Omit<HttpClientOptions, 'prefixUrl' | 'tok
|
|
|
15
18
|
schemaCacheTtl?: number;
|
|
16
19
|
resilience?: ResiliencePolicyOptions;
|
|
17
20
|
typesenseVersion?: string;
|
|
21
|
+
onCircuitBreakerStateChange?: (state: 'open' | 'closed' | 'half-open', metadata?: any) => void;
|
|
22
|
+
onRateLimitUpdate?: (info: TypesenseRateLimitInfo) => void;
|
|
18
23
|
}
|
|
19
24
|
/**
|
|
20
25
|
* Modern, modular Typesense API client with grouped functionality
|
|
@@ -40,53 +45,130 @@ interface TypesenseApiOptions extends Omit<HttpClientOptions, 'prefixUrl' | 'tok
|
|
|
40
45
|
* await api.admin.getMetrics()
|
|
41
46
|
* ```
|
|
42
47
|
*/
|
|
43
|
-
|
|
48
|
+
/**
|
|
49
|
+
* Factory helper for creating typed TypesenseApi instances
|
|
50
|
+
* @example
|
|
51
|
+
* ```typescript
|
|
52
|
+
* interface Product { id: string; title: string; price: number; }
|
|
53
|
+
* const productApi = createTypedApi<Product>()({
|
|
54
|
+
* prefixUrl: 'http://localhost:8108',
|
|
55
|
+
* token: 'xyz',
|
|
56
|
+
* collectionName: 'products'
|
|
57
|
+
* })
|
|
58
|
+
*
|
|
59
|
+
* // Now all document operations are typed
|
|
60
|
+
* await productApi.documents.insert({ id: "1", title: "Foo", price: 42 }) // ✅ typed
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
export declare const createTypedApi: <TDoc extends Record<string, any>>() => (options: TypesenseApiOptions) => TypesenseApi<TDoc>;
|
|
64
|
+
/**
|
|
65
|
+
* Type-safe multitenant API wrapper
|
|
66
|
+
*/
|
|
67
|
+
export type TenantApi<TDoc, TenantId extends string> = TypesenseApi<TDoc> & {
|
|
68
|
+
readonly tenantId: TenantId;
|
|
69
|
+
};
|
|
70
|
+
export declare class TypesenseApi<TDoc extends Record<string, any> = Record<string, any>> {
|
|
44
71
|
private readonly ctx;
|
|
45
72
|
private withCtx;
|
|
46
73
|
private readonly options;
|
|
47
74
|
readonly httpClient: TypesenseHttpClient;
|
|
48
75
|
readonly resilience: ResiliencePolicy;
|
|
49
76
|
readonly schemaManager: CollectionSchemaManager;
|
|
77
|
+
/**
|
|
78
|
+
* Define a strongly-typed collection schema
|
|
79
|
+
* @example
|
|
80
|
+
* ```typescript
|
|
81
|
+
* const ProductCollection = TypesenseApi.defineCollection({
|
|
82
|
+
* name: 'products',
|
|
83
|
+
* fields: [
|
|
84
|
+
* { name: 'id', type: 'string' as const },
|
|
85
|
+
* { name: 'title', type: 'string' as const },
|
|
86
|
+
* { name: 'price', type: 'float' as const },
|
|
87
|
+
* { name: 'inStock', type: 'bool' as const }
|
|
88
|
+
* ] as const
|
|
89
|
+
* } as const)
|
|
90
|
+
* ```
|
|
91
|
+
*/
|
|
92
|
+
static defineCollection: typeof defineCollectionUtil;
|
|
93
|
+
/**
|
|
94
|
+
* Create a strongly-typed API instance from a collection schema
|
|
95
|
+
* @example
|
|
96
|
+
* ```typescript
|
|
97
|
+
* const ProductCollection = TypesenseApi.defineCollection({...})
|
|
98
|
+
*
|
|
99
|
+
* const api = TypesenseApi.createSchemaTypedApi(ProductCollection)({
|
|
100
|
+
* prefixUrl: 'http://localhost:8108',
|
|
101
|
+
* token: 'xyz'
|
|
102
|
+
* })
|
|
103
|
+
*
|
|
104
|
+
* // Now all document operations are fully typed
|
|
105
|
+
* await api.documents.insert({
|
|
106
|
+
* id: '1',
|
|
107
|
+
* title: 'Product',
|
|
108
|
+
* price: 99.99,
|
|
109
|
+
* inStock: true
|
|
110
|
+
* })
|
|
111
|
+
* ```
|
|
112
|
+
*/
|
|
113
|
+
static createSchemaTypedApi: typeof createSchemaTypedApiUtil;
|
|
114
|
+
/**
|
|
115
|
+
* Create a typed API from an inline collection definition (convenience method)
|
|
116
|
+
* @example
|
|
117
|
+
* ```typescript
|
|
118
|
+
* const api = TypesenseApi.createFromSchema({
|
|
119
|
+
* name: 'products',
|
|
120
|
+
* fields: [
|
|
121
|
+
* { name: 'id', type: 'string' as const },
|
|
122
|
+
* { name: 'title', type: 'string' as const },
|
|
123
|
+
* { name: 'price', type: 'float' as const }
|
|
124
|
+
* ] as const
|
|
125
|
+
* } as const)({
|
|
126
|
+
* prefixUrl: 'http://localhost:8108',
|
|
127
|
+
* token: 'xyz'
|
|
128
|
+
* })
|
|
129
|
+
* ```
|
|
130
|
+
*/
|
|
131
|
+
static createFromSchema<const C extends TypesenseCollection>(collection: C): (options: Omit<TypesenseApiOptions, "collectionName">) => TypesenseApi<InferFromCollection<C>>;
|
|
50
132
|
constructor(options: TypesenseApiOptions);
|
|
51
133
|
private checkVersion;
|
|
52
134
|
/**
|
|
53
135
|
* Collection management operations
|
|
54
136
|
*/
|
|
55
137
|
get collections(): {
|
|
56
|
-
create: (collection:
|
|
138
|
+
create: (collection: TypesenseCollection) => any;
|
|
57
139
|
get: (collectionName?: string) => any;
|
|
58
|
-
update: (collection: Partial<
|
|
140
|
+
update: (collection: Partial<TypesenseCollection>, options?: TypesenseCollectionOptions) => any;
|
|
59
141
|
delete: (collectionName?: string) => any;
|
|
60
142
|
list: () => any;
|
|
61
|
-
getOrCreate: (collection:
|
|
143
|
+
getOrCreate: (collection: TypesenseCollection) => any;
|
|
62
144
|
};
|
|
63
145
|
/**
|
|
64
146
|
* Document CRUD operations
|
|
65
147
|
*/
|
|
66
148
|
get documents(): {
|
|
67
|
-
insert: (document:
|
|
68
|
-
upsert: (document:
|
|
69
|
-
update: (document: Partial<
|
|
149
|
+
insert: (document: WithRequiredId<TDoc>, options?: TypesenseCollectionOptions) => Promise<TypesenseDocument<TDoc>>;
|
|
150
|
+
upsert: (document: WithRequiredId<TDoc>, options?: TypesenseCollectionOptions) => Promise<TypesenseDocument<TDoc>>;
|
|
151
|
+
update: (document: Partial<TypesenseDocument<TDoc>> & {
|
|
70
152
|
id: string | number;
|
|
71
|
-
}, options?:
|
|
72
|
-
delete: (id: string | number, options?:
|
|
73
|
-
getById: (id: string | number, options?:
|
|
74
|
-
import: (documents: string | import("stream").Readable |
|
|
75
|
-
export: (format?: import("./typesense.model").TypesenseExportFormat, options?: import("./typesense.model").TypesenseExportOptions &
|
|
76
|
-
exportStream: (options?: import("./typesense.model").TypesenseExportOptions &
|
|
77
|
-
deleteByFilter: (filter: string, options?: import("./typesense.model").TypesenseDeleteByFilterOptions &
|
|
78
|
-
clear: (options?:
|
|
79
|
-
search: (query: import("./typesense.model").TypesenseQuery, options?:
|
|
80
|
-
searchText: (query: import("./typesense.model").TypesenseTextQuery, options?:
|
|
81
|
-
searchVector: (query: import("./typesense.model").TypesenseVectorQuery, options?:
|
|
153
|
+
}, options?: TypesenseCollectionOptions) => Promise<TypesenseDocument<TDoc>>;
|
|
154
|
+
delete: (id: string | number, options?: TypesenseCollectionOptions) => any;
|
|
155
|
+
getById: (id: string | number, options?: TypesenseCollectionOptions) => any;
|
|
156
|
+
import: (documents: string | import("stream").Readable | TypesenseDocument<Record<string, any>>[], format?: import("./typesense.model").TypesenseImportFormat, importOptions?: import("./typesense.model").TypesenseImportOptions, collectionOptions?: TypesenseCollectionOptions) => any;
|
|
157
|
+
export: (format?: import("./typesense.model").TypesenseExportFormat, options?: import("./typesense.model").TypesenseExportOptions & TypesenseCollectionOptions) => any;
|
|
158
|
+
exportStream: (options?: import("./typesense.model").TypesenseExportOptions & TypesenseCollectionOptions) => any;
|
|
159
|
+
deleteByFilter: (filter: string, options?: import("./typesense.model").TypesenseDeleteByFilterOptions & TypesenseCollectionOptions) => any;
|
|
160
|
+
clear: (options?: TypesenseCollectionOptions) => any;
|
|
161
|
+
search: (query: import("./typesense.model").TypesenseQuery, options?: TypesenseCollectionOptions) => any;
|
|
162
|
+
searchText: (query: import("./typesense.model").TypesenseTextQuery, options?: TypesenseCollectionOptions) => any;
|
|
163
|
+
searchVector: (query: import("./typesense.model").TypesenseVectorQuery, options?: TypesenseCollectionOptions) => any;
|
|
82
164
|
};
|
|
83
165
|
/**
|
|
84
166
|
* Search operations (alias for documents.search*)
|
|
85
167
|
*/
|
|
86
168
|
get search(): {
|
|
87
|
-
query: (query: import("./typesense.model").TypesenseQuery, options?:
|
|
88
|
-
text: (query: import("./typesense.model").TypesenseTextQuery, options?:
|
|
89
|
-
vector: (query: import("./typesense.model").TypesenseVectorQuery, options?:
|
|
169
|
+
query: (query: import("./typesense.model").TypesenseQuery, options?: TypesenseCollectionOptions) => any;
|
|
170
|
+
text: (query: import("./typesense.model").TypesenseTextQuery, options?: TypesenseCollectionOptions) => any;
|
|
171
|
+
vector: (query: import("./typesense.model").TypesenseVectorQuery, options?: TypesenseCollectionOptions) => any;
|
|
90
172
|
multi: (request: import("./typesense.model").TypesenseMultiSearchRequest) => any;
|
|
91
173
|
};
|
|
92
174
|
/**
|
|
@@ -112,19 +194,19 @@ export declare class TypesenseApi<T extends Record<string, any> = Record<string,
|
|
|
112
194
|
* Synonym management (v29+)
|
|
113
195
|
*/
|
|
114
196
|
get synonyms(): {
|
|
115
|
-
upsert: (synonym: import("./typesense.model").TypesenseSynonym, options?:
|
|
116
|
-
get: (synonymId: string, options?:
|
|
117
|
-
list: (options?:
|
|
118
|
-
delete: (synonymId: string, options?:
|
|
197
|
+
upsert: (synonym: import("./typesense.model").TypesenseSynonym, options?: TypesenseCollectionOptions) => any;
|
|
198
|
+
get: (synonymId: string, options?: TypesenseCollectionOptions) => any;
|
|
199
|
+
list: (options?: TypesenseCollectionOptions) => any;
|
|
200
|
+
delete: (synonymId: string, options?: TypesenseCollectionOptions) => any;
|
|
119
201
|
};
|
|
120
202
|
/**
|
|
121
203
|
* Search override management (v29+)
|
|
122
204
|
*/
|
|
123
205
|
get overrides(): {
|
|
124
|
-
upsert: (override: import("./typesense.model").TypesenseOverride, options?:
|
|
125
|
-
get: (overrideId: string, options?:
|
|
126
|
-
list: (options?:
|
|
127
|
-
delete: (overrideId: string, options?:
|
|
206
|
+
upsert: (override: import("./typesense.model").TypesenseOverride, options?: TypesenseCollectionOptions) => any;
|
|
207
|
+
get: (overrideId: string, options?: TypesenseCollectionOptions) => any;
|
|
208
|
+
list: (options?: TypesenseCollectionOptions) => any;
|
|
209
|
+
delete: (overrideId: string, options?: TypesenseCollectionOptions) => any;
|
|
128
210
|
};
|
|
129
211
|
/**
|
|
130
212
|
* Preset management (v29+)
|
|
@@ -144,12 +226,12 @@ export declare class TypesenseApi<T extends Record<string, any> = Record<string,
|
|
|
144
226
|
circuitOpenUntil: number;
|
|
145
227
|
rateLimited: boolean;
|
|
146
228
|
retryAfterUntil: number;
|
|
147
|
-
rateLimit:
|
|
229
|
+
rateLimit: TypesenseRateLimitInfo | null;
|
|
148
230
|
};
|
|
149
231
|
/**
|
|
150
232
|
* Get current rate limit info
|
|
151
233
|
*/
|
|
152
|
-
getRateLimit():
|
|
234
|
+
getRateLimit(): TypesenseRateLimitInfo;
|
|
153
235
|
/**
|
|
154
236
|
* Get cache statistics
|
|
155
237
|
*/
|
|
@@ -189,41 +271,3 @@ export declare class TypesenseApi<T extends Record<string, any> = Record<string,
|
|
|
189
271
|
*/
|
|
190
272
|
destroy(): void;
|
|
191
273
|
}
|
|
192
|
-
export * from './actions/collections/createCollection';
|
|
193
|
-
export * from './actions/collections/getCollection';
|
|
194
|
-
export * from './actions/collections/updateCollection';
|
|
195
|
-
export * from './actions/collections/deleteCollection';
|
|
196
|
-
export * from './actions/collections/listCollections';
|
|
197
|
-
export * from './actions/collections/getOrCreateCollection';
|
|
198
|
-
export * from './actions/documents/insertDocument';
|
|
199
|
-
export * from './actions/documents/upsertDocument';
|
|
200
|
-
export * from './actions/documents/updateDocument';
|
|
201
|
-
export * from './actions/documents/deleteDocument';
|
|
202
|
-
export * from './actions/documents/getDocumentById';
|
|
203
|
-
export * from './actions/documents/importDocuments';
|
|
204
|
-
export * from './actions/documents/exportDocuments';
|
|
205
|
-
export * from './actions/documents/deleteByFilter';
|
|
206
|
-
export * from './actions/documents/clearCollection';
|
|
207
|
-
export * from './actions/search/search';
|
|
208
|
-
export * from './actions/search/multiSearch';
|
|
209
|
-
export * from './actions/admin/health';
|
|
210
|
-
export * from './actions/admin/metrics';
|
|
211
|
-
export * from './actions/admin/getCollectionStats';
|
|
212
|
-
export * from './actions/aliases/createOrUpdateAlias';
|
|
213
|
-
export * from './actions/aliases/getAlias';
|
|
214
|
-
export * from './actions/aliases/listAliases';
|
|
215
|
-
export * from './actions/aliases/deleteAlias';
|
|
216
|
-
export * from './actions/synonyms/upsertSynonym';
|
|
217
|
-
export * from './actions/synonyms/getSynonym';
|
|
218
|
-
export * from './actions/synonyms/listSynonyms';
|
|
219
|
-
export * from './actions/synonyms/deleteSynonym';
|
|
220
|
-
export * from './actions/overrides/upsertOverride';
|
|
221
|
-
export * from './actions/overrides/getOverride';
|
|
222
|
-
export * from './actions/overrides/listOverrides';
|
|
223
|
-
export * from './actions/overrides/deleteOverride';
|
|
224
|
-
export * from './actions/presets/upsertPreset';
|
|
225
|
-
export * from './actions/presets/getPreset';
|
|
226
|
-
export * from './actions/presets/listPresets';
|
|
227
|
-
export * from './actions/presets/deletePreset';
|
|
228
|
-
export * from './utils/tenant';
|
|
229
|
-
export type { TypesenseCollectionOutput } from './typesense.model';
|