redis-om-type 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,1398 @@
1
+ import { createClient, createCluster, RediSearchSchema, SearchOptions } from 'redis';
2
+
3
+ /** The Symbol used to access the entity ID of an {@link Entity}. */
4
+ declare const EntityId: unique symbol;
5
+ /** The Symbol used to access the keyname of an {@link Entity}. */
6
+ declare const EntityKeyName: unique symbol;
7
+ type EntityInternal = {
8
+ /** The unique ID of the {@link Entity}. Access using the {@link EntityId} Symbol. */
9
+ [EntityId]?: string;
10
+ /** The key the {@link Entity} is stored under inside of Redis. Access using the {@link EntityKeyName} Symbol. */
11
+ [EntityKeyName]?: string;
12
+ };
13
+ /** Defines the objects returned from calls to {@link Repository | repositories }. */
14
+ type Entity = EntityData & EntityInternal;
15
+ type EntityKeys<T extends Entity> = Exclude<keyof T, keyof EntityInternal>;
16
+ /** The free-form data associated with an {@link Entity}. */
17
+ type EntityData = {
18
+ [key: string]: EntityDataValue | EntityData | Array<EntityDataValue | EntityData>;
19
+ };
20
+ /** Valid types for values in an {@link Entity}. */
21
+ type EntityDataValue = string | number | boolean | Date | Point | null | undefined | Array<EntityDataValue | EntityData>;
22
+ /** Defines a point on the globe using longitude and latitude. */
23
+ type Point = {
24
+ /** The longitude of the point. */
25
+ longitude: number;
26
+ /** The latitude of the point. */
27
+ latitude: number;
28
+ };
29
+
30
+ /** Valid field types for a {@link FieldDefinition}. */
31
+ type FieldType = 'boolean' | 'date' | 'number' | 'number[]' | 'point' | 'string' | 'string[]' | 'text';
32
+ /** All configuration properties that any field might have, regardless of type. */
33
+ type AllFieldDefinition = {
34
+ /** The type of the field (i.e. string, number, boolean, etc.) */
35
+ type: FieldType;
36
+ /**
37
+ * The default field name in Redis is the property name defined in the
38
+ * {@link SchemaDefinition}. Overrides the field name for a Hash to this
39
+ * value or in the case of JSON documents, sets the JSONPath to this
40
+ * value preceded by `$.`. Overridden by {@link field} and/or {@link path}
41
+ * settings.
42
+ * @deprecated
43
+ */
44
+ alias?: string;
45
+ /**
46
+ * Is this field indexed and thus searchable with Redis OM. Defaults
47
+ * to true.
48
+ */
49
+ indexed?: boolean;
50
+ /**
51
+ * The field name used to store this in a Redis Hash. Defaults to the
52
+ * name used in the {@link SchemaDefinition} or the {@link alias}
53
+ * property.
54
+ */
55
+ field?: string;
56
+ /**
57
+ * The JSONPath expression this field references. Used only by search
58
+ * and only for JSON documents. Defaults to the name used in the
59
+ * {@link SchemaDefinition} or the {@link alias} property prefixed
60
+ * with `$.` .
61
+ */
62
+ path?: string;
63
+ /** Enables sorting by this field. */
64
+ sortable?: boolean;
65
+ /** Is the original case of this field indexed with Redis OM. Defaults to false. */
66
+ caseSensitive?: boolean;
67
+ /** Is this (sortable) field normalized when indexed. Defaults to true. */
68
+ normalized?: boolean;
69
+ /**
70
+ * Due to how RediSearch works, strings and arrays are sometimes stored the same in Redis, as a
71
+ * simple string. This is the separator used to split those strings when it is an array. If your
72
+ * StringField contains this separator, this can cause problems. You can change it here to avoid
73
+ * those problems. Defaults to `|`.
74
+ */
75
+ separator?: string;
76
+ /**
77
+ * Enables setting the phonetic matcher to use, supported matchers are:
78
+ * dm:en - Double Metaphone for English
79
+ * dm:fr - Double Metaphone for French
80
+ * dm:pt - Double Metaphone for Portuguese
81
+ * dm:es - Double Metaphone for Spanish
82
+ */
83
+ matcher?: 'dm:en' | 'dm:fr' | 'dm:pt' | 'dm:es';
84
+ /** Is word stemming applied to this field with Redis OM. Defaults to true. */
85
+ stemming?: boolean;
86
+ /** Enables setting the weight to apply to a text field */
87
+ weight?: number;
88
+ };
89
+ /** The configuration properties that all fields have in common. */
90
+ type CommonFieldDefinition = Pick<AllFieldDefinition, "type" | "alias" | "indexed" | "field" | "path">;
91
+ /** A field representing a boolean. */
92
+ type BooleanFieldDefinition = {
93
+ type: 'boolean';
94
+ } & CommonFieldDefinition & Pick<AllFieldDefinition, "sortable">;
95
+ /** A field representing a date/time. */
96
+ type DateFieldDefinition = {
97
+ type: 'date';
98
+ } & CommonFieldDefinition & Pick<AllFieldDefinition, "sortable">;
99
+ /** A field representing a number. */
100
+ type NumberFieldDefinition = {
101
+ type: 'number';
102
+ } & CommonFieldDefinition & Pick<AllFieldDefinition, "sortable">;
103
+ /** A field representing an array of numbers. */
104
+ type NumberArrayFieldDefinition = {
105
+ type: 'number[]';
106
+ } & CommonFieldDefinition & Pick<AllFieldDefinition, "sortable">;
107
+ /** A field representing a point on the globe. */
108
+ type PointFieldDefinition = {
109
+ type: 'point';
110
+ } & CommonFieldDefinition;
111
+ /** A field representing a whole string. */
112
+ type StringFieldDefinition = {
113
+ type: 'string';
114
+ } & CommonFieldDefinition & Pick<AllFieldDefinition, "sortable" | "caseSensitive" | "normalized" | "separator">;
115
+ /** A field representing an array of strings. */
116
+ type StringArrayFieldDefinition = {
117
+ type: 'string[]';
118
+ } & CommonFieldDefinition & Pick<AllFieldDefinition, "sortable" | "caseSensitive" | "normalized" | "separator">;
119
+ /** A field representing searchable text. */
120
+ type TextFieldDefinition = {
121
+ type: 'text';
122
+ } & CommonFieldDefinition & Pick<AllFieldDefinition, "sortable" | "normalized" | "matcher" | "stemming" | "weight">;
123
+ /** Contains instructions telling how to map a property on an {@link Entity} to Redis. */
124
+ type FieldDefinition = BooleanFieldDefinition | DateFieldDefinition | NumberFieldDefinition | NumberArrayFieldDefinition | PointFieldDefinition | StringFieldDefinition | StringArrayFieldDefinition | TextFieldDefinition;
125
+ /** Group of {@link FieldDefinition}s that define the schema for an {@link Entity}. */
126
+ type SchemaDefinition<T extends Entity = Record<string, any>> = Record<EntityKeys<T>, FieldDefinition>;
127
+
128
+ /**
129
+ * Describes a field in a {@link Schema}.
130
+ */
131
+ declare class Field {
132
+ #private;
133
+ /**
134
+ * Creates a Field.
135
+ *
136
+ * @param name The name of the Field.
137
+ * @param definition The underlying {@link FieldDefinition}.
138
+ */
139
+ constructor(name: string, definition: FieldDefinition);
140
+ /** The name of the field. */
141
+ get name(): string;
142
+ /** The {@link FieldType | type} of the field. */
143
+ get type(): FieldType;
144
+ /** The field name used to store this {@link Field} in a Hash. */
145
+ get hashField(): string;
146
+ /** The JSONPath used to store this {@link Field} in a JSON document. */
147
+ get jsonPath(): string;
148
+ /** The separator for string[] fields when stored in Hashes. */
149
+ get separator(): string;
150
+ /** Indicates that the field as sortable. */
151
+ get sortable(): boolean;
152
+ /** The case-sensitivity of the field. */
153
+ get caseSensitive(): boolean;
154
+ /** Indicates the field as being indexed—and thus queryable—by RediSearch. */
155
+ get indexed(): boolean;
156
+ /** Indicates that the field as indexed with stemming support. */
157
+ get stemming(): boolean;
158
+ /** Indicates that the field is normalized. Ignored if sortable is false. */
159
+ get normalized(): boolean;
160
+ /** The search weight of the field. */
161
+ get weight(): number | null;
162
+ /** The phonetic matcher for the field. */
163
+ get matcher(): string | null;
164
+ /** Is this type an array or not. */
165
+ get isArray(): boolean;
166
+ }
167
+
168
+ /** The type of data structure in Redis to map objects to. */
169
+ type DataStructure = 'HASH' | 'JSON';
170
+ /** A function that generates random entityIds. */
171
+ type IdStrategy = () => Promise<string>;
172
+ /** Valid values for how to use stop words for a given {@link Schema}. */
173
+ type StopWordOptions = 'OFF' | 'DEFAULT' | 'CUSTOM';
174
+ /** Configuration options for a {@link Schema}. */
175
+ type SchemaOptions = {
176
+ /**
177
+ * The name used by RediSearch to store the index for this {@link Schema}. Defaults
178
+ * to prefix followed by `:index`. So, for a prefix of `Foo`, it would use `Foo:index`.
179
+ */
180
+ indexName?: string;
181
+ /**
182
+ * The name used by Redis OM to store the hash of the index for this {@link Schema}.
183
+ * Defaults to prefix followed by `:index:hash`. So, for a prefix of `Foo`, it would
184
+ * use `Foo:index:hash`.
185
+ */
186
+ indexHashName?: string;
187
+ /** The data structure used to store the {@link Entity} in Redis. Can be set
188
+ * to either `JSON` or `HASH`. Defaults to JSON.
189
+ */
190
+ dataStructure?: DataStructure;
191
+ /**
192
+ * A function that generates a random entityId. Defaults to a function that generates
193
+ * [ULIDs](https://github.com/ulid/spec). Combined with prefix to generate a Redis key.
194
+ * If prefix is `Foo` and idStratgey returns `12345` then the generated key would be
195
+ * `Foo:12345`.
196
+ */
197
+ idStrategy?: IdStrategy;
198
+ /**
199
+ * Configures the usage of stop words. Valid values are `OFF`, `DEFAULT`, and `CUSTOM`.
200
+ * Setting this to `OFF` disables all stop words. Setting this to `DEFAULT` uses the
201
+ * stop words intrinsic to RediSearch. Setting this to `CUSTOM` tells RediSearch to
202
+ * use the stop words in `stopWords`.
203
+ */
204
+ useStopWords?: StopWordOptions;
205
+ /**
206
+ * Stop words to be used by this schema. If `useStopWords` is
207
+ * anything other than `CUSTOM`, this option is ignored.
208
+ */
209
+ stopWords?: Array<string>;
210
+ };
211
+
212
+ /**
213
+ * Defines a schema that determines how an {@link Entity} is mapped
214
+ * to Redis data structures. Construct by passing in a schema name,
215
+ * a {@link SchemaDefinition}, and optionally {@link SchemaOptions}:
216
+ *
217
+ * ```typescript
218
+ * interface Foo extends Entity {
219
+ * aString: string,
220
+ * aNumber: number,
221
+ * aBoolean: boolean,
222
+ * someText: string,
223
+ * aPoint: Point,
224
+ * aDate: Date,
225
+ * someStrings: string[],
226
+ * }
227
+ *
228
+ * const schema = new Schema<Foo>('foo', {
229
+ * aString: { type: 'string' },
230
+ * aNumber: { type: 'number' },
231
+ * aBoolean: { type: 'boolean' },
232
+ * someText: { type: 'text' },
233
+ * aPoint: { type: 'point' },
234
+ * aDate: { type: 'date' },
235
+ * someStrings: { type: 'string[]' }
236
+ * }, {
237
+ * dataStructure: 'HASH'
238
+ * })
239
+ * ```
240
+ *
241
+ * A Schema is primarily used by a {@link Repository} which requires a Schema in
242
+ * its constructor.
243
+ */
244
+ declare class Schema<T extends Entity = Record<string, any>> {
245
+ #private;
246
+ /**
247
+ * Constructs a Schema.
248
+ *
249
+ * @param schemaName The name of the schema. Prefixes the ID when creating Redis keys.
250
+ * @param schemaDef Defines all of the fields for the Schema and how they are mapped to Redis.
251
+ * @param options Additional options for this Schema.
252
+ */
253
+ constructor(schemaName: string, schemaDef: SchemaDefinition<T>, options?: SchemaOptions);
254
+ /**
255
+ * The name of the schema. Prefixes the ID when creating Redis keys. Combined
256
+ * with the results of idStrategy to generate a key. If name is `foo` and
257
+ * idStrategy returns `12345` then the generated key would be `foo:12345`.
258
+ */
259
+ get schemaName(): string;
260
+ /** The {@link Field | Fields} defined by this Schema. */
261
+ get fields(): Field[];
262
+ /**
263
+ * Gets a single {@link Field} defined by this Schema.
264
+ *
265
+ * @param name The name of the {@link Field} in this Schema.
266
+ * @returns The {@link Field}, or null of not found.
267
+ */
268
+ fieldByName(name: EntityKeys<T>): Field | null;
269
+ /** The configured name for the RediSearch index for this Schema. */
270
+ get indexName(): string;
271
+ /** The configured name for the RediSearch index hash for this Schema. */
272
+ get indexHashName(): string;
273
+ /**
274
+ * The configured data structure, a string with the value of either `HASH` or `JSON`,
275
+ * that this Schema uses to store {@link Entity | Entities} in Redis.
276
+ */
277
+ get dataStructure(): DataStructure;
278
+ /**
279
+ * The configured usage of stop words, a string with the value of either `OFF`, `DEFAULT`,
280
+ * or `CUSTOM`. See {@link SchemaOptions} for more details.
281
+ */
282
+ get useStopWords(): StopWordOptions;
283
+ /**
284
+ * The configured stop words. Ignored if {@link Schema.useStopWords} is anything other
285
+ * than `CUSTOM`.
286
+ */
287
+ get stopWords(): Array<string>;
288
+ /**
289
+ * Generates a unique string using the configured {@link IdStrategy}.
290
+ *
291
+ * @returns The generated id.
292
+ */
293
+ generateId(): Promise<string>;
294
+ /**
295
+ * A hash for this Schema that is used to determine if the Schema has been
296
+ * changed when calling {@link Repository#createIndex}.
297
+ */
298
+ get indexHash(): string;
299
+ }
300
+ type InferSchema<T> = T extends Schema<infer R> ? R : never;
301
+
302
+ /**
303
+ * Abstract base class used extensively with {@link Search}.
304
+ */
305
+ declare abstract class Where {
306
+ /**
307
+ * Converts this {@link Where} into a portion of a RediSearch query.
308
+ */
309
+ abstract toString(): string;
310
+ }
311
+
312
+ type Units = 'm' | 'km' | 'ft' | 'mi';
313
+ /** A function that defines a circle for `.inCircle` searches. */
314
+ type CircleFunction = (circle: Circle) => Circle;
315
+ /** A builder that defines a circle. */
316
+ declare class Circle {
317
+ /** @internal */
318
+ longitudeOfOrigin: number;
319
+ /** @internal */
320
+ latitudeOfOrigin: number;
321
+ /** @internal */
322
+ size: number;
323
+ /** @internal */
324
+ units: Units;
325
+ /**
326
+ * Sets the longitude. If not set, defaults to 0.0.
327
+ *
328
+ * @param value The longitude.
329
+ * @returns This instance.
330
+ */
331
+ longitude(value: number): this;
332
+ /**
333
+ * Sets the latitude. If not set, defaults to 0.0.
334
+ *
335
+ * @param value The latitude.
336
+ * @returns This instance.
337
+ */
338
+ latitude(value: number): this;
339
+ /**
340
+ * Sets the origin of the circle using a {@link Point}. If not
341
+ * set, defaults to [Null Island](https://en.wikipedia.org/wiki/Null_Island).
342
+ *
343
+ * @param point A {@link Point} containing the longitude and latitude of the origin.
344
+ * @returns This instance.
345
+ */
346
+ origin(point: Point): Circle;
347
+ /**
348
+ * Sets the origin of the circle. If not set, defaults to
349
+ * [Null Island](https://en.wikipedia.org/wiki/Null_Island).
350
+ *
351
+ * @param longitude The longitude.
352
+ * @param latitude The latitude.
353
+ * @returns This instance.
354
+ */
355
+ origin(longitude: number, latitude: number): Circle;
356
+ /**
357
+ * Sets the radius of the {@link Circle}. Defaults to 1. If units are
358
+ * not specified, defaults to meters.
359
+ *
360
+ * @param size The radius of the circle.
361
+ * @returns This instance.
362
+ */
363
+ radius(size: number): this;
364
+ /**
365
+ * Sets the units to meters.
366
+ * @returns This instance.
367
+ */
368
+ get m(): this;
369
+ /**
370
+ * Sets the units to meters.
371
+ * @returns This instance.
372
+ */
373
+ get meter(): this;
374
+ /**
375
+ * Sets the units to meters.
376
+ * @returns This instance.
377
+ */
378
+ get meters(): this;
379
+ /**
380
+ * Sets the units to kilometers.
381
+ * @returns This instance.
382
+ */
383
+ get km(): this;
384
+ /**
385
+ * Sets the units to kilometers.
386
+ * @returns This instance.
387
+ */
388
+ get kilometer(): this;
389
+ /**
390
+ * Sets the units to kilometers.
391
+ * @returns This instance.
392
+ */
393
+ get kilometers(): this;
394
+ /**
395
+ * Sets the units to feet.
396
+ * @returns This instance.
397
+ */
398
+ get ft(): this;
399
+ /**
400
+ * Sets the units to feet.
401
+ * @returns This instance.
402
+ */
403
+ get foot(): this;
404
+ /**
405
+ * Sets the units to feet.
406
+ * @returns This instance.
407
+ */
408
+ get feet(): this;
409
+ /**
410
+ * Sets the units to miles.
411
+ * @returns This instance.
412
+ */
413
+ get mi(): this;
414
+ /**
415
+ * Sets the units to miles.
416
+ * @returns This instance.
417
+ */
418
+ get mile(): this;
419
+ /**
420
+ * Sets the units to miles.
421
+ * @returns This instance.
422
+ */
423
+ get miles(): this;
424
+ }
425
+
426
+ /**
427
+ * Interface with all the methods from all the concrete
428
+ * classes under {@link WhereField}.
429
+ */
430
+ interface WhereField<T extends Entity = Record<string, any>> extends Where {
431
+ /**
432
+ * Adds an equals comparison to the query.
433
+ *
434
+ * NOTE: this function is not available for strings where full-text
435
+ * search is enabled. In that scenario, use `.match`.
436
+ * @param value The value to be compared
437
+ * @returns The {@link Search} that was called to create this {@link WhereField}.
438
+ */
439
+ eq(value: string | number | boolean | Date): Search<T>;
440
+ /**
441
+ * Adds an equals comparison to the query.
442
+ *
443
+ * NOTE: this function is not available for strings where full-text
444
+ * search is enabled. In that scenario, use `.match`.
445
+ * @param value The value to be compared
446
+ * @returns The {@link Search} that was called to create this {@link WhereField}.
447
+ */
448
+ equal(value: string | number | boolean | Date): Search<T>;
449
+ /**
450
+ * Adds an equals comparison to the query.
451
+ *
452
+ * NOTE: this function is not available for strings where full-text
453
+ * search is enabled. In that scenario, use `.match`.
454
+ * @param value The value to be compared
455
+ * @returns The {@link Search} that was called to create this {@link WhereField}.
456
+ */
457
+ equals(value: string | number | boolean | Date): Search<T>;
458
+ /**
459
+ * Adds an equals comparison to the query.
460
+ *
461
+ * NOTE: this function is not available for strings where full-text
462
+ * search is enabled. In that scenario, use `.match`.
463
+ * @param value The value to be compared
464
+ * @returns The {@link Search} that was called to create this {@link WhereField}.
465
+ */
466
+ equalTo(value: string | number | boolean | Date): Search<T>;
467
+ /**
468
+ * Adds a full-text search comparison to the query.
469
+ * @param value The word or phrase sought.
470
+ * @param options
471
+ * @param options.fuzzyMatching Whether to use fuzzy matching to find the sought word or phrase. Defaults to `false`.
472
+ * @param options.levenshteinDistance The levenshtein distance to use for fuzzy matching. Supported values are `1`, `2`, and `3`. Defaults to `1`.
473
+ * @returns The {@link Search} that was called to create this {@link WhereField}.
474
+ */
475
+ match(value: string | number | boolean, options?: {
476
+ fuzzyMatching?: boolean;
477
+ levenshteinDistance?: 1 | 2 | 3;
478
+ }): Search<T>;
479
+ /**
480
+ * Adds a full-text search comparison to the query.
481
+ * @param value The word or phrase sought.
482
+ * @param options
483
+ * @param options.fuzzyMatching Whether to use fuzzy matching to find the sought word or phrase. Defaults to `false`.
484
+ * @param options.levenshteinDistance The levenshtein distance to use for fuzzy matching. Supported values are `1`, `2`, and `3`. Defaults to `1`.
485
+ * @returns The {@link Search} that was called to create this {@link WhereField}.
486
+ */
487
+ matches(value: string | number | boolean, options?: {
488
+ fuzzyMatching?: boolean;
489
+ levenshteinDistance?: 1 | 2 | 3;
490
+ }): Search<T>;
491
+ /**
492
+ * Adds a full-text search comparison to the query that matches an exact word or phrase.
493
+ * @param value The word or phrase sought.
494
+ * @returns The {@link Search} that was called to create this {@link WhereField}.
495
+ */
496
+ matchExact(value: string | number | boolean): Search<T>;
497
+ /**
498
+ * Adds a full-text search comparison to the query that matches an exact word or phrase.
499
+ * @param value The word or phrase sought.
500
+ * @returns The {@link Search} that was called to create this {@link WhereField}.
501
+ */
502
+ matchExactly(value: string | number | boolean): Search<T>;
503
+ /**
504
+ * Adds a full-text search comparison to the query that matches an exact word or phrase.
505
+ * @param value The word or phrase sought.
506
+ * @returns The {@link Search} that was called to create this {@link WhereField}.
507
+ */
508
+ matchesExactly(value: string | number | boolean): Search<T>;
509
+ /**
510
+ * Makes a call to {@link WhereField.match} a {@link WhereField.matchExact} call. Calling
511
+ * this multiple times will have no effect.
512
+ * @returns this.
513
+ */
514
+ readonly exact: WhereField<T>;
515
+ /**
516
+ * Makes a call to {@link WhereField.match} a {@link WhereField.matchExact} call. Calling
517
+ * this multiple times will have no effect.
518
+ * @returns this.
519
+ */
520
+ readonly exactly: WhereField<T>;
521
+ /**
522
+ * Adds a boolean match with a value of `true` to the query.
523
+ * @returns The {@link Search} that was called to create this {@link WhereField}.
524
+ */
525
+ true(): Search<T>;
526
+ /**
527
+ * Adds a boolean match with a value of `false` to the query.
528
+ * @returns The {@link Search} that was called to create this {@link WhereField}.
529
+ */
530
+ false(): Search<T>;
531
+ /**
532
+ * Adds a greater than comparison against a field to the search query.
533
+ * @param value The value to compare against.
534
+ * @returns The {@link Search} that was called to create this {@link WhereField}.
535
+ */
536
+ gt(value: string | number | Date): Search<T>;
537
+ /**
538
+ * Adds a greater than comparison against a field to the search query.
539
+ * @param value The value to compare against.
540
+ * @returns The {@link Search} that was called to create this {@link WhereField}.
541
+ */
542
+ greaterThan(value: string | number | Date): Search<T>;
543
+ /**
544
+ * Adds a greater than or equal to comparison against a field to the search query.
545
+ * @param value The value to compare against.
546
+ * @returns The {@link Search} that was called to create this {@link WhereField}.
547
+ */
548
+ gte(value: string | number | Date): Search<T>;
549
+ /**
550
+ * Adds a greater than or equal to comparison against a field to the search query.
551
+ * @param value The value to compare against.
552
+ * @returns The {@link Search} that was called to create this {@link WhereField}.
553
+ */
554
+ greaterThanOrEqualTo(value: string | number | Date): Search<T>;
555
+ /**
556
+ * Adds a less than comparison against a field to the search query.
557
+ * @param value The value to compare against.
558
+ * @returns The {@link Search} that was called to create this {@link WhereField}.
559
+ */
560
+ lt(value: string | number | Date): Search<T>;
561
+ /**
562
+ * Adds a less than comparison against a field to the search query.
563
+ * @param value The value to compare against.
564
+ * @returns The {@link Search} that was called to create this {@link WhereField}.
565
+ */
566
+ lessThan(value: string | number | Date): Search<T>;
567
+ /**
568
+ * Adds a less than or equal to comparison against a field to the search query.
569
+ * @param value The value to compare against.
570
+ * @returns The {@link Search} that was called to create this {@link WhereField}.
571
+ */
572
+ lte(value: string | number | Date): Search<T>;
573
+ /**
574
+ * Adds a less than or equal to comparison against a field to the search query.
575
+ * @param value The value to compare against.
576
+ * @returns The {@link Search} that was called to create this {@link WhereField}.
577
+ */
578
+ lessThanOrEqualTo(value: string | number | Date): Search<T>;
579
+ /**
580
+ * Adds an inclusive range comparison against a field to the search query.
581
+ * @param lower The lower bound of the range.
582
+ * @param upper The upper bound of the range.
583
+ * @returns The {@link Search} that was called to create this {@link WhereField}.
584
+ */
585
+ between(lower: string | number | Date, upper: string | number | Date): Search<T>;
586
+ /**
587
+ * Adds a whole-string match for a value within a string array to the search query.
588
+ * @param value The string to be matched.
589
+ * @returns The {@link Search} that was called to create this {@link WhereField}.
590
+ */
591
+ contain(value: string): Search<T>;
592
+ /**
593
+ * Adds a whole-string match for a value within a string array to the search query.
594
+ * @param value The string to be matched.
595
+ * @returns The {@link Search} that was called to create this {@link WhereField}.
596
+ */
597
+ contains(value: string): Search<T>;
598
+ /**
599
+ * Adds a whole-string match against a string array to the query. If any of the provided
600
+ * strings in `value` is matched in the array, this matched.
601
+ * @param value An array of strings that you want to match one of.
602
+ * @returns The {@link Search} that was called to create this {@link WhereField}.
603
+ */
604
+ containOneOf(...value: Array<string>): Search<T>;
605
+ /**
606
+ * Adds a whole-string match against a string array to the query. If any of the provided
607
+ * strings in `value` is matched in the array, this matched.
608
+ * @param value An array of strings that you want to match one of.
609
+ * @returns The {@link Search} that was called to create this {@link WhereField}.
610
+ */
611
+ containsOneOf(...value: Array<string>): Search<T>;
612
+ /**
613
+ * Adds a search for points that fall within a defined circle.
614
+ * @param circleFn A function that returns a {@link Circle} instance defining the search area.
615
+ * @returns The {@link Search} that was called to create this {@link WhereField}.
616
+ */
617
+ inCircle(circleFn: CircleFunction): Search<T>;
618
+ /**
619
+ * Adds a search for points that fall within a defined radius.
620
+ * @param circleFn A function that returns a {@link Circle} instance defining the search area.
621
+ * @returns The {@link Search} that was called to create this {@link WhereField}.
622
+ */
623
+ inRadius(circleFn: CircleFunction): Search<T>;
624
+ /**
625
+ * Add a search for an exact UTC datetime to the query.
626
+ * @param value The datetime to match.
627
+ * @returns The {@link Search} that was called to create this {@link WhereField}.
628
+ */
629
+ on(value: string | number | Date): Search<T>;
630
+ /**
631
+ * Add a search that matches all datetimes *before* the provided UTC datetime to the query.
632
+ * @param value The datetime to compare against.
633
+ * @returns The {@link Search} that was called to create this {@link WhereField}.
634
+ */
635
+ before(value: string | number | Date): Search<T>;
636
+ /**
637
+ * Add a search that matches all datetimes *after* the provided UTC datetime to the query.
638
+ * @param value The datetime to compare against.
639
+ * @returns The {@link Search} that was called to create this {@link WhereField}.
640
+ */
641
+ after(value: string | number | Date): Search<T>;
642
+ /**
643
+ * Add a search that matches all datetimes *on or before* the provided UTC datetime to the query.
644
+ * @param value The datetime to compare against.
645
+ * @returns The {@link Search} that was called to create this {@link WhereField}.
646
+ */
647
+ onOrBefore(value: string | number | Date): Search<T>;
648
+ /**
649
+ * Add a search that matches all datetimes *on or after* the provided UTC datetime to the query.
650
+ * @param value The datetime to compare against.
651
+ * @returns The {@link Search} that was called to create this {@link WhereField}.
652
+ */
653
+ onOrAfter(value: string | number | Date): Search<T>;
654
+ }
655
+ /**
656
+ * Abstract base class that all fields you want to filter
657
+ * with extend. When you call {@link Search.where}, a
658
+ * subclass of this is returned.
659
+ */
660
+ declare abstract class WhereField<T extends Entity> {
661
+ private negated;
662
+ /** @internal */
663
+ protected search: Search<T>;
664
+ /** @internal */
665
+ protected field: Field;
666
+ /** @internal */
667
+ constructor(search: Search<T>, field: Field);
668
+ /**
669
+ * Returns the current instance. Syntactic sugar to make your code more fluent.
670
+ * @returns this
671
+ */
672
+ get is(): this;
673
+ /**
674
+ * Returns the current instance. Syntactic sugar to make your code more fluent.
675
+ * @returns this
676
+ */
677
+ get does(): this;
678
+ /**
679
+ * Negates the query on the field, cause it to match when the condition is
680
+ * *not* met. Calling this multiple times will negate the negation.
681
+ * @returns this
682
+ */
683
+ get not(): this;
684
+ abstract toString(): string;
685
+ /** @internal */
686
+ protected negate(): void;
687
+ /** @internal */
688
+ protected buildQuery(valuePortion: string): string;
689
+ /** @internal */
690
+ protected escapePunctuation(value: string): string;
691
+ /** @internal */
692
+ protected escapePunctuationAndSpaces(value: string): string;
693
+ }
694
+
695
+ /**
696
+ * A function that takes a {@link Search} and returns a {@link Search}. Used in nested queries.
697
+ * @template TEntity The type of {@link Entity} being sought.
698
+ */
699
+ type SubSearchFunction<T extends Entity> = (search: Search<T>) => Search<T>;
700
+ type SortOptions = {
701
+ BY: string;
702
+ DIRECTION: 'ASC' | 'DESC';
703
+ };
704
+ /**
705
+ * Abstract base class for {@link Search} and {@link RawSearch} that
706
+ * contains methods to return search results.
707
+ * @template TEntity The type of {@link Entity} being sought.
708
+ */
709
+ declare abstract class AbstractSearch<T extends Entity = Record<string, any>> {
710
+ /** @internal */
711
+ protected schema: Schema<T>;
712
+ /** @internal */
713
+ protected client: Client;
714
+ /** @internal */
715
+ protected sortOptions?: SortOptions;
716
+ /** @internal */
717
+ constructor(schema: Schema<T>, client: Client);
718
+ /** @internal */
719
+ abstract get query(): string;
720
+ /**
721
+ * Applies an ascending sort to the query.
722
+ * @param field The field to sort by.
723
+ * @returns this
724
+ */
725
+ sortAscending(field: EntityKeys<T>): AbstractSearch<T>;
726
+ /**
727
+ * Alias for {@link Search.sortDescending}.
728
+ */
729
+ sortDesc(field: EntityKeys<T>): AbstractSearch<T>;
730
+ /**
731
+ * Applies a descending sort to the query.
732
+ * @param field The field to sort by.
733
+ * @returns this
734
+ */
735
+ sortDescending(field: EntityKeys<T>): AbstractSearch<T>;
736
+ /**
737
+ * Alias for {@link Search.sortAscending}.
738
+ */
739
+ sortAsc(field: EntityKeys<T>): AbstractSearch<T>;
740
+ /**
741
+ * Applies sorting for the query.
742
+ * @param fieldName The field to sort by.
743
+ * @param order The order of returned {@link Entity | Entities} Defaults to `ASC` (ascending) if not specified
744
+ * @returns this
745
+ */
746
+ sortBy(fieldName: EntityKeys<T>, order?: 'ASC' | 'DESC'): AbstractSearch<T>;
747
+ /**
748
+ * Finds the {@link Entity} with the minimal value for a field.
749
+ * @param field The field with the minimal value.
750
+ * @returns The {@link Entity} with the minimal value
751
+ */
752
+ min(field: EntityKeys<T>): Promise<T | null>;
753
+ /**
754
+ * Finds the entity ID with the minimal value for a field.
755
+ * @param field The field with the minimal value.
756
+ * @returns The entity ID with the minimal value
757
+ */
758
+ minId(field: EntityKeys<T>): Promise<string | null>;
759
+ /**
760
+ * Finds the key name in Redis with the minimal value for a field.
761
+ * @param field The field with the minimal value.
762
+ * @returns The key name with the minimal value
763
+ */
764
+ minKey(field: EntityKeys<T>): Promise<string | null>;
765
+ /**
766
+ * Finds the {@link Entity} with the maximal value for a field.
767
+ * @param field The field with the maximal value.
768
+ * @returns The entity ID {@link Entity} with the maximal value
769
+ */
770
+ max(field: EntityKeys<T>): Promise<T | null>;
771
+ /**
772
+ * Finds the entity ID with the maximal value for a field.
773
+ * @param field The field with the maximal value.
774
+ * @returns The entity ID with the maximal value
775
+ */
776
+ maxId(field: EntityKeys<T>): Promise<string | null>;
777
+ /**
778
+ * Finds the key name in Redis with the maximal value for a field.
779
+ * @param field The field with the maximal value.
780
+ * @returns The key name with the maximal value
781
+ */
782
+ maxKey(field: EntityKeys<T>): Promise<string | null>;
783
+ /**
784
+ * Returns the number of {@link Entity | Entities} that match this query.
785
+ * @returns
786
+ */
787
+ count(): Promise<number>;
788
+ /**
789
+ * Returns a page of {@link Entity | Entities} that match this query.
790
+ * @param offset The offset for where to start returning {@link Entity | Entities}.
791
+ * @param count The number of {@link Entity | Entities} to return.
792
+ * @returns An array of {@link Entity | Entities} matching the query.
793
+ */
794
+ page(offset: number, count: number): Promise<T[]>;
795
+ /**
796
+ * Returns a page of entity IDs that match this query.
797
+ * @param offset The offset for where to start returning entity IDs.
798
+ * @param count The number of entity IDs to return.
799
+ * @returns An array of strings matching the query.
800
+ */
801
+ pageOfIds(offset: number, count: number): Promise<string[]>;
802
+ /**
803
+ * Returns a page of key names in Redis that match this query.
804
+ * @param offset The offset for where to start returning key names.
805
+ * @param count The number of key names to return.
806
+ * @returns An array of strings matching the query.
807
+ */
808
+ pageOfKeys(offset: number, count: number): Promise<string[]>;
809
+ /**
810
+ * Returns the first {@link Entity} that matches this query.
811
+ */
812
+ first(): Promise<T | null>;
813
+ /**
814
+ * Returns the first entity ID that matches this query.
815
+ */
816
+ firstId(): Promise<string | null>;
817
+ /**
818
+ * Returns the first key name that matches this query.
819
+ */
820
+ firstKey(): Promise<string | null>;
821
+ /**
822
+ * Returns all the {@link Entity | Entities} that match this query. This method
823
+ * makes multiple calls to Redis until all the {@link Entity | Entities} are returned.
824
+ * You can specify the batch size by setting the `pageSize` property on the
825
+ * options:
826
+ *
827
+ * ```typescript
828
+ * const entities = await repository.search().returnAll({ pageSize: 100 })
829
+ * ```
830
+ *
831
+ * @param options Options for the call.
832
+ * @param options.pageSize Number of {@link Entity | Entities} returned per batch.
833
+ * @returns An array of {@link Entity | Entities} matching the query.
834
+ */
835
+ all(options?: {
836
+ pageSize: number;
837
+ }): Promise<T[]>;
838
+ /**
839
+ * Returns all the entity IDs that match this query. This method
840
+ * makes multiple calls to Redis until all the entity IDs are returned.
841
+ * You can specify the batch size by setting the `pageSize` property on the
842
+ * options:
843
+ *
844
+ * ```typescript
845
+ * const keys = await repository.search().returnAllIds({ pageSize: 100 })
846
+ * ```
847
+ *
848
+ * @param options Options for the call.
849
+ * @param options.pageSize Number of entity IDs returned per batch.
850
+ * @returns An array of entity IDs matching the query.
851
+ */
852
+ allIds(options?: {
853
+ pageSize: number;
854
+ }): Promise<string[]>;
855
+ /**
856
+ * Returns all the key names in Redis that match this query. This method
857
+ * makes multiple calls to Redis until all the key names are returned.
858
+ * You can specify the batch size by setting the `pageSize` property on the
859
+ * options:
860
+ *
861
+ * ```typescript
862
+ * const keys = await repository.search().returnAllKeys({ pageSize: 100 })
863
+ * ```
864
+ *
865
+ * @param options Options for the call.
866
+ * @param options.pageSize Number of key names returned per batch.
867
+ * @returns An array of key names matching the query.
868
+ */
869
+ allKeys(options?: {
870
+ pageSize: number;
871
+ }): Promise<string[]>;
872
+ /**
873
+ * Returns the current instance. Syntactic sugar to make your code more fluent.
874
+ * @returns this
875
+ */
876
+ get return(): AbstractSearch<T>;
877
+ /**
878
+ * Alias for {@link Search.min}.
879
+ */
880
+ returnMin(field: EntityKeys<T>): Promise<T | null>;
881
+ /**
882
+ * Alias for {@link Search.minId}.
883
+ */
884
+ returnMinId(field: EntityKeys<T>): Promise<string | null>;
885
+ /**
886
+ * Alias for {@link Search.minKey}.
887
+ */
888
+ returnMinKey(field: EntityKeys<T>): Promise<string | null>;
889
+ /**
890
+ * Alias for {@link Search.max}.
891
+ */
892
+ returnMax(field: EntityKeys<T>): Promise<T | null>;
893
+ /**
894
+ * Alias for {@link Search.maxId}.
895
+ */
896
+ returnMaxId(field: EntityKeys<T>): Promise<string | null>;
897
+ /**
898
+ * Alias for {@link Search.maxKey}.
899
+ */
900
+ returnMaxKey(field: EntityKeys<T>): Promise<string | null>;
901
+ /**
902
+ * Alias for {@link Search.count}.
903
+ */
904
+ returnCount(): Promise<number>;
905
+ /**
906
+ * Alias for {@link Search.page}.
907
+ */
908
+ returnPage(offset: number, count: number): Promise<T[]>;
909
+ /**
910
+ * Alias for {@link Search.pageOfIds}.
911
+ */
912
+ returnPageOfIds(offset: number, count: number): Promise<string[]>;
913
+ /**
914
+ * Alias for {@link Search.pageOfKeys}.
915
+ */
916
+ returnPageOfKeys(offset: number, count: number): Promise<string[]>;
917
+ /**
918
+ * Alias for {@link Search.first}.
919
+ */
920
+ returnFirst(): Promise<T | null>;
921
+ /**
922
+ * Alias for {@link Search.firstId}.
923
+ */
924
+ returnFirstId(): Promise<string | null>;
925
+ /**
926
+ * Alias for {@link Search.firstKey}.
927
+ */
928
+ returnFirstKey(): Promise<string | null>;
929
+ /**
930
+ * Alias for {@link Search.all}.
931
+ */
932
+ returnAll(options?: {
933
+ pageSize: number;
934
+ }): Promise<T[]>;
935
+ /**
936
+ * Alias for {@link Search.allIds}.
937
+ */
938
+ returnAllIds(options?: {
939
+ pageSize: number;
940
+ }): Promise<string[]>;
941
+ /**
942
+ * Alias for {@link Search.allKeys}.
943
+ */
944
+ returnAllKeys(options?: {
945
+ pageSize: number;
946
+ }): Promise<string[]>;
947
+ private allThings;
948
+ private callSearch;
949
+ }
950
+ /**
951
+ * Entry point to raw search which allows using raw RediSearch queries
952
+ * against Redis OM. Requires that RediSearch (and optionally RedisJSON) be
953
+ * installed.
954
+ * @template TEntity The type of {@link Entity} being sought.
955
+ */
956
+ declare class RawSearch<T extends Entity = Record<string, any>> extends AbstractSearch<T> {
957
+ private readonly rawQuery;
958
+ /** @internal */
959
+ constructor(schema: Schema<T>, client: Client, query?: string);
960
+ /** @internal */
961
+ get query(): string;
962
+ }
963
+ /**
964
+ * Entry point to fluent search. This is the default Redis OM experience.
965
+ * Requires that RediSearch (and optionally RedisJSON) be installed.
966
+ * @template TEntity The type of {@link Entity} being sought.
967
+ */
968
+ declare class Search<T extends Entity = Record<string, any>> extends AbstractSearch<T> {
969
+ private rootWhere?;
970
+ /** @internal */
971
+ get query(): string;
972
+ /**
973
+ * Sets up a query matching a particular field. If there are multiple calls
974
+ * to {@link Search.where}, they are treated logically as AND.
975
+ * @param field The field to filter on.
976
+ * @returns A subclass of {@link WhereField} matching the type of the field.
977
+ */
978
+ where(field: EntityKeys<T>): WhereField<T>;
979
+ /**
980
+ * Sets up a nested search. If there are multiple calls to {@link Search.where},
981
+ * they are treated logically as AND.
982
+ * @param subSearchFn A function that takes a {@link Search} and returns another {@link Search}.
983
+ * @returns `this`.
984
+ */
985
+ where(subSearchFn: SubSearchFunction<T>): Search<T>;
986
+ /**
987
+ * Sets up a query matching a particular field as a logical AND.
988
+ * @param field The field to filter on.
989
+ * @returns A subclass of {@link WhereField} matching the type of the field.
990
+ */
991
+ and(field: EntityKeys<T>): WhereField<T>;
992
+ /**
993
+ * Sets up a nested search as a logical AND.
994
+ * @param subSearchFn A function that takes a {@link Search} and returns another {@link Search}.
995
+ * @returns `this`.
996
+ */
997
+ and(subSearchFn: SubSearchFunction<T>): Search<T>;
998
+ /**
999
+ * Sets up a query matching a particular field as a logical OR.
1000
+ * @param field The field to filter on.
1001
+ * @returns A subclass of {@link WhereField} matching the type of the field.
1002
+ */
1003
+ or(field: EntityKeys<T>): WhereField<T>;
1004
+ /**
1005
+ * Sets up a nested search as a logical OR.
1006
+ * @param subSearchFn A function that takes a {@link Search} and returns another {@link Search}.
1007
+ * @returns `this`.
1008
+ */
1009
+ or(subSearchFn: SubSearchFunction<T>): Search<T>;
1010
+ private anyWhere;
1011
+ private anyWhereForField;
1012
+ private anyWhereForFunction;
1013
+ private createWhere;
1014
+ }
1015
+
1016
+ /**
1017
+ * A repository is the main interaction point for reading, writing, and
1018
+ * removing {@link Entity | Entities} from Redis. Create one by calling
1019
+ * {@link Client.fetchRepository} and passing in a {@link Schema}. Then
1020
+ * use the {@link Repository#fetch}, {@link Repository#save}, and
1021
+ * {@link Repository#remove} methods to manage your data:
1022
+ *
1023
+ * ```typescript
1024
+ * const repository = client.fetchRepository(schema)
1025
+ *
1026
+ * const foo = await repository.fetch('01FK6TCJBDK41RJ766A4SBWDJ9')
1027
+ * foo.aString = 'bar'
1028
+ * foo.aBoolean = false
1029
+ * await repository.save(foo)
1030
+ * ```
1031
+ *
1032
+ * Use the repository to create a new instance of an {@link Entity}
1033
+ * before you save it:
1034
+ *
1035
+ * ```typescript
1036
+ * const foo = await repository.createEntity()
1037
+ * foo.aString = 'bar'
1038
+ * foo.aBoolean = false
1039
+ * await repository.save(foo)
1040
+ * ```
1041
+ *
1042
+ * If you want to use the {@link Repository#search} method, you need to create an index
1043
+ * first, and you need RediSearch or RedisJSON installed on your instance of Redis:
1044
+ *
1045
+ * ```typescript
1046
+ * await repository.createIndex()
1047
+ * const entities = await repository.search()
1048
+ * .where('aString').eq('bar')
1049
+ * .and('aBoolean').is.false().returnAll()
1050
+ * ```
1051
+ */
1052
+ declare class Repository<T extends Entity = Record<string, any>> {
1053
+ #private;
1054
+ private readonly client;
1055
+ /**
1056
+ * Creates a new {@link Repository}.
1057
+ *
1058
+ * @param schema The schema defining that data in the repository.
1059
+ * @param clientOrConnection A client to talk to Redis.
1060
+ */
1061
+ constructor(schema: Schema<T>, clientOrConnection: Client | RedisConnection);
1062
+ /**
1063
+ * Creates an index in Redis for use by the {@link Repository#search} method.
1064
+ * Does not create a new index if the index hasn't changed. Requires that
1065
+ * RediSearch and RedisJSON are installed on your instance of Redis.
1066
+ */
1067
+ createIndex(): Promise<void>;
1068
+ /**
1069
+ * Removes an existing index from Redis. Use this method if you want to swap out your index
1070
+ * because your {@link Entity} has changed. Requires that RediSearch and RedisJSON are installed
1071
+ * on your instance of Redis.
1072
+ */
1073
+ dropIndex(): Promise<void>;
1074
+ /**
1075
+ * Insert or update an {@link Entity} to Redis using its entityId property
1076
+ * if present. If it's not, one is generated.
1077
+ *
1078
+ * @param entity The Entity to save.
1079
+ * @returns A copy of the provided Entity with EntityId and EntityKeyName properties added.
1080
+ */
1081
+ save(entity: T): Promise<T>;
1082
+ /**
1083
+ * Insert or update the {@link Entity} to Redis using the provided entityId.
1084
+ *
1085
+ * @param id The id to save the Entity under.
1086
+ * @param entity The Entity to save.
1087
+ * @returns A copy of the provided Entity with EntityId and EntityKeyName properties added.
1088
+ */
1089
+ save(id: string, entity: T): Promise<T>;
1090
+ /**
1091
+ * Read and return an {@link Entity} from Redis for the given id. If
1092
+ * the {@link Entity} is not found, returns an empty {@link Entity}.
1093
+ *
1094
+ * @param id The ID of the {@link Entity} you seek.
1095
+ * @returns The matching Entity.
1096
+ */
1097
+ fetch(id: string): Promise<T>;
1098
+ /**
1099
+ * Read and return the {@link Entity | Entities} from Redis with the given IDs. If
1100
+ * a particular {@link Entity} is not found, returns that {@link Entity} as empty.
1101
+ *
1102
+ * @param ids The IDs of the {@link Entity | Entities} you seek.
1103
+ * @returns The matching Entities.
1104
+ */
1105
+ fetch(...ids: string[]): Promise<T[]>;
1106
+ /**
1107
+ * Read and return the {@link Entity | Entities} from Redis with the given IDs. If
1108
+ * a particular {@link Entity} is not found, returns that {@link Entity} as empty.
1109
+ *
1110
+ * @param ids The IDs of the {@link Entity | Entities} you seek.
1111
+ * @returns The matching Entities.
1112
+ */
1113
+ fetch(ids: string[]): Promise<T[]>;
1114
+ /**
1115
+ * Remove an {@link Entity} from Redis for the given id. If the {@link Entity} is
1116
+ * not found, does nothing.
1117
+ *
1118
+ * @param id The ID of the {@link Entity} you wish to delete.
1119
+ */
1120
+ remove(id: string): Promise<void>;
1121
+ /**
1122
+ * Remove the {@link Entity | Entities} from Redis for the given ids. If a
1123
+ * particular {@link Entity} is not found, does nothing.
1124
+ *
1125
+ * @param ids The IDs of the {@link Entity | Entities} you wish to delete.
1126
+ */
1127
+ remove(...ids: string[]): Promise<void>;
1128
+ /**
1129
+ * Remove the {@link Entity | Entities} from Redis for the given ids. If a
1130
+ * particular {@link Entity} is not found, does nothing.
1131
+ *
1132
+ * @param ids The IDs of the {@link Entity | Entities} you wish to delete.
1133
+ */
1134
+ remove(ids: string[]): Promise<void>;
1135
+ /**
1136
+ * Set the time to live of the {@link Entity}. If the {@link Entity} is not
1137
+ * found, does nothing.
1138
+ *
1139
+ * @param id The ID of the {@link Entity} to set and expiration for.
1140
+ * @param ttlInSeconds The time to live in seconds.
1141
+ */
1142
+ expire(id: string, ttlInSeconds: number): Promise<void>;
1143
+ /**
1144
+ * Set the time to live of the {@link Entity | Entities} in Redis with the given
1145
+ * ids. If a particular {@link Entity} is not found, does nothing.
1146
+ *
1147
+ * @param ids The IDs of the {@link Entity | Entities} you wish to delete.
1148
+ * @param ttlInSeconds The time to live in seconds.
1149
+ */
1150
+ expire(ids: string[], ttlInSeconds: number): Promise<void>;
1151
+ /**
1152
+ * Use Date object to set the {@link Entity}'s time to live. If the {@link Entity}
1153
+ * is not found, does nothing.
1154
+ *
1155
+ * @param id The ID of the {@link Entity} to set an expiration date for.
1156
+ * @param expirationDate The time the data should expire.
1157
+ */
1158
+ expireAt(id: string, expirationDate: Date): Promise<void>;
1159
+ /**
1160
+ * Use Date object to set the {@link Entity | Entities} in Redis with the given
1161
+ * ids. If a particular {@link Entity} is not found, does nothing.
1162
+ *
1163
+ * @param ids The IDs of the {@link Entity | Entities} to set an expiration date for.
1164
+ * @param expirationDate The time the data should expire.
1165
+ */
1166
+ expireAt(ids: string[], expirationDate: Date): Promise<void>;
1167
+ /**
1168
+ * Kicks off the process of building a query. Requires that RediSearch (and optionally
1169
+ * RedisJSON) be installed on your instance of Redis.
1170
+ *
1171
+ * @returns A {@link Search} object.
1172
+ */
1173
+ search(): Search<T>;
1174
+ /**
1175
+ * Creates a search that bypasses Redis OM and instead allows you to execute a raw
1176
+ * RediSearch query. Requires that RediSearch (and optionally RedisJSON) be installed
1177
+ * on your instance of Redis.
1178
+ *
1179
+ * Refer to https://redis.io/docs/stack/search/reference/query_syntax/ for details on
1180
+ * RediSearch query syntax.
1181
+ *
1182
+ * @query The raw RediSearch query you want to rune.
1183
+ * @returns A {@link RawSearch} object.
1184
+ */
1185
+ searchRaw(query: string): RawSearch<T>;
1186
+ private writeEntity;
1187
+ private readEntities;
1188
+ private readEntitiesFromHash;
1189
+ private writeEntityToJson;
1190
+ private readEntitiesFromJson;
1191
+ private makeKeys;
1192
+ private makeKey;
1193
+ }
1194
+
1195
+ /** A conventional Redis connection. */
1196
+ type RedisClientConnection = ReturnType<typeof createClient>;
1197
+ /** A clustered Redis connection. */
1198
+ type RedisClusterConnection = ReturnType<typeof createCluster>;
1199
+ /** A Redis connection, clustered or conventional. */
1200
+ type RedisConnection = RedisClientConnection | RedisClusterConnection;
1201
+ /** @internal This is a defintion for the type that calls to ft.search in Node Redis return. */
1202
+ type SearchResults = {
1203
+ total: number;
1204
+ documents: SearchDocument[];
1205
+ };
1206
+ /** @internal This is a defintion for the return type of calls to ft.search in Node Redis. */
1207
+ type SearchDocument = {
1208
+ id: string;
1209
+ value: {
1210
+ [key: string]: any;
1211
+ };
1212
+ };
1213
+ /** @internal */
1214
+ type RedisHashData = {
1215
+ [key: string]: string;
1216
+ };
1217
+ /** @internal */
1218
+ type RedisJsonData = {
1219
+ [key: string]: any;
1220
+ };
1221
+ /** @internal */
1222
+ type SearchDataStructure = 'HASH' | 'JSON';
1223
+ /**
1224
+ * @internal This is a simplified redefintion of the CreateOptions type that is not exported by Node Redis.
1225
+ * TODO: Remove this type once CreateOptions is exported by Node Redis.
1226
+ * https://github.com/redis/node-redis/blob/master/packages/search/lib/commands/CREATE.ts#L4
1227
+ */
1228
+ type CreateOptions = {
1229
+ ON: SearchDataStructure;
1230
+ PREFIX: string;
1231
+ STOPWORDS?: string[];
1232
+ };
1233
+ /**
1234
+ * A Client is the starting point for working with Redis OM. Clients manage the
1235
+ * connection to Redis and provide limited functionality for executing Redis commands.
1236
+ * Create a client and open it before you use it:
1237
+ *
1238
+ * ```typescript
1239
+ * const client = new Client()
1240
+ * await client.open()
1241
+ * ```
1242
+ *
1243
+ * A Client is primarily used by a {@link Repository} which requires a client in
1244
+ * its constructor.
1245
+ *
1246
+ * @deprecated Just used Node Redis client directly and pass it to the Repository.
1247
+ */
1248
+ declare class Client {
1249
+ #private;
1250
+ /** Returns the underlying Node Redis connection being used. */
1251
+ get redis(): RedisConnection | undefined;
1252
+ /**
1253
+ * Attaches an existing Node Redis connection to this Redis OM client. Closes
1254
+ * any existing connection.
1255
+ *
1256
+ * @param connection An existing Node Redis client.
1257
+ * @returns This {@link Client} instance.
1258
+ */
1259
+ use(connection: RedisConnection): Promise<Client>;
1260
+ /**
1261
+ * Attaches an existing Node Redis connection to this Redis OM client. Does
1262
+ * not close any existing connection.
1263
+ *
1264
+ * @param connection An existing Node Redis client.
1265
+ * @returns This {@link Client} instance.
1266
+ */
1267
+ useNoClose(connection: RedisConnection): Client;
1268
+ /**
1269
+ * Open a connection to Redis at the provided URL.
1270
+ *
1271
+ * @param url A URL to Redis as defined with the [IANA](https://www.iana.org/assignments/uri-schemes/prov/redis).
1272
+ * @returns This {@link Client} instance.
1273
+ */
1274
+ open(url?: string): Promise<Client>;
1275
+ /**
1276
+ * Creates a repository for the given schema.
1277
+ *
1278
+ * @param schema The schema.
1279
+ * @returns A repository for the provided schema.
1280
+ */
1281
+ fetchRepository<T extends Schema<any>>(schema: T): Repository<InferSchema<T>>;
1282
+ /**
1283
+ * Close the connection to Redis.
1284
+ */
1285
+ close(): Promise<void>;
1286
+ /** @internal */
1287
+ createIndex(indexName: string, schema: RediSearchSchema, options: CreateOptions): Promise<void>;
1288
+ /** @internal */
1289
+ dropIndex(indexName: string): Promise<void>;
1290
+ /** @internal */
1291
+ search(indexName: string, query: string, options?: SearchOptions): Promise<SearchResults>;
1292
+ /** @internal */
1293
+ unlink(...keys: string[]): Promise<void>;
1294
+ /** @internal */
1295
+ expire(key: string, ttl: number): Promise<void>;
1296
+ /** @internal */
1297
+ expireAt(key: string, timestamp: Date): Promise<void>;
1298
+ /** @internal */
1299
+ get(key: string): Promise<string | null>;
1300
+ /** @internal */
1301
+ set(key: string, value: string): Promise<void>;
1302
+ /** @internal */
1303
+ hgetall(key: string): Promise<RedisHashData>;
1304
+ /** @internal */
1305
+ hsetall(key: string, data: RedisHashData): Promise<void>;
1306
+ /** @internal */
1307
+ jsonget(key: string): Promise<RedisJsonData | null>;
1308
+ /** @internal */
1309
+ jsonset(key: string, data: RedisJsonData): Promise<void>;
1310
+ /**
1311
+ * @returns Whether a connection is already open.
1312
+ */
1313
+ isOpen(): boolean;
1314
+ }
1315
+
1316
+ declare class RedisOmError extends Error {
1317
+ }
1318
+
1319
+ declare class InvalidInput extends RedisOmError {
1320
+ }
1321
+ declare class NullJsonInput extends InvalidInput {
1322
+ #private;
1323
+ constructor(field: Field);
1324
+ get fieldName(): string;
1325
+ get fieldType(): FieldType;
1326
+ get jsonPath(): string;
1327
+ }
1328
+ declare class InvalidJsonInput extends InvalidInput {
1329
+ #private;
1330
+ constructor(field: Field);
1331
+ get fieldName(): string;
1332
+ get fieldType(): FieldType;
1333
+ get jsonPath(): string;
1334
+ }
1335
+ declare class InvalidHashInput extends InvalidInput {
1336
+ #private;
1337
+ constructor(field: Field);
1338
+ get fieldName(): string;
1339
+ get fieldType(): FieldType;
1340
+ }
1341
+ declare class NestedHashInput extends InvalidInput {
1342
+ #private;
1343
+ constructor(property: string);
1344
+ get field(): string;
1345
+ }
1346
+ declare class ArrayHashInput extends InvalidInput {
1347
+ #private;
1348
+ constructor(property: string);
1349
+ get field(): string;
1350
+ }
1351
+
1352
+ declare class InvalidSchema extends RedisOmError {
1353
+ }
1354
+
1355
+ declare class InvalidValue extends RedisOmError {
1356
+ }
1357
+ declare class NullJsonValue extends InvalidValue {
1358
+ #private;
1359
+ constructor(field: Field);
1360
+ get fieldName(): string;
1361
+ get fieldType(): FieldType;
1362
+ get jsonPath(): string;
1363
+ }
1364
+ declare class InvalidJsonValue extends InvalidValue {
1365
+ #private;
1366
+ constructor(field: Field);
1367
+ get fieldName(): string;
1368
+ get fieldType(): FieldType;
1369
+ get jsonPath(): string;
1370
+ }
1371
+ declare class InvalidHashValue extends InvalidValue {
1372
+ #private;
1373
+ constructor(field: Field);
1374
+ get fieldName(): string;
1375
+ get fieldType(): FieldType;
1376
+ get hashField(): string;
1377
+ }
1378
+
1379
+ declare class PointOutOfRange extends RedisOmError {
1380
+ #private;
1381
+ constructor(point: Point);
1382
+ get point(): {
1383
+ longitude: number;
1384
+ latitude: number;
1385
+ };
1386
+ }
1387
+
1388
+ declare class SearchError extends RedisOmError {
1389
+ }
1390
+ declare class SemanticSearchError extends SearchError {
1391
+ }
1392
+ declare class FieldNotInSchema extends SearchError {
1393
+ #private;
1394
+ constructor(fieldName: string);
1395
+ get field(): string;
1396
+ }
1397
+
1398
+ export { AbstractSearch, AllFieldDefinition, ArrayHashInput, BooleanFieldDefinition, Circle, CircleFunction, Client, CommonFieldDefinition, DataStructure, DateFieldDefinition, Entity, EntityData, EntityDataValue, EntityId, EntityKeyName, Field, FieldDefinition, FieldNotInSchema, FieldType, IdStrategy, InvalidHashInput, InvalidHashValue, InvalidInput, InvalidJsonInput, InvalidJsonValue, InvalidSchema, InvalidValue, NestedHashInput, NullJsonInput, NullJsonValue, NumberArrayFieldDefinition, NumberFieldDefinition, Point, PointFieldDefinition, PointOutOfRange, RawSearch, RedisClientConnection, RedisClusterConnection, RedisConnection, RedisOmError, Repository, Schema, SchemaDefinition, SchemaOptions, Search, SearchError, SemanticSearchError, StopWordOptions, StringArrayFieldDefinition, StringFieldDefinition, SubSearchFunction, TextFieldDefinition, Where, WhereField };