Socket
Socket
Sign inDemoInstall

redis-om

Package Overview
Dependencies
13
Maintainers
3
Versions
26
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.3.6 to 0.4.0-beta.1

docs/classes/ArrayHashInput.md

927

dist/index.d.ts

@@ -1,5 +0,22 @@

import { createClient } from 'redis';
import { createClient, createCluster, RediSearchSchema, SearchOptions } from 'redis';
/** The Symbol used to access the entity ID of an {@link Entity}. */
declare const EntityId: unique symbol;
/** The Symbol used to access the keyname of an {@link Entity}. */
declare const EntityKeyName: unique symbol;
/** Defines the objects returned from calls to {@link Repository | repositories }. */
type Entity = EntityData & {
/** The unique ID of the {@link Entity}. Access using the {@link EntityId} Symbol. */
[EntityId]?: string;
/** The key the {@link Entity} is stored under inside of Redis. Access using the {@link EntityKeyName} Symbol. */
[EntityKeyName]?: string;
};
/** The free-form data associated with an {@link Entity}. */
type EntityData = {
[key: string]: EntityDataValue | EntityData | Array<EntityDataValue | EntityData>;
};
/** Valid types for values in an {@link Entity}. */
type EntityDataValue = string | number | boolean | Date | Point | null | undefined;
/** Defines a point on the globe using longitude and latitude. */
declare type Point = {
type Point = {
/** The longitude of the point. */

@@ -11,94 +28,143 @@ longitude: number;

/**
* Valid types for properties on an {@link Entity}.
*/
declare type EntityValue = string | number | boolean | Point | Date | any[] | null;
/**
* A JavaScript object containing the underlying data of an {@link Entity}.
*/
declare type EntityData = Record<string, EntityValue>;
/**
* An Entity is the class from which objects that Redis OM maps to are made. You need
* to subclass Entity in your application:
*
* ```typescript
* class Foo extends Entity {}
* ```
*/
declare abstract class Entity {
/** The generated entity ID. */
readonly entityId: string;
private schemaDef;
private prefix;
private entityFields;
/** Valid field types for a {@link FieldDefinition}. */
type FieldType = 'boolean' | 'date' | 'number' | 'point' | 'string' | 'string[]' | 'text';
/** All configuration properties that any field might have, regardless of type. */
type AllFieldDefinition = {
/** The type of the field (i.e. string, number, boolean, etc.) */
type: FieldType;
/**
* Creates an new Entity.
* @internal
* The default field name in Redis is the property name defined in the
* {@link SchemaDefinition}. Overrides the field name for a Hash to this
* value or in the case of JSON documents, sets the JSONPath to this
* value preceded by `$.`. Overridden by {@link field} and/or {@link path}
* settings.
* @deprecated
*/
constructor(schema: Schema<any>, id: string, data?: EntityData);
alias?: string;
/**
* Create the fields on the Entity.
* @internal
* Is this field indexed and thus searchable with Redis OM. Defaults
* to true.
*/
private createFields;
indexed?: boolean;
/**
* @returns The keyname this {@link Entity} is stored with in Redis.
* The field name used to store this in a Redis Hash. Defaults to the
* name used in the {@link SchemaDefinition} or the {@link alias}
* property.
*/
get keyName(): string;
field?: string;
/**
* Converts this {@link Entity} to a JavaScript object suitable for stringification.
* @returns a JavaScript object.
* The JSONPath expression this field references. Used only by search
* and only for JSON documents. Defaults to the name used in the
* {@link SchemaDefinition} or the {@link alias} property prefixed
* with `$.` .
*/
toJSON(): Record<string, any>;
path?: string;
/** Enables sorting by this field. */
sortable?: boolean;
/** Is the original case of this field indexed with Redis OM. Defaults to false. */
caseSensitive?: boolean;
/** Is this (sortable) field normalized when indexed. Defaults to true. */
normalized?: boolean;
/**
* Converts this {@link Entity} to a JavaScript object suitable for writing to RedisJSON.
* @internal
* Due to how RediSearch works, strings and arrays are sometimes stored the same in Redis, as a
* simple string. This is the separator used to split those strings when it is an array. If your
* StringField contains this separator, this can cause problems. You can change it here to avoid
* those problems. Defaults to `|`.
*/
toRedisJson(): RedisJsonData;
separator?: string;
/**
* Loads this {@link Entity} from Redis JSON data.
* @internal
* Enables setting the phonetic matcher to use, supported matchers are:
* dm:en - Double Metaphone for English
* dm:fr - Double Metaphone for French
* dm:pt - Double Metaphone for Portuguese
* dm:es - Double Metaphone for Spanish
*/
fromRedisJson(data: RedisJsonData): undefined;
matcher?: 'dm:en' | 'dm:fr' | 'dm:pt' | 'dm:es';
/** Is word stemming applied to this field with Redis OM. Defaults to true. */
stemming?: boolean;
/** Enables setting the weight to apply to a text field */
weight?: number;
};
/** The configuration properties that all fields have in common. */
type CommonFieldDefinition = Pick<AllFieldDefinition, "type" | "alias" | "indexed" | "field" | "path">;
/** A field representing a boolean. */
type BooleanFieldDefinition = {
type: 'boolean';
} & CommonFieldDefinition & Pick<AllFieldDefinition, "sortable">;
/** A field representing a date/time. */
type DateFieldDefinition = {
type: 'date';
} & CommonFieldDefinition & Pick<AllFieldDefinition, "sortable">;
/** A field representing a number. */
type NumberFieldDefinition = {
type: 'number';
} & CommonFieldDefinition & Pick<AllFieldDefinition, "sortable">;
/** A field representing a point on the globe. */
type PointFieldDefinition = {
type: 'point';
} & CommonFieldDefinition;
/** A field representing an array of strings. */
type StringArrayFieldDefinition = {
type: 'string[]';
} & CommonFieldDefinition & Pick<AllFieldDefinition, "sortable" | "caseSensitive" | "normalized" | "separator">;
/** A field representing a whole string. */
type StringFieldDefinition = {
type: 'string';
} & CommonFieldDefinition & Pick<AllFieldDefinition, "sortable" | "caseSensitive" | "normalized" | "separator">;
/** A field representing searchable text. */
type TextFieldDefinition = {
type: 'text';
} & CommonFieldDefinition & Pick<AllFieldDefinition, "sortable" | "normalized" | "matcher" | "stemming" | "weight">;
/** Contains instructions telling how to map a property on an {@link Entity} to Redis. */
type FieldDefinition = BooleanFieldDefinition | DateFieldDefinition | NumberFieldDefinition | PointFieldDefinition | StringArrayFieldDefinition | StringFieldDefinition | TextFieldDefinition;
/** Group of {@link FieldDefinition}s that define the schema for an {@link Entity}. */
type SchemaDefinition = Record<string, FieldDefinition>;
/**
* Describes a field in a {@link Schema}.
*/
declare class Field {
#private;
/**
* Converts this {@link Entity} to a JavaScript object suitable for writing to a Redis Hash.
* @internal
* Creates a Field.
*
* @param name The name of the Field.
* @param definition The underlying {@link FieldDefinition}.
*/
toRedisHash(): RedisHashData;
/**
* Loads this {@link Entity} from Redis Hash data.
* @internal
*/
fromRedisHash(data: RedisHashData): void;
constructor(name: string, definition: FieldDefinition);
/** The name of the field. */
get name(): string;
/** The {@link FieldType | type} of the field. */
get type(): FieldType;
/** The field name used to store this {@link Field} in a Hash. */
get hashField(): string;
/** The JSONPath used to store this {@link Field} in a JSON document. */
get jsonPath(): string;
/** The separator for string[] fields when stored in Hashes. */
get separator(): string;
/** Indicates that the field as sortable. */
get sortable(): boolean;
/** The case-sensitivity of the field. */
get caseSensitive(): boolean;
/** Indicates the field as being indexed—and thus queryable—by RediSearch. */
get indexed(): boolean;
/** Indicates that the field as indexed with stemming support. */
get stemming(): boolean;
/** Indicates that the field is normalized. Ignored if sortable is false. */
get normalized(): boolean;
/** The search weight of the field. */
get weight(): number | null;
/** The phonetic matcher for the field. */
get matcher(): string | null;
}
/**
* A constructor that creates an {@link Entity} of type TEntity.
* @template TEntity The {@link Entity} type.
*/
declare type EntityConstructor<TEntity> = new (schema: Schema<any>, id: string, data?: EntityData) => TEntity;
/** The type of data structure in Redis to map objects to. */
declare type DataStructure = 'HASH' | 'JSON';
/** A function that generates random {@link Entity.entityId | Entity IDs}. */
declare type IdStrategy = () => string;
type DataStructure = 'HASH' | 'JSON';
/** A function that generates random entityIds. */
type IdStrategy = () => Promise<string>;
/** Valid values for how to use stop words for a given {@link Schema}. */
declare type StopWordOptions = 'OFF' | 'DEFAULT' | 'CUSTOM';
/**
* Configuration options for a {@link Schema}.
*/
declare type SchemaOptions = {
type StopWordOptions = 'OFF' | 'DEFAULT' | 'CUSTOM';
/** Configuration options for a {@link Schema}. */
type SchemaOptions = {
/**
* The string that comes before the ID when creating Redis keys for
* {@link Entity | Entities}. Defaults to the class name of the {@link Entity}.
* Combined with the results of idStrategy to generate a key. If prefix is `Foo`
* and idStrategy returns `12345` then the generated key would be `Foo:12345`.
* */
prefix?: string;
/**
* The name used by RediSearch to store the index for this {@link Schema}. Defaults

@@ -115,9 +181,10 @@ * to prefix followed by `:index`. So, for a prefix of `Foo`, it would use `Foo:index`.

/** The data structure used to store the {@link Entity} in Redis. Can be set
* to either `JSON` or `HASH`. Defaults to JSON. */
* to either `JSON` or `HASH`. Defaults to JSON.
*/
dataStructure?: DataStructure;
/**
* A function that generates a random {@link Entity.entityId | Entity ID}. Defaults
* to a function that generates [ULIDs](https://github.com/ulid/spec). Combined with
* prefix to generate a Redis key. If prefix is `Foo` and idStratgey returns `12345`
* then the generated key would be `Foo:12345`.
* A function that generates a random entityId. Defaults to a function that generates
* [ULIDs](https://github.com/ulid/spec). Combined with prefix to generate a Redis key.
* If prefix is `Foo` and idStratgey returns `12345` then the generated key would be
* `Foo:12345`.
*/

@@ -137,148 +204,11 @@ idStrategy?: IdStrategy;

stopWords?: Array<string>;
/**
* Whether fields are indexed by default
*/
indexedDefault?: boolean;
};
/**
* Valid types a {@link FieldDefinition}.
*/
declare type SchemaFieldType = 'string' | 'number' | 'boolean' | 'text' | 'date' | 'point' | 'string[]';
/** Base interface for all fields. */
interface BaseFieldDefinition {
/** The type of the field (i.e. string, number, boolean, etc.) */
type: SchemaFieldType;
/**
* The default field name in Redis is the key name defined in the
* {@link SchemaDefinition}. Overrides the Redis key name if set.
*/
alias?: string;
/**
* Is this field indexed and thus searchable with Redis OM. Defaults
* to the schema indexedDefault value, currently true.
*/
indexed?: boolean;
}
/** Mixin for adding sortability to a field. */
interface SortableFieldDefinition {
/** Enables sorting by this field. */
sortable?: boolean;
}
/** A field representing a boolean. */
interface BooleanFieldDefinition extends BaseFieldDefinition, SortableFieldDefinition {
/** Yep. It's a boolean. */
type: 'boolean';
}
/** Mixin for adding caseSensitive to a TAG field. */
interface CaseSensitiveFieldDefinition {
/**
* Is the original case of this field indexed with Redis OM. Defaults
* to false.
*/
caseSensitive?: boolean;
}
/** A field representing a date/time. */
interface DateFieldDefinition extends BaseFieldDefinition, SortableFieldDefinition {
/** Yep. It's a date. */
type: 'date';
}
/** A field representing a number. */
interface NumberFieldDefinition extends BaseFieldDefinition, SortableFieldDefinition {
/** Yep. It's a number. */
type: 'number';
}
/** A field representing a point on the globe. */
interface PointFieldDefinition extends BaseFieldDefinition {
/** Yep. It's a point. */
type: 'point';
}
/** Mixin for adding unf to a field. */
interface NormalizedFieldDefinition {
/**
* Is this (sortable) field normalized when indexed. Defaults
* to true.
*/
normalized?: boolean;
}
/** Mixin for adding parsing for TAG fields in RediSearch. */
interface SeparableFieldDefinition {
/**
* Due to how RediSearch works, strings and arrays are sometimes stored the same in Redis, as a
* simple string. This is the separator used to split those strings when it is an array. If your
* StringField contains this separator, this can cause problems. You can change it here to avoid
* those problems. Defaults to `|`.
*/
separator?: string;
}
/** A field representing an array of strings. */
interface StringArrayFieldDefinition extends BaseFieldDefinition, SeparableFieldDefinition, SortableFieldDefinition, CaseSensitiveFieldDefinition, NormalizedFieldDefinition {
/** Yep. It's a string array. */
type: 'string[]';
}
/** A field representing a whole string. */
interface StringFieldDefinition extends BaseFieldDefinition, SeparableFieldDefinition, SortableFieldDefinition, CaseSensitiveFieldDefinition, NormalizedFieldDefinition {
/** Yep. It's a string. */
type: 'string';
}
/** Mixin for adding stemming to a field. */
interface StemmingFieldDefinition {
/**
* Is word stemming applied to this field with Redis OM. Defaults
* to true.
*/
stemming?: boolean;
}
/** Mixin for adding phonetic matching for TEXT fields in RediSearch. */
interface PhoneticFieldDefinition {
/**
* Enables setting the phonetic matcher to use, supported matchers are:
* dm:en - Double Metaphone for English
* dm:fr - Double Metaphone for French
* dm:pt - Double Metaphone for Portuguese
* dm:es - Double Metaphone for Spanish
*/
matcher?: 'dm:en' | 'dm:fr' | 'dm:pt' | 'dm:es';
}
/** Mixin for adding weight for TEXT fields in RediSearch. */
interface WeightFieldDefinition {
/** Enables setting the weight to apply to a text field */
weight?: number;
}
/** A field representing searchable text. */
interface TextFieldDefinition extends BaseFieldDefinition, SortableFieldDefinition, StemmingFieldDefinition, PhoneticFieldDefinition, NormalizedFieldDefinition, WeightFieldDefinition {
/** Yep. It's searchable text. */
type: 'text';
}
/** Contains instructions telling how to map a property on an {@link Entity} to Redis. */
declare type FieldDefinition = StringFieldDefinition | TextFieldDefinition | NumberFieldDefinition | BooleanFieldDefinition | PointFieldDefinition | DateFieldDefinition | StringArrayFieldDefinition;
/**
* Group of {@link FieldDefinition}s that define the schema for an {@link Entity}.
*/
declare type SchemaDefinition = Record<string, FieldDefinition>;
/**
* Defines a schema that determines how an {@link Entity} is mapped to Redis
* data structures. Construct by passing in an {@link EntityConstructor},
* Defines a schema that determines how an {@link Entity} is mapped
* to Redis data structures. Construct by passing in a schema name,
* a {@link SchemaDefinition}, and optionally {@link SchemaOptions}:
*
* ```typescript
* const schema = new Schema(Foo, {
* const schema = new Schema('foo', {
* aString: { type: 'string' },

@@ -293,3 +223,3 @@ * aNumber: { type: 'number' },

* dataStructure: 'HASH'
* });
* })
* ```

@@ -299,26 +229,28 @@ *

* its constructor.
*
* @template TEntity The {@link Entity} this Schema defines.
*/
declare class Schema<TEntity extends Entity> {
declare class Schema {
#private;
/**
* The provided {@link EntityConstructor}.
* @internal
* Constructs a Schema.
*
* @param schemaName The name of the schema. Prefixes the ID when creating Redis keys.
* @param schemaDef Defines all of the fields for the Schema and how they are mapped to Redis.
* @param options Additional options for this Schema.
*/
readonly entityCtor: EntityConstructor<TEntity>;
constructor(schemaName: string, schemaDef: SchemaDefinition, options?: SchemaOptions);
/**
* The provided {@link SchemaDefinition}.
* @internal
* The name of the schema. Prefixes the ID when creating Redis keys. Combined
* with the results of idStrategy to generate a key. If name is `foo` and
* idStrategy returns `12345` then the generated key would be `foo:12345`.
*/
readonly definition: SchemaDefinition;
private options?;
get schemaName(): string;
/** The {@link Field | Fields} defined by this Schema. */
get fields(): Field[];
/**
* @template TEntity The {@link Entity} this Schema defines.
* @param ctor A constructor that creates an {@link Entity} of type TEntity.
* @param schemaDef Defines all of the fields for the Schema and how they are mapped to Redis.
* @param options Additional options for this Schema.
* Gets a single {@link Field} defined by this Schema.
*
* @param name The name of the {@link Field} in this Schema.
* @returns The {@link Field}, or null of not found.
*/
constructor(ctor: EntityConstructor<TEntity>, schemaDef: SchemaDefinition, options?: SchemaOptions);
/** The configured keyspace prefix in Redis for this Schema. */
get prefix(): string;
fieldByName(name: string): Field | null;
/** The configured name for the RediSearch index for this Schema. */

@@ -331,8 +263,7 @@ get indexName(): string;

* that this Schema uses to store {@link Entity | Entities} in Redis.
* */
*/
get dataStructure(): DataStructure;
/**
* The configured usage of stop words, a string with the value of either `OFF`, `DEFAULT`,
* or `CUSTOM`. See {@link SchemaOptions.useStopWords} and {@link SchemaOptions.stopWords}
* for more details.
* or `CUSTOM`. See {@link SchemaOptions} for more details.
*/

@@ -346,17 +277,12 @@ get useStopWords(): StopWordOptions;

/**
* The configured indexed default setting for fields
* Generates a unique string using the configured {@link IdStrategy}.
*
* @returns The generated id.
*/
get indexedDefault(): boolean;
/** The hash value of this index. Stored in Redis under {@link Schema.indexHashName}. */
get indexHash(): string;
/** @internal */
get redisSchema(): Array<string>;
generateId(): Promise<string>;
/**
* Generates a unique string using the configured {@link IdStrategy}.
* @returns
* A hash for this Schema that is used to determine if the Schema has been
* changed when calling {@link Repository#createIndex}.
*/
generateId(): string;
private defineProperties;
private validateOptions;
private validateFieldDef;
get indexHash(): string;
}

@@ -374,5 +300,5 @@

declare type Units = 'm' | 'km' | 'ft' | 'mi';
type Units = 'm' | 'km' | 'ft' | 'mi';
/** A function that defines a circle for `.inCircle` searches. */
declare type CircleFunction = (circle: Circle) => Circle;
type CircleFunction = (circle: Circle) => Circle;
/** A builder that defines a circle. */

@@ -493,3 +419,3 @@ declare class Circle {

*/
interface WhereField<TEntity> extends Where {
interface WhereField extends Where {
/**

@@ -503,3 +429,3 @@ * Adds an equals comparison to the query.

*/
eq(value: string | number | boolean | Date): Search<TEntity>;
eq(value: string | number | boolean | Date): Search;
/**

@@ -513,3 +439,3 @@ * Adds an equals comparison to the query.

*/
equal(value: string | number | boolean | Date): Search<TEntity>;
equal(value: string | number | boolean | Date): Search;
/**

@@ -523,3 +449,3 @@ * Adds an equals comparison to the query.

*/
equals(value: string | number | boolean | Date): Search<TEntity>;
equals(value: string | number | boolean | Date): Search;
/**

@@ -533,3 +459,3 @@ * Adds an equals comparison to the query.

*/
equalTo(value: string | number | boolean | Date): Search<TEntity>;
equalTo(value: string | number | boolean | Date): Search;
/**

@@ -540,3 +466,3 @@ * Adds a full-text search comparison to the query.

*/
match(value: string | number | boolean): Search<TEntity>;
match(value: string | number | boolean): Search;
/**

@@ -547,3 +473,3 @@ * Adds a full-text search comparison to the query.

*/
matches(value: string | number | boolean): Search<TEntity>;
matches(value: string | number | boolean): Search;
/**

@@ -554,3 +480,3 @@ * Adds a full-text search comparison to the query that matches an exact word or phrase.

*/
matchExact(value: string | number | boolean): Search<TEntity>;
matchExact(value: string | number | boolean): Search;
/**

@@ -561,3 +487,3 @@ * Adds a full-text search comparison to the query that matches an exact word or phrase.

*/
matchExactly(value: string | number | boolean): Search<TEntity>;
matchExactly(value: string | number | boolean): Search;
/**

@@ -568,3 +494,3 @@ * Adds a full-text search comparison to the query that matches an exact word or phrase.

*/
matchesExactly(value: string | number | boolean): Search<TEntity>;
matchesExactly(value: string | number | boolean): Search;
/**

@@ -575,3 +501,3 @@ * Makes a call to {@link WhereField.match} a {@link WhereField.matchExact} call. Calling

*/
readonly exact: WhereField<TEntity>;
readonly exact: WhereField;
/**

@@ -582,3 +508,3 @@ * Makes a call to {@link WhereField.match} a {@link WhereField.matchExact} call. Calling

*/
readonly exactly: WhereField<TEntity>;
readonly exactly: WhereField;
/**

@@ -588,3 +514,3 @@ * Adds a boolean match with a value of `true` to the query.

*/
true(): Search<TEntity>;
true(): Search;
/**

@@ -594,3 +520,3 @@ * Adds a boolean match with a value of `false` to the query.

*/
false(): Search<TEntity>;
false(): Search;
/**

@@ -601,3 +527,3 @@ * Adds a greater than comparison against a field to the search query.

*/
gt(value: string | number | Date): Search<TEntity>;
gt(value: string | number | Date): Search;
/**

@@ -608,3 +534,3 @@ * Adds a greater than comparison against a field to the search query.

*/
greaterThan(value: string | number | Date): Search<TEntity>;
greaterThan(value: string | number | Date): Search;
/**

@@ -615,3 +541,3 @@ * Adds a greater than or equal to comparison against a field to the search query.

*/
gte(value: string | number | Date): Search<TEntity>;
gte(value: string | number | Date): Search;
/**

@@ -622,3 +548,3 @@ * Adds a greater than or equal to comparison against a field to the search query.

*/
greaterThanOrEqualTo(value: string | number | Date): Search<TEntity>;
greaterThanOrEqualTo(value: string | number | Date): Search;
/**

@@ -629,3 +555,3 @@ * Adds a less than comparison against a field to the search query.

*/
lt(value: string | number | Date): Search<TEntity>;
lt(value: string | number | Date): Search;
/**

@@ -636,3 +562,3 @@ * Adds a less than comparison against a field to the search query.

*/
lessThan(value: string | number | Date): Search<TEntity>;
lessThan(value: string | number | Date): Search;
/**

@@ -643,3 +569,3 @@ * Adds a less than or equal to comparison against a field to the search query.

*/
lte(value: string | number | Date): Search<TEntity>;
lte(value: string | number | Date): Search;
/**

@@ -650,3 +576,3 @@ * Adds a less than or equal to comparison against a field to the search query.

*/
lessThanOrEqualTo(value: string | number | Date): Search<TEntity>;
lessThanOrEqualTo(value: string | number | Date): Search;
/**

@@ -658,3 +584,3 @@ * Adds an inclusive range comparison against a field to the search query.

*/
between(lower: string | number | Date, upper: string | number | Date): Search<TEntity>;
between(lower: string | number | Date, upper: string | number | Date): Search;
/**

@@ -665,3 +591,3 @@ * Adds a whole-string match for a value within a string array to the search query.

*/
contain(value: string): Search<TEntity>;
contain(value: string): Search;
/**

@@ -672,3 +598,3 @@ * Adds a whole-string match for a value within a string array to the search query.

*/
contains(value: string): Search<TEntity>;
contains(value: string): Search;
/**

@@ -680,3 +606,3 @@ * Adds a whole-string match against a string array to the query. If any of the provided

*/
containOneOf(...value: Array<string>): Search<TEntity>;
containOneOf(...value: Array<string>): Search;
/**

@@ -688,3 +614,3 @@ * Adds a whole-string match against a string array to the query. If any of the provided

*/
containsOneOf(...value: Array<string>): Search<TEntity>;
containsOneOf(...value: Array<string>): Search;
/**

@@ -695,3 +621,3 @@ * Adds a search for points that fall within a defined circle.

*/
inCircle(circleFn: CircleFunction): Search<TEntity>;
inCircle(circleFn: CircleFunction): Search;
/**

@@ -702,3 +628,3 @@ * Adds a search for points that fall within a defined radius.

*/
inRadius(circleFn: CircleFunction): Search<TEntity>;
inRadius(circleFn: CircleFunction): Search;
/**

@@ -709,3 +635,3 @@ * Add a search for an exact UTC datetime to the query.

*/
on(value: string | number | Date): Search<TEntity>;
on(value: string | number | Date): Search;
/**

@@ -716,3 +642,3 @@ * Add a search that matches all datetimes *before* the provided UTC datetime to the query.

*/
before(value: string | number | Date): Search<TEntity>;
before(value: string | number | Date): Search;
/**

@@ -723,3 +649,3 @@ * Add a search that matches all datetimes *after* the provided UTC datetime to the query.

*/
after(value: string | number | Date): Search<TEntity>;
after(value: string | number | Date): Search;
/**

@@ -730,3 +656,3 @@ * Add a search that matches all datetimes *on or before* the provided UTC datetime to the query.

*/
onOrBefore(value: string | number | Date): Search<TEntity>;
onOrBefore(value: string | number | Date): Search;
/**

@@ -737,3 +663,3 @@ * Add a search that matches all datetimes *on or after* the provided UTC datetime to the query.

*/
onOrAfter(value: string | number | Date): Search<TEntity>;
onOrAfter(value: string | number | Date): Search;
}

@@ -745,10 +671,10 @@ /**

*/
declare abstract class WhereField<TEntity extends Entity> {
declare abstract class WhereField {
private negated;
/** @internal */
protected search: Search<TEntity>;
protected search: Search;
/** @internal */
protected field: String;
protected field: Field;
/** @internal */
constructor(search: Search<TEntity>, field: string);
constructor(search: Search, field: Field);
/**

@@ -781,3 +707,7 @@ * Returns the current instance. Syntactic sugar to make your code more fluent.

*/
declare type SubSearchFunction<TEntity extends Entity> = (search: Search<TEntity>) => Search<TEntity>;
type SubSearchFunction = (search: Search) => Search;
type SortOptions = {
BY: string;
DIRECTION: 'ASC' | 'DESC';
};
/**

@@ -788,11 +718,11 @@ * Abstract base class for {@link Search} and {@link RawSearch} that

*/
declare abstract class AbstractSearch<TEntity extends Entity> {
declare abstract class AbstractSearch {
/** @internal */
protected schema: Schema<TEntity>;
protected schema: Schema;
/** @internal */
protected client: Client;
/** @internal */
protected sort?: SortOptions;
protected sortOptions?: SortOptions;
/** @internal */
constructor(schema: Schema<TEntity>, client: Client);
constructor(schema: Schema, client: Client);
/** @internal */

@@ -805,7 +735,7 @@ abstract get query(): string;

*/
sortAscending(field: string): AbstractSearch<TEntity>;
sortAscending(field: string): AbstractSearch;
/**
* Alias for {@link Search.sortDescending}.
*/
sortDesc(field: string): AbstractSearch<TEntity>;
sortDesc(field: string): AbstractSearch;
/**

@@ -816,7 +746,7 @@ * Applies a descending sort to the query.

*/
sortDescending(field: string): AbstractSearch<TEntity>;
sortDescending(field: string): AbstractSearch;
/**
* Alias for {@link Search.sortAscending}.
*/
sortAsc(field: string): AbstractSearch<TEntity>;
sortAsc(field: string): AbstractSearch;
/**

@@ -828,3 +758,3 @@ * Applies sorting for the query.

*/
sortBy(field: string, order?: 'ASC' | 'DESC'): AbstractSearch<TEntity>;
sortBy(fieldName: string, order?: 'ASC' | 'DESC'): AbstractSearch;
/**

@@ -835,3 +765,3 @@ * Finds the {@link Entity} with the minimal value for a field.

*/
min(field: string): Promise<TEntity | null>;
min(field: string): Promise<Entity | null>;
/**

@@ -854,3 +784,3 @@ * Finds the entity ID with the minimal value for a field.

*/
max(field: string): Promise<TEntity | null>;
max(field: string): Promise<Entity | null>;
/**

@@ -879,3 +809,3 @@ * Finds the entity ID with the maximal value for a field.

*/
page(offset: number, count: number): Promise<TEntity[]>;
page(offset: number, count: number): Promise<Entity[]>;
/**

@@ -898,3 +828,3 @@ * Returns a page of entity IDs that match this query.

*/
first(): Promise<TEntity | null>;
first(): Promise<Entity | null>;
/**

@@ -915,3 +845,3 @@ * Returns the first entity ID that matches this query.

* ```typescript
* const entities = await repository.search().returnAll({ pageSize: 100 });
* const entities = await repository.search().returnAll({ pageSize: 100 })
* ```

@@ -925,3 +855,3 @@ *

pageSize: number;
}): Promise<TEntity[]>;
}): Promise<Entity[]>;
/**

@@ -934,3 +864,3 @@ * Returns all the entity IDs that match this query. This method

* ```typescript
* const keys = await repository.search().returnAllIds({ pageSize: 100 });
* const keys = await repository.search().returnAllIds({ pageSize: 100 })
* ```

@@ -952,3 +882,3 @@ *

* ```typescript
* const keys = await repository.search().returnAllKeys({ pageSize: 100 });
* const keys = await repository.search().returnAllKeys({ pageSize: 100 })
* ```

@@ -967,7 +897,7 @@ *

*/
get return(): AbstractSearch<TEntity>;
get return(): AbstractSearch;
/**
* Alias for {@link Search.min}.
*/
returnMin(field: string): Promise<TEntity | null>;
returnMin(field: string): Promise<Entity | null>;
/**

@@ -984,3 +914,3 @@ * Alias for {@link Search.minId}.

*/
returnMax(field: string): Promise<TEntity | null>;
returnMax(field: string): Promise<Entity | null>;
/**

@@ -1001,3 +931,3 @@ * Alias for {@link Search.maxId}.

*/
returnPage(offset: number, count: number): Promise<TEntity[]>;
returnPage(offset: number, count: number): Promise<Entity[]>;
/**

@@ -1008,3 +938,3 @@ * Alias for {@link Search.pageOfIds}.

/**
* Alias for {@link Search.pageOrKeys}.
* Alias for {@link Search.pageOfKeys}.
*/

@@ -1015,3 +945,3 @@ returnPageOfKeys(offset: number, count: number): Promise<string[]>;

*/
returnFirst(): Promise<TEntity | null>;
returnFirst(): Promise<Entity | null>;
/**

@@ -1030,3 +960,3 @@ * Alias for {@link Search.firstId}.

pageSize: number;
}): Promise<TEntity[]>;
}): Promise<Entity[]>;
/**

@@ -1044,5 +974,4 @@ * Alias for {@link Search.allIds}.

}): Promise<string[]>;
private allThings;
private callSearch;
private keysToEntityIds;
private keyToEntityId;
}

@@ -1055,6 +984,6 @@ /**

*/
declare class RawSearch<TEntity extends Entity> extends AbstractSearch<TEntity> {
declare class RawSearch extends AbstractSearch {
private rawQuery;
/** @internal */
constructor(schema: Schema<TEntity>, client: Client, query?: string);
constructor(schema: Schema, client: Client, query?: string);
/** @internal */

@@ -1068,3 +997,3 @@ get query(): string;

*/
declare class Search<TEntity extends Entity> extends AbstractSearch<TEntity> {
declare class Search extends AbstractSearch {
private rootWhere?;

@@ -1079,3 +1008,3 @@ /** @internal */

*/
where(field: string): WhereField<TEntity>;
where(field: string): WhereField;
/**

@@ -1087,3 +1016,3 @@ * Sets up a nested search. If there are multiple calls to {@link Search.where},

*/
where(subSearchFn: SubSearchFunction<TEntity>): Search<TEntity>;
where(subSearchFn: SubSearchFunction): Search;
/**

@@ -1094,3 +1023,3 @@ * Sets up a query matching a particular field as a logical AND.

*/
and(field: string): WhereField<TEntity>;
and(field: string): WhereField;
/**

@@ -1101,3 +1030,3 @@ * Sets up a nested search as a logical AND.

*/
and(subSearchFn: SubSearchFunction<TEntity>): Search<TEntity>;
and(subSearchFn: SubSearchFunction): Search;
/**

@@ -1108,3 +1037,3 @@ * Sets up a query matching a particular field as a logical OR.

*/
or(field: string): WhereField<TEntity>;
or(field: string): WhereField;
/**

@@ -1115,3 +1044,3 @@ * Sets up a nested search as a logical OR.

*/
or(subSearchFn: SubSearchFunction<TEntity>): Search<TEntity>;
or(subSearchFn: SubSearchFunction): Search;
private anyWhere;

@@ -1127,49 +1056,53 @@ private anyWhereForField;

* {@link Client.fetchRepository} and passing in a {@link Schema}. Then
* use the {@link Repository.fetch}, {@link Repository.save}, and
* {@link Repository.remove} methods to manage your data:
* use the {@link Repository#fetch}, {@link Repository#save}, and
* {@link Repository#remove} methods to manage your data:
*
* ```typescript
* const repository = client.fetchRepository<Foo>(schema);
* const repository = client.fetchRepository(schema)
*
* const foo = await repository.fetch('01FK6TCJBDK41RJ766A4SBWDJ9');
* foo.aString = 'bar';
* foo.aBoolean = false;
* await repository.save(foo);
* const foo = await repository.fetch('01FK6TCJBDK41RJ766A4SBWDJ9')
* foo.aString = 'bar'
* foo.aBoolean = false
* await repository.save(foo)
* ```
*
* Be sure to use the repository to create a new instance of an
* {@link Entity} you want to create before you save it:
* Use the repository to create a new instance of an {@link Entity}
* before you save it:
*
* ```typescript
* const foo = await repository.createEntity();
* foo.aString = 'bar';
* foo.aBoolean = false;
* await repository.save(foo);
* const foo = await repository.createEntity()
* foo.aString = 'bar'
* foo.aBoolean = false
* await repository.save(foo)
* ```
*
* If you want to the {@link Repository.search} method, you need to create an index
* If you want to use the {@link Repository#search} method, you need to create an index
* first, and you need RediSearch or RedisJSON installed on your instance of Redis:
*
* ```typescript
* await repository.createIndex();
* await repository.createIndex()
* const entities = await repository.search()
* .where('aString').eq('bar')
* .and('aBoolean').is.false().returnAll();
* .and('aBoolean').is.false().returnAll()
* ```
*
* @template TEntity The type of {@link Entity} that this repository manages.
*/
declare abstract class Repository<TEntity extends Entity> {
protected client: Client;
protected schema: Schema<TEntity>;
/** @internal */
constructor(schema: Schema<TEntity>, client: Client);
declare class Repository {
#private;
private client;
/**
* Creates an index in Redis for use by the {@link Repository.search} method. Requires
* that RediSearch or RedisJSON is installed on your instance of Redis.
* Creates a new {@link Repository}.
*
* @param schema The schema defining that data in the repository.
* @param client A client to talk to Redis.
*/
constructor(schema: Schema, clientOrConnection: Client | RedisConnection);
/**
* Creates an index in Redis for use by the {@link Repository#search} method.
* Does not create a new index if the index hasn't changed. Requires that
* RediSearch and RedisJSON are installed on your instance of Redis.
*/
createIndex(): Promise<void>;
/**
* Removes an existing index from Redis. Use this method if you want to swap out your index
* because your {@link Entity} has changed. Requires that RediSearch or RedisJSON is installed
* because your {@link Entity} has changed. Requires that RediSearch and RedisJSON are installed
* on your instance of Redis.

@@ -1179,48 +1112,45 @@ */

/**
* Creates an {@link Entity} with a populated {@link Entity.entityId} property.
* @param data Optional values with which to initialize the entity.
* @returns A newly created Entity.
* Insert or update an {@link Entity} to Redis using its entityId property
* if present. If it's not, one is generated.
*
* @param entity The Entity to save.
* @returns A copy of the provided Entity with EntityId and EntityKeyName properties added.
*/
createEntity(data?: EntityData): TEntity;
save(entity: Entity): Promise<Entity>;
/**
* Save the {@link Entity} to Redis. If it already exists, it will be updated. If it doesn't
* exist, it will be created.
* Insert or update the {@link Entity} to Redis using the provided entityId.
*
* @param id The id to save the Entity under.
* @param entity The Entity to save.
* @returns The ID of the Entity just saved.
* @returns A copy of the provided Entity with EntityId and EntityKeyName properties added.
*/
save(entity: TEntity): Promise<string>;
save(id: string, entity: Entity): Promise<Entity>;
/**
* Creates and saves an {@link Entity}. Equivalent of calling
* {@link Repository.createEntity} followed by {@link Repository.save}.
* @param data Optional values with which to initialize the entity.
* @returns The newly created and saved Entity.
*/
createAndSave(data?: EntityData): Promise<TEntity>;
/**
* Read and return an {@link Entity} from Redis with the given id. If
* the {@link Entity} is not found, returns an {@link Entity} with all
* properties set to `null`.
* Read and return an {@link Entity} from Redis for the given id. If
* the {@link Entity} is not found, returns an empty {@link Entity}.
*
* @param id The ID of the {@link Entity} you seek.
* @returns The matching Entity.
*/
fetch(id: string): Promise<TEntity>;
fetch(id: string): Promise<Entity>;
/**
* Read and return the {@link Entity | Entities} from Redis with the given IDs. If
* a particular {@link Entity} is not found, returns an {@link Entity} with all
* properties set to `null`.
* a particular {@link Entity} is not found, returns that {@link Entity} as empty.
*
* @param ids The IDs of the {@link Entity | Entities} you seek.
* @returns The matching Entities.
*/
fetch(...ids: string[]): Promise<TEntity[]>;
fetch(...ids: string[]): Promise<Entity[]>;
/**
* Read and return the {@link Entity | Entities} from Redis with the given IDs. If
* a particular {@link Entity} is not found, returns an {@link Entity} with all
* properties set to `null`.
* a particular {@link Entity} is not found, returns that {@link Entity} as empty.
*
* @param ids The IDs of the {@link Entity | Entities} you seek.
* @returns The matching Entities.
*/
fetch(ids: string[]): Promise<TEntity[]>;
fetch(ids: string[]): Promise<Entity[]>;
/**
* Remove an {@link Entity} from Redis with the given id. If the {@link Entity} is
* Remove an {@link Entity} from Redis for the given id. If the {@link Entity} is
* not found, does nothing.
*
* @param id The ID of the {@link Entity} you wish to delete.

@@ -1230,4 +1160,5 @@ */

/**
* Remove the {@link Entity | Entities} from Redis with the given ids. If a
* Remove the {@link Entity | Entities} from Redis for the given ids. If a
* particular {@link Entity} is not found, does nothing.
*
* @param ids The IDs of the {@link Entity | Entities} you wish to delete.

@@ -1237,4 +1168,5 @@ */

/**
* Remove the {@link Entity | Entities} from Redis with the given ids. If a
* Remove the {@link Entity | Entities} from Redis for the given ids. If a
* particular {@link Entity} is not found, does nothing.
*
* @param ids The IDs of the {@link Entity | Entities} you wish to delete.

@@ -1246,2 +1178,3 @@ */

* found, does nothing.
*
* @param id The ID of the {@link Entity} to set and expiration for.

@@ -1252,70 +1185,75 @@ * @param ttlInSeconds The time to live in seconds.

/**
* Set the time to live of the {@link Entity | Entities} in Redis with the given
* ids. If a particular {@link Entity} is not found, does nothing.
*
* @param ids The IDs of the {@link Entity | Entities} you wish to delete.
*/
expire(ids: string[], ttlInSeconds: number): Promise<void>;
/**
* Kicks off the process of building a query. Requires that RediSearch (and optionally
* RedisJSON) be is installed on your instance of Redis.
* @template TEntity The type of {@link Entity} sought.
* RedisJSON) be installed on your instance of Redis.
*
* @returns A {@link Search} object.
*/
search(): Search<TEntity>;
search(): Search;
/**
* Creates a search that bypassed Redis OM and instead allows you to execute a raw
* Creates a search that bypasses Redis OM and instead allows you to execute a raw
* RediSearch query. Requires that RediSearch (and optionally RedisJSON) be installed
* on your instance of Redis.
* @template TEntity The type of {@link Entity} sought.
*
* Refer to https://redis.io/docs/stack/search/reference/query_syntax/ for details on
* RediSearch query syntax.
*
* @query The raw RediSearch query you want to rune.
* @returns A {@link RawSearch} object.
*/
searchRaw(query: string): RawSearch<TEntity>;
/** @internal */
protected abstract writeEntity(entity: TEntity): Promise<void>;
/** @internal */
protected abstract readEntities(ids: string[]): Promise<TEntity[]>;
/** @internal */
protected makeKeys(ids: string[]): string[];
/** @internal */
protected makeKey(id: string): string;
searchRaw(query: string): RawSearch;
private writeEntity;
private readEntities;
private writeEntityToHash;
private readEntitiesFromHash;
private writeEntityToJson;
private readEntitiesFromJson;
private makeKeys;
private makeKey;
}
declare type RedisConnection = ReturnType<typeof createClient>;
/**
* Alias for a JavaScript object used by HSET.
* @internal
*/
declare type RedisHashData = {
[key: string]: string;
/** A conventional Redis connection. */
type RedisClientConnection = ReturnType<typeof createClient>;
/** A clustered Redis connection. */
type RedisClusterConnection = ReturnType<typeof createCluster>;
/** A Redis connection, clustered or conventional. */
type RedisConnection = RedisClientConnection | RedisClusterConnection;
/** @internal This is a defintion for the type that calls to ft.search in Node Redis return. */
type SearchResults = {
total: number;
documents: SearchDocument[];
};
/**
* Alias for any old JavaScript object used by JSON.SET.
* @internal
*/
declare type RedisJsonData = {
[key: string]: any;
/** @internal This is a defintion for the return type of calls to ft.search in Node Redis. */
type SearchDocument = {
id: string;
value: {
[key: string]: any;
};
};
/** The type of data structure in Redis to map objects to. */
declare type SearchDataStructure = 'HASH' | 'JSON';
/** @internal */
declare type CreateIndexOptions = {
indexName: string;
dataStructure: SearchDataStructure;
schema: Array<string>;
prefix: string;
stopWords?: Array<string>;
type RedisHashData = {
[key: string]: string;
};
/** @internal */
declare type LimitOptions = {
offset: number;
count: number;
type RedisJsonData = {
[key: string]: any;
};
/** @internal */
declare type SortOptions = {
field: string;
order: 'ASC' | 'DESC';
type SearchDataStructure = 'HASH' | 'JSON';
/**
* @internal This is a simplified redefintion of the CreateOptions type that is not exported by Node Redis.
* TODO: Remove this type once CreateOptions is exported by Node Redis.
* https://github.com/redis/node-redis/blob/master/packages/search/lib/commands/CREATE.ts#L4
*/
type CreateOptions = {
ON: SearchDataStructure;
PREFIX: string;
STOPWORDS?: string[];
};
/** @internal */
declare type SearchOptions = {
indexName: string;
query: string;
limit?: LimitOptions;
sort?: SortOptions;
keysOnly?: boolean;
};
/**

@@ -1327,4 +1265,4 @@ * A Client is the starting point for working with Redis OM. Clients manage the

* ```typescript
* const client = new Client();
* await client.open();
* const client = new Client()
* await client.open()
* ```

@@ -1334,9 +1272,13 @@ *

* its constructor.
*
* @deprecated Just used Node Redis client directly and pass it to the Repository.
*/
declare class Client {
/** @internal */
protected redis?: RedisConnection;
#private;
/** Returns the underlying Node Redis connection being used. */
get redis(): RedisConnection | undefined;
/**
* Attaches an existing Node Redis connection to this Redis OM client. Closes
* any existing connection.
*
* @param connection An existing Node Redis client.

@@ -1347,3 +1289,12 @@ * @returns This {@link Client} instance.

/**
* Attaches an existing Node Redis connection to this Redis OM client. Does
* not close any existing connection.
*
* @param connection An existing Node Redis client.
* @returns This {@link Client} instance.
*/
useNoClose(connection: RedisConnection): Client;
/**
* Open a connection to Redis at the provided URL.
*
* @param url A URL to Redis as defined with the [IANA](https://www.iana.org/assignments/uri-schemes/prov/redis).

@@ -1354,15 +1305,8 @@ * @returns This {@link Client} instance.

/**
* Execute an arbitrary Redis command.
* @template TResult Expect result type such as `string`, `Array<string>`, or whatever complex type Redis returns.
* @param command The command to execute.
* @returns The raw results of calling the Redis command.
*/
execute(command: Array<string | number | boolean>): Promise<unknown>;
/**
* Creates a repository for the given schema.
* @template TEntity The entity type for this {@link Schema} and {@link Repository}.
*
* @param schema The schema.
* @returns A repository for the provided schema.
*/
fetchRepository<TEntity extends Entity>(schema: Schema<TEntity>): Repository<TEntity>;
fetchRepository(schema: Schema): Repository;
/**

@@ -1373,7 +1317,7 @@ * Close the connection to Redis.

/** @internal */
createIndex(options: CreateIndexOptions): Promise<void>;
createIndex(indexName: string, schema: RediSearchSchema, options: CreateOptions): Promise<void>;
/** @internal */
dropIndex(indexName: string): Promise<void>;
/** @internal */
search(options: SearchOptions): Promise<any[]>;
search(indexName: string, query: string, options?: SearchOptions): Promise<SearchResults>;
/** @internal */

@@ -1392,3 +1336,3 @@ unlink(...keys: string[]): Promise<void>;

/** @internal */
jsonget(key: string): Promise<RedisJsonData>;
jsonget(key: string): Promise<RedisJsonData | null>;
/** @internal */

@@ -1400,9 +1344,86 @@ jsonset(key: string, data: RedisJsonData): Promise<void>;

isOpen(): boolean;
private validateRedisOpen;
}
declare class RedisError extends Error {
constructor(message: string);
declare class RedisOmError extends Error {
}
export { AbstractSearch, BaseFieldDefinition, BooleanFieldDefinition, CaseSensitiveFieldDefinition, Circle, CircleFunction, Client, DataStructure, DateFieldDefinition, Entity, EntityConstructor, EntityData, EntityValue, FieldDefinition, IdStrategy, NormalizedFieldDefinition, NumberFieldDefinition, PhoneticFieldDefinition, Point, PointFieldDefinition, RawSearch, RedisError, RedisHashData, RedisJsonData, Repository, Schema, SchemaDefinition, SchemaFieldType, SchemaOptions, Search, SearchDataStructure, SeparableFieldDefinition, SortableFieldDefinition, StemmingFieldDefinition, StopWordOptions, StringArrayFieldDefinition, StringFieldDefinition, SubSearchFunction, TextFieldDefinition, WeightFieldDefinition, Where, WhereField };
declare class InvalidInput extends RedisOmError {
}
declare class NullJsonInput extends InvalidInput {
#private;
constructor(field: Field);
get fieldName(): string;
get fieldType(): FieldType;
get jsonPath(): string;
}
declare class InvalidJsonInput extends InvalidInput {
#private;
constructor(field: Field);
get fieldName(): string;
get fieldType(): FieldType;
get jsonPath(): string;
}
declare class InvalidHashInput extends InvalidInput {
#private;
constructor(field: Field);
get fieldName(): string;
get fieldType(): FieldType;
}
declare class NestedHashInput extends InvalidInput {
#private;
constructor(property: string);
get field(): string;
}
declare class ArrayHashInput extends InvalidInput {
#private;
constructor(property: string);
get field(): string;
}
declare class InvalidSchema extends RedisOmError {
}
declare class InvalidValue extends RedisOmError {
}
declare class NullJsonValue extends InvalidValue {
#private;
constructor(field: Field);
get fieldName(): string;
get fieldType(): FieldType;
get jsonPath(): string;
}
declare class InvalidJsonValue extends InvalidValue {
#private;
constructor(field: Field);
get fieldName(): string;
get fieldType(): FieldType;
get jsonPath(): string;
}
declare class InvalidHashValue extends InvalidValue {
#private;
constructor(field: Field);
get fieldName(): string;
get fieldType(): FieldType;
get hashField(): string;
}
declare class PointOutOfRange extends RedisOmError {
#private;
constructor(point: Point);
get point(): {
longitude: number;
latitude: number;
};
}
declare class SearchError extends RedisOmError {
}
declare class SemanticSearchError extends SearchError {
}
declare class FieldNotInSchema extends SearchError {
#private;
constructor(fieldName: string);
get field(): string;
}
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, NumberFieldDefinition, Point, PointFieldDefinition, PointOutOfRange, RawSearch, RedisClientConnection, RedisClusterConnection, RedisConnection, RedisOmError, Repository, Schema, SchemaDefinition, SchemaOptions, Search, SearchError, SemanticSearchError, StopWordOptions, StringArrayFieldDefinition, StringFieldDefinition, SubSearchFunction, TextFieldDefinition, Where, WhereField };
"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;

@@ -18,2 +20,6 @@ var __export = (target, all) => {

};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

@@ -25,10 +31,27 @@

AbstractSearch: () => AbstractSearch,
ArrayHashInput: () => ArrayHashInput,
Circle: () => Circle,
Client: () => Client,
Entity: () => Entity,
EntityId: () => EntityId,
EntityKeyName: () => EntityKeyName,
Field: () => Field,
FieldNotInSchema: () => FieldNotInSchema,
InvalidHashInput: () => InvalidHashInput,
InvalidHashValue: () => InvalidHashValue,
InvalidInput: () => InvalidInput,
InvalidJsonInput: () => InvalidJsonInput,
InvalidJsonValue: () => InvalidJsonValue,
InvalidSchema: () => InvalidSchema,
InvalidValue: () => InvalidValue,
NestedHashInput: () => NestedHashInput,
NullJsonInput: () => NullJsonInput,
NullJsonValue: () => NullJsonValue,
PointOutOfRange: () => PointOutOfRange,
RawSearch: () => RawSearch,
RedisError: () => RedisError,
RedisOmError: () => RedisOmError,
Repository: () => Repository,
Schema: () => Schema,
Search: () => Search,
SearchError: () => SearchError,
SemanticSearchError: () => SemanticSearchError,
Where: () => Where,

@@ -39,5 +62,675 @@ WhereField: () => WhereField

// lib/client.ts
// lib/client/client.ts
var import_redis2 = require("redis");
// lib/entity/entity.ts
var EntityId = Symbol("entityId");
var EntityKeyName = Symbol("entityKeyName");
// lib/indexer/index-builder.ts
var import_redis = require("redis");
var entryBuilders = { HASH: addHashEntry, JSON: addJsonEntry };
function buildRediSearchSchema(schema) {
const addEntry = entryBuilders[schema.dataStructure];
return schema.fields.reduce(addEntry, {});
}
function addHashEntry(schema, field) {
const hashField = field.hashField;
switch (field.type) {
case "boolean":
schema[hashField] = buildHashBoolean(field);
break;
case "date":
schema[hashField] = buildDateNumber(field);
break;
case "number":
schema[hashField] = buildDateNumber(field);
break;
case "point":
schema[hashField] = buildPoint(field);
break;
case "string[]":
case "string":
schema[hashField] = buildHashString(field);
break;
case "text":
schema[hashField] = buildText(field);
break;
}
return schema;
}
function addJsonEntry(schema, field) {
const jsonPath = field.jsonPath;
switch (field.type) {
case "boolean":
schema[jsonPath] = buildJsonBoolean(field);
break;
case "date":
schema[jsonPath] = buildDateNumber(field);
break;
case "number":
schema[jsonPath] = buildDateNumber(field);
break;
case "point":
schema[jsonPath] = buildPoint(field);
break;
case "string[]":
case "string":
schema[jsonPath] = buildJsonString(field);
break;
case "text":
schema[jsonPath] = buildText(field);
break;
}
return schema;
}
function buildHashBoolean(field) {
const schemaField = { type: import_redis.SchemaFieldTypes.TAG, AS: field.name };
addSortable(schemaField, field);
addIndexed(schemaField, field);
return schemaField;
}
function buildJsonBoolean(field) {
if (field.sortable)
console.warn(`You have marked a boolean field as sortable but RediSearch doesn't support the SORTABLE argument on a TAG for JSON. Ignored.`);
const schemaField = { type: import_redis.SchemaFieldTypes.TAG, AS: field.name };
addIndexed(schemaField, field);
return schemaField;
}
function buildDateNumber(field) {
const schemaField = { type: import_redis.SchemaFieldTypes.NUMERIC, AS: field.name };
addSortable(schemaField, field);
addIndexed(schemaField, field);
return schemaField;
}
function buildPoint(field) {
const schemaField = { type: import_redis.SchemaFieldTypes.GEO, AS: field.name };
addIndexed(schemaField, field);
return schemaField;
}
function buildHashString(field) {
const schemaField = { type: import_redis.SchemaFieldTypes.TAG, AS: field.name };
addCaseInsensitive(schemaField, field), addSeparable(schemaField, field), addSortable(schemaField, field);
addIndexed(schemaField, field);
return schemaField;
}
function buildJsonString(field) {
if (field.sortable)
console.warn(`You have marked a ${field.type} field as sortable but RediSearch doesn't support the SORTABLE argument on a TAG for JSON. Ignored.`);
const schemaField = { type: import_redis.SchemaFieldTypes.TAG, AS: field.name };
addCaseInsensitive(schemaField, field), addSeparable(schemaField, field), addIndexed(schemaField, field);
return schemaField;
}
function buildText(field) {
const schemaField = { type: import_redis.SchemaFieldTypes.TEXT, AS: field.name };
addSortable(schemaField, field);
addStemming(schemaField, field);
addIndexed(schemaField, field);
addPhonetic(schemaField, field);
addWeight(schemaField, field);
return schemaField;
}
function addCaseInsensitive(schemaField, field) {
if (field.caseSensitive)
schemaField.CASESENSITIVE = true;
}
function addIndexed(schemaField, field) {
if (!field.indexed)
schemaField.NOINDEX = true;
}
function addStemming(schemaField, field) {
if (!field.stemming)
schemaField.NOSTEM = true;
}
function addPhonetic(schemaField, field) {
if (field.matcher)
schemaField.PHONETIC = field.matcher;
}
function addSeparable(schemaField, field) {
schemaField.SEPARATOR = field.separator;
}
function addSortable(schemaField, field) {
if (field.normalized) {
if (field.sortable)
schemaField.SORTABLE = true;
} else {
schemaField.SORTABLE = "UNF";
}
}
function addWeight(schemaField, field) {
if (field.weight)
schemaField.WEIGHT = field.weight;
}
// lib/error/redis-om-error.ts
var RedisOmError = class extends Error {
};
// lib/error/invalid-input.ts
var InvalidInput = class extends RedisOmError {
};
var NullJsonInput = class extends InvalidInput {
#field;
constructor(field) {
const message = `Null or undefined found in field '${field.name}' of type '${field.type}' in JSON at "${field.jsonPath}".`;
super(message);
this.#field = field;
}
get fieldName() {
return this.#field.name;
}
get fieldType() {
return this.#field.type;
}
get jsonPath() {
return this.#field.jsonPath;
}
};
var InvalidJsonInput = class extends InvalidInput {
#field;
constructor(field) {
const message = `Unexpected value for field '${field.name}' of type '${field.type}' in JSON at "${field.jsonPath}".`;
super(message);
this.#field = field;
}
get fieldName() {
return this.#field.name;
}
get fieldType() {
return this.#field.type;
}
get jsonPath() {
return this.#field.jsonPath;
}
};
var InvalidHashInput = class extends InvalidInput {
#field;
constructor(field) {
const message = `Unexpected value for field '${field.name}' of type '${field.type}' in Hash.`;
super(message);
this.#field = field;
}
get fieldName() {
return this.#field.name;
}
get fieldType() {
return this.#field.type;
}
};
var NestedHashInput = class extends InvalidInput {
#property;
constructor(property) {
const message = `Unexpected object in Hash at property '${property}'. You can not store a nested object in a Redis Hash.`;
super(message);
this.#property = property;
}
get field() {
return this.#property;
}
};
var ArrayHashInput = class extends InvalidInput {
#property;
constructor(property) {
const message = `Unexpected array in Hash at property '${property}'. You can not store an array in a Redis Hash without defining it in the Schema.`;
super(message);
this.#property = property;
}
get field() {
return this.#property;
}
};
// lib/error/invalid-schema.ts
var InvalidSchema = class extends RedisOmError {
};
// lib/error/invalid-value.ts
var InvalidValue = class extends RedisOmError {
};
var NullJsonValue = class extends InvalidValue {
#field;
constructor(field) {
const message = `Null or undefined found in field '${field.name}' of type '${field.type}' from JSON path "${field.jsonPath}" in Redis.`;
super(message);
this.#field = field;
}
get fieldName() {
return this.#field.name;
}
get fieldType() {
return this.#field.type;
}
get jsonPath() {
return this.#field.jsonPath;
}
};
var InvalidJsonValue = class extends InvalidValue {
#field;
constructor(field) {
const message = `Unexpected value for field '${field.name}' of type '${field.type}' from JSON path "${field.jsonPath}" in Redis.`;
super(message);
this.#field = field;
}
get fieldName() {
return this.#field.name;
}
get fieldType() {
return this.#field.type;
}
get jsonPath() {
return this.#field.jsonPath;
}
};
var InvalidHashValue = class extends InvalidValue {
#field;
constructor(field) {
const message = `Unexpected value for field '${field.name}' of type '${field.type}' from Hash field "${field.hashField}" read from Redis.`;
super(message);
this.#field = field;
}
get fieldName() {
return this.#field.name;
}
get fieldType() {
return this.#field.type;
}
get hashField() {
return this.#field.hashField;
}
};
// lib/error/point-out-of-range.ts
var PointOutOfRange = class extends RedisOmError {
#latitude;
#longitude;
constructor(point) {
super("Points must be between \xB185.05112878 latitude and \xB1180 longitude.");
this.#longitude = point.longitude;
this.#latitude = point.latitude;
}
get point() {
return { longitude: this.#longitude, latitude: this.#latitude };
}
};
// lib/error/search-error.ts
var SearchError = class extends RedisOmError {
};
var SemanticSearchError = class extends SearchError {
};
var FieldNotInSchema = class extends SearchError {
#field;
constructor(fieldName) {
super(`The field '${fieldName}' is not part of the schema and thus cannot be used to search.`);
this.#field = fieldName;
}
get field() {
return this.#field;
}
};
// lib/transformer/transformer-common.ts
var isNull = (value) => value === null;
var isDefined = (value) => value !== void 0;
var isUndefined = (value) => value === void 0;
var isNotNullish = (value) => value !== void 0 && value !== null;
var isBoolean = (value) => typeof value === "boolean";
var isNumber = (value) => typeof value === "number";
var isString = (value) => typeof value === "string";
var isDate = (value) => value instanceof Date;
var isDateString = (value) => isString(value) && !isNaN(new Date(value).getTime());
var isArray = (value) => Array.isArray(value);
var isObject = (value) => value !== null && typeof value === "object" && !isArray(value) && !isDate(value);
var isPoint = (value) => isObject(value) && Object.keys(value).length === 2 && typeof value.latitude === "number" && typeof value.longitude === "number";
var isNumberString = (value) => !isNaN(Number(value));
var isPointString = (value) => /^-?\d+(\.\d*)?,-?\d+(\.\d*)?$/.test(value);
var isValidPoint = (value) => Math.abs(value.latitude) <= 85.05112878 && Math.abs(value.longitude) <= 180;
var convertBooleanToString = (value) => value ? "1" : "0";
var convertNumberToString = (value) => value.toString();
var convertStringToNumber = (value) => Number.parseFloat(value);
var convertDateToEpoch = (value) => value.getTime() / 1e3;
var convertDateToString = (value) => convertDateToEpoch(value).toString();
var convertEpochDateToString = (value) => convertNumberToString(value);
var convertIsoDateToEpoch = (value) => convertDateToEpoch(new Date(value));
var convertIsoDateToString = (value) => convertDateToString(new Date(value));
var convertEpochStringToDate = (value) => new Date(convertEpochToDate(convertStringToNumber(value)));
var convertEpochToDate = (value) => new Date(value * 1e3);
var convertPointToString = (value) => {
if (isValidPoint(value))
return `${value.longitude},${value.latitude}`;
throw new PointOutOfRange(value);
};
var convertStringToPoint = (value) => {
const [longitude, latitude] = value.split(",").map(convertStringToNumber);
return { longitude, latitude };
};
function convertKnownValueToString(value) {
if (isBoolean(value))
return value.toString();
if (isNumber(value))
return value.toString();
if (isString(value))
return value;
throw new RedisOmError(`Expected a string but received: ${stringifyError(value)}`);
}
var stringifyError = (value) => JSON.stringify(value, null, 1);
// lib/transformer/from-hash-transformer.ts
function fromRedisHash(schema, hashData) {
const data = { ...hashData };
schema.fields.forEach((field) => {
if (field.hashField)
delete data[field.hashField];
const value = hashData[field.hashField];
if (isNotNullish(value))
data[field.name] = convertKnownValueFromString(field, value);
});
return data;
}
function convertKnownValueFromString(field, value) {
switch (field.type) {
case "boolean":
if (value === "1")
return true;
if (value === "0")
return false;
throw new InvalidHashValue(field);
case "number":
if (isNumberString(value))
return convertStringToNumber(value);
throw new InvalidHashValue(field);
case "date":
if (isNumberString(value))
return convertEpochStringToDate(value);
throw new InvalidHashValue(field);
case "point":
if (isPointString(value))
return convertStringToPoint(value);
throw new InvalidHashValue(field);
case "string":
case "text":
return value;
case "string[]":
return convertStringToStringArray(value, field.separator);
}
}
var convertStringToStringArray = (value, separator) => value.split(separator);
// lib/transformer/from-json-transformer.ts
var import_jsonpath_plus = require("jsonpath-plus");
var import_just_clone = __toESM(require("just-clone"));
function fromRedisJson(schema, json) {
const data = (0, import_just_clone.default)(json);
convertFromRedisJsonKnown(schema, data);
return data;
}
function convertFromRedisJsonKnown(schema, data) {
schema.fields.forEach((field) => {
const path = field.jsonPath;
const results = (0, import_jsonpath_plus.JSONPath)({ resultType: "all", path, json: data });
if (results.length === 1) {
const [{ value, parent, parentProperty }] = results;
parent[parentProperty] = convertKnownValueFromJson(field, value);
} else if (results.length > 1) {
if (field.type === "string[]") {
results.forEach((result) => {
const { value, parent, parentProperty } = result;
if (isNull(value))
throw new NullJsonValue(field);
parent[parentProperty] = convertKnownValueToString(value);
});
}
}
});
}
function convertKnownValueFromJson(field, value) {
if (isNull(value))
return value;
switch (field.type) {
case "boolean":
if (isBoolean(value))
return value;
throw new InvalidJsonValue(field);
case "number":
if (isNumber(value))
return value;
throw new InvalidJsonValue(field);
case "date":
if (isNumber(value))
return convertEpochToDate(value);
throw new InvalidJsonValue(field);
case "point":
if (isPointString(value))
return convertStringToPoint(value);
throw new InvalidJsonValue(field);
case "string":
case "text":
if (isBoolean(value))
return value.toString();
if (isNumber(value))
return value.toString();
if (isString(value))
return value;
throw new InvalidJsonValue(field);
case "string[]":
if (isArray(value))
return convertFromJsonArrayToStringArray(field, value);
throw new NullJsonValue(field);
}
}
var convertFromJsonArrayToStringArray = (field, array) => array.map((value) => {
if (isNull(value))
throw new NullJsonValue(field);
return value.toString();
});
// lib/transformer/to-hash-transformer.ts
function toRedisHash(schema, data) {
const hashData = {};
Object.entries(data).forEach(([key, value]) => {
if (isNotNullish(value)) {
const field = schema.fieldByName(key);
const hashField = field ? field.hashField : key;
hashData[hashField] = field ? convertKnownValueToString2(field, value) : convertUnknownValueToString(key, value);
}
});
return hashData;
}
function convertKnownValueToString2(field, value) {
switch (field.type) {
case "boolean":
if (isBoolean(value))
return convertBooleanToString(value);
throw new InvalidHashInput(field);
case "number":
if (isNumber(value))
return convertNumberToString(value);
throw new InvalidHashInput(field);
case "date":
if (isNumber(value))
return convertEpochDateToString(value);
if (isDate(value))
return convertDateToString(value);
if (isDateString(value))
return convertIsoDateToString(value);
throw new InvalidHashInput(field);
case "point":
if (isPoint(value))
return convertPointToString(value);
throw new InvalidHashInput(field);
case "string":
case "text":
if (isBoolean(value))
return value.toString();
if (isNumber(value))
return value.toString();
if (isString(value))
return value;
throw new InvalidHashInput(field);
case "string[]":
if (isArray(value))
return convertStringArrayToString(value, field.separator);
throw new InvalidHashInput(field);
default:
throw new RedisOmError(`Expected a valid field type but received: ${field.type}`);
}
}
function convertUnknownValueToString(key, value) {
if (isBoolean(value))
return convertBooleanToString(value);
if (isNumber(value))
return convertNumberToString(value);
if (isDate(value))
return convertDateToString(value);
if (isPoint(value))
return convertPointToString(value);
if (isArray(value))
throw new ArrayHashInput(key);
if (isObject(value))
throw new NestedHashInput(key);
return value.toString();
}
var convertStringArrayToString = (value, separator) => value.join(separator);
// lib/transformer/to-json-transformer.ts
var import_jsonpath_plus2 = require("jsonpath-plus");
var import_just_clone2 = __toESM(require("just-clone"));
function toRedisJson(schema, data) {
let json = (0, import_just_clone2.default)(data);
convertToRedisJsonKnown(schema, json);
return convertToRedisJsonUnknown(json);
}
function convertToRedisJsonKnown(schema, json) {
schema.fields.forEach((field) => {
const results = (0, import_jsonpath_plus2.JSONPath)({ resultType: "all", path: field.jsonPath, json });
if (field.type === "string[]") {
convertKnownResultsToJson(field, results);
return;
}
if (results.length === 0)
return;
if (results.length === 1) {
convertKnownResultToJson(field, results[0]);
return;
}
throw new InvalidJsonInput(field);
});
}
function convertToRedisJsonUnknown(json) {
Object.entries(json).forEach(([key, value]) => {
if (isUndefined(value)) {
delete json[key];
} else if (isObject(value)) {
json[key] = convertToRedisJsonUnknown(value);
} else {
json[key] = convertUnknownValueToJson(value);
}
});
return json;
}
function convertKnownResultToJson(field, result) {
const { value, parent, parentProperty } = result;
if (isDefined(value))
parent[parentProperty] = convertKnownValueToJson(field, value);
}
function convertKnownResultsToJson(field, results) {
results.forEach((result) => {
const { value, parent, parentProperty } = result;
if (isNull(value))
throw new NullJsonInput(field);
if (isUndefined(value) && isArray(parent))
throw new NullJsonInput(field);
if (isDefined(value))
parent[parentProperty] = convertKnownValueToString(value);
});
}
function convertKnownValueToJson(field, value) {
if (isNull(value))
return value;
switch (field.type) {
case "boolean":
if (isBoolean(value))
return value;
throw new InvalidJsonInput(field);
case "number":
if (isNumber(value))
return value;
throw new InvalidJsonInput(field);
case "date":
if (isNumber(value))
return value;
if (isDate(value))
return convertDateToEpoch(value);
if (isDateString(value))
return convertIsoDateToEpoch(value);
throw new InvalidJsonInput(field);
case "point":
if (isPoint(value))
return convertPointToString(value);
throw new InvalidJsonInput(field);
case "string":
case "text":
if (isBoolean(value))
return value.toString();
if (isNumber(value))
return value.toString();
if (isString(value))
return value;
throw new InvalidJsonInput(field);
}
}
function convertUnknownValueToJson(value) {
if (isDate(value))
return convertDateToEpoch(value);
return value;
}
// lib/search/results-converter.ts
function extractCountFromSearchResults(results) {
return results.total;
}
function extractKeyNamesFromSearchResults(results) {
return results.documents.map((document) => document.id);
}
function extractEntityIdsFromSearchResults(schema, results) {
const keyNames = extractKeyNamesFromSearchResults(results);
const entityIds = keyNamesToEntityIds(schema.schemaName, keyNames);
return entityIds;
}
function extractEntitiesFromSearchResults(schema, results) {
if (schema.dataStructure === "HASH") {
return results.documents.map((document) => hashDocumentToEntity(schema, document));
} else {
return results.documents.map((document) => jsonDocumentToEntity(schema, document));
}
}
function hashDocumentToEntity(schema, document) {
const keyName = document.id;
const hashData = document.value;
const entityData = fromRedisHash(schema, hashData);
const entity = enrichEntityData(schema.schemaName, keyName, entityData);
return entity;
}
function jsonDocumentToEntity(schema, document) {
const keyName = document.id;
const jsonData = document.value["$"] ?? false ? JSON.parse(document.value["$"]) : document.value;
const entityData = fromRedisJson(schema, jsonData);
const entity = enrichEntityData(schema.schemaName, keyName, entityData);
return entity;
}
function enrichEntityData(keyPrefix, keyName, entityData) {
const entityId = keyNameToEntityId(keyPrefix, keyName);
const entity = { ...entityData, [EntityId]: entityId, [EntityKeyName]: keyName };
return entity;
}
function keyNamesToEntityIds(keyPrefix, keyNames) {
return keyNames.map((keyName) => keyNameToEntityId(keyPrefix, keyName));
}
function keyNameToEntityId(keyPrefix, keyName) {
const escapedPrefix = keyPrefix.replace(/[/\-\\^$*+?.()|[\]{}]/g, "\\$&");
const regex = new RegExp(`^${escapedPrefix}:`);
const entityId = keyName.replace(regex, "");
return entityId;
}
// lib/search/where.ts

@@ -99,3 +792,3 @@ var Where = class {

const negationPortion = this.negated ? "-" : "";
const fieldPortion = this.field;
const fieldPortion = this.field.name;
return `(${negationPortion}@${fieldPortion}:${valuePortion})`;

@@ -324,10 +1017,2 @@ }

// lib/errors.ts
var RedisError = class extends Error {
constructor(message) {
super(message);
this.name = "RedisError";
}
};
// lib/search/where-string.ts

@@ -376,6 +1061,6 @@ var WhereString = class extends WhereField {

throwMatchExcpetion() {
throw new RedisError("Cannot perform full-text search operations like .match on field of type 'string'. If full-text search is needed on this field, change the type to 'text' in the Schema.");
throw new SemanticSearchError("Cannot perform full-text search operations like .match on field of type 'string'. If full-text search is needed on this field, change the type to 'text' in the Schema.");
}
throwMatchExcpetionReturningThis() {
throw new RedisError("Cannot perform full-text search operations like .match on field of type 'string'. If full-text search is needed on this field, change the type to 'text' in the Schema.");
throw new SemanticSearchError("Cannot perform full-text search operations like .match on field of type 'string'. If full-text search is needed on this field, change the type to 'text' in the Schema.");
}

@@ -434,59 +1119,6 @@ };

throwEqualsExcpetion() {
throw new RedisError("Cannot call .equals on a field of type 'text', either use .match to perform full-text search or change the type to 'string' in the Schema.");
throw new SemanticSearchError("Cannot call .equals on a field of type 'text', either use .match to perform full-text search or change the type to 'string' in the Schema.");
}
};
// lib/search/results-converter.ts
var SearchResultsConverter = class {
results;
schema;
constructor(schema, results) {
this.schema = schema;
this.results = results;
}
get count() {
const [count] = this.results;
return Number.parseInt(count);
}
get ids() {
return this.keys.map((key) => key.replace(/^.*:/, ""));
}
get keys() {
const [_count, ...keysAndValues] = this.results;
return keysAndValues.filter((_entry, index) => index % 2 === 0);
}
get values() {
const [_count, ...keysAndValues] = this.results;
return keysAndValues.filter((_entry, index) => index % 2 !== 0);
}
get entities() {
const ids = this.ids;
const values = this.values;
return values.map((array, index) => this.arrayToEntity(ids[index], array));
}
};
var HashSearchResultsConverter = class extends SearchResultsConverter {
arrayToEntity(id, array) {
const keys = array.filter((_entry, index) => index % 2 === 0);
const values = array.filter((_entry, index) => index % 2 !== 0);
const hashData = keys.reduce((object, key, index) => {
object[key] = values[index];
return object;
}, {});
const entity = new this.schema.entityCtor(this.schema, id);
entity.fromRedisHash(hashData);
return entity;
}
};
var JsonSearchResultsConverter = class extends SearchResultsConverter {
arrayToEntity(id, array) {
const index = array.findIndex((value) => value === "$") + 1;
const jsonString = array[index];
const jsonData = JSON.parse(jsonString);
const entity = new this.schema.entityCtor(this.schema, id);
entity.fromRedisJson(jsonData);
return entity;
}
};
// lib/search/where-date.ts

@@ -596,3 +1228,3 @@ var WhereDate = class extends WhereField {

client;
sort;
sortOptions;
constructor(schema, client) {

@@ -614,12 +1246,12 @@ this.schema = schema;

}
sortBy(field, order = "ASC") {
const fieldDef = this.schema.definition[field];
sortBy(fieldName, order = "ASC") {
const field = this.schema.fieldByName(fieldName);
const dataStructure = this.schema.dataStructure;
if (fieldDef === void 0) {
const message = `'sortBy' was called on field '${field}' which is not defined in the Schema.`;
if (!field) {
const message = `'sortBy' was called on field '${fieldName}' which is not defined in the Schema.`;
console.error(message);
throw new RedisError(message);
throw new RedisOmError(message);
}
const type = fieldDef.type;
const markedSortable = fieldDef.sortable;
const type = field.type;
const markedSortable = field.sortable;
const UNSORTABLE = ["point", "string[]"];

@@ -629,11 +1261,11 @@ const JSON_SORTABLE = ["number", "text", "date"];

if (UNSORTABLE.includes(type)) {
const message = `'sortBy' was called on '${type}' field '${field}' which cannot be sorted.`;
const message = `'sortBy' was called on '${field.type}' field '${field.name}' which cannot be sorted.`;
console.error(message);
throw new RedisError(message);
throw new RedisOmError(message);
}
if (dataStructure === "JSON" && JSON_SORTABLE.includes(type) && !markedSortable)
console.warn(`'sortBy' was called on field '${field}' which is not marked as sortable in the Schema. This may result is slower searches. If possible, mark the field as sortable in the Schema.`);
console.warn(`'sortBy' was called on field '${field.name}' which is not marked as sortable in the Schema. This may result is slower searches. If possible, mark the field as sortable in the Schema.`);
if (dataStructure === "HASH" && HASH_SORTABLE.includes(type) && !markedSortable)
console.warn(`'sortBy' was called on field '${field}' which is not marked as sortable in the Schema. This may result is slower searches. If possible, mark the field as sortable in the Schema.`);
this.sort = { field, order };
console.warn(`'sortBy' was called on field '${field.name}' which is not marked as sortable in the Schema. This may result is slower searches. If possible, mark the field as sortable in the Schema.`);
this.sortOptions = { BY: field.name, DIRECTION: order };
return this;

@@ -645,4 +1277,3 @@ }

async minId(field) {
const key = await this.minKey(field);
return this.keyToEntityId(key);
return await this.sortBy(field, "ASC").firstId();
}

@@ -656,4 +1287,3 @@ async minKey(field) {

async maxId(field) {
const key = await this.maxKey(field);
return this.keyToEntityId(key);
return await this.sortBy(field, "DESC").firstId();
}

@@ -665,15 +1295,15 @@ async maxKey(field) {

const searchResults = await this.callSearch();
return this.schema.dataStructure === "JSON" ? new JsonSearchResultsConverter(this.schema, searchResults).count : new HashSearchResultsConverter(this.schema, searchResults).count;
return extractCountFromSearchResults(searchResults);
}
async page(offset, count) {
const searchResults = await this.callSearch({ offset, count });
return this.schema.dataStructure === "JSON" ? new JsonSearchResultsConverter(this.schema, searchResults).entities : new HashSearchResultsConverter(this.schema, searchResults).entities;
const searchResults = await this.callSearch(offset, count);
return extractEntitiesFromSearchResults(this.schema, searchResults);
}
async pageOfIds(offset, count) {
const keys = await this.pageOfKeys(offset, count);
return this.keysToEntityIds(keys);
const searchResults = await this.callSearch(offset, count, true);
return extractEntityIdsFromSearchResults(this.schema, searchResults);
}
async pageOfKeys(offset, count) {
const [_count, ...keys] = await this.callSearch({ offset, count }, true);
return keys;
const searchResults = await this.callSearch(offset, count, true);
return extractKeyNamesFromSearchResults(searchResults);
}

@@ -685,38 +1315,17 @@ async first() {

async firstId() {
const key = await this.firstKey();
return this.keyToEntityId(key);
const foundIds = await this.pageOfIds(0, 1);
return foundIds[0] ?? null;
}
async firstKey() {
const foundIds = await this.pageOfKeys(0, 1);
return foundIds[0] ?? null;
const foundKeys = await this.pageOfKeys(0, 1);
return foundKeys[0] ?? null;
}
async all(options = { pageSize: 10 }) {
const entities = [];
let offset = 0;
const pageSize = options.pageSize;
while (true) {
const foundEntities = await this.page(offset, pageSize);
entities.push(...foundEntities);
if (foundEntities.length < pageSize)
break;
offset += pageSize;
}
return entities;
return this.allThings(this.page, options);
}
async allIds(options = { pageSize: 10 }) {
const keys = await this.allKeys(options);
return this.keysToEntityIds(keys);
return this.allThings(this.pageOfIds, options);
}
async allKeys(options = { pageSize: 10 }) {
const keys = [];
let offset = 0;
const pageSize = options.pageSize;
while (true) {
const foundKeys = await this.pageOfKeys(offset, pageSize);
keys.push(...foundKeys);
if (foundKeys.length < pageSize)
break;
offset += pageSize;
}
return keys;
return this.allThings(this.pageOfKeys, options);
}

@@ -774,18 +1383,36 @@ get return() {

}
async callSearch(limit = { offset: 0, count: 0 }, keysOnly = false) {
async allThings(pageFn, options = { pageSize: 10 }) {
const things = [];
let offset = 0;
const pageSize = options.pageSize;
while (true) {
const foundThings = await pageFn.call(this, offset, pageSize);
things.push(...foundThings);
if (foundThings.length < pageSize)
break;
offset += pageSize;
}
return things;
}
async callSearch(offset = 0, count = 0, keysOnly = false) {
const dataStructure = this.schema.dataStructure;
const indexName = this.schema.indexName;
const query = this.query;
const options = {
indexName: this.schema.indexName,
query: this.query,
limit,
keysOnly
LIMIT: { from: offset, size: count }
};
if (this.sort !== void 0)
options.sort = this.sort;
if (this.sortOptions !== void 0)
options.SORTBY = this.sortOptions;
if (keysOnly) {
options.RETURN = [];
} else if (dataStructure === "JSON") {
options.RETURN = "$";
}
let searchResults;
try {
searchResults = await this.client.search(options);
searchResults = await this.client.search(indexName, query, options);
} catch (error) {
const message = error.message;
if (message.startsWith("Syntax error")) {
throw new RedisError(`The query to RediSearch had a syntax error: "${message}".
throw new SearchError(`The query to RediSearch had a syntax error: "${message}".
This is often the result of using a stop word in the query. Either change the query to not use a stop word or change the stop words in the schema definition. You can check the RediSearch source for the default stop words at: https://github.com/RediSearch/RediSearch/blob/master/src/stopwords.h.`);

@@ -797,8 +1424,2 @@ }

}
keysToEntityIds(keys) {
return keys.map((key) => this.keyToEntityId(key) ?? "");
}
keyToEntityId(key) {
return key ? key.replace(`${this.schema.prefix}:`, "") : null;
}
};

@@ -851,3 +1472,3 @@ var RawSearch = class extends AbstractSearch {

if (subSearch.rootWhere === void 0) {
throw new Error("Sub-search without and root where was somehow defined.");
throw new SearchError("Sub-search without a root where was somehow defined.");
} else {

@@ -862,50 +1483,66 @@ if (this.rootWhere === void 0) {

}
createWhere(field) {
const fieldDef = this.schema.definition[field];
if (fieldDef === void 0)
throw new Error(`The field '${field}' is not part of the schema.`);
if (fieldDef.type === "boolean" && this.schema.dataStructure === "HASH")
createWhere(fieldName) {
const field = this.schema.fieldByName(fieldName);
if (field === null)
throw new FieldNotInSchema(fieldName);
if (field.type === "boolean" && this.schema.dataStructure === "HASH")
return new WhereHashBoolean(this, field);
if (fieldDef.type === "boolean" && this.schema.dataStructure === "JSON")
if (field.type === "boolean" && this.schema.dataStructure === "JSON")
return new WhereJsonBoolean(this, field);
if (fieldDef.type === "date")
if (field.type === "date")
return new WhereDate(this, field);
if (fieldDef.type === "number")
if (field.type === "number")
return new WhereNumber(this, field);
if (fieldDef.type === "point")
if (field.type === "point")
return new WherePoint(this, field);
if (fieldDef.type === "text")
if (field.type === "text")
return new WhereText(this, field);
if (fieldDef.type === "string")
if (field.type === "string")
return new WhereString(this, field);
if (fieldDef.type === "string[]")
if (field.type === "string[]")
return new WhereStringArray(this, field);
throw new Error(`The field type of '${fieldDef.type}' is not a valid field type. Valid types include 'boolean', 'date', 'number', 'point', 'string', and 'string[]'.`);
throw new RedisOmError(`The field type of '${fieldDef.type}' is not a valid field type. Valid types include 'boolean', 'date', 'number', 'point', 'string', and 'string[]'.`);
}
};
// lib/repository/index.ts
// lib/repository/repository.ts
var Repository = class {
client;
schema;
constructor(schema, client) {
this.schema = schema;
this.client = client;
#schema;
constructor(schema, clientOrConnection) {
this.#schema = schema;
if (clientOrConnection instanceof Client) {
this.client = clientOrConnection;
} else {
this.client = new Client();
this.client.useNoClose(clientOrConnection);
}
}
async createIndex() {
const currentIndexHash = await this.client.get(this.schema.indexHashName);
if (currentIndexHash !== this.schema.indexHash) {
const currentIndexHash = await this.client.get(this.#schema.indexHashName);
const incomingIndexHash = this.#schema.indexHash;
if (currentIndexHash !== incomingIndexHash) {
await this.dropIndex();
const {
indexName,
indexHashName,
dataStructure,
schemaName: prefix,
useStopWords,
stopWords
} = this.#schema;
const schema = buildRediSearchSchema(this.#schema);
const options = {
indexName: this.schema.indexName,
dataStructure: this.schema.dataStructure,
prefix: `${this.schema.prefix}:`,
schema: this.schema.redisSchema
ON: dataStructure,
PREFIX: `${prefix}:`
};
if (this.schema.useStopWords === "OFF")
options.stopWords = [];
if (this.schema.useStopWords === "CUSTOM")
options.stopWords = this.schema.stopWords;
await this.client.createIndex(options);
await this.client.set(this.schema.indexHashName, this.schema.indexHash);
if (useStopWords === "OFF") {
options.STOPWORDS = [];
} else if (useStopWords === "CUSTOM") {
options.STOPWORDS = stopWords;
}
await Promise.all([
this.client.createIndex(indexName, schema, options),
this.client.set(indexHashName, incomingIndexHash)
]);
}

@@ -915,4 +1552,6 @@ }

try {
await this.client.unlink(this.schema.indexHashName);
await this.client.dropIndex(this.schema.indexName);
await Promise.all([
this.client.unlink(this.#schema.indexHashName),
this.client.dropIndex(this.#schema.indexName)
]);
} catch (e) {

@@ -925,24 +1564,24 @@ if (e instanceof Error && e.message === "Unknown Index name") {

}
createEntity(data = {}) {
const id = this.schema.generateId();
return new this.schema.entityCtor(this.schema, id, data);
async save(entityOrId, maybeEntity) {
let entity;
let entityId;
if (typeof entityOrId !== "string") {
entity = entityOrId;
entityId = entity[EntityId] ?? await this.#schema.generateId();
} else {
entity = maybeEntity;
entityId = entityOrId;
}
const keyName = `${this.#schema.schemaName}:${entityId}`;
const clonedEntity = { ...entity, [EntityId]: entityId, [EntityKeyName]: keyName };
await this.writeEntity(clonedEntity);
return clonedEntity;
}
async save(entity) {
await this.writeEntity(entity);
return entity.entityId;
}
async createAndSave(data = {}) {
const entity = this.createEntity(data);
await this.save(entity);
return entity;
}
async fetch(ids) {
if (arguments.length > 1) {
if (arguments.length > 1)
return this.readEntities([...arguments]);
}
if (Array.isArray(ids)) {
if (Array.isArray(ids))
return this.readEntities(ids);
}
const entities = await this.readEntities([ids]);
return entities[0];
const [entity] = await this.readEntities([ids]);
return entity;
}

@@ -955,59 +1594,79 @@ async remove(ids) {

}
async expire(id, ttlInSeconds) {
const key = this.makeKey(id);
await this.client.expire(key, ttlInSeconds);
async expire(idOrIds, ttlInSeconds) {
const ids = typeof idOrIds === "string" ? [idOrIds] : idOrIds;
await Promise.all(
ids.map((id) => {
const key = this.makeKey(id);
return this.client.expire(key, ttlInSeconds);
})
);
}
search() {
return new Search(this.schema, this.client);
return new Search(this.#schema, this.client);
}
searchRaw(query) {
return new RawSearch(this.schema, this.client, query);
return new RawSearch(this.#schema, this.client, query);
}
makeKeys(ids) {
return ids.map((id) => this.makeKey(id));
async writeEntity(entity) {
return this.#schema.dataStructure === "HASH" ? this.writeEntityToHash(entity) : this.writeEntityToJson(entity);
}
makeKey(id) {
return `${this.schema.prefix}:${id}`;
async readEntities(ids) {
return this.#schema.dataStructure === "HASH" ? this.readEntitiesFromHash(ids) : this.readEntitiesFromJson(ids);
}
};
var HashRepository = class extends Repository {
async writeEntity(entity) {
const data = entity.toRedisHash();
if (Object.keys(data).length === 0) {
await this.client.unlink(entity.keyName);
return;
async writeEntityToHash(entity) {
const keyName = entity[EntityKeyName];
const hashData = toRedisHash(this.#schema, entity);
if (Object.keys(hashData).length === 0) {
await this.client.unlink(keyName);
} else {
await this.client.hsetall(keyName, hashData);
}
await this.client.hsetall(entity.keyName, data);
}
async readEntities(ids) {
return Promise.all(ids.map(async (id) => {
const key = this.makeKey(id);
const hashData = await this.client.hgetall(key);
const entity = new this.schema.entityCtor(this.schema, id);
entity.fromRedisHash(hashData);
return entity;
}));
async readEntitiesFromHash(ids) {
return Promise.all(
ids.map(async (entityId) => {
const keyName = this.makeKey(entityId);
const hashData = await this.client.hgetall(keyName);
const entityData = fromRedisHash(this.#schema, hashData);
const entity = { ...entityData, [EntityId]: entityId, [EntityKeyName]: keyName };
return entity;
})
);
}
};
var JsonRepository = class extends Repository {
async writeEntity(entity) {
await this.client.jsonset(entity.keyName, entity.toRedisJson());
async writeEntityToJson(entity) {
const keyName = entity[EntityKeyName];
const jsonData = toRedisJson(this.#schema, entity);
await this.client.jsonset(keyName, jsonData);
}
async readEntities(ids) {
return Promise.all(ids.map(async (id) => {
const key = this.makeKey(id);
const jsonData = await this.client.jsonget(key);
const entity = new this.schema.entityCtor(this.schema, id);
entity.fromRedisJson(jsonData);
return entity;
}));
async readEntitiesFromJson(ids) {
return Promise.all(
ids.map(async (entityId) => {
const keyName = this.makeKey(entityId);
const jsonData = await this.client.jsonget(keyName) ?? {};
const entityData = fromRedisJson(this.#schema, jsonData);
const entity = { ...entityData, [EntityId]: entityId, [EntityKeyName]: keyName };
return entity;
})
);
}
makeKeys(ids) {
return ids.map((id) => this.makeKey(id));
}
makeKey(id) {
return `${this.#schema.schemaName}:${id}`;
}
};
// lib/client.ts
// lib/client/client.ts
var Client = class {
redis;
#redis;
get redis() {
return this.#redis;
}
async use(connection) {
await this.close();
this.redis = connection;
return this.useNoClose(connection);
}
useNoClose(connection) {
this.#redis = connection;
return this;

@@ -1017,66 +1676,33 @@ }

if (!this.isOpen()) {
this.redis = (0, import_redis.createClient)({ url });
await this.redis.connect();
const redis = (0, import_redis2.createClient)({ url });
await redis.connect();
this.#redis = redis;
}
return this;
}
async execute(command) {
this.validateRedisOpen();
return this.redis.sendCommand(command.map((arg) => {
if (arg === false)
return "0";
if (arg === true)
return "1";
return arg.toString();
}));
}
fetchRepository(schema) {
this.validateRedisOpen();
if (schema.dataStructure === "JSON") {
return new JsonRepository(schema, this);
} else {
return new HashRepository(schema, this);
}
this.#validateRedisOpen();
return new Repository(schema, this);
}
async close() {
if (this.redis) {
await this.redis.quit();
}
this.redis = void 0;
if (this.#redis)
await this.#redis.quit();
this.#redis = void 0;
}
async createIndex(options) {
this.validateRedisOpen();
const { indexName, dataStructure, prefix, schema, stopWords } = options;
const command = [
"FT.CREATE",
indexName,
"ON",
dataStructure,
"PREFIX",
"1",
`${prefix}`
];
if (stopWords !== void 0)
command.push("STOPWORDS", `${stopWords.length}`, ...stopWords);
command.push("SCHEMA", ...schema);
await this.redis.sendCommand(command);
async createIndex(indexName, schema, options) {
this.#validateRedisOpen();
await this.redis.ft.create(indexName, schema, options);
}
async dropIndex(indexName) {
this.validateRedisOpen();
await this.redis.sendCommand(["FT.DROPINDEX", indexName]);
this.#validateRedisOpen();
await this.redis.ft.dropIndex(indexName);
}
async search(options) {
this.validateRedisOpen();
const { indexName, query, limit, sort, keysOnly } = options;
const command = ["FT.SEARCH", indexName, query];
if (limit !== void 0)
command.push("LIMIT", limit.offset.toString(), limit.count.toString());
if (sort !== void 0)
command.push("SORTBY", sort.field, sort.order);
if (keysOnly)
command.push("RETURN", "0");
return this.redis.sendCommand(command);
async search(indexName, query, options) {
this.#validateRedisOpen();
if (options)
return await this.redis.ft.search(indexName, query, options);
return await this.redis.ft.search(indexName, query);
}
async unlink(...keys) {
this.validateRedisOpen();
this.#validateRedisOpen();
if (keys.length > 0)

@@ -1086,381 +1712,86 @@ await this.redis.unlink(keys);

async expire(key, ttl) {
this.validateRedisOpen();
this.#validateRedisOpen();
await this.redis.expire(key, ttl);
}
async get(key) {
this.validateRedisOpen();
this.#validateRedisOpen();
return this.redis.get(key);
}
async set(key, value) {
this.validateRedisOpen();
this.#validateRedisOpen();
await this.redis.set(key, value);
}
async hgetall(key) {
this.validateRedisOpen();
this.#validateRedisOpen();
return this.redis.hGetAll(key);
}
async hsetall(key, data) {
this.validateRedisOpen();
try {
await this.redis.executeIsolated(async (isolatedClient) => {
await isolatedClient.watch(key);
await isolatedClient.multi().unlink(key).hSet(key, data).exec();
});
} catch (error) {
if (error.name === "WatchError")
throw new RedisError("Watch error when setting HASH.");
throw error;
}
this.#validateRedisOpen();
await this.redis.multi().unlink(key).hSet(key, data).exec();
}
async jsonget(key) {
this.validateRedisOpen();
const json = await this.redis.sendCommand(["JSON.GET", key, "."]);
return JSON.parse(json);
this.#validateRedisOpen();
const json = await this.redis.json.get(key, { path: "$" });
return json === null ? null : json[0];
}
async jsonset(key, data) {
this.validateRedisOpen();
const json = JSON.stringify(data);
await this.redis.sendCommand(["JSON.SET", key, ".", json]);
this.#validateRedisOpen();
await this.redis.json.set(key, "$", data);
}
isOpen() {
return !!this.redis;
return !!this.#redis;
}
validateRedisOpen() {
#validateRedisOpen() {
if (!this.redis)
throw new RedisError("Redis connection needs to be open.");
throw new RedisOmError("Redis connection needs to be open.");
}
};
// lib/entity/fields/entity-field.ts
var EntityField = class {
_name;
_value = null;
fieldDef;
constructor(name, fieldDef, value) {
this.fieldDef = fieldDef;
this.value = value ?? null;
this._name = name;
// lib/schema/field.ts
var Field = class {
#name;
#definition;
constructor(name, definition) {
this.#name = name;
this.#definition = definition;
}
get name() {
return this.fieldDef.alias ?? this._name;
return this.#name;
}
get value() {
return this._value;
get type() {
return this.#definition.type;
}
set value(value) {
this.validateValue(value);
this._value = this.convertValue(value);
get hashField() {
return this.#definition.field ?? this.#definition.alias ?? this.name;
}
toRedisJson() {
const data = {};
if (this.value !== null)
data[this.name] = this.value;
return data;
get jsonPath() {
if (this.#definition.path)
return this.#definition.path;
const alias = this.#definition.alias ?? this.name;
return this.type === "string[]" ? `$.${alias}[*]` : `$.${alias}`;
}
fromRedisJson(value) {
this.value = value;
}
toRedisHash() {
const data = {};
if (this.value !== null)
data[this.name] = this.value.toString();
return data;
}
fromRedisHash(value) {
this.value = value;
}
validateValue(value) {
if (value === void 0)
throw Error(`Property cannot be set to undefined. Use null instead.`);
}
convertValue(value) {
return value;
}
isString(value) {
return typeof value === "string";
}
isNumber(value) {
return typeof value === "number";
}
isBoolean(value) {
return typeof value === "boolean";
}
};
// lib/entity/fields/entity-boolean-field.ts
var EntityBooleanField = class extends EntityField {
toRedisHash() {
const data = {};
if (this.value !== null)
data[this.name] = this.value ? "1" : "0".toString();
return data;
}
fromRedisHash(value) {
if (value === "0") {
this.value = false;
} else if (value === "1") {
this.value = true;
} else {
throw Error(`Non-boolean value of '${value}' read from Redis for boolean field.`);
}
}
validateValue(value) {
super.validateValue(value);
if (value !== null && !this.isBoolean(value))
throw Error(`Expected value with type of 'boolean' but received '${value}'.`);
}
};
// lib/entity/fields/entity-date-field.ts
var EntityDateField = class extends EntityField {
toRedisJson() {
const data = {};
if (this.value !== null)
data[this.name] = this.valueAsNumber;
return data;
}
fromRedisJson(value) {
if (this.isNumber(value) || value === null)
this.value = value;
else
throw Error(`Non-numeric value of '${value}' read from Redis for date field.`);
}
toRedisHash() {
const data = {};
if (this.value !== null)
data[this.name] = this.valueAsNumber.toString();
return data;
}
fromRedisHash(value) {
const parsed = Number.parseFloat(value);
if (Number.isNaN(parsed))
throw Error(`Non-numeric value of '${value}' read from Redis for date field.`);
const date = new Date();
date.setTime(parsed * 1e3);
this.value = date;
}
validateValue(value) {
super.validateValue(value);
if (value !== null && !this.isDateable(value))
throw Error(`Expected value with type of 'date' but received '${value}'.`);
}
convertValue(value) {
if (this.isString(value)) {
return new Date(value);
}
if (this.isNumber(value)) {
const newValue = new Date();
newValue.setTime(value * 1e3);
return newValue;
}
return super.convertValue(value);
}
isDateable(value) {
return this.isDate(value) || this.isNumber(value) || this.isString(value);
}
isDate(value) {
return value instanceof Date;
}
get valueAsNumber() {
return this.value.getTime() / 1e3;
}
};
// lib/entity/fields/entity-number-field.ts
var EntityNumberField = class extends EntityField {
fromRedisHash(value) {
const number = Number.parseFloat(value);
if (Number.isNaN(number))
throw Error(`Non-numeric value of '${value}' read from Redis for number field.`);
this.value = number;
}
validateValue(value) {
super.validateValue(value);
if (value !== null && !this.isNumber(value))
throw Error(`Expected value with type of 'number' but received '${value}'.`);
}
};
// lib/entity/fields/entity-point-field.ts
var IS_COORD_PAIR = /^-?\d+(\.\d*)?,-?\d+(\.\d*)?$/;
var EntityPointField = class extends EntityField {
toRedisJson() {
const data = {};
if (this.value !== null)
data[this.name] = this.valueAsString;
return data;
}
fromRedisJson(value) {
if (value === null) {
this.value = null;
} else if (value.toString().match(IS_COORD_PAIR)) {
const [longitude, latitude] = value.split(",").map(Number.parseFloat);
this.value = { longitude, latitude };
} else {
throw Error(`Non-point value of '${value}' read from Redis for point field.`);
}
}
toRedisHash() {
const data = {};
if (this.value !== null)
data[this.name] = this.valueAsString;
return data;
}
fromRedisHash(value) {
if (value.match(IS_COORD_PAIR)) {
const [longitude, latitude] = value.split(",").map(Number.parseFloat);
this.value = { longitude, latitude };
} else {
throw Error(`Non-point value of '${value}' read from Redis for point field.`);
}
}
validateValue(value) {
super.validateValue(value);
if (value !== null) {
if (!this.isPoint(value))
throw Error(`Expected value with type of 'point' but received '${value}'.`);
const { longitude, latitude } = value;
if (Math.abs(latitude) > 85.05112878 || Math.abs(longitude) > 180)
throw Error(`Expected value with valid 'point' but received '${longitude},${latitude}'.`);
}
}
isPoint(value) {
return this.isNumber(value.longitude) && this.isNumber(value.latitude);
}
get valueAsString() {
const { longitude, latitude } = this.value;
return `${longitude},${latitude}`;
}
};
// lib/entity/fields/entity-string-array-field.ts
var EntityStringArrayField = class extends EntityField {
toRedisHash() {
const data = {};
if (this.value !== null)
data[this.name] = this.value.join(this.separator);
return data;
}
fromRedisHash(value) {
this.value = value.split(this.separator);
}
validateValue(value) {
super.validateValue(value);
if (value !== null && !this.isArray(value))
throw Error(`Expected value with type of 'string[]' but received '${value}'.`);
}
convertValue(value) {
if (this.isArray(value)) {
return value.map((v) => v.toString());
}
return super.convertValue(value);
}
get separator() {
return this.fieldDef.separator ?? "|";
return this.#definition.separator ?? "|";
}
isArray(value) {
return Array.isArray(value);
get sortable() {
return this.#definition.sortable ?? false;
}
};
// lib/entity/fields/entity-stringish-field.ts
var EntityStringishField = class extends EntityField {
convertValue(value) {
if (value !== null && this.isStringable(value)) {
return value.toString();
}
return super.convertValue(value);
get caseSensitive() {
return this.#definition.caseSensitive ?? false;
}
isStringable(value) {
return this.isString(value) || this.isNumber(value) || this.isBoolean(value);
get indexed() {
return this.#definition.indexed ?? true;
}
};
// lib/entity/fields/entity-string-field.ts
var EntityStringField = class extends EntityStringishField {
validateValue(value) {
super.validateValue(value);
if (value !== null && !this.isStringable(value))
throw Error(`Expected value with type of 'string' but received '${value}'.`);
get stemming() {
return this.#definition.stemming ?? true;
}
};
// lib/entity/fields/entity-text-field.ts
var EntityTextField = class extends EntityStringishField {
validateValue(value) {
super.validateValue(value);
if (value !== null && !this.isStringable(value))
throw Error(`Expected value with type of 'text' but received '${value}'.`);
get normalized() {
return this.#definition.normalized ?? true;
}
};
// lib/entity/entity.ts
var ENTITY_FIELD_CONSTRUCTORS = {
"string": EntityStringField,
"number": EntityNumberField,
"boolean": EntityBooleanField,
"text": EntityTextField,
"date": EntityDateField,
"point": EntityPointField,
"string[]": EntityStringArrayField
};
var Entity = class {
entityId;
schemaDef;
prefix;
entityFields = {};
constructor(schema, id, data = {}) {
this.schemaDef = schema.definition;
this.prefix = schema.prefix;
this.entityId = id;
this.createFields(data);
get weight() {
return this.#definition.weight ?? null;
}
createFields(data) {
Object.keys(this.schemaDef).forEach((fieldName) => {
const fieldDef = this.schemaDef[fieldName];
const fieldType = fieldDef.type;
const fieldAlias = fieldDef.alias ?? fieldName;
const fieldValue = data[fieldAlias] ?? null;
const entityField = new ENTITY_FIELD_CONSTRUCTORS[fieldType](fieldName, fieldDef, fieldValue);
this.entityFields[fieldAlias] = entityField;
});
get matcher() {
return this.#definition.matcher ?? null;
}
get keyName() {
return `${this.prefix}:${this.entityId}`;
}
toJSON() {
const json = { entityId: this.entityId };
Object.keys(this.schemaDef).forEach((field) => {
json[field] = this[field];
});
return json;
}
toRedisJson() {
let data = {};
Object.keys(this.entityFields).forEach((field) => {
const entityField = this.entityFields[field];
data = { ...data, ...entityField.toRedisJson() };
});
return data;
}
fromRedisJson(data) {
if (!data)
return data;
Object.keys(data).forEach((field) => {
this.entityFields[field].fromRedisJson(data[field]);
});
}
toRedisHash() {
let data = {};
Object.keys(this.entityFields).forEach((field) => {
const entityField = this.entityFields[field];
data = { ...data, ...entityField.toRedisHash() };
});
return data;
}
fromRedisHash(data) {
Object.keys(data).forEach((field) => {
this.entityFields[field].fromRedisHash(data[field]);
});
}
};

@@ -1564,209 +1895,47 @@

// lib/schema/builders/schema-builder.ts
var SchemaBuilder = class {
schema;
constructor(schema) {
this.schema = schema;
// lib/schema/schema.ts
var Schema = class {
#schemaName;
#fieldsByName = {};
#definition;
#options;
constructor(schemaName, schemaDef, options) {
this.#schemaName = schemaName;
this.#definition = schemaDef;
this.#options = options;
this.#validateOptions();
this.#createFields();
}
get redisSchema() {
const redisSchema = [];
Object.keys(this.schema.definition).forEach((field) => {
redisSchema.push(...this.buildEntry(field));
});
return redisSchema;
get schemaName() {
return this.#schemaName;
}
buildCaseInsensitive(field) {
return field.caseSensitive ? ["CASESENSITIVE"] : [];
get fields() {
return Object.entries(this.#fieldsByName).map(([_name, field]) => field);
}
buildIndexed(field) {
return field.indexed ?? this.schema.indexedDefault ? [] : ["NOINDEX"];
fieldByName(name) {
return this.#fieldsByName[name] ?? null;
}
buildStemming(field) {
return field.stemming ?? true ? [] : ["NOSTEM"];
}
buildPhonetic(field) {
return field.matcher ? ["PHONETIC", field.matcher] : [];
}
buildSeparable(field) {
return ["SEPARATOR", field.separator || "|"];
}
buildSortable(field) {
return field.sortable ? ["SORTABLE"] : [];
}
buildNormalized(field) {
return field.normalized ?? true ? [] : ["UNF"];
}
buildWeight(field) {
return field.weight ? ["WEIGHT", field.weight.toString()] : [];
}
};
// lib/schema/builders/hash-schema-builder.ts
var HashSchemaBuilder = class extends SchemaBuilder {
buildEntry(field) {
const fieldDef = this.schema.definition[field];
const fieldAlias = fieldDef.alias ?? field;
switch (fieldDef.type) {
case "date":
return [
fieldAlias,
"NUMERIC",
...this.buildSortable(fieldDef),
...this.buildIndexed(fieldDef)
];
case "boolean":
return [
fieldAlias,
"TAG",
...this.buildSortable(fieldDef),
...this.buildIndexed(fieldDef)
];
case "number":
return [
fieldAlias,
"NUMERIC",
...this.buildSortable(fieldDef),
...this.buildIndexed(fieldDef)
];
case "point":
return [
fieldAlias,
"GEO",
...this.buildIndexed(fieldDef)
];
case "string[]":
case "string":
return [
fieldAlias,
"TAG",
...this.buildCaseInsensitive(fieldDef),
...this.buildSeparable(fieldDef),
...this.buildSortable(fieldDef),
...this.buildNormalized(fieldDef),
...this.buildIndexed(fieldDef)
];
case "text":
return [
fieldAlias,
"TEXT",
...this.buildStemming(fieldDef),
...this.buildPhonetic(fieldDef),
...this.buildSortable(fieldDef),
...this.buildNormalized(fieldDef),
...this.buildWeight(fieldDef),
...this.buildIndexed(fieldDef)
];
}
;
}
};
// lib/schema/builders/json-schema-builder.ts
var JsonSchemaBuilder = class extends SchemaBuilder {
buildEntry(field) {
const fieldDef = this.schema.definition[field];
const fieldAlias = fieldDef.alias ?? field;
const fieldPath = `$.${fieldAlias}${fieldDef.type === "string[]" ? "[*]" : ""}`;
const fieldInfo = [fieldPath, "AS", fieldAlias];
switch (fieldDef.type) {
case "date":
return [
...fieldInfo,
"NUMERIC",
...this.buildSortable(fieldDef),
...this.buildIndexed(fieldDef)
];
case "boolean":
if (fieldDef.sortable)
console.warn(`You have marked the boolean field '${field}' as sortable but RediSearch doesn't support the SORTABLE argument on a TAG for JSON. Ignored.`);
return [
...fieldInfo,
"TAG",
...this.buildIndexed(fieldDef)
];
case "number":
return [
...fieldInfo,
"NUMERIC",
...this.buildSortable(fieldDef),
...this.buildIndexed(fieldDef)
];
case "point":
return [
...fieldInfo,
"GEO",
...this.buildIndexed(fieldDef)
];
case "string[]":
case "string":
if (fieldDef.sortable)
console.warn(`You have marked the ${fieldDef.type} field '${field}' as sortable but RediSearch doesn't support the SORTABLE argument on a TAG for JSON. Ignored.`);
return [
...fieldInfo,
"TAG",
...this.buildCaseInsensitive(fieldDef),
...this.buildSeparable(fieldDef),
...this.buildNormalized(fieldDef),
...this.buildIndexed(fieldDef)
];
case "text":
return [
...fieldInfo,
"TEXT",
...this.buildStemming(fieldDef),
...this.buildPhonetic(fieldDef),
...this.buildSortable(fieldDef),
...this.buildNormalized(fieldDef),
...this.buildWeight(fieldDef),
...this.buildIndexed(fieldDef)
];
}
;
}
};
// lib/schema/schema.ts
var Schema = class {
entityCtor;
definition;
options;
constructor(ctor, schemaDef, options) {
this.entityCtor = ctor;
this.definition = schemaDef;
this.options = options;
this.validateOptions();
this.defineProperties();
}
get prefix() {
var _a;
return ((_a = this.options) == null ? void 0 : _a.prefix) ?? this.entityCtor.name;
}
get indexName() {
var _a;
return ((_a = this.options) == null ? void 0 : _a.indexName) ?? `${this.prefix}:index`;
return this.#options?.indexName ?? `${this.schemaName}:index`;
}
get indexHashName() {
var _a;
return ((_a = this.options) == null ? void 0 : _a.indexHashName) ?? `${this.prefix}:index:hash`;
return this.#options?.indexHashName ?? `${this.schemaName}:index:hash`;
}
get dataStructure() {
var _a;
return ((_a = this.options) == null ? void 0 : _a.dataStructure) ?? "JSON";
return this.#options?.dataStructure ?? "JSON";
}
get useStopWords() {
var _a;
return ((_a = this.options) == null ? void 0 : _a.useStopWords) ?? "DEFAULT";
return this.#options?.useStopWords ?? "DEFAULT";
}
get stopWords() {
var _a;
return ((_a = this.options) == null ? void 0 : _a.stopWords) ?? [];
return this.#options?.stopWords ?? [];
}
get indexedDefault() {
var _a;
return ((_a = this.options) == null ? void 0 : _a.indexedDefault) ?? true;
async generateId() {
const ulidStrategy = () => ulid();
return await (this.#options?.idStrategy ?? ulidStrategy)();
}
get indexHash() {
const data = JSON.stringify({
definition: this.definition,
prefix: this.prefix,
definition: this.#definition,
prefix: this.schemaName,
indexName: this.indexName,

@@ -1780,46 +1949,26 @@ indexHashName: this.indexHashName,

}
get redisSchema() {
if (this.dataStructure === "HASH")
return new HashSchemaBuilder(this).redisSchema;
if (this.dataStructure === "JSON")
return new JsonSchemaBuilder(this).redisSchema;
throw new Error(`'${this.dataStructure}' in an invalid data structure. Valid data structures are 'HASH' and 'JSON'.`);
}
generateId() {
var _a;
const ulidStrategy = () => ulid();
return (((_a = this.options) == null ? void 0 : _a.idStrategy) ?? ulidStrategy)();
}
defineProperties() {
Object.keys(this.definition).forEach((fieldName) => {
const fieldDef = this.definition[fieldName];
const fieldAlias = fieldDef.alias ?? fieldName;
this.validateFieldDef(fieldName, fieldDef);
Object.defineProperty(this.entityCtor.prototype, fieldName, {
configurable: true,
get: function() {
return this.entityFields[fieldAlias].value;
},
set: function(value) {
this.entityFields[fieldAlias].value = value;
}
});
#createFields() {
return Object.entries(this.#definition).forEach(([fieldName, fieldDef2]) => {
const field = new Field(fieldName, fieldDef2);
this.#validateField(field);
this.#fieldsByName[fieldName] = field;
});
}
validateOptions() {
var _a;
if (!["HASH", "JSON"].includes(this.dataStructure))
throw Error(`'${this.dataStructure}' in an invalid data structure. Valid data structures are 'HASH' and 'JSON'.`);
if (!["OFF", "DEFAULT", "CUSTOM"].includes(this.useStopWords))
throw Error(`'${this.useStopWords}' in an invalid value for stop words. Valid values are 'OFF', 'DEFAULT', and 'CUSTOM'.`);
if (((_a = this.options) == null ? void 0 : _a.idStrategy) && !(this.options.idStrategy instanceof Function))
throw Error("ID strategy must be a function that takes no arguments and returns a string.");
if (this.prefix === "")
throw Error(`Prefix must be a non-empty string.`);
#validateOptions() {
const { dataStructure, useStopWords } = this;
if (dataStructure !== "HASH" && dataStructure !== "JSON")
throw new InvalidSchema(`'${dataStructure}' in an invalid data structure. Valid data structures are 'HASH' and 'JSON'.`);
if (useStopWords !== "OFF" && useStopWords !== "DEFAULT" && useStopWords !== "CUSTOM")
throw new InvalidSchema(`'${useStopWords}' in an invalid value for stop words. Valid values are 'OFF', 'DEFAULT', and 'CUSTOM'.`);
if (this.#options?.idStrategy && typeof this.#options.idStrategy !== "function")
throw new InvalidSchema("ID strategy must be a function that takes no arguments and returns a string.");
if (this.schemaName === "")
throw new InvalidSchema(`Schema name must be a non-empty string.`);
if (this.indexName === "")
throw Error(`Index name must be a non-empty string.`);
throw new InvalidSchema(`Index name must be a non-empty string.`);
}
validateFieldDef(field, fieldDef) {
if (!["boolean", "date", "number", "point", "string", "string[]", "text"].includes(fieldDef.type))
throw Error(`The field '${field}' is configured with a type of '${fieldDef.type}'. Valid types include 'boolean', 'date', 'number', 'point', 'string', 'string[]', and 'text'.`);
#validateField(field) {
const { type } = field;
if (type !== "boolean" && type !== "date" && type !== "number" && type !== "point" && type !== "string" && type !== "string[]" && type !== "text")
throw new InvalidSchema(`The field '${field.name}' is configured with a type of '${field.type}'. Valid types include 'boolean', 'date', 'number', 'point', 'string', 'string[]', and 'text'.`);
}

@@ -1830,12 +1979,29 @@ };

AbstractSearch,
ArrayHashInput,
Circle,
Client,
Entity,
EntityId,
EntityKeyName,
Field,
FieldNotInSchema,
InvalidHashInput,
InvalidHashValue,
InvalidInput,
InvalidJsonInput,
InvalidJsonValue,
InvalidSchema,
InvalidValue,
NestedHashInput,
NullJsonInput,
NullJsonValue,
PointOutOfRange,
RawSearch,
RedisError,
RedisOmError,
Repository,
Schema,
Search,
SearchError,
SemanticSearchError,
Where,
WhereField
});
[redis-om](../README.md) / AbstractSearch
# Class: AbstractSearch<TEntity\>
# Class: AbstractSearch

@@ -8,7 +8,5 @@ Abstract base class for [Search](Search.md) and [RawSearch](RawSearch.md) that

## Type parameters
**`Template`**
| Name | Type | Description |
| :------ | :------ | :------ |
| `TEntity` | extends [`Entity`](Entity.md) | The type of [Entity](Entity.md) being sought. |
The type of [Entity](../README.md#entity) being sought.

@@ -19,6 +17,6 @@ ## Hierarchy

↳ [`RawSearch`](RawSearch.md)
↳ [`Search`](Search.md)
↳ [`RawSearch`](RawSearch.md)
## Table of contents

@@ -74,3 +72,3 @@

• `get` **return**(): [`AbstractSearch`](AbstractSearch.md)<`TEntity`\>
• `get` **return**(): [`AbstractSearch`](AbstractSearch.md)

@@ -81,3 +79,3 @@ Returns the current instance. Syntactic sugar to make your code more fluent.

[`AbstractSearch`](AbstractSearch.md)<`TEntity`\>
[`AbstractSearch`](AbstractSearch.md)

@@ -88,3 +86,3 @@ this

[lib/search/search.ts:333](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/search.ts#L333)
[lib/search/search.ts:308](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/search.ts#L308)

@@ -95,6 +93,6 @@ ## Methods

▸ **all**(`options?`): `Promise`<`TEntity`[]\>
▸ **all**(`options?`): `Promise`<[`Entity`](../README.md#entity)[]\>
Returns all the [Entities](Entity.md) that match this query. This method
makes multiple calls to Redis until all the [Entities](Entity.md) are returned.
Returns all the [Entities](../README.md#entity) that match this query. This method
makes multiple calls to Redis until all the [Entities](../README.md#entity) are returned.
You can specify the batch size by setting the `pageSize` property on the

@@ -104,3 +102,3 @@ options:

```typescript
const entities = await repository.search().returnAll({ pageSize: 100 });
const entities = await repository.search().returnAll({ pageSize: 100 })
```

@@ -113,13 +111,13 @@

| `options` | `Object` | `undefined` | Options for the call. |
| `options.pageSize` | `number` | `10` | Number of [Entities](Entity.md) returned per batch. |
| `options.pageSize` | `number` | `10` | Number of [Entities](../README.md#entity) returned per batch. |
#### Returns
`Promise`<`TEntity`[]\>
`Promise`<[`Entity`](../README.md#entity)[]\>
An array of [Entities](Entity.md) matching the query.
An array of [Entities](../README.md#entity) matching the query.
#### Defined in
[lib/search/search.ts:266](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/search.ts#L266)
[lib/search/search.ts:264](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/search.ts#L264)

@@ -138,3 +136,3 @@ ___

```typescript
const keys = await repository.search().returnAllIds({ pageSize: 100 });
const keys = await repository.search().returnAllIds({ pageSize: 100 })
```

@@ -157,3 +155,3 @@

[lib/search/search.ts:295](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/search.ts#L295)
[lib/search/search.ts:282](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/search.ts#L282)

@@ -172,3 +170,3 @@ ___

```typescript
const keys = await repository.search().returnAllKeys({ pageSize: 100 });
const keys = await repository.search().returnAllKeys({ pageSize: 100 })
```

@@ -191,3 +189,3 @@

[lib/search/search.ts:314](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/search.ts#L314)
[lib/search/search.ts:300](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/search.ts#L300)

@@ -200,3 +198,3 @@ ___

Returns the number of [Entities](Entity.md) that match this query.
Returns the number of [Entities](../README.md#entity) that match this query.

@@ -209,3 +207,3 @@ #### Returns

[lib/search/search.ts:186](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/search.ts#L186)
[lib/search/search.ts:188](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/search.ts#L188)

@@ -216,13 +214,13 @@ ___

▸ **first**(): `Promise`<``null`` \| `TEntity`\>
▸ **first**(): `Promise`<``null`` \| [`Entity`](../README.md#entity)\>
Returns the first [Entity](Entity.md) that matches this query.
Returns the first [Entity](../README.md#entity) that matches this query.
#### Returns
`Promise`<``null`` \| `TEntity`\>
`Promise`<``null`` \| [`Entity`](../README.md#entity)\>
#### Defined in
[lib/search/search.ts:231](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/search.ts#L231)
[lib/search/search.ts:229](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/search.ts#L229)

@@ -243,3 +241,3 @@ ___

[lib/search/search.ts:239](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/search.ts#L239)
[lib/search/search.ts:237](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/search.ts#L237)

@@ -260,3 +258,3 @@ ___

[lib/search/search.ts:247](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/search.ts#L247)
[lib/search/search.ts:245](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/search.ts#L245)

@@ -267,5 +265,5 @@ ___

▸ **max**(`field`): `Promise`<``null`` \| `TEntity`\>
▸ **max**(`field`): `Promise`<``null`` \| [`Entity`](../README.md#entity)\>
Finds the [Entity](Entity.md) with the maximal value for a field.
Finds the [Entity](../README.md#entity) with the maximal value for a field.

@@ -280,9 +278,9 @@ #### Parameters

`Promise`<``null`` \| `TEntity`\>
`Promise`<``null`` \| [`Entity`](../README.md#entity)\>
The entity ID [Entity](Entity.md) with the maximal value
The entity ID [Entity](../README.md#entity) with the maximal value
#### Defined in
[lib/search/search.ts:159](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/search.ts#L159)
[lib/search/search.ts:162](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/search.ts#L162)

@@ -311,3 +309,3 @@ ___

[lib/search/search.ts:168](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/search.ts#L168)
[lib/search/search.ts:171](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/search.ts#L171)

@@ -336,3 +334,3 @@ ___

[lib/search/search.ts:178](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/search.ts#L178)
[lib/search/search.ts:180](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/search.ts#L180)

@@ -343,5 +341,5 @@ ___

▸ **min**(`field`): `Promise`<``null`` \| `TEntity`\>
▸ **min**(`field`): `Promise`<``null`` \| [`Entity`](../README.md#entity)\>
Finds the [Entity](Entity.md) with the minimal value for a field.
Finds the [Entity](../README.md#entity) with the minimal value for a field.

@@ -356,9 +354,9 @@ #### Parameters

`Promise`<``null`` \| `TEntity`\>
`Promise`<``null`` \| [`Entity`](../README.md#entity)\>
The [Entity](Entity.md) with the minimal value
The [Entity](../README.md#entity) with the minimal value
#### Defined in
[lib/search/search.ts:131](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/search.ts#L131)
[lib/search/search.ts:135](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/search.ts#L135)

@@ -387,3 +385,3 @@ ___

[lib/search/search.ts:140](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/search.ts#L140)
[lib/search/search.ts:144](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/search.ts#L144)

@@ -412,3 +410,3 @@ ___

[lib/search/search.ts:150](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/search.ts#L150)
[lib/search/search.ts:153](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/search.ts#L153)

@@ -419,5 +417,5 @@ ___

▸ **page**(`offset`, `count`): `Promise`<`TEntity`[]\>
▸ **page**(`offset`, `count`): `Promise`<[`Entity`](../README.md#entity)[]\>
Returns a page of [Entities](Entity.md) that match this query.
Returns a page of [Entities](../README.md#entity) that match this query.

@@ -428,14 +426,14 @@ #### Parameters

| :------ | :------ | :------ |
| `offset` | `number` | The offset for where to start returning [Entities](Entity.md). |
| `count` | `number` | The number of [Entities](Entity.md) to return. |
| `offset` | `number` | The offset for where to start returning [Entities](../README.md#entity). |
| `count` | `number` | The number of [Entities](../README.md#entity) to return. |
#### Returns
`Promise`<`TEntity`[]\>
`Promise`<[`Entity`](../README.md#entity)[]\>
An array of [Entities](Entity.md) matching the query.
An array of [Entities](../README.md#entity) matching the query.
#### Defined in
[lib/search/search.ts:199](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/search.ts#L199)
[lib/search/search.ts:199](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/search.ts#L199)

@@ -465,3 +463,3 @@ ___

[lib/search/search.ts:212](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/search.ts#L212)
[lib/search/search.ts:210](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/search.ts#L210)

@@ -491,3 +489,3 @@ ___

[lib/search/search.ts:223](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/search.ts#L223)
[lib/search/search.ts:221](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/search.ts#L221)

@@ -498,5 +496,5 @@ ___

▸ **returnAll**(`options?`): `Promise`<`TEntity`[]\>
▸ **returnAll**(`options?`): `Promise`<[`Entity`](../README.md#entity)[]\>
Alias for [Search.all](Search.md#all).
Alias for [all](Search.md#all).

@@ -512,7 +510,7 @@ #### Parameters

`Promise`<`TEntity`[]\>
`Promise`<[`Entity`](../README.md#entity)[]\>
#### Defined in
[lib/search/search.ts:431](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/search.ts#L431)
[lib/search/search.ts:406](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/search.ts#L406)

@@ -525,3 +523,3 @@ ___

Alias for [Search.allIds](Search.md#allids).
Alias for [allIds](Search.md#allids).

@@ -541,3 +539,3 @@ #### Parameters

[lib/search/search.ts:438](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/search.ts#L438)
[lib/search/search.ts:413](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/search.ts#L413)

@@ -550,3 +548,3 @@ ___

Alias for [Search.allKeys](Search.md#allkeys).
Alias for [allKeys](Search.md#allkeys).

@@ -566,3 +564,3 @@ #### Parameters

[lib/search/search.ts:445](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/search.ts#L445)
[lib/search/search.ts:420](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/search.ts#L420)

@@ -575,3 +573,3 @@ ___

Alias for [Search.count](Search.md#count).
Alias for [count](Search.md#count).

@@ -584,3 +582,3 @@ #### Returns

[lib/search/search.ts:382](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/search.ts#L382)
[lib/search/search.ts:357](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/search.ts#L357)

@@ -591,13 +589,13 @@ ___

▸ **returnFirst**(): `Promise`<``null`` \| `TEntity`\>
▸ **returnFirst**(): `Promise`<``null`` \| [`Entity`](../README.md#entity)\>
Alias for [Search.first](Search.md#first).
Alias for [first](Search.md#first).
#### Returns
`Promise`<``null`` \| `TEntity`\>
`Promise`<``null`` \| [`Entity`](../README.md#entity)\>
#### Defined in
[lib/search/search.ts:410](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/search.ts#L410)
[lib/search/search.ts:385](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/search.ts#L385)

@@ -610,3 +608,3 @@ ___

Alias for [Search.firstId](Search.md#firstid).
Alias for [firstId](Search.md#firstid).

@@ -619,3 +617,3 @@ #### Returns

[lib/search/search.ts:417](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/search.ts#L417)
[lib/search/search.ts:392](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/search.ts#L392)

@@ -628,3 +626,3 @@ ___

Alias for [Search.firstKey](Search.md#firstkey).
Alias for [firstKey](Search.md#firstkey).

@@ -637,3 +635,3 @@ #### Returns

[lib/search/search.ts:424](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/search.ts#L424)
[lib/search/search.ts:399](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/search.ts#L399)

@@ -644,5 +642,5 @@ ___

▸ **returnMax**(`field`): `Promise`<``null`` \| `TEntity`\>
▸ **returnMax**(`field`): `Promise`<``null`` \| [`Entity`](../README.md#entity)\>
Alias for [Search.max](Search.md#max).
Alias for [max](Search.md#max).

@@ -657,7 +655,7 @@ #### Parameters

`Promise`<``null`` \| `TEntity`\>
`Promise`<``null`` \| [`Entity`](../README.md#entity)\>
#### Defined in
[lib/search/search.ts:361](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/search.ts#L361)
[lib/search/search.ts:336](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/search.ts#L336)

@@ -670,3 +668,3 @@ ___

Alias for [Search.maxId](Search.md#maxid).
Alias for [maxId](Search.md#maxid).

@@ -685,3 +683,3 @@ #### Parameters

[lib/search/search.ts:368](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/search.ts#L368)
[lib/search/search.ts:343](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/search.ts#L343)

@@ -694,3 +692,3 @@ ___

Alias for [Search.maxKey](Search.md#maxkey).
Alias for [maxKey](Search.md#maxkey).

@@ -709,3 +707,3 @@ #### Parameters

[lib/search/search.ts:375](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/search.ts#L375)
[lib/search/search.ts:350](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/search.ts#L350)

@@ -716,5 +714,5 @@ ___

▸ **returnMin**(`field`): `Promise`<``null`` \| `TEntity`\>
▸ **returnMin**(`field`): `Promise`<``null`` \| [`Entity`](../README.md#entity)\>
Alias for [Search.min](Search.md#min).
Alias for [min](Search.md#min).

@@ -729,7 +727,7 @@ #### Parameters

`Promise`<``null`` \| `TEntity`\>
`Promise`<``null`` \| [`Entity`](../README.md#entity)\>
#### Defined in
[lib/search/search.ts:340](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/search.ts#L340)
[lib/search/search.ts:315](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/search.ts#L315)

@@ -742,3 +740,3 @@ ___

Alias for [Search.minId](Search.md#minid).
Alias for [minId](Search.md#minid).

@@ -757,3 +755,3 @@ #### Parameters

[lib/search/search.ts:347](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/search.ts#L347)
[lib/search/search.ts:322](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/search.ts#L322)

@@ -766,3 +764,3 @@ ___

Alias for [Search.minKey](Search.md#minkey).
Alias for [minKey](Search.md#minkey).

@@ -781,3 +779,3 @@ #### Parameters

[lib/search/search.ts:354](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/search.ts#L354)
[lib/search/search.ts:329](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/search.ts#L329)

@@ -788,5 +786,5 @@ ___

▸ **returnPage**(`offset`, `count`): `Promise`<`TEntity`[]\>
▸ **returnPage**(`offset`, `count`): `Promise`<[`Entity`](../README.md#entity)[]\>
Alias for [Search.page](Search.md#page).
Alias for [page](Search.md#page).

@@ -802,7 +800,7 @@ #### Parameters

`Promise`<`TEntity`[]\>
`Promise`<[`Entity`](../README.md#entity)[]\>
#### Defined in
[lib/search/search.ts:389](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/search.ts#L389)
[lib/search/search.ts:364](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/search.ts#L364)

@@ -815,3 +813,3 @@ ___

Alias for [Search.pageOfIds](Search.md#pageofids).
Alias for [pageOfIds](Search.md#pageofids).

@@ -831,3 +829,3 @@ #### Parameters

[lib/search/search.ts:396](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/search.ts#L396)
[lib/search/search.ts:371](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/search.ts#L371)

@@ -840,3 +838,3 @@ ___

Alias for {@link Search.pageOrKeys}.
Alias for [pageOfKeys](Search.md#pageofkeys).

@@ -856,3 +854,3 @@ #### Parameters

[lib/search/search.ts:403](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/search.ts#L403)
[lib/search/search.ts:378](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/search.ts#L378)

@@ -863,5 +861,5 @@ ___

▸ **sortAsc**(`field`): [`AbstractSearch`](AbstractSearch.md)<`TEntity`\>
▸ **sortAsc**(`field`): [`AbstractSearch`](AbstractSearch.md)
Alias for [Search.sortAscending](Search.md#sortascending).
Alias for [sortAscending](Search.md#sortascending).

@@ -876,7 +874,7 @@ #### Parameters

[`AbstractSearch`](AbstractSearch.md)<`TEntity`\>
[`AbstractSearch`](AbstractSearch.md)
#### Defined in
[lib/search/search.ts:83](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/search.ts#L83)
[lib/search/search.ts:86](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/search.ts#L86)

@@ -887,3 +885,3 @@ ___

▸ **sortAscending**(`field`): [`AbstractSearch`](AbstractSearch.md)<`TEntity`\>
▸ **sortAscending**(`field`): [`AbstractSearch`](AbstractSearch.md)

@@ -900,3 +898,3 @@ Applies an ascending sort to the query.

[`AbstractSearch`](AbstractSearch.md)<`TEntity`\>
[`AbstractSearch`](AbstractSearch.md)

@@ -907,3 +905,3 @@ this

[lib/search/search.ts:60](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/search.ts#L60)
[lib/search/search.ts:63](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/search.ts#L63)

@@ -914,3 +912,3 @@ ___

▸ **sortBy**(`field`, `order?`): [`AbstractSearch`](AbstractSearch.md)<`TEntity`\>
▸ **sortBy**(`fieldName`, `order?`): [`AbstractSearch`](AbstractSearch.md)

@@ -923,8 +921,8 @@ Applies sorting for the query.

| :------ | :------ | :------ | :------ |
| `field` | `string` | `undefined` | The field to sort by. |
| `order` | ``"ASC"`` \| ``"DESC"`` | `'ASC'` | The order of returned [Entities](Entity.md) Defaults to `ASC` (ascending) if not specified |
| `fieldName` | `string` | `undefined` | - |
| `order` | ``"ASC"`` \| ``"DESC"`` | `'ASC'` | The order of returned [Entities](../README.md#entity) Defaults to `ASC` (ascending) if not specified |
#### Returns
[`AbstractSearch`](AbstractSearch.md)<`TEntity`\>
[`AbstractSearch`](AbstractSearch.md)

@@ -935,3 +933,3 @@ this

[lib/search/search.ts:93](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/search.ts#L93)
[lib/search/search.ts:96](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/search.ts#L96)

@@ -942,5 +940,5 @@ ___

▸ **sortDesc**(`field`): [`AbstractSearch`](AbstractSearch.md)<`TEntity`\>
▸ **sortDesc**(`field`): [`AbstractSearch`](AbstractSearch.md)
Alias for [Search.sortDescending](Search.md#sortdescending).
Alias for [sortDescending](Search.md#sortdescending).

@@ -955,7 +953,7 @@ #### Parameters

[`AbstractSearch`](AbstractSearch.md)<`TEntity`\>
[`AbstractSearch`](AbstractSearch.md)
#### Defined in
[lib/search/search.ts:67](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/search.ts#L67)
[lib/search/search.ts:70](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/search.ts#L70)

@@ -966,3 +964,3 @@ ___

▸ **sortDescending**(`field`): [`AbstractSearch`](AbstractSearch.md)<`TEntity`\>
▸ **sortDescending**(`field`): [`AbstractSearch`](AbstractSearch.md)

@@ -979,3 +977,3 @@ Applies a descending sort to the query.

[`AbstractSearch`](AbstractSearch.md)<`TEntity`\>
[`AbstractSearch`](AbstractSearch.md)

@@ -986,2 +984,2 @@ this

[lib/search/search.ts:76](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/search.ts#L76)
[lib/search/search.ts:79](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/search.ts#L79)

@@ -32,2 +32,3 @@ [redis-om](../README.md) / Circle

- [longitude](Circle.md#longitude)
- [origin](Circle.md#origin)
- [radius](Circle.md#radius)

@@ -57,3 +58,3 @@

[lib/search/where-point.ts:150](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/where-point.ts#L150)
[lib/search/where-point.ts:149](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/where-point.ts#L149)

@@ -76,3 +77,3 @@ ___

[lib/search/where-point.ts:144](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/where-point.ts#L144)
[lib/search/where-point.ts:143](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/where-point.ts#L143)

@@ -95,3 +96,3 @@ ___

[lib/search/where-point.ts:138](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/where-point.ts#L138)
[lib/search/where-point.ts:137](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/where-point.ts#L137)

@@ -114,3 +115,3 @@ ___

[lib/search/where-point.ts:123](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/where-point.ts#L123)
[lib/search/where-point.ts:122](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/where-point.ts#L122)

@@ -133,3 +134,3 @@ ___

[lib/search/where-point.ts:129](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/where-point.ts#L129)
[lib/search/where-point.ts:128](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/where-point.ts#L128)

@@ -152,3 +153,3 @@ ___

[lib/search/where-point.ts:117](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/where-point.ts#L117)
[lib/search/where-point.ts:116](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/where-point.ts#L116)

@@ -171,3 +172,3 @@ ___

[lib/search/where-point.ts:96](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/where-point.ts#L96)
[lib/search/where-point.ts:95](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/where-point.ts#L95)

@@ -190,3 +191,3 @@ ___

[lib/search/where-point.ts:102](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/where-point.ts#L102)
[lib/search/where-point.ts:101](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/where-point.ts#L101)

@@ -209,3 +210,3 @@ ___

[lib/search/where-point.ts:108](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/where-point.ts#L108)
[lib/search/where-point.ts:107](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/where-point.ts#L107)

@@ -228,3 +229,3 @@ ___

[lib/search/where-point.ts:159](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/where-point.ts#L159)
[lib/search/where-point.ts:158](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/where-point.ts#L158)

@@ -247,3 +248,3 @@ ___

[lib/search/where-point.ts:165](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/where-point.ts#L165)
[lib/search/where-point.ts:164](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/where-point.ts#L164)

@@ -266,3 +267,3 @@ ___

[lib/search/where-point.ts:171](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/where-point.ts#L171)
[lib/search/where-point.ts:170](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/where-point.ts#L170)

@@ -291,3 +292,3 @@ ## Methods

[lib/search/where-point.ts:43](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/where-point.ts#L43)
[lib/search/where-point.ts:42](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/where-point.ts#L42)

@@ -316,6 +317,53 @@ ___

[lib/search/where-point.ts:32](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/where-point.ts#L32)
[lib/search/where-point.ts:31](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/where-point.ts#L31)
___
### origin
▸ **origin**(`point`): [`Circle`](Circle.md)
Sets the origin of the circle using a [Point](../README.md#point). If not
set, defaults to [Null Island](https://en.wikipedia.org/wiki/Null_Island).
#### Parameters
| Name | Type | Description |
| :------ | :------ | :------ |
| `point` | [`Point`](../README.md#point) | A [Point](../README.md#point) containing the longitude and latitude of the origin. |
#### Returns
[`Circle`](Circle.md)
This instance.
#### Defined in
[lib/search/where-point.ts:54](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/where-point.ts#L54)
▸ **origin**(`longitude`, `latitude`): [`Circle`](Circle.md)
Sets the origin of the circle. If not set, defaults to
[Null Island](https://en.wikipedia.org/wiki/Null_Island).
#### Parameters
| Name | Type | Description |
| :------ | :------ | :------ |
| `longitude` | `number` | The longitude. |
| `latitude` | `number` | The latitude. |
#### Returns
[`Circle`](Circle.md)
This instance.
#### Defined in
[lib/search/where-point.ts:64](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/where-point.ts#L64)
___
### radius

@@ -342,2 +390,2 @@

[lib/search/where-point.ts:87](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/where-point.ts#L87)
[lib/search/where-point.ts:86](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/where-point.ts#L86)

@@ -10,4 +10,4 @@ [redis-om](../README.md) / Client

```typescript
const client = new Client();
await client.open();
const client = new Client()
await client.open()
```

@@ -18,2 +18,6 @@

**`Deprecated`**
Just used Node Redis client directly and pass it to the Repository.
## Table of contents

@@ -25,6 +29,9 @@

### Accessors
- [redis](Client.md#redis)
### Methods
- [close](Client.md#close)
- [execute](Client.md#execute)
- [fetchRepository](Client.md#fetchrepository)

@@ -34,2 +41,3 @@ - [isOpen](Client.md#isopen)

- [use](Client.md#use)
- [useNoClose](Client.md#usenoclose)

@@ -42,41 +50,33 @@ ## Constructors

## Methods
## Accessors
### close
### redis
▸ **close**(): `Promise`<`void`\>
• `get` **redis**(): `undefined` \| [`RedisConnection`](../README.md#redisconnection)
Close the connection to Redis.
Returns the underlying Node Redis connection being used.
#### Returns
`Promise`<`void`\>
`undefined` \| [`RedisConnection`](../README.md#redisconnection)
#### Defined in
[lib/client.ts:131](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/client.ts#L131)
[lib/client/client.ts:70](https://github.com/redis/redis-om-node/blob/5777b6c/lib/client/client.ts#L70)
___
## Methods
### execute
### close
▸ **execute**(`command`): `Promise`<`unknown`\>
▸ **close**(): `Promise`<`void`\>
Execute an arbitrary Redis command.
Close the connection to Redis.
#### Parameters
| Name | Type | Description |
| :------ | :------ | :------ |
| `command` | (`string` \| `number` \| `boolean`)[] | The command to execute. |
#### Returns
`Promise`<`unknown`\>
`Promise`<`void`\>
The raw results of calling the Redis command.
#### Defined in
[lib/client.ts:104](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/client.ts#L104)
[lib/client/client.ts:127](https://github.com/redis/redis-om-node/blob/5777b6c/lib/client/client.ts#L127)

@@ -87,12 +87,6 @@ ___

▸ **fetchRepository**<`TEntity`\>(`schema`): [`Repository`](Repository.md)<`TEntity`\>
▸ **fetchRepository**(`schema`): [`Repository`](Repository.md)
Creates a repository for the given schema.
#### Type parameters
| Name | Type | Description |
| :------ | :------ | :------ |
| `TEntity` | extends [`Entity`](Entity.md)<`TEntity`\> | The entity type for this [Schema](Schema.md) and [Repository](Repository.md). |
#### Parameters

@@ -102,7 +96,7 @@

| :------ | :------ | :------ |
| `schema` | [`Schema`](Schema.md)<`TEntity`\> | The schema. |
| `schema` | [`Schema`](Schema.md) | The schema. |
#### Returns
[`Repository`](Repository.md)<`TEntity`\>
[`Repository`](Repository.md)

@@ -113,3 +107,3 @@ A repository for the provided schema.

[lib/client.ts:119](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/client.ts#L119)
[lib/client/client.ts:119](https://github.com/redis/redis-om-node/blob/5777b6c/lib/client/client.ts#L119)

@@ -130,3 +124,3 @@ ___

[lib/client.ts:245](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/client.ts#L245)
[lib/client/client.ts:207](https://github.com/redis/redis-om-node/blob/5777b6c/lib/client/client.ts#L207)

@@ -155,3 +149,3 @@ ___

[lib/client.ts:90](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/client.ts#L90)
[lib/client/client.ts:104](https://github.com/redis/redis-om-node/blob/5777b6c/lib/client/client.ts#L104)

@@ -171,3 +165,3 @@ ___

| :------ | :------ | :------ |
| `connection` | `RedisClientType`<{ `bf`: { `ADD`: `__module` ; `EXISTS`: `__module` ; `INFO`: `__module` ; `INSERT`: `__module` ; `LOADCHUNK`: `__module` ; `MADD`: `__module` ; `MEXISTS`: `__module` ; `RESERVE`: `__module` ; `SCANDUMP`: `__module` ; `add`: `__module` ; `exists`: `__module` ; `info`: `__module` ; `insert`: `__module` ; `loadChunk`: `__module` ; `mAdd`: `__module` ; `mExists`: `__module` ; `reserve`: `__module` ; `scanDump`: `__module` } ; `cf`: { `ADD`: `__module` ; `ADDNX`: `__module` ; `COUNT`: `__module` ; `DEL`: `__module` ; `EXISTS`: `__module` ; `INFO`: `__module` ; `INSERT`: `__module` ; `INSERTNX`: `__module` ; `LOADCHUNK`: `__module` ; `RESERVE`: `__module` ; `SCANDUMP`: `__module` ; `add`: `__module` ; `addNX`: `__module` ; `count`: `__module` ; `del`: `__module` ; `exists`: `__module` ; `info`: `__module` ; `insert`: `__module` ; `insertNX`: `__module` ; `loadChunk`: `__module` ; `reserve`: `__module` ; `scanDump`: `__module` } ; `cms`: { `INCRBY`: `__module` ; `INFO`: `__module` ; `INITBYDIM`: `__module` ; `INITBYPROB`: `__module` ; `MERGE`: `__module` ; `QUERY`: `__module` ; `incrBy`: `__module` ; `info`: `__module` ; `initByDim`: `__module` ; `initByProb`: `__module` ; `merge`: `__module` ; `query`: `__module` } ; `ft`: { `AGGREGATE`: `__module` ; `ALIASADD`: `__module` ; `ALIASDEL`: `__module` ; `ALIASUPDATE`: `__module` ; `ALTER`: `__module` ; `CONFIG_GET`: `__module` ; `CONFIG_SET`: `__module` ; `CREATE`: `__module` ; `DICTADD`: `__module` ; `DICTDEL`: `__module` ; `DICTDUMP`: `__module` ; `DROPINDEX`: `__module` ; `EXPLAIN`: `__module` ; `EXPLAINCLI`: `__module` ; `INFO`: `__module` ; `PROFILEAGGREGATE`: `__module` ; `PROFILESEARCH`: `__module` ; `SEARCH`: `__module` ; `SPELLCHECK`: `__module` ; `SUGADD`: `__module` ; `SUGDEL`: `__module` ; `SUGGET`: `__module` ; `SUGGET_WITHPAYLOADS`: `__module` ; `SUGGET_WITHSCORES`: `__module` ; `SUGGET_WITHSCORES_WITHPAYLOADS`: `__module` ; `SUGLEN`: `__module` ; `SYNDUMP`: `__module` ; `SYNUPDATE`: `__module` ; `TAGVALS`: `__module` ; `_LIST`: `__module` ; `_list`: `__module` ; `aggregate`: `__module` ; `aliasAdd`: `__module` ; `aliasDel`: `__module` ; `aliasUpdate`: `__module` ; `alter`: `__module` ; `configGet`: `__module` ; `configSet`: `__module` ; `create`: `__module` ; `dictAdd`: `__module` ; `dictDel`: `__module` ; `dictDump`: `__module` ; `dropIndex`: `__module` ; `explain`: `__module` ; `explainCli`: `__module` ; `info`: `__module` ; `profileAggregate`: `__module` ; `profileSearch`: `__module` ; `search`: `__module` ; `spellCheck`: `__module` ; `sugAdd`: `__module` ; `sugDel`: `__module` ; `sugGet`: `__module` ; `sugGetWithPayloads`: `__module` ; `sugGetWithScores`: `__module` ; `sugGetWithScoresWithPayloads`: `__module` ; `sugLen`: `__module` ; `synDump`: `__module` ; `synUpdate`: `__module` ; `tagVals`: `__module` } ; `graph`: { `CONFIG_GET`: `__module` ; `CONFIG_SET`: `__module` ; `DELETE`: `__module` ; `EXPLAIN`: `__module` ; `LIST`: `__module` ; `PROFILE`: `__module` ; `QUERY`: `__module` ; `QUERY_RO`: `__module` ; `SLOWLOG`: `__module` ; `configGet`: `__module` ; `configSet`: `__module` ; `delete`: `__module` ; `explain`: `__module` ; `list`: `__module` ; `profile`: `__module` ; `query`: `__module` ; `queryRo`: `__module` ; `slowLog`: `__module` } ; `json`: { `ARRAPPEND`: `__module` ; `ARRINDEX`: `__module` ; `ARRINSERT`: `__module` ; `ARRLEN`: `__module` ; `ARRPOP`: `__module` ; `ARRTRIM`: `__module` ; `DEBUG_MEMORY`: `__module` ; `DEL`: `__module` ; `FORGET`: `__module` ; `GET`: `__module` ; `MGET`: `__module` ; `NUMINCRBY`: `__module` ; `NUMMULTBY`: `__module` ; `OBJKEYS`: `__module` ; `OBJLEN`: `__module` ; `RESP`: `__module` ; `SET`: `__module` ; `STRAPPEND`: `__module` ; `STRLEN`: `__module` ; `TYPE`: `__module` ; `arrAppend`: `__module` ; `arrIndex`: `__module` ; `arrInsert`: `__module` ; `arrLen`: `__module` ; `arrPop`: `__module` ; `arrTrim`: `__module` ; `debugMemory`: `__module` ; `del`: `__module` ; `forget`: `__module` ; `get`: `__module` ; `mGet`: `__module` ; `numIncrBy`: `__module` ; `numMultBy`: `__module` ; `objKeys`: `__module` ; `objLen`: `__module` ; `resp`: `__module` ; `set`: `__module` ; `strAppend`: `__module` ; `strLen`: `__module` ; `type`: `__module` } ; `topK`: { `ADD`: `__module` ; `COUNT`: `__module` ; `INCRBY`: `__module` ; `INFO`: `__module` ; `LIST`: `__module` ; `LIST_WITHCOUNT`: `__module` ; `QUERY`: `__module` ; `RESERVE`: `__module` ; `add`: `__module` ; `count`: `__module` ; `incrBy`: `__module` ; `info`: `__module` ; `list`: `__module` ; `listWithCount`: `__module` ; `query`: `__module` ; `reserve`: `__module` } ; `ts`: { `ADD`: `__module` ; `ALTER`: `__module` ; `CREATE`: `__module` ; `CREATERULE`: `__module` ; `DECRBY`: `__module` ; `DEL`: `__module` ; `DELETERULE`: `__module` ; `GET`: `__module` ; `INCRBY`: `__module` ; `INFO`: `__module` ; `INFO_DEBUG`: `__module` ; `MADD`: `__module` ; `MGET`: `__module` ; `MGET_WITHLABELS`: `__module` ; `MRANGE`: `__module` ; `MRANGE_WITHLABELS`: `__module` ; `MREVRANGE`: `__module` ; `MREVRANGE_WITHLABELS`: `__module` ; `QUERYINDEX`: `__module` ; `RANGE`: `__module` ; `REVRANGE`: `__module` ; `add`: `__module` ; `alter`: `__module` ; `create`: `__module` ; `createRule`: `__module` ; `decrBy`: `__module` ; `del`: `__module` ; `deleteRule`: `__module` ; `get`: `__module` ; `incrBy`: `__module` ; `info`: `__module` ; `infoDebug`: `__module` ; `mAdd`: `__module` ; `mGet`: `__module` ; `mGetWithLabels`: `__module` ; `mRange`: `__module` ; `mRangeWithLabels`: `__module` ; `mRevRange`: `__module` ; `mRevRangeWithLabels`: `__module` ; `queryIndex`: `__module` ; `range`: `__module` ; `revRange`: `__module` } } & `RedisModules`, `RedisFunctions`, `RedisScripts`\> | An existing Node Redis client. |
| `connection` | [`RedisConnection`](../README.md#redisconnection) | An existing Node Redis client. |

@@ -182,2 +176,27 @@ #### Returns

[lib/client.ts:78](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/client.ts#L78)
[lib/client/client.ts:81](https://github.com/redis/redis-om-node/blob/5777b6c/lib/client/client.ts#L81)
___
### useNoClose
▸ **useNoClose**(`connection`): [`Client`](Client.md)
Attaches an existing Node Redis connection to this Redis OM client. Does
not close any existing connection.
#### Parameters
| Name | Type | Description |
| :------ | :------ | :------ |
| `connection` | [`RedisConnection`](../README.md#redisconnection) | An existing Node Redis client. |
#### Returns
[`Client`](Client.md)
This [Client](Client.md) instance.
#### Defined in
[lib/client/client.ts:93](https://github.com/redis/redis-om-node/blob/5777b6c/lib/client/client.ts#L93)
[redis-om](../README.md) / RawSearch
# Class: RawSearch<TEntity\>
# Class: RawSearch

@@ -9,11 +9,9 @@ Entry point to raw search which allows using raw RediSearch queries

## Type parameters
**`Template`**
| Name | Type | Description |
| :------ | :------ | :------ |
| `TEntity` | extends [`Entity`](Entity.md) | The type of [Entity](Entity.md) being sought. |
The type of [Entity](../README.md#entity) being sought.
## Hierarchy
- [`AbstractSearch`](AbstractSearch.md)<`TEntity`\>
- [`AbstractSearch`](AbstractSearch.md)

@@ -72,3 +70,3 @@ ↳ **`RawSearch`**

• `get` **return**(): [`AbstractSearch`](AbstractSearch.md)<`TEntity`\>
• `get` **return**(): [`AbstractSearch`](AbstractSearch.md)

@@ -79,3 +77,3 @@ Returns the current instance. Syntactic sugar to make your code more fluent.

[`AbstractSearch`](AbstractSearch.md)<`TEntity`\>
[`AbstractSearch`](AbstractSearch.md)

@@ -90,3 +88,3 @@ this

[lib/search/search.ts:333](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/search.ts#L333)
[lib/search/search.ts:308](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/search.ts#L308)

@@ -97,6 +95,6 @@ ## Methods

▸ **all**(`options?`): `Promise`<`TEntity`[]\>
▸ **all**(`options?`): `Promise`<[`Entity`](../README.md#entity)[]\>
Returns all the [Entities](Entity.md) that match this query. This method
makes multiple calls to Redis until all the [Entities](Entity.md) are returned.
Returns all the [Entities](../README.md#entity) that match this query. This method
makes multiple calls to Redis until all the [Entities](../README.md#entity) are returned.
You can specify the batch size by setting the `pageSize` property on the

@@ -106,3 +104,3 @@ options:

```typescript
const entities = await repository.search().returnAll({ pageSize: 100 });
const entities = await repository.search().returnAll({ pageSize: 100 })
```

@@ -115,9 +113,9 @@

| `options` | `Object` | `undefined` | Options for the call. |
| `options.pageSize` | `number` | `10` | Number of [Entities](Entity.md) returned per batch. |
| `options.pageSize` | `number` | `10` | Number of [Entities](../README.md#entity) returned per batch. |
#### Returns
`Promise`<`TEntity`[]\>
`Promise`<[`Entity`](../README.md#entity)[]\>
An array of [Entities](Entity.md) matching the query.
An array of [Entities](../README.md#entity) matching the query.

@@ -130,3 +128,3 @@ #### Inherited from

[lib/search/search.ts:266](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/search.ts#L266)
[lib/search/search.ts:264](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/search.ts#L264)

@@ -145,3 +143,3 @@ ___

```typescript
const keys = await repository.search().returnAllIds({ pageSize: 100 });
const keys = await repository.search().returnAllIds({ pageSize: 100 })
```

@@ -168,3 +166,3 @@

[lib/search/search.ts:295](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/search.ts#L295)
[lib/search/search.ts:282](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/search.ts#L282)

@@ -183,3 +181,3 @@ ___

```typescript
const keys = await repository.search().returnAllKeys({ pageSize: 100 });
const keys = await repository.search().returnAllKeys({ pageSize: 100 })
```

@@ -206,3 +204,3 @@

[lib/search/search.ts:314](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/search.ts#L314)
[lib/search/search.ts:300](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/search.ts#L300)

@@ -215,3 +213,3 @@ ___

Returns the number of [Entities](Entity.md) that match this query.
Returns the number of [Entities](../README.md#entity) that match this query.

@@ -228,3 +226,3 @@ #### Returns

[lib/search/search.ts:186](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/search.ts#L186)
[lib/search/search.ts:188](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/search.ts#L188)

@@ -235,9 +233,9 @@ ___

▸ **first**(): `Promise`<``null`` \| `TEntity`\>
▸ **first**(): `Promise`<``null`` \| [`Entity`](../README.md#entity)\>
Returns the first [Entity](Entity.md) that matches this query.
Returns the first [Entity](../README.md#entity) that matches this query.
#### Returns
`Promise`<``null`` \| `TEntity`\>
`Promise`<``null`` \| [`Entity`](../README.md#entity)\>

@@ -250,3 +248,3 @@ #### Inherited from

[lib/search/search.ts:231](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/search.ts#L231)
[lib/search/search.ts:229](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/search.ts#L229)

@@ -271,3 +269,3 @@ ___

[lib/search/search.ts:239](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/search.ts#L239)
[lib/search/search.ts:237](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/search.ts#L237)

@@ -292,3 +290,3 @@ ___

[lib/search/search.ts:247](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/search.ts#L247)
[lib/search/search.ts:245](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/search.ts#L245)

@@ -299,5 +297,5 @@ ___

▸ **max**(`field`): `Promise`<``null`` \| `TEntity`\>
▸ **max**(`field`): `Promise`<``null`` \| [`Entity`](../README.md#entity)\>
Finds the [Entity](Entity.md) with the maximal value for a field.
Finds the [Entity](../README.md#entity) with the maximal value for a field.

@@ -312,5 +310,5 @@ #### Parameters

`Promise`<``null`` \| `TEntity`\>
`Promise`<``null`` \| [`Entity`](../README.md#entity)\>
The entity ID [Entity](Entity.md) with the maximal value
The entity ID [Entity](../README.md#entity) with the maximal value

@@ -323,3 +321,3 @@ #### Inherited from

[lib/search/search.ts:159](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/search.ts#L159)
[lib/search/search.ts:162](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/search.ts#L162)

@@ -352,3 +350,3 @@ ___

[lib/search/search.ts:168](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/search.ts#L168)
[lib/search/search.ts:171](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/search.ts#L171)

@@ -381,3 +379,3 @@ ___

[lib/search/search.ts:178](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/search.ts#L178)
[lib/search/search.ts:180](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/search.ts#L180)

@@ -388,5 +386,5 @@ ___

▸ **min**(`field`): `Promise`<``null`` \| `TEntity`\>
▸ **min**(`field`): `Promise`<``null`` \| [`Entity`](../README.md#entity)\>
Finds the [Entity](Entity.md) with the minimal value for a field.
Finds the [Entity](../README.md#entity) with the minimal value for a field.

@@ -401,5 +399,5 @@ #### Parameters

`Promise`<``null`` \| `TEntity`\>
`Promise`<``null`` \| [`Entity`](../README.md#entity)\>
The [Entity](Entity.md) with the minimal value
The [Entity](../README.md#entity) with the minimal value

@@ -412,3 +410,3 @@ #### Inherited from

[lib/search/search.ts:131](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/search.ts#L131)
[lib/search/search.ts:135](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/search.ts#L135)

@@ -441,3 +439,3 @@ ___

[lib/search/search.ts:140](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/search.ts#L140)
[lib/search/search.ts:144](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/search.ts#L144)

@@ -470,3 +468,3 @@ ___

[lib/search/search.ts:150](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/search.ts#L150)
[lib/search/search.ts:153](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/search.ts#L153)

@@ -477,5 +475,5 @@ ___

▸ **page**(`offset`, `count`): `Promise`<`TEntity`[]\>
▸ **page**(`offset`, `count`): `Promise`<[`Entity`](../README.md#entity)[]\>
Returns a page of [Entities](Entity.md) that match this query.
Returns a page of [Entities](../README.md#entity) that match this query.

@@ -486,10 +484,10 @@ #### Parameters

| :------ | :------ | :------ |
| `offset` | `number` | The offset for where to start returning [Entities](Entity.md). |
| `count` | `number` | The number of [Entities](Entity.md) to return. |
| `offset` | `number` | The offset for where to start returning [Entities](../README.md#entity). |
| `count` | `number` | The number of [Entities](../README.md#entity) to return. |
#### Returns
`Promise`<`TEntity`[]\>
`Promise`<[`Entity`](../README.md#entity)[]\>
An array of [Entities](Entity.md) matching the query.
An array of [Entities](../README.md#entity) matching the query.

@@ -502,3 +500,3 @@ #### Inherited from

[lib/search/search.ts:199](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/search.ts#L199)
[lib/search/search.ts:199](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/search.ts#L199)

@@ -532,3 +530,3 @@ ___

[lib/search/search.ts:212](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/search.ts#L212)
[lib/search/search.ts:210](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/search.ts#L210)

@@ -562,3 +560,3 @@ ___

[lib/search/search.ts:223](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/search.ts#L223)
[lib/search/search.ts:221](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/search.ts#L221)

@@ -569,5 +567,5 @@ ___

▸ **returnAll**(`options?`): `Promise`<`TEntity`[]\>
▸ **returnAll**(`options?`): `Promise`<[`Entity`](../README.md#entity)[]\>
Alias for [Search.all](Search.md#all).
Alias for [all](Search.md#all).

@@ -583,3 +581,3 @@ #### Parameters

`Promise`<`TEntity`[]\>
`Promise`<[`Entity`](../README.md#entity)[]\>

@@ -592,3 +590,3 @@ #### Inherited from

[lib/search/search.ts:431](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/search.ts#L431)
[lib/search/search.ts:406](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/search.ts#L406)

@@ -601,3 +599,3 @@ ___

Alias for [Search.allIds](Search.md#allids).
Alias for [allIds](Search.md#allids).

@@ -621,3 +619,3 @@ #### Parameters

[lib/search/search.ts:438](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/search.ts#L438)
[lib/search/search.ts:413](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/search.ts#L413)

@@ -630,3 +628,3 @@ ___

Alias for [Search.allKeys](Search.md#allkeys).
Alias for [allKeys](Search.md#allkeys).

@@ -650,3 +648,3 @@ #### Parameters

[lib/search/search.ts:445](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/search.ts#L445)
[lib/search/search.ts:420](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/search.ts#L420)

@@ -659,3 +657,3 @@ ___

Alias for [Search.count](Search.md#count).
Alias for [count](Search.md#count).

@@ -672,3 +670,3 @@ #### Returns

[lib/search/search.ts:382](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/search.ts#L382)
[lib/search/search.ts:357](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/search.ts#L357)

@@ -679,9 +677,9 @@ ___

▸ **returnFirst**(): `Promise`<``null`` \| `TEntity`\>
▸ **returnFirst**(): `Promise`<``null`` \| [`Entity`](../README.md#entity)\>
Alias for [Search.first](Search.md#first).
Alias for [first](Search.md#first).
#### Returns
`Promise`<``null`` \| `TEntity`\>
`Promise`<``null`` \| [`Entity`](../README.md#entity)\>

@@ -694,3 +692,3 @@ #### Inherited from

[lib/search/search.ts:410](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/search.ts#L410)
[lib/search/search.ts:385](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/search.ts#L385)

@@ -703,3 +701,3 @@ ___

Alias for [Search.firstId](Search.md#firstid).
Alias for [firstId](Search.md#firstid).

@@ -716,3 +714,3 @@ #### Returns

[lib/search/search.ts:417](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/search.ts#L417)
[lib/search/search.ts:392](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/search.ts#L392)

@@ -725,3 +723,3 @@ ___

Alias for [Search.firstKey](Search.md#firstkey).
Alias for [firstKey](Search.md#firstkey).

@@ -738,3 +736,3 @@ #### Returns

[lib/search/search.ts:424](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/search.ts#L424)
[lib/search/search.ts:399](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/search.ts#L399)

@@ -745,5 +743,5 @@ ___

▸ **returnMax**(`field`): `Promise`<``null`` \| `TEntity`\>
▸ **returnMax**(`field`): `Promise`<``null`` \| [`Entity`](../README.md#entity)\>
Alias for [Search.max](Search.md#max).
Alias for [max](Search.md#max).

@@ -758,3 +756,3 @@ #### Parameters

`Promise`<``null`` \| `TEntity`\>
`Promise`<``null`` \| [`Entity`](../README.md#entity)\>

@@ -767,3 +765,3 @@ #### Inherited from

[lib/search/search.ts:361](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/search.ts#L361)
[lib/search/search.ts:336](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/search.ts#L336)

@@ -776,3 +774,3 @@ ___

Alias for [Search.maxId](Search.md#maxid).
Alias for [maxId](Search.md#maxid).

@@ -795,3 +793,3 @@ #### Parameters

[lib/search/search.ts:368](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/search.ts#L368)
[lib/search/search.ts:343](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/search.ts#L343)

@@ -804,3 +802,3 @@ ___

Alias for [Search.maxKey](Search.md#maxkey).
Alias for [maxKey](Search.md#maxkey).

@@ -823,3 +821,3 @@ #### Parameters

[lib/search/search.ts:375](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/search.ts#L375)
[lib/search/search.ts:350](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/search.ts#L350)

@@ -830,5 +828,5 @@ ___

▸ **returnMin**(`field`): `Promise`<``null`` \| `TEntity`\>
▸ **returnMin**(`field`): `Promise`<``null`` \| [`Entity`](../README.md#entity)\>
Alias for [Search.min](Search.md#min).
Alias for [min](Search.md#min).

@@ -843,3 +841,3 @@ #### Parameters

`Promise`<``null`` \| `TEntity`\>
`Promise`<``null`` \| [`Entity`](../README.md#entity)\>

@@ -852,3 +850,3 @@ #### Inherited from

[lib/search/search.ts:340](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/search.ts#L340)
[lib/search/search.ts:315](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/search.ts#L315)

@@ -861,3 +859,3 @@ ___

Alias for [Search.minId](Search.md#minid).
Alias for [minId](Search.md#minid).

@@ -880,3 +878,3 @@ #### Parameters

[lib/search/search.ts:347](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/search.ts#L347)
[lib/search/search.ts:322](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/search.ts#L322)

@@ -889,3 +887,3 @@ ___

Alias for [Search.minKey](Search.md#minkey).
Alias for [minKey](Search.md#minkey).

@@ -908,3 +906,3 @@ #### Parameters

[lib/search/search.ts:354](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/search.ts#L354)
[lib/search/search.ts:329](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/search.ts#L329)

@@ -915,5 +913,5 @@ ___

▸ **returnPage**(`offset`, `count`): `Promise`<`TEntity`[]\>
▸ **returnPage**(`offset`, `count`): `Promise`<[`Entity`](../README.md#entity)[]\>
Alias for [Search.page](Search.md#page).
Alias for [page](Search.md#page).

@@ -929,3 +927,3 @@ #### Parameters

`Promise`<`TEntity`[]\>
`Promise`<[`Entity`](../README.md#entity)[]\>

@@ -938,3 +936,3 @@ #### Inherited from

[lib/search/search.ts:389](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/search.ts#L389)
[lib/search/search.ts:364](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/search.ts#L364)

@@ -947,3 +945,3 @@ ___

Alias for [Search.pageOfIds](Search.md#pageofids).
Alias for [pageOfIds](Search.md#pageofids).

@@ -967,3 +965,3 @@ #### Parameters

[lib/search/search.ts:396](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/search.ts#L396)
[lib/search/search.ts:371](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/search.ts#L371)

@@ -976,3 +974,3 @@ ___

Alias for {@link Search.pageOrKeys}.
Alias for [pageOfKeys](Search.md#pageofkeys).

@@ -996,3 +994,3 @@ #### Parameters

[lib/search/search.ts:403](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/search.ts#L403)
[lib/search/search.ts:378](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/search.ts#L378)

@@ -1003,5 +1001,5 @@ ___

▸ **sortAsc**(`field`): [`AbstractSearch`](AbstractSearch.md)<`TEntity`\>
▸ **sortAsc**(`field`): [`AbstractSearch`](AbstractSearch.md)
Alias for [Search.sortAscending](Search.md#sortascending).
Alias for [sortAscending](Search.md#sortascending).

@@ -1016,3 +1014,3 @@ #### Parameters

[`AbstractSearch`](AbstractSearch.md)<`TEntity`\>
[`AbstractSearch`](AbstractSearch.md)

@@ -1025,3 +1023,3 @@ #### Inherited from

[lib/search/search.ts:83](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/search.ts#L83)
[lib/search/search.ts:86](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/search.ts#L86)

@@ -1032,3 +1030,3 @@ ___

▸ **sortAscending**(`field`): [`AbstractSearch`](AbstractSearch.md)<`TEntity`\>
▸ **sortAscending**(`field`): [`AbstractSearch`](AbstractSearch.md)

@@ -1045,3 +1043,3 @@ Applies an ascending sort to the query.

[`AbstractSearch`](AbstractSearch.md)<`TEntity`\>
[`AbstractSearch`](AbstractSearch.md)

@@ -1056,3 +1054,3 @@ this

[lib/search/search.ts:60](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/search.ts#L60)
[lib/search/search.ts:63](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/search.ts#L63)

@@ -1063,3 +1061,3 @@ ___

▸ **sortBy**(`field`, `order?`): [`AbstractSearch`](AbstractSearch.md)<`TEntity`\>
▸ **sortBy**(`fieldName`, `order?`): [`AbstractSearch`](AbstractSearch.md)

@@ -1072,8 +1070,8 @@ Applies sorting for the query.

| :------ | :------ | :------ | :------ |
| `field` | `string` | `undefined` | The field to sort by. |
| `order` | ``"ASC"`` \| ``"DESC"`` | `'ASC'` | The order of returned [Entities](Entity.md) Defaults to `ASC` (ascending) if not specified |
| `fieldName` | `string` | `undefined` | - |
| `order` | ``"ASC"`` \| ``"DESC"`` | `'ASC'` | The order of returned [Entities](../README.md#entity) Defaults to `ASC` (ascending) if not specified |
#### Returns
[`AbstractSearch`](AbstractSearch.md)<`TEntity`\>
[`AbstractSearch`](AbstractSearch.md)

@@ -1088,3 +1086,3 @@ this

[lib/search/search.ts:93](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/search.ts#L93)
[lib/search/search.ts:96](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/search.ts#L96)

@@ -1095,5 +1093,5 @@ ___

▸ **sortDesc**(`field`): [`AbstractSearch`](AbstractSearch.md)<`TEntity`\>
▸ **sortDesc**(`field`): [`AbstractSearch`](AbstractSearch.md)
Alias for [Search.sortDescending](Search.md#sortdescending).
Alias for [sortDescending](Search.md#sortdescending).

@@ -1108,3 +1106,3 @@ #### Parameters

[`AbstractSearch`](AbstractSearch.md)<`TEntity`\>
[`AbstractSearch`](AbstractSearch.md)

@@ -1117,3 +1115,3 @@ #### Inherited from

[lib/search/search.ts:67](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/search.ts#L67)
[lib/search/search.ts:70](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/search.ts#L70)

@@ -1124,3 +1122,3 @@ ___

▸ **sortDescending**(`field`): [`AbstractSearch`](AbstractSearch.md)<`TEntity`\>
▸ **sortDescending**(`field`): [`AbstractSearch`](AbstractSearch.md)

@@ -1137,3 +1135,3 @@ Applies a descending sort to the query.

[`AbstractSearch`](AbstractSearch.md)<`TEntity`\>
[`AbstractSearch`](AbstractSearch.md)

@@ -1148,2 +1146,2 @@ this

[lib/search/search.ts:76](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/search.ts#L76)
[lib/search/search.ts:79](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/search.ts#L79)
[redis-om](../README.md) / Repository
# Class: Repository<TEntity\>
# Class: Repository
A repository is the main interaction point for reading, writing, and
removing [Entities](Entity.md) from Redis. Create one by calling
[Client.fetchRepository](Client.md#fetchrepository) and passing in a [Schema](Schema.md). Then
use the [Repository.fetch](Repository.md#fetch), [Repository.save](Repository.md#save), and
[Repository.remove](Repository.md#remove) methods to manage your data:
removing [Entities](../README.md#entity) from Redis. Create one by calling
[fetchRepository](Client.md#fetchrepository) and passing in a [Schema](Schema.md). Then
use the [fetch](Repository.md#fetch), [save](Repository.md#save), and
[remove](Repository.md#remove) methods to manage your data:
```typescript
const repository = client.fetchRepository<Foo>(schema);
const repository = client.fetchRepository(schema)
const foo = await repository.fetch('01FK6TCJBDK41RJ766A4SBWDJ9');
foo.aString = 'bar';
foo.aBoolean = false;
await repository.save(foo);
const foo = await repository.fetch('01FK6TCJBDK41RJ766A4SBWDJ9')
foo.aString = 'bar'
foo.aBoolean = false
await repository.save(foo)
```
Be sure to use the repository to create a new instance of an
[Entity](Entity.md) you want to create before you save it:
Use the repository to create a new instance of an [Entity](../README.md#entity)
before you save it:
```typescript
const foo = await repository.createEntity();
foo.aString = 'bar';
foo.aBoolean = false;
await repository.save(foo);
const foo = await repository.createEntity()
foo.aString = 'bar'
foo.aBoolean = false
await repository.save(foo)
```
If you want to the [Repository.search](Repository.md#search) method, you need to create an index
If you want to use the [search](Repository.md#search) method, you need to create an index
first, and you need RediSearch or RedisJSON installed on your instance of Redis:
```typescript
await repository.createIndex();
await repository.createIndex()
const entities = await repository.search()
.where('aString').eq('bar')
.and('aBoolean').is.false().returnAll();
.and('aBoolean').is.false().returnAll()
```
## Type parameters
| Name | Type | Description |
| :------ | :------ | :------ |
| `TEntity` | extends [`Entity`](Entity.md) | The type of [Entity](Entity.md) that this repository manages. |
## Table of contents
### Properties
### Constructors
- [client](Repository.md#client)
- [schema](Repository.md#schema)
- [constructor](Repository.md#constructor)
### Methods
- [createAndSave](Repository.md#createandsave)
- [createEntity](Repository.md#createentity)
- [createIndex](Repository.md#createindex)

@@ -66,31 +57,10 @@ - [dropIndex](Repository.md#dropindex)

## Properties
## Constructors
### client
### constructor
• `Protected` **client**: [`Client`](Client.md)
• **new Repository**(`schema`, `clientOrConnection`)
#### Defined in
Creates a new [Repository](Repository.md).
[lib/repository/index.ts:49](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/repository/index.ts#L49)
___
### schema
• `Protected` **schema**: [`Schema`](Schema.md)<`TEntity`\>
#### Defined in
[lib/repository/index.ts:50](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/repository/index.ts#L50)
## Methods
### createAndSave
▸ **createAndSave**(`data?`): `Promise`<`TEntity`\>
Creates and saves an [Entity](Entity.md). Equivalent of calling
[Repository.createEntity](Repository.md#createentity) followed by [Repository.save](Repository.md#save).
#### Parameters

@@ -100,40 +70,11 @@

| :------ | :------ | :------ |
| `data` | [`EntityData`](../README.md#entitydata) | Optional values with which to initialize the entity. |
| `schema` | [`Schema`](Schema.md) | The schema defining that data in the repository. |
| `clientOrConnection` | [`Client`](Client.md) \| [`RedisConnection`](../README.md#redisconnection) | - |
#### Returns
`Promise`<`TEntity`\>
The newly created and saved Entity.
#### Defined in
[lib/repository/index.ts:130](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/repository/index.ts#L130)
[lib/repository/repository.ts:56](https://github.com/redis/redis-om-node/blob/5777b6c/lib/repository/repository.ts#L56)
___
## Methods
### createEntity
▸ **createEntity**(`data?`): `TEntity`
Creates an [Entity](Entity.md) with a populated [Entity.entityId](Entity.md#entityid) property.
#### Parameters
| Name | Type | Description |
| :------ | :------ | :------ |
| `data` | [`EntityData`](../README.md#entitydata) | Optional values with which to initialize the entity. |
#### Returns
`TEntity`
A newly created Entity.
#### Defined in
[lib/repository/index.ts:108](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/repository/index.ts#L108)
___
### createIndex

@@ -143,4 +84,5 @@

Creates an index in Redis for use by the [Repository.search](Repository.md#search) method. Requires
that RediSearch or RedisJSON is installed on your instance of Redis.
Creates an index in Redis for use by the [search](Repository.md#search) method.
Does not create a new index if the index hasn't changed. Requires that
RediSearch and RedisJSON are installed on your instance of Redis.

@@ -153,3 +95,3 @@ #### Returns

[lib/repository/index.ts:62](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/repository/index.ts#L62)
[lib/repository/repository.ts:71](https://github.com/redis/redis-om-node/blob/5777b6c/lib/repository/repository.ts#L71)

@@ -163,3 +105,3 @@ ___

Removes an existing index from Redis. Use this method if you want to swap out your index
because your [Entity](Entity.md) has changed. Requires that RediSearch or RedisJSON is installed
because your [Entity](../README.md#entity) has changed. Requires that RediSearch and RedisJSON are installed
on your instance of Redis.

@@ -173,3 +115,3 @@

[lib/repository/index.ts:90](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/repository/index.ts#L90)
[lib/repository/repository.ts:109](https://github.com/redis/redis-om-node/blob/5777b6c/lib/repository/repository.ts#L109)

@@ -182,3 +124,3 @@ ___

Set the time to live of the [Entity](Entity.md). If the [Entity](Entity.md) is not
Set the time to live of the [Entity](../README.md#entity). If the [Entity](../README.md#entity) is not
found, does nothing.

@@ -190,3 +132,3 @@

| :------ | :------ | :------ |
| `id` | `string` | The ID of the [Entity](Entity.md) to set and expiration for. |
| `id` | `string` | The ID of the [Entity](../README.md#entity) to set and expiration for. |
| `ttlInSeconds` | `number` | The time to live in seconds. |

@@ -200,4 +142,24 @@

[lib/repository/index.ts:214](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/repository/index.ts#L214)
[lib/repository/repository.ts:242](https://github.com/redis/redis-om-node/blob/5777b6c/lib/repository/repository.ts#L242)
▸ **expire**(`ids`, `ttlInSeconds`): `Promise`<`void`\>
Set the time to live of the [Entities](../README.md#entity) in Redis with the given
ids. If a particular [Entity](../README.md#entity) is not found, does nothing.
#### Parameters
| Name | Type | Description |
| :------ | :------ | :------ |
| `ids` | `string`[] | The IDs of the [Entities](../README.md#entity) you wish to delete. |
| `ttlInSeconds` | `number` | - |
#### Returns
`Promise`<`void`\>
#### Defined in
[lib/repository/repository.ts:250](https://github.com/redis/redis-om-node/blob/5777b6c/lib/repository/repository.ts#L250)
___

@@ -207,7 +169,6 @@

▸ **fetch**(`id`): `Promise`<`TEntity`\>
▸ **fetch**(`id`): `Promise`<[`Entity`](../README.md#entity)\>
Read and return an [Entity](Entity.md) from Redis with the given id. If
the [Entity](Entity.md) is not found, returns an [Entity](Entity.md) with all
properties set to `null`.
Read and return an [Entity](../README.md#entity) from Redis for the given id. If
the [Entity](../README.md#entity) is not found, returns an empty [Entity](../README.md#entity).

@@ -218,7 +179,7 @@ #### Parameters

| :------ | :------ | :------ |
| `id` | `string` | The ID of the [Entity](Entity.md) you seek. |
| `id` | `string` | The ID of the [Entity](../README.md#entity) you seek. |
#### Returns
`Promise`<`TEntity`\>
`Promise`<[`Entity`](../README.md#entity)\>

@@ -229,9 +190,8 @@ The matching Entity.

[lib/repository/index.ts:143](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/repository/index.ts#L143)
[lib/repository/repository.ts:171](https://github.com/redis/redis-om-node/blob/5777b6c/lib/repository/repository.ts#L171)
▸ **fetch**(...`ids`): `Promise`<`TEntity`[]\>
▸ **fetch**(`...ids`): `Promise`<[`Entity`](../README.md#entity)[]\>
Read and return the [Entities](Entity.md) from Redis with the given IDs. If
a particular [Entity](Entity.md) is not found, returns an [Entity](Entity.md) with all
properties set to `null`.
Read and return the [Entities](../README.md#entity) from Redis with the given IDs. If
a particular [Entity](../README.md#entity) is not found, returns that [Entity](../README.md#entity) as empty.

@@ -242,7 +202,7 @@ #### Parameters

| :------ | :------ | :------ |
| `...ids` | `string`[] | The IDs of the [Entities](Entity.md) you seek. |
| `...ids` | `string`[] | The IDs of the [Entities](../README.md#entity) you seek. |
#### Returns
`Promise`<`TEntity`[]\>
`Promise`<[`Entity`](../README.md#entity)[]\>

@@ -253,9 +213,8 @@ The matching Entities.

[lib/repository/index.ts:152](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/repository/index.ts#L152)
[lib/repository/repository.ts:180](https://github.com/redis/redis-om-node/blob/5777b6c/lib/repository/repository.ts#L180)
▸ **fetch**(`ids`): `Promise`<`TEntity`[]\>
▸ **fetch**(`ids`): `Promise`<[`Entity`](../README.md#entity)[]\>
Read and return the [Entities](Entity.md) from Redis with the given IDs. If
a particular [Entity](Entity.md) is not found, returns an [Entity](Entity.md) with all
properties set to `null`.
Read and return the [Entities](../README.md#entity) from Redis with the given IDs. If
a particular [Entity](../README.md#entity) is not found, returns that [Entity](../README.md#entity) as empty.

@@ -266,7 +225,7 @@ #### Parameters

| :------ | :------ | :------ |
| `ids` | `string`[] | The IDs of the [Entities](Entity.md) you seek. |
| `ids` | `string`[] | The IDs of the [Entities](../README.md#entity) you seek. |
#### Returns
`Promise`<`TEntity`[]\>
`Promise`<[`Entity`](../README.md#entity)[]\>

@@ -277,3 +236,3 @@ The matching Entities.

[lib/repository/index.ts:161](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/repository/index.ts#L161)
[lib/repository/repository.ts:189](https://github.com/redis/redis-om-node/blob/5777b6c/lib/repository/repository.ts#L189)

@@ -286,3 +245,3 @@ ___

Remove an [Entity](Entity.md) from Redis with the given id. If the [Entity](Entity.md) is
Remove an [Entity](../README.md#entity) from Redis for the given id. If the [Entity](../README.md#entity) is
not found, does nothing.

@@ -294,3 +253,3 @@

| :------ | :------ | :------ |
| `id` | `string` | The ID of the [Entity](Entity.md) you wish to delete. |
| `id` | `string` | The ID of the [Entity](../README.md#entity) you wish to delete. |

@@ -303,8 +262,8 @@ #### Returns

[lib/repository/index.ts:181](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/repository/index.ts#L181)
[lib/repository/repository.ts:205](https://github.com/redis/redis-om-node/blob/5777b6c/lib/repository/repository.ts#L205)
▸ **remove**(...`ids`): `Promise`<`void`\>
▸ **remove**(`...ids`): `Promise`<`void`\>
Remove the [Entities](Entity.md) from Redis with the given ids. If a
particular [Entity](Entity.md) is not found, does nothing.
Remove the [Entities](../README.md#entity) from Redis for the given ids. If a
particular [Entity](../README.md#entity) is not found, does nothing.

@@ -315,3 +274,3 @@ #### Parameters

| :------ | :------ | :------ |
| `...ids` | `string`[] | The IDs of the [Entities](Entity.md) you wish to delete. |
| `...ids` | `string`[] | The IDs of the [Entities](../README.md#entity) you wish to delete. |

@@ -324,8 +283,8 @@ #### Returns

[lib/repository/index.ts:188](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/repository/index.ts#L188)
[lib/repository/repository.ts:213](https://github.com/redis/redis-om-node/blob/5777b6c/lib/repository/repository.ts#L213)
▸ **remove**(`ids`): `Promise`<`void`\>
Remove the [Entities](Entity.md) from Redis with the given ids. If a
particular [Entity](Entity.md) is not found, does nothing.
Remove the [Entities](../README.md#entity) from Redis for the given ids. If a
particular [Entity](../README.md#entity) is not found, does nothing.

@@ -336,3 +295,3 @@ #### Parameters

| :------ | :------ | :------ |
| `ids` | `string`[] | The IDs of the [Entities](Entity.md) you wish to delete. |
| `ids` | `string`[] | The IDs of the [Entities](../README.md#entity) you wish to delete. |

@@ -345,3 +304,3 @@ #### Returns

[lib/repository/index.ts:195](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/repository/index.ts#L195)
[lib/repository/repository.ts:221](https://github.com/redis/redis-om-node/blob/5777b6c/lib/repository/repository.ts#L221)

@@ -352,6 +311,6 @@ ___

▸ **save**(`entity`): `Promise`<`string`\>
▸ **save**(`entity`): `Promise`<[`Entity`](../README.md#entity)\>
Save the [Entity](Entity.md) to Redis. If it already exists, it will be updated. If it doesn't
exist, it will be created.
Insert or update an [Entity](../README.md#entity) to Redis using its entityId property
if present. If it's not, one is generated.

@@ -362,14 +321,35 @@ #### Parameters

| :------ | :------ | :------ |
| `entity` | `TEntity` | The Entity to save. |
| `entity` | [`Entity`](../README.md#entity) | The Entity to save. |
#### Returns
`Promise`<`string`\>
`Promise`<[`Entity`](../README.md#entity)\>
The ID of the Entity just saved.
A copy of the provided Entity with EntityId and EntityKeyName properties added.
#### Defined in
[lib/repository/index.ts:119](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/repository/index.ts#L119)
[lib/repository/repository.ts:134](https://github.com/redis/redis-om-node/blob/5777b6c/lib/repository/repository.ts#L134)
▸ **save**(`id`, `entity`): `Promise`<[`Entity`](../README.md#entity)\>
Insert or update the [Entity](../README.md#entity) to Redis using the provided entityId.
#### Parameters
| Name | Type | Description |
| :------ | :------ | :------ |
| `id` | `string` | The id to save the Entity under. |
| `entity` | [`Entity`](../README.md#entity) | The Entity to save. |
#### Returns
`Promise`<[`Entity`](../README.md#entity)\>
A copy of the provided Entity with EntityId and EntityKeyName properties added.
#### Defined in
[lib/repository/repository.ts:143](https://github.com/redis/redis-om-node/blob/5777b6c/lib/repository/repository.ts#L143)
___

@@ -379,10 +359,10 @@

▸ **search**(): [`Search`](Search.md)<`TEntity`\>
▸ **search**(): [`Search`](Search.md)
Kicks off the process of building a query. Requires that RediSearch (and optionally
RedisJSON) be is installed on your instance of Redis.
RedisJSON) be installed on your instance of Redis.
#### Returns
[`Search`](Search.md)<`TEntity`\>
[`Search`](Search.md)

@@ -393,3 +373,3 @@ A [Search](Search.md) object.

[lib/repository/index.ts:225](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/repository/index.ts#L225)
[lib/repository/repository.ts:268](https://github.com/redis/redis-om-node/blob/5777b6c/lib/repository/repository.ts#L268)

@@ -400,10 +380,15 @@ ___

▸ **searchRaw**(`query`): [`RawSearch`](RawSearch.md)<`TEntity`\>
▸ **searchRaw**(`query`): [`RawSearch`](RawSearch.md)
Creates a search that bypassed Redis OM and instead allows you to execute a raw
Creates a search that bypasses Redis OM and instead allows you to execute a raw
RediSearch query. Requires that RediSearch (and optionally RedisJSON) be installed
on your instance of Redis.
**`query`** The raw RediSearch query you want to rune.
Refer to https://redis.io/docs/stack/search/reference/query_syntax/ for details on
RediSearch query syntax.
**`Query`**
The raw RediSearch query you want to rune.
#### Parameters

@@ -417,3 +402,3 @@

[`RawSearch`](RawSearch.md)<`TEntity`\>
[`RawSearch`](RawSearch.md)

@@ -424,2 +409,2 @@ A [RawSearch](RawSearch.md) object.

[lib/repository/index.ts:237](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/repository/index.ts#L237)
[lib/repository/repository.ts:283](https://github.com/redis/redis-om-node/blob/5777b6c/lib/repository/repository.ts#L283)
[redis-om](../README.md) / Schema
# Class: Schema<TEntity\>
# Class: Schema
Defines a schema that determines how an [Entity](Entity.md) is mapped to Redis
data structures. Construct by passing in an [EntityConstructor](../README.md#entityconstructor),
Defines a schema that determines how an [Entity](../README.md#entity) is mapped
to Redis data structures. Construct by passing in a schema name,
a [SchemaDefinition](../README.md#schemadefinition), and optionally [SchemaOptions](../README.md#schemaoptions):
```typescript
const schema = new Schema(Foo, {
const schema = new Schema('foo', {
aString: { type: 'string' },

@@ -20,3 +20,3 @@ aNumber: { type: 'number' },

dataStructure: 'HASH'
});
})
```

@@ -27,8 +27,2 @@

## Type parameters
| Name | Type | Description |
| :------ | :------ | :------ |
| `TEntity` | extends [`Entity`](Entity.md) | The [Entity](Entity.md) this Schema defines. |
## Table of contents

@@ -43,7 +37,7 @@

- [dataStructure](Schema.md#datastructure)
- [fields](Schema.md#fields)
- [indexHash](Schema.md#indexhash)
- [indexHashName](Schema.md#indexhashname)
- [indexName](Schema.md#indexname)
- [indexedDefault](Schema.md#indexeddefault)
- [prefix](Schema.md#prefix)
- [schemaName](Schema.md#schemaname)
- [stopWords](Schema.md#stopwords)

@@ -54,2 +48,3 @@ - [useStopWords](Schema.md#usestopwords)

- [fieldByName](Schema.md#fieldbyname)
- [generateId](Schema.md#generateid)

@@ -61,10 +56,6 @@

• **new Schema**<`TEntity`\>(`ctor`, `schemaDef`, `options?`)
• **new Schema**(`schemaName`, `schemaDef`, `options?`)
#### Type parameters
Constructs a Schema.
| Name | Type | Description |
| :------ | :------ | :------ |
| `TEntity` | extends [`Entity`](Entity.md)<`TEntity`\> | The [Entity](Entity.md) this Schema defines. |
#### Parameters

@@ -74,3 +65,3 @@

| :------ | :------ | :------ |
| `ctor` | [`EntityConstructor`](../README.md#entityconstructor)<`TEntity`\> | A constructor that creates an [Entity](Entity.md) of type TEntity. |
| `schemaName` | `string` | The name of the schema. Prefixes the ID when creating Redis keys. |
| `schemaDef` | [`SchemaDefinition`](../README.md#schemadefinition) | Defines all of the fields for the Schema and how they are mapped to Redis. |

@@ -81,3 +72,3 @@ | `options?` | [`SchemaOptions`](../README.md#schemaoptions) | Additional options for this Schema. |

[lib/schema/schema.ts:57](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/schema/schema.ts#L57)
[lib/schema/schema.ts:49](https://github.com/redis/redis-om-node/blob/5777b6c/lib/schema/schema.ts#L49)

@@ -91,3 +82,3 @@ ## Accessors

The configured data structure, a string with the value of either `HASH` or `JSON`,
that this Schema uses to store [Entities](Entity.md) in Redis.
that this Schema uses to store [Entities](../README.md#entity) in Redis.

@@ -100,27 +91,28 @@ #### Returns

[lib/schema/schema.ts:79](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/schema/schema.ts#L79)
[lib/schema/schema.ts:92](https://github.com/redis/redis-om-node/blob/5777b6c/lib/schema/schema.ts#L92)
___
### indexHash
### fields
• `get` **indexHash**(): `string`
• `get` **fields**(): [`Field`](Field.md)[]
The hash value of this index. Stored in Redis under [Schema.indexHashName](Schema.md#indexhashname).
The [Fields](Field.md) defined by this Schema.
#### Returns
`string`
[`Field`](Field.md)[]
#### Defined in
[lib/schema/schema.ts:100](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/schema/schema.ts#L100)
[lib/schema/schema.ts:68](https://github.com/redis/redis-om-node/blob/5777b6c/lib/schema/schema.ts#L68)
___
### indexHashName
### indexHash
• `get` **indexHashName**(): `string`
• `get` **indexHash**(): `string`
The configured name for the RediSearch index hash for this Schema.
A hash for this Schema that is used to determine if the Schema has been
changed when calling [createIndex](Repository.md#createindex).

@@ -133,11 +125,11 @@ #### Returns

[lib/schema/schema.ts:73](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/schema/schema.ts#L73)
[lib/schema/schema.ts:120](https://github.com/redis/redis-om-node/blob/5777b6c/lib/schema/schema.ts#L120)
___
### indexName
### indexHashName
• `get` **indexName**(): `string`
• `get` **indexHashName**(): `string`
The configured name for the RediSearch index for this Schema.
The configured name for the RediSearch index hash for this Schema.

@@ -150,27 +142,29 @@ #### Returns

[lib/schema/schema.ts:70](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/schema/schema.ts#L70)
[lib/schema/schema.ts:86](https://github.com/redis/redis-om-node/blob/5777b6c/lib/schema/schema.ts#L86)
___
### indexedDefault
### indexName
• `get` **indexedDefault**(): `boolean`
• `get` **indexName**(): `string`
The configured indexed default setting for fields
The configured name for the RediSearch index for this Schema.
#### Returns
`boolean`
`string`
#### Defined in
[lib/schema/schema.ts:97](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/schema/schema.ts#L97)
[lib/schema/schema.ts:83](https://github.com/redis/redis-om-node/blob/5777b6c/lib/schema/schema.ts#L83)
___
### prefix
### schemaName
• `get` **prefix**(): `string`
• `get` **schemaName**(): `string`
The configured keyspace prefix in Redis for this Schema.
The name of the schema. Prefixes the ID when creating Redis keys. Combined
with the results of idStrategy to generate a key. If name is `foo` and
idStrategy returns `12345` then the generated key would be `foo:12345`.

@@ -183,3 +177,3 @@ #### Returns

[lib/schema/schema.ts:67](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/schema/schema.ts#L67)
[lib/schema/schema.ts:63](https://github.com/redis/redis-om-node/blob/5777b6c/lib/schema/schema.ts#L63)

@@ -192,3 +186,3 @@ ___

The configured stop words. Ignored if [Schema.useStopWords](Schema.md#usestopwords) is anything other
The configured stop words. Ignored if [useStopWords](Schema.md#usestopwords) is anything other
than `CUSTOM`.

@@ -202,3 +196,3 @@

[lib/schema/schema.ts:92](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/schema/schema.ts#L92)
[lib/schema/schema.ts:104](https://github.com/redis/redis-om-node/blob/5777b6c/lib/schema/schema.ts#L104)

@@ -212,4 +206,3 @@ ___

The configured usage of stop words, a string with the value of either `OFF`, `DEFAULT`,
or `CUSTOM`. See {@link SchemaOptions.useStopWords} and {@link SchemaOptions.stopWords}
for more details.
or `CUSTOM`. See [SchemaOptions](../README.md#schemaoptions) for more details.

@@ -222,9 +215,33 @@ #### Returns

[lib/schema/schema.ts:86](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/schema/schema.ts#L86)
[lib/schema/schema.ts:98](https://github.com/redis/redis-om-node/blob/5777b6c/lib/schema/schema.ts#L98)
## Methods
### fieldByName
▸ **fieldByName**(`name`): ``null`` \| [`Field`](Field.md)
Gets a single [Field](Field.md) defined by this Schema.
#### Parameters
| Name | Type | Description |
| :------ | :------ | :------ |
| `name` | `string` | The name of the [Field](Field.md) in this Schema. |
#### Returns
``null`` \| [`Field`](Field.md)
The [Field](Field.md), or null of not found.
#### Defined in
[lib/schema/schema.ts:78](https://github.com/redis/redis-om-node/blob/5777b6c/lib/schema/schema.ts#L78)
___
### generateId
▸ **generateId**(): `string`
▸ **generateId**(): `Promise`<`string`\>

@@ -235,6 +252,8 @@ Generates a unique string using the configured [IdStrategy](../README.md#idstrategy).

`string`
`Promise`<`string`\>
The generated id.
#### Defined in
[lib/schema/schema.ts:126](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/schema/schema.ts#L126)
[lib/schema/schema.ts:111](https://github.com/redis/redis-om-node/blob/5777b6c/lib/schema/schema.ts#L111)
[redis-om](../README.md) / Search
# Class: Search<TEntity\>
# Class: Search

@@ -8,11 +8,9 @@ Entry point to fluent search. This is the default Redis OM experience.

## Type parameters
**`Template`**
| Name | Type | Description |
| :------ | :------ | :------ |
| `TEntity` | extends [`Entity`](Entity.md) | The type of [Entity](Entity.md) being sought. |
The type of [Entity](../README.md#entity) being sought.
## Hierarchy
- [`AbstractSearch`](AbstractSearch.md)<`TEntity`\>
- [`AbstractSearch`](AbstractSearch.md)

@@ -74,3 +72,3 @@ ↳ **`Search`**

• `get` **return**(): [`AbstractSearch`](AbstractSearch.md)<`TEntity`\>
• `get` **return**(): [`AbstractSearch`](AbstractSearch.md)

@@ -81,3 +79,3 @@ Returns the current instance. Syntactic sugar to make your code more fluent.

[`AbstractSearch`](AbstractSearch.md)<`TEntity`\>
[`AbstractSearch`](AbstractSearch.md)

@@ -92,3 +90,3 @@ this

[lib/search/search.ts:333](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/search.ts#L333)
[lib/search/search.ts:308](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/search.ts#L308)

@@ -99,6 +97,6 @@ ## Methods

▸ **all**(`options?`): `Promise`<`TEntity`[]\>
▸ **all**(`options?`): `Promise`<[`Entity`](../README.md#entity)[]\>
Returns all the [Entities](Entity.md) that match this query. This method
makes multiple calls to Redis until all the [Entities](Entity.md) are returned.
Returns all the [Entities](../README.md#entity) that match this query. This method
makes multiple calls to Redis until all the [Entities](../README.md#entity) are returned.
You can specify the batch size by setting the `pageSize` property on the

@@ -108,3 +106,3 @@ options:

```typescript
const entities = await repository.search().returnAll({ pageSize: 100 });
const entities = await repository.search().returnAll({ pageSize: 100 })
```

@@ -117,9 +115,9 @@

| `options` | `Object` | `undefined` | Options for the call. |
| `options.pageSize` | `number` | `10` | Number of [Entities](Entity.md) returned per batch. |
| `options.pageSize` | `number` | `10` | Number of [Entities](../README.md#entity) returned per batch. |
#### Returns
`Promise`<`TEntity`[]\>
`Promise`<[`Entity`](../README.md#entity)[]\>
An array of [Entities](Entity.md) matching the query.
An array of [Entities](../README.md#entity) matching the query.

@@ -132,3 +130,3 @@ #### Inherited from

[lib/search/search.ts:266](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/search.ts#L266)
[lib/search/search.ts:264](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/search.ts#L264)

@@ -147,3 +145,3 @@ ___

```typescript
const keys = await repository.search().returnAllIds({ pageSize: 100 });
const keys = await repository.search().returnAllIds({ pageSize: 100 })
```

@@ -170,3 +168,3 @@

[lib/search/search.ts:295](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/search.ts#L295)
[lib/search/search.ts:282](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/search.ts#L282)

@@ -185,3 +183,3 @@ ___

```typescript
const keys = await repository.search().returnAllKeys({ pageSize: 100 });
const keys = await repository.search().returnAllKeys({ pageSize: 100 })
```

@@ -208,3 +206,3 @@

[lib/search/search.ts:314](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/search.ts#L314)
[lib/search/search.ts:300](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/search.ts#L300)

@@ -215,3 +213,3 @@ ___

▸ **and**(`field`): [`WhereField`](WhereField.md)<`TEntity`\>
▸ **and**(`field`): [`WhereField`](WhereField.md)

@@ -228,3 +226,3 @@ Sets up a query matching a particular field as a logical AND.

[`WhereField`](WhereField.md)<`TEntity`\>
[`WhereField`](WhereField.md)

@@ -235,5 +233,5 @@ A subclass of [WhereField](WhereField.md) matching the type of the field.

[lib/search/search.ts:542](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/search.ts#L542)
[lib/search/search.ts:530](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/search.ts#L530)
▸ **and**(`subSearchFn`): [`Search`](Search.md)<`TEntity`\>
▸ **and**(`subSearchFn`): [`Search`](Search.md)

@@ -246,7 +244,7 @@ Sets up a nested search as a logical AND.

| :------ | :------ | :------ |
| `subSearchFn` | [`SubSearchFunction`](../README.md#subsearchfunction)<`TEntity`\> | A function that takes a [Search](Search.md) and returns another [Search](Search.md). |
| `subSearchFn` | [`SubSearchFunction`](../README.md#subsearchfunction) | A function that takes a [Search](Search.md) and returns another [Search](Search.md). |
#### Returns
[`Search`](Search.md)<`TEntity`\>
[`Search`](Search.md)

@@ -257,3 +255,3 @@ `this`.

[lib/search/search.ts:549](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/search.ts#L549)
[lib/search/search.ts:537](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/search.ts#L537)

@@ -266,3 +264,3 @@ ___

Returns the number of [Entities](Entity.md) that match this query.
Returns the number of [Entities](../README.md#entity) that match this query.

@@ -279,3 +277,3 @@ #### Returns

[lib/search/search.ts:186](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/search.ts#L186)
[lib/search/search.ts:188](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/search.ts#L188)

@@ -286,9 +284,9 @@ ___

▸ **first**(): `Promise`<``null`` \| `TEntity`\>
▸ **first**(): `Promise`<``null`` \| [`Entity`](../README.md#entity)\>
Returns the first [Entity](Entity.md) that matches this query.
Returns the first [Entity](../README.md#entity) that matches this query.
#### Returns
`Promise`<``null`` \| `TEntity`\>
`Promise`<``null`` \| [`Entity`](../README.md#entity)\>

@@ -301,3 +299,3 @@ #### Inherited from

[lib/search/search.ts:231](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/search.ts#L231)
[lib/search/search.ts:229](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/search.ts#L229)

@@ -322,3 +320,3 @@ ___

[lib/search/search.ts:239](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/search.ts#L239)
[lib/search/search.ts:237](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/search.ts#L237)

@@ -343,3 +341,3 @@ ___

[lib/search/search.ts:247](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/search.ts#L247)
[lib/search/search.ts:245](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/search.ts#L245)

@@ -350,5 +348,5 @@ ___

▸ **max**(`field`): `Promise`<``null`` \| `TEntity`\>
▸ **max**(`field`): `Promise`<``null`` \| [`Entity`](../README.md#entity)\>
Finds the [Entity](Entity.md) with the maximal value for a field.
Finds the [Entity](../README.md#entity) with the maximal value for a field.

@@ -363,5 +361,5 @@ #### Parameters

`Promise`<``null`` \| `TEntity`\>
`Promise`<``null`` \| [`Entity`](../README.md#entity)\>
The entity ID [Entity](Entity.md) with the maximal value
The entity ID [Entity](../README.md#entity) with the maximal value

@@ -374,3 +372,3 @@ #### Inherited from

[lib/search/search.ts:159](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/search.ts#L159)
[lib/search/search.ts:162](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/search.ts#L162)

@@ -403,3 +401,3 @@ ___

[lib/search/search.ts:168](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/search.ts#L168)
[lib/search/search.ts:171](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/search.ts#L171)

@@ -432,3 +430,3 @@ ___

[lib/search/search.ts:178](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/search.ts#L178)
[lib/search/search.ts:180](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/search.ts#L180)

@@ -439,5 +437,5 @@ ___

▸ **min**(`field`): `Promise`<``null`` \| `TEntity`\>
▸ **min**(`field`): `Promise`<``null`` \| [`Entity`](../README.md#entity)\>
Finds the [Entity](Entity.md) with the minimal value for a field.
Finds the [Entity](../README.md#entity) with the minimal value for a field.

@@ -452,5 +450,5 @@ #### Parameters

`Promise`<``null`` \| `TEntity`\>
`Promise`<``null`` \| [`Entity`](../README.md#entity)\>
The [Entity](Entity.md) with the minimal value
The [Entity](../README.md#entity) with the minimal value

@@ -463,3 +461,3 @@ #### Inherited from

[lib/search/search.ts:131](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/search.ts#L131)
[lib/search/search.ts:135](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/search.ts#L135)

@@ -492,3 +490,3 @@ ___

[lib/search/search.ts:140](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/search.ts#L140)
[lib/search/search.ts:144](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/search.ts#L144)

@@ -521,3 +519,3 @@ ___

[lib/search/search.ts:150](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/search.ts#L150)
[lib/search/search.ts:153](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/search.ts#L153)

@@ -528,3 +526,3 @@ ___

▸ **or**(`field`): [`WhereField`](WhereField.md)<`TEntity`\>
▸ **or**(`field`): [`WhereField`](WhereField.md)

@@ -541,3 +539,3 @@ Sets up a query matching a particular field as a logical OR.

[`WhereField`](WhereField.md)<`TEntity`\>
[`WhereField`](WhereField.md)

@@ -548,5 +546,5 @@ A subclass of [WhereField](WhereField.md) matching the type of the field.

[lib/search/search.ts:559](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/search.ts#L559)
[lib/search/search.ts:547](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/search.ts#L547)
▸ **or**(`subSearchFn`): [`Search`](Search.md)<`TEntity`\>
▸ **or**(`subSearchFn`): [`Search`](Search.md)

@@ -559,7 +557,7 @@ Sets up a nested search as a logical OR.

| :------ | :------ | :------ |
| `subSearchFn` | [`SubSearchFunction`](../README.md#subsearchfunction)<`TEntity`\> | A function that takes a [Search](Search.md) and returns another [Search](Search.md). |
| `subSearchFn` | [`SubSearchFunction`](../README.md#subsearchfunction) | A function that takes a [Search](Search.md) and returns another [Search](Search.md). |
#### Returns
[`Search`](Search.md)<`TEntity`\>
[`Search`](Search.md)

@@ -570,3 +568,3 @@ `this`.

[lib/search/search.ts:566](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/search.ts#L566)
[lib/search/search.ts:554](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/search.ts#L554)

@@ -577,5 +575,5 @@ ___

▸ **page**(`offset`, `count`): `Promise`<`TEntity`[]\>
▸ **page**(`offset`, `count`): `Promise`<[`Entity`](../README.md#entity)[]\>
Returns a page of [Entities](Entity.md) that match this query.
Returns a page of [Entities](../README.md#entity) that match this query.

@@ -586,10 +584,10 @@ #### Parameters

| :------ | :------ | :------ |
| `offset` | `number` | The offset for where to start returning [Entities](Entity.md). |
| `count` | `number` | The number of [Entities](Entity.md) to return. |
| `offset` | `number` | The offset for where to start returning [Entities](../README.md#entity). |
| `count` | `number` | The number of [Entities](../README.md#entity) to return. |
#### Returns
`Promise`<`TEntity`[]\>
`Promise`<[`Entity`](../README.md#entity)[]\>
An array of [Entities](Entity.md) matching the query.
An array of [Entities](../README.md#entity) matching the query.

@@ -602,3 +600,3 @@ #### Inherited from

[lib/search/search.ts:199](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/search.ts#L199)
[lib/search/search.ts:199](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/search.ts#L199)

@@ -632,3 +630,3 @@ ___

[lib/search/search.ts:212](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/search.ts#L212)
[lib/search/search.ts:210](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/search.ts#L210)

@@ -662,3 +660,3 @@ ___

[lib/search/search.ts:223](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/search.ts#L223)
[lib/search/search.ts:221](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/search.ts#L221)

@@ -669,5 +667,5 @@ ___

▸ **returnAll**(`options?`): `Promise`<`TEntity`[]\>
▸ **returnAll**(`options?`): `Promise`<[`Entity`](../README.md#entity)[]\>
Alias for [Search.all](Search.md#all).
Alias for [all](Search.md#all).

@@ -683,3 +681,3 @@ #### Parameters

`Promise`<`TEntity`[]\>
`Promise`<[`Entity`](../README.md#entity)[]\>

@@ -692,3 +690,3 @@ #### Inherited from

[lib/search/search.ts:431](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/search.ts#L431)
[lib/search/search.ts:406](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/search.ts#L406)

@@ -701,3 +699,3 @@ ___

Alias for [Search.allIds](Search.md#allids).
Alias for [allIds](Search.md#allids).

@@ -721,3 +719,3 @@ #### Parameters

[lib/search/search.ts:438](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/search.ts#L438)
[lib/search/search.ts:413](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/search.ts#L413)

@@ -730,3 +728,3 @@ ___

Alias for [Search.allKeys](Search.md#allkeys).
Alias for [allKeys](Search.md#allkeys).

@@ -750,3 +748,3 @@ #### Parameters

[lib/search/search.ts:445](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/search.ts#L445)
[lib/search/search.ts:420](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/search.ts#L420)

@@ -759,3 +757,3 @@ ___

Alias for [Search.count](Search.md#count).
Alias for [count](Search.md#count).

@@ -772,3 +770,3 @@ #### Returns

[lib/search/search.ts:382](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/search.ts#L382)
[lib/search/search.ts:357](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/search.ts#L357)

@@ -779,9 +777,9 @@ ___

▸ **returnFirst**(): `Promise`<``null`` \| `TEntity`\>
▸ **returnFirst**(): `Promise`<``null`` \| [`Entity`](../README.md#entity)\>
Alias for [Search.first](Search.md#first).
Alias for [first](Search.md#first).
#### Returns
`Promise`<``null`` \| `TEntity`\>
`Promise`<``null`` \| [`Entity`](../README.md#entity)\>

@@ -794,3 +792,3 @@ #### Inherited from

[lib/search/search.ts:410](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/search.ts#L410)
[lib/search/search.ts:385](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/search.ts#L385)

@@ -803,3 +801,3 @@ ___

Alias for [Search.firstId](Search.md#firstid).
Alias for [firstId](Search.md#firstid).

@@ -816,3 +814,3 @@ #### Returns

[lib/search/search.ts:417](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/search.ts#L417)
[lib/search/search.ts:392](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/search.ts#L392)

@@ -825,3 +823,3 @@ ___

Alias for [Search.firstKey](Search.md#firstkey).
Alias for [firstKey](Search.md#firstkey).

@@ -838,3 +836,3 @@ #### Returns

[lib/search/search.ts:424](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/search.ts#L424)
[lib/search/search.ts:399](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/search.ts#L399)

@@ -845,5 +843,5 @@ ___

▸ **returnMax**(`field`): `Promise`<``null`` \| `TEntity`\>
▸ **returnMax**(`field`): `Promise`<``null`` \| [`Entity`](../README.md#entity)\>
Alias for [Search.max](Search.md#max).
Alias for [max](Search.md#max).

@@ -858,3 +856,3 @@ #### Parameters

`Promise`<``null`` \| `TEntity`\>
`Promise`<``null`` \| [`Entity`](../README.md#entity)\>

@@ -867,3 +865,3 @@ #### Inherited from

[lib/search/search.ts:361](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/search.ts#L361)
[lib/search/search.ts:336](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/search.ts#L336)

@@ -876,3 +874,3 @@ ___

Alias for [Search.maxId](Search.md#maxid).
Alias for [maxId](Search.md#maxid).

@@ -895,3 +893,3 @@ #### Parameters

[lib/search/search.ts:368](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/search.ts#L368)
[lib/search/search.ts:343](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/search.ts#L343)

@@ -904,3 +902,3 @@ ___

Alias for [Search.maxKey](Search.md#maxkey).
Alias for [maxKey](Search.md#maxkey).

@@ -923,3 +921,3 @@ #### Parameters

[lib/search/search.ts:375](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/search.ts#L375)
[lib/search/search.ts:350](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/search.ts#L350)

@@ -930,5 +928,5 @@ ___

▸ **returnMin**(`field`): `Promise`<``null`` \| `TEntity`\>
▸ **returnMin**(`field`): `Promise`<``null`` \| [`Entity`](../README.md#entity)\>
Alias for [Search.min](Search.md#min).
Alias for [min](Search.md#min).

@@ -943,3 +941,3 @@ #### Parameters

`Promise`<``null`` \| `TEntity`\>
`Promise`<``null`` \| [`Entity`](../README.md#entity)\>

@@ -952,3 +950,3 @@ #### Inherited from

[lib/search/search.ts:340](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/search.ts#L340)
[lib/search/search.ts:315](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/search.ts#L315)

@@ -961,3 +959,3 @@ ___

Alias for [Search.minId](Search.md#minid).
Alias for [minId](Search.md#minid).

@@ -980,3 +978,3 @@ #### Parameters

[lib/search/search.ts:347](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/search.ts#L347)
[lib/search/search.ts:322](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/search.ts#L322)

@@ -989,3 +987,3 @@ ___

Alias for [Search.minKey](Search.md#minkey).
Alias for [minKey](Search.md#minkey).

@@ -1008,3 +1006,3 @@ #### Parameters

[lib/search/search.ts:354](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/search.ts#L354)
[lib/search/search.ts:329](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/search.ts#L329)

@@ -1015,5 +1013,5 @@ ___

▸ **returnPage**(`offset`, `count`): `Promise`<`TEntity`[]\>
▸ **returnPage**(`offset`, `count`): `Promise`<[`Entity`](../README.md#entity)[]\>
Alias for [Search.page](Search.md#page).
Alias for [page](Search.md#page).

@@ -1029,3 +1027,3 @@ #### Parameters

`Promise`<`TEntity`[]\>
`Promise`<[`Entity`](../README.md#entity)[]\>

@@ -1038,3 +1036,3 @@ #### Inherited from

[lib/search/search.ts:389](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/search.ts#L389)
[lib/search/search.ts:364](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/search.ts#L364)

@@ -1047,3 +1045,3 @@ ___

Alias for [Search.pageOfIds](Search.md#pageofids).
Alias for [pageOfIds](Search.md#pageofids).

@@ -1067,3 +1065,3 @@ #### Parameters

[lib/search/search.ts:396](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/search.ts#L396)
[lib/search/search.ts:371](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/search.ts#L371)

@@ -1076,3 +1074,3 @@ ___

Alias for {@link Search.pageOrKeys}.
Alias for [pageOfKeys](Search.md#pageofkeys).

@@ -1096,3 +1094,3 @@ #### Parameters

[lib/search/search.ts:403](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/search.ts#L403)
[lib/search/search.ts:378](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/search.ts#L378)

@@ -1103,5 +1101,5 @@ ___

▸ **sortAsc**(`field`): [`AbstractSearch`](AbstractSearch.md)<`TEntity`\>
▸ **sortAsc**(`field`): [`AbstractSearch`](AbstractSearch.md)
Alias for [Search.sortAscending](Search.md#sortascending).
Alias for [sortAscending](Search.md#sortascending).

@@ -1116,3 +1114,3 @@ #### Parameters

[`AbstractSearch`](AbstractSearch.md)<`TEntity`\>
[`AbstractSearch`](AbstractSearch.md)

@@ -1125,3 +1123,3 @@ #### Inherited from

[lib/search/search.ts:83](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/search.ts#L83)
[lib/search/search.ts:86](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/search.ts#L86)

@@ -1132,3 +1130,3 @@ ___

▸ **sortAscending**(`field`): [`AbstractSearch`](AbstractSearch.md)<`TEntity`\>
▸ **sortAscending**(`field`): [`AbstractSearch`](AbstractSearch.md)

@@ -1145,3 +1143,3 @@ Applies an ascending sort to the query.

[`AbstractSearch`](AbstractSearch.md)<`TEntity`\>
[`AbstractSearch`](AbstractSearch.md)

@@ -1156,3 +1154,3 @@ this

[lib/search/search.ts:60](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/search.ts#L60)
[lib/search/search.ts:63](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/search.ts#L63)

@@ -1163,3 +1161,3 @@ ___

▸ **sortBy**(`field`, `order?`): [`AbstractSearch`](AbstractSearch.md)<`TEntity`\>
▸ **sortBy**(`fieldName`, `order?`): [`AbstractSearch`](AbstractSearch.md)

@@ -1172,8 +1170,8 @@ Applies sorting for the query.

| :------ | :------ | :------ | :------ |
| `field` | `string` | `undefined` | The field to sort by. |
| `order` | ``"ASC"`` \| ``"DESC"`` | `'ASC'` | The order of returned [Entities](Entity.md) Defaults to `ASC` (ascending) if not specified |
| `fieldName` | `string` | `undefined` | - |
| `order` | ``"ASC"`` \| ``"DESC"`` | `'ASC'` | The order of returned [Entities](../README.md#entity) Defaults to `ASC` (ascending) if not specified |
#### Returns
[`AbstractSearch`](AbstractSearch.md)<`TEntity`\>
[`AbstractSearch`](AbstractSearch.md)

@@ -1188,3 +1186,3 @@ this

[lib/search/search.ts:93](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/search.ts#L93)
[lib/search/search.ts:96](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/search.ts#L96)

@@ -1195,5 +1193,5 @@ ___

▸ **sortDesc**(`field`): [`AbstractSearch`](AbstractSearch.md)<`TEntity`\>
▸ **sortDesc**(`field`): [`AbstractSearch`](AbstractSearch.md)
Alias for [Search.sortDescending](Search.md#sortdescending).
Alias for [sortDescending](Search.md#sortdescending).

@@ -1208,3 +1206,3 @@ #### Parameters

[`AbstractSearch`](AbstractSearch.md)<`TEntity`\>
[`AbstractSearch`](AbstractSearch.md)

@@ -1217,3 +1215,3 @@ #### Inherited from

[lib/search/search.ts:67](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/search.ts#L67)
[lib/search/search.ts:70](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/search.ts#L70)

@@ -1224,3 +1222,3 @@ ___

▸ **sortDescending**(`field`): [`AbstractSearch`](AbstractSearch.md)<`TEntity`\>
▸ **sortDescending**(`field`): [`AbstractSearch`](AbstractSearch.md)

@@ -1237,3 +1235,3 @@ Applies a descending sort to the query.

[`AbstractSearch`](AbstractSearch.md)<`TEntity`\>
[`AbstractSearch`](AbstractSearch.md)

@@ -1248,3 +1246,3 @@ this

[lib/search/search.ts:76](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/search.ts#L76)
[lib/search/search.ts:79](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/search.ts#L79)

@@ -1255,6 +1253,6 @@ ___

▸ **where**(`field`): [`WhereField`](WhereField.md)<`TEntity`\>
▸ **where**(`field`): [`WhereField`](WhereField.md)
Sets up a query matching a particular field. If there are multiple calls
to [Search.where](Search.md#where), they are treated logically as AND.
to [where](Search.md#where), they are treated logically as AND.

@@ -1269,3 +1267,3 @@ #### Parameters

[`WhereField`](WhereField.md)<`TEntity`\>
[`WhereField`](WhereField.md)

@@ -1276,7 +1274,7 @@ A subclass of [WhereField](WhereField.md) matching the type of the field.

[lib/search/search.ts:524](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/search.ts#L524)
[lib/search/search.ts:512](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/search.ts#L512)
▸ **where**(`subSearchFn`): [`Search`](Search.md)<`TEntity`\>
▸ **where**(`subSearchFn`): [`Search`](Search.md)
Sets up a nested search. If there are multiple calls to [Search.where](Search.md#where),
Sets up a nested search. If there are multiple calls to [where](Search.md#where),
they are treated logically as AND.

@@ -1288,7 +1286,7 @@

| :------ | :------ | :------ |
| `subSearchFn` | [`SubSearchFunction`](../README.md#subsearchfunction)<`TEntity`\> | A function that takes a [Search](Search.md) and returns another [Search](Search.md). |
| `subSearchFn` | [`SubSearchFunction`](../README.md#subsearchfunction) | A function that takes a [Search](Search.md) and returns another [Search](Search.md). |
#### Returns
[`Search`](Search.md)<`TEntity`\>
[`Search`](Search.md)

@@ -1299,2 +1297,2 @@ `this`.

[lib/search/search.ts:532](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/search.ts#L532)
[lib/search/search.ts:520](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/search.ts#L520)

@@ -43,2 +43,2 @@ [redis-om](../README.md) / Where

[lib/search/where.ts:8](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/where.ts#L8)
[lib/search/where.ts:8](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/where.ts#L8)
[redis-om](../README.md) / WhereField
# Class: WhereField<TEntity\>
# Class: WhereField
Abstract base class that all fields you want to filter
with extend. When you call [Search.where](Search.md#where), a
with extend. When you call [where](Search.md#where), a
subclass of this is returned.
## Type parameters
| Name |
| :------ |
| `TEntity` |
## Hierarchy

@@ -73,12 +67,10 @@

• `Readonly` **exact**: [`WhereField`](WhereField.md)<`TEntity`\>
• `Readonly` **exact**: [`WhereField`](WhereField.md)
Makes a call to [WhereField.match](WhereField.md#match) a [WhereField.matchExact](WhereField.md#matchexact) call. Calling
Makes a call to [match](WhereField.md#match) a [matchExact](WhereField.md#matchexact) call. Calling
this multiple times will have no effect.
**`returns`** this.
#### Defined in
[lib/search/where-field.ts:92](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/where-field.ts#L92)
[lib/search/where-field.ts:92](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/where-field.ts#L92)

@@ -89,12 +81,10 @@ ___

• `Readonly` **exactly**: [`WhereField`](WhereField.md)<`TEntity`\>
• `Readonly` **exactly**: [`WhereField`](WhereField.md)
Makes a call to [WhereField.match](WhereField.md#match) a [WhereField.matchExact](WhereField.md#matchexact) call. Calling
Makes a call to [match](WhereField.md#match) a [matchExact](WhereField.md#matchexact) call. Calling
this multiple times will have no effect.
**`returns`** this.
#### Defined in
[lib/search/where-field.ts:99](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/where-field.ts#L99)
[lib/search/where-field.ts:99](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/where-field.ts#L99)

@@ -117,3 +107,3 @@ ## Accessors

[lib/search/where-field.ts:289](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/where-field.ts#L289)
[lib/search/where-field.ts:289](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/where-field.ts#L289)

@@ -136,3 +126,3 @@ ___

[lib/search/where-field.ts:281](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/where-field.ts#L281)
[lib/search/where-field.ts:281](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/where-field.ts#L281)

@@ -156,3 +146,3 @@ ___

[lib/search/where-field.ts:298](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/where-field.ts#L298)
[lib/search/where-field.ts:298](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/where-field.ts#L298)

@@ -163,3 +153,3 @@ ## Methods

▸ **after**(`value`): [`Search`](Search.md)<`TEntity`\>
▸ **after**(`value`): [`Search`](Search.md)

@@ -176,3 +166,3 @@ Add a search that matches all datetimes *after* the provided UTC datetime to the query.

[`Search`](Search.md)<`TEntity`\>
[`Search`](Search.md)

@@ -183,3 +173,3 @@ The [Search](Search.md) that was called to create this [WhereField](WhereField.md).

[lib/search/where-field.ts:240](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/where-field.ts#L240)
[lib/search/where-field.ts:240](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/where-field.ts#L240)

@@ -190,3 +180,3 @@ ___

▸ **before**(`value`): [`Search`](Search.md)<`TEntity`\>
▸ **before**(`value`): [`Search`](Search.md)

@@ -203,3 +193,3 @@ Add a search that matches all datetimes *before* the provided UTC datetime to the query.

[`Search`](Search.md)<`TEntity`\>
[`Search`](Search.md)

@@ -210,3 +200,3 @@ The [Search](Search.md) that was called to create this [WhereField](WhereField.md).

[lib/search/where-field.ts:233](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/where-field.ts#L233)
[lib/search/where-field.ts:233](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/where-field.ts#L233)

@@ -217,3 +207,3 @@ ___

▸ **between**(`lower`, `upper`): [`Search`](Search.md)<`TEntity`\>
▸ **between**(`lower`, `upper`): [`Search`](Search.md)

@@ -231,3 +221,3 @@ Adds an inclusive range comparison against a field to the search query.

[`Search`](Search.md)<`TEntity`\>
[`Search`](Search.md)

@@ -238,3 +228,3 @@ The [Search](Search.md) that was called to create this [WhereField](WhereField.md).

[lib/search/where-field.ts:175](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/where-field.ts#L175)
[lib/search/where-field.ts:175](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/where-field.ts#L175)

@@ -245,3 +235,3 @@ ___

▸ **contain**(`value`): [`Search`](Search.md)<`TEntity`\>
▸ **contain**(`value`): [`Search`](Search.md)

@@ -258,3 +248,3 @@ Adds a whole-string match for a value within a string array to the search query.

[`Search`](Search.md)<`TEntity`\>
[`Search`](Search.md)

@@ -265,3 +255,3 @@ The [Search](Search.md) that was called to create this [WhereField](WhereField.md).

[lib/search/where-field.ts:182](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/where-field.ts#L182)
[lib/search/where-field.ts:182](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/where-field.ts#L182)

@@ -272,3 +262,3 @@ ___

▸ **containOneOf**(...`value`): [`Search`](Search.md)<`TEntity`\>
▸ **containOneOf**(`...value`): [`Search`](Search.md)

@@ -286,3 +276,3 @@ Adds a whole-string match against a string array to the query. If any of the provided

[`Search`](Search.md)<`TEntity`\>
[`Search`](Search.md)

@@ -293,3 +283,3 @@ The [Search](Search.md) that was called to create this [WhereField](WhereField.md).

[lib/search/where-field.ts:197](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/where-field.ts#L197)
[lib/search/where-field.ts:197](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/where-field.ts#L197)

@@ -300,3 +290,3 @@ ___

▸ **contains**(`value`): [`Search`](Search.md)<`TEntity`\>
▸ **contains**(`value`): [`Search`](Search.md)

@@ -313,3 +303,3 @@ Adds a whole-string match for a value within a string array to the search query.

[`Search`](Search.md)<`TEntity`\>
[`Search`](Search.md)

@@ -320,3 +310,3 @@ The [Search](Search.md) that was called to create this [WhereField](WhereField.md).

[lib/search/where-field.ts:189](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/where-field.ts#L189)
[lib/search/where-field.ts:189](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/where-field.ts#L189)

@@ -327,3 +317,3 @@ ___

▸ **containsOneOf**(...`value`): [`Search`](Search.md)<`TEntity`\>
▸ **containsOneOf**(`...value`): [`Search`](Search.md)

@@ -341,3 +331,3 @@ Adds a whole-string match against a string array to the query. If any of the provided

[`Search`](Search.md)<`TEntity`\>
[`Search`](Search.md)

@@ -348,3 +338,3 @@ The [Search](Search.md) that was called to create this [WhereField](WhereField.md).

[lib/search/where-field.ts:205](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/where-field.ts#L205)
[lib/search/where-field.ts:205](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/where-field.ts#L205)

@@ -355,3 +345,3 @@ ___

▸ **eq**(`value`): [`Search`](Search.md)<`TEntity`\>
▸ **eq**(`value`): [`Search`](Search.md)

@@ -371,3 +361,3 @@ Adds an equals comparison to the query.

[`Search`](Search.md)<`TEntity`\>
[`Search`](Search.md)

@@ -378,3 +368,3 @@ The [Search](Search.md) that was called to create this [WhereField](WhereField.md).

[lib/search/where-field.ts:20](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/where-field.ts#L20)
[lib/search/where-field.ts:20](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/where-field.ts#L20)

@@ -385,3 +375,3 @@ ___

▸ **equal**(`value`): [`Search`](Search.md)<`TEntity`\>
▸ **equal**(`value`): [`Search`](Search.md)

@@ -401,3 +391,3 @@ Adds an equals comparison to the query.

[`Search`](Search.md)<`TEntity`\>
[`Search`](Search.md)

@@ -408,3 +398,3 @@ The [Search](Search.md) that was called to create this [WhereField](WhereField.md).

[lib/search/where-field.ts:30](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/where-field.ts#L30)
[lib/search/where-field.ts:30](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/where-field.ts#L30)

@@ -415,3 +405,3 @@ ___

▸ **equalTo**(`value`): [`Search`](Search.md)<`TEntity`\>
▸ **equalTo**(`value`): [`Search`](Search.md)

@@ -431,3 +421,3 @@ Adds an equals comparison to the query.

[`Search`](Search.md)<`TEntity`\>
[`Search`](Search.md)

@@ -438,3 +428,3 @@ The [Search](Search.md) that was called to create this [WhereField](WhereField.md).

[lib/search/where-field.ts:50](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/where-field.ts#L50)
[lib/search/where-field.ts:50](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/where-field.ts#L50)

@@ -445,3 +435,3 @@ ___

▸ **equals**(`value`): [`Search`](Search.md)<`TEntity`\>
▸ **equals**(`value`): [`Search`](Search.md)

@@ -461,3 +451,3 @@ Adds an equals comparison to the query.

[`Search`](Search.md)<`TEntity`\>
[`Search`](Search.md)

@@ -468,3 +458,3 @@ The [Search](Search.md) that was called to create this [WhereField](WhereField.md).

[lib/search/where-field.ts:40](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/where-field.ts#L40)
[lib/search/where-field.ts:40](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/where-field.ts#L40)

@@ -475,3 +465,3 @@ ___

▸ **false**(): [`Search`](Search.md)<`TEntity`\>
▸ **false**(): [`Search`](Search.md)

@@ -482,3 +472,3 @@ Adds a boolean match with a value of `false` to the query.

[`Search`](Search.md)<`TEntity`\>
[`Search`](Search.md)

@@ -489,3 +479,3 @@ The [Search](Search.md) that was called to create this [WhereField](WhereField.md).

[lib/search/where-field.ts:111](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/where-field.ts#L111)
[lib/search/where-field.ts:111](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/where-field.ts#L111)

@@ -496,3 +486,3 @@ ___

▸ **greaterThan**(`value`): [`Search`](Search.md)<`TEntity`\>
▸ **greaterThan**(`value`): [`Search`](Search.md)

@@ -509,3 +499,3 @@ Adds a greater than comparison against a field to the search query.

[`Search`](Search.md)<`TEntity`\>
[`Search`](Search.md)

@@ -516,3 +506,3 @@ The [Search](Search.md) that was called to create this [WhereField](WhereField.md).

[lib/search/where-field.ts:125](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/where-field.ts#L125)
[lib/search/where-field.ts:125](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/where-field.ts#L125)

@@ -523,3 +513,3 @@ ___

▸ **greaterThanOrEqualTo**(`value`): [`Search`](Search.md)<`TEntity`\>
▸ **greaterThanOrEqualTo**(`value`): [`Search`](Search.md)

@@ -536,3 +526,3 @@ Adds a greater than or equal to comparison against a field to the search query.

[`Search`](Search.md)<`TEntity`\>
[`Search`](Search.md)

@@ -543,3 +533,3 @@ The [Search](Search.md) that was called to create this [WhereField](WhereField.md).

[lib/search/where-field.ts:139](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/where-field.ts#L139)
[lib/search/where-field.ts:139](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/where-field.ts#L139)

@@ -550,3 +540,3 @@ ___

▸ **gt**(`value`): [`Search`](Search.md)<`TEntity`\>
▸ **gt**(`value`): [`Search`](Search.md)

@@ -563,3 +553,3 @@ Adds a greater than comparison against a field to the search query.

[`Search`](Search.md)<`TEntity`\>
[`Search`](Search.md)

@@ -570,3 +560,3 @@ The [Search](Search.md) that was called to create this [WhereField](WhereField.md).

[lib/search/where-field.ts:118](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/where-field.ts#L118)
[lib/search/where-field.ts:118](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/where-field.ts#L118)

@@ -577,3 +567,3 @@ ___

▸ **gte**(`value`): [`Search`](Search.md)<`TEntity`\>
▸ **gte**(`value`): [`Search`](Search.md)

@@ -590,3 +580,3 @@ Adds a greater than or equal to comparison against a field to the search query.

[`Search`](Search.md)<`TEntity`\>
[`Search`](Search.md)

@@ -597,3 +587,3 @@ The [Search](Search.md) that was called to create this [WhereField](WhereField.md).

[lib/search/where-field.ts:132](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/where-field.ts#L132)
[lib/search/where-field.ts:132](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/where-field.ts#L132)

@@ -604,3 +594,3 @@ ___

▸ **inCircle**(`circleFn`): [`Search`](Search.md)<`TEntity`\>
▸ **inCircle**(`circleFn`): [`Search`](Search.md)

@@ -617,3 +607,3 @@ Adds a search for points that fall within a defined circle.

[`Search`](Search.md)<`TEntity`\>
[`Search`](Search.md)

@@ -624,3 +614,3 @@ The [Search](Search.md) that was called to create this [WhereField](WhereField.md).

[lib/search/where-field.ts:212](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/where-field.ts#L212)
[lib/search/where-field.ts:212](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/where-field.ts#L212)

@@ -631,3 +621,3 @@ ___

▸ **inRadius**(`circleFn`): [`Search`](Search.md)<`TEntity`\>
▸ **inRadius**(`circleFn`): [`Search`](Search.md)

@@ -644,3 +634,3 @@ Adds a search for points that fall within a defined radius.

[`Search`](Search.md)<`TEntity`\>
[`Search`](Search.md)

@@ -651,3 +641,3 @@ The [Search](Search.md) that was called to create this [WhereField](WhereField.md).

[lib/search/where-field.ts:219](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/where-field.ts#L219)
[lib/search/where-field.ts:219](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/where-field.ts#L219)

@@ -658,3 +648,3 @@ ___

▸ **lessThan**(`value`): [`Search`](Search.md)<`TEntity`\>
▸ **lessThan**(`value`): [`Search`](Search.md)

@@ -671,3 +661,3 @@ Adds a less than comparison against a field to the search query.

[`Search`](Search.md)<`TEntity`\>
[`Search`](Search.md)

@@ -678,3 +668,3 @@ The [Search](Search.md) that was called to create this [WhereField](WhereField.md).

[lib/search/where-field.ts:153](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/where-field.ts#L153)
[lib/search/where-field.ts:153](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/where-field.ts#L153)

@@ -685,3 +675,3 @@ ___

▸ **lessThanOrEqualTo**(`value`): [`Search`](Search.md)<`TEntity`\>
▸ **lessThanOrEqualTo**(`value`): [`Search`](Search.md)

@@ -698,3 +688,3 @@ Adds a less than or equal to comparison against a field to the search query.

[`Search`](Search.md)<`TEntity`\>
[`Search`](Search.md)

@@ -705,3 +695,3 @@ The [Search](Search.md) that was called to create this [WhereField](WhereField.md).

[lib/search/where-field.ts:167](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/where-field.ts#L167)
[lib/search/where-field.ts:167](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/where-field.ts#L167)

@@ -712,3 +702,3 @@ ___

▸ **lt**(`value`): [`Search`](Search.md)<`TEntity`\>
▸ **lt**(`value`): [`Search`](Search.md)

@@ -725,3 +715,3 @@ Adds a less than comparison against a field to the search query.

[`Search`](Search.md)<`TEntity`\>
[`Search`](Search.md)

@@ -732,3 +722,3 @@ The [Search](Search.md) that was called to create this [WhereField](WhereField.md).

[lib/search/where-field.ts:146](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/where-field.ts#L146)
[lib/search/where-field.ts:146](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/where-field.ts#L146)

@@ -739,3 +729,3 @@ ___

▸ **lte**(`value`): [`Search`](Search.md)<`TEntity`\>
▸ **lte**(`value`): [`Search`](Search.md)

@@ -752,3 +742,3 @@ Adds a less than or equal to comparison against a field to the search query.

[`Search`](Search.md)<`TEntity`\>
[`Search`](Search.md)

@@ -759,3 +749,3 @@ The [Search](Search.md) that was called to create this [WhereField](WhereField.md).

[lib/search/where-field.ts:160](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/where-field.ts#L160)
[lib/search/where-field.ts:160](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/where-field.ts#L160)

@@ -766,3 +756,3 @@ ___

▸ **match**(`value`): [`Search`](Search.md)<`TEntity`\>
▸ **match**(`value`): [`Search`](Search.md)

@@ -779,3 +769,3 @@ Adds a full-text search comparison to the query.

[`Search`](Search.md)<`TEntity`\>
[`Search`](Search.md)

@@ -786,3 +776,3 @@ The [Search](Search.md) that was called to create this [WhereField](WhereField.md).

[lib/search/where-field.ts:57](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/where-field.ts#L57)
[lib/search/where-field.ts:57](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/where-field.ts#L57)

@@ -793,3 +783,3 @@ ___

▸ **matchExact**(`value`): [`Search`](Search.md)<`TEntity`\>
▸ **matchExact**(`value`): [`Search`](Search.md)

@@ -806,3 +796,3 @@ Adds a full-text search comparison to the query that matches an exact word or phrase.

[`Search`](Search.md)<`TEntity`\>
[`Search`](Search.md)

@@ -813,3 +803,3 @@ The [Search](Search.md) that was called to create this [WhereField](WhereField.md).

[lib/search/where-field.ts:71](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/where-field.ts#L71)
[lib/search/where-field.ts:71](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/where-field.ts#L71)

@@ -820,3 +810,3 @@ ___

▸ **matchExactly**(`value`): [`Search`](Search.md)<`TEntity`\>
▸ **matchExactly**(`value`): [`Search`](Search.md)

@@ -833,3 +823,3 @@ Adds a full-text search comparison to the query that matches an exact word or phrase.

[`Search`](Search.md)<`TEntity`\>
[`Search`](Search.md)

@@ -840,3 +830,3 @@ The [Search](Search.md) that was called to create this [WhereField](WhereField.md).

[lib/search/where-field.ts:78](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/where-field.ts#L78)
[lib/search/where-field.ts:78](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/where-field.ts#L78)

@@ -847,3 +837,3 @@ ___

▸ **matches**(`value`): [`Search`](Search.md)<`TEntity`\>
▸ **matches**(`value`): [`Search`](Search.md)

@@ -860,3 +850,3 @@ Adds a full-text search comparison to the query.

[`Search`](Search.md)<`TEntity`\>
[`Search`](Search.md)

@@ -867,3 +857,3 @@ The [Search](Search.md) that was called to create this [WhereField](WhereField.md).

[lib/search/where-field.ts:64](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/where-field.ts#L64)
[lib/search/where-field.ts:64](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/where-field.ts#L64)

@@ -874,3 +864,3 @@ ___

▸ **matchesExactly**(`value`): [`Search`](Search.md)<`TEntity`\>
▸ **matchesExactly**(`value`): [`Search`](Search.md)

@@ -887,3 +877,3 @@ Adds a full-text search comparison to the query that matches an exact word or phrase.

[`Search`](Search.md)<`TEntity`\>
[`Search`](Search.md)

@@ -894,3 +884,3 @@ The [Search](Search.md) that was called to create this [WhereField](WhereField.md).

[lib/search/where-field.ts:85](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/where-field.ts#L85)
[lib/search/where-field.ts:85](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/where-field.ts#L85)

@@ -901,3 +891,3 @@ ___

▸ **on**(`value`): [`Search`](Search.md)<`TEntity`\>
▸ **on**(`value`): [`Search`](Search.md)

@@ -914,3 +904,3 @@ Add a search for an exact UTC datetime to the query.

[`Search`](Search.md)<`TEntity`\>
[`Search`](Search.md)

@@ -921,3 +911,3 @@ The [Search](Search.md) that was called to create this [WhereField](WhereField.md).

[lib/search/where-field.ts:226](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/where-field.ts#L226)
[lib/search/where-field.ts:226](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/where-field.ts#L226)

@@ -928,3 +918,3 @@ ___

▸ **onOrAfter**(`value`): [`Search`](Search.md)<`TEntity`\>
▸ **onOrAfter**(`value`): [`Search`](Search.md)

@@ -941,3 +931,3 @@ Add a search that matches all datetimes *on or after* the provided UTC datetime to the query.

[`Search`](Search.md)<`TEntity`\>
[`Search`](Search.md)

@@ -948,3 +938,3 @@ The [Search](Search.md) that was called to create this [WhereField](WhereField.md).

[lib/search/where-field.ts:254](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/where-field.ts#L254)
[lib/search/where-field.ts:254](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/where-field.ts#L254)

@@ -955,3 +945,3 @@ ___

▸ **onOrBefore**(`value`): [`Search`](Search.md)<`TEntity`\>
▸ **onOrBefore**(`value`): [`Search`](Search.md)

@@ -968,3 +958,3 @@ Add a search that matches all datetimes *on or before* the provided UTC datetime to the query.

[`Search`](Search.md)<`TEntity`\>
[`Search`](Search.md)

@@ -975,3 +965,3 @@ The [Search](Search.md) that was called to create this [WhereField](WhereField.md).

[lib/search/where-field.ts:247](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/where-field.ts#L247)
[lib/search/where-field.ts:247](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/where-field.ts#L247)

@@ -996,3 +986,3 @@ ___

[lib/search/where-field.ts:303](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/where-field.ts#L303)
[lib/search/where-field.ts:303](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/where-field.ts#L303)

@@ -1003,3 +993,3 @@ ___

▸ **true**(): [`Search`](Search.md)<`TEntity`\>
▸ **true**(): [`Search`](Search.md)

@@ -1010,3 +1000,3 @@ Adds a boolean match with a value of `true` to the query.

[`Search`](Search.md)<`TEntity`\>
[`Search`](Search.md)

@@ -1017,2 +1007,2 @@ The [Search](Search.md) that was called to create this [WhereField](WhereField.md).

[lib/search/where-field.ts:105](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/where-field.ts#L105)
[lib/search/where-field.ts:105](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/where-field.ts#L105)

@@ -10,50 +10,104 @@ redis-om

- [AbstractSearch](classes/AbstractSearch.md)
- [ArrayHashInput](classes/ArrayHashInput.md)
- [Circle](classes/Circle.md)
- [Client](classes/Client.md)
- [Entity](classes/Entity.md)
- [Field](classes/Field.md)
- [FieldNotInSchema](classes/FieldNotInSchema.md)
- [InvalidHashInput](classes/InvalidHashInput.md)
- [InvalidHashValue](classes/InvalidHashValue.md)
- [InvalidInput](classes/InvalidInput.md)
- [InvalidJsonInput](classes/InvalidJsonInput.md)
- [InvalidJsonValue](classes/InvalidJsonValue.md)
- [InvalidSchema](classes/InvalidSchema.md)
- [InvalidValue](classes/InvalidValue.md)
- [NestedHashInput](classes/NestedHashInput.md)
- [NullJsonInput](classes/NullJsonInput.md)
- [NullJsonValue](classes/NullJsonValue.md)
- [PointOutOfRange](classes/PointOutOfRange.md)
- [RawSearch](classes/RawSearch.md)
- [RedisError](classes/RedisError.md)
- [RedisOmError](classes/RedisOmError.md)
- [Repository](classes/Repository.md)
- [Schema](classes/Schema.md)
- [Search](classes/Search.md)
- [SearchError](classes/SearchError.md)
- [SemanticSearchError](classes/SemanticSearchError.md)
- [Where](classes/Where.md)
- [WhereField](classes/WhereField.md)
### Interfaces
- [BaseFieldDefinition](interfaces/BaseFieldDefinition.md)
- [BooleanFieldDefinition](interfaces/BooleanFieldDefinition.md)
- [CaseSensitiveFieldDefinition](interfaces/CaseSensitiveFieldDefinition.md)
- [DateFieldDefinition](interfaces/DateFieldDefinition.md)
- [NormalizedFieldDefinition](interfaces/NormalizedFieldDefinition.md)
- [NumberFieldDefinition](interfaces/NumberFieldDefinition.md)
- [PhoneticFieldDefinition](interfaces/PhoneticFieldDefinition.md)
- [PointFieldDefinition](interfaces/PointFieldDefinition.md)
- [SeparableFieldDefinition](interfaces/SeparableFieldDefinition.md)
- [SortableFieldDefinition](interfaces/SortableFieldDefinition.md)
- [StemmingFieldDefinition](interfaces/StemmingFieldDefinition.md)
- [StringArrayFieldDefinition](interfaces/StringArrayFieldDefinition.md)
- [StringFieldDefinition](interfaces/StringFieldDefinition.md)
- [TextFieldDefinition](interfaces/TextFieldDefinition.md)
- [WeightFieldDefinition](interfaces/WeightFieldDefinition.md)
### Type Aliases
- [AllFieldDefinition](README.md#allfielddefinition)
- [BooleanFieldDefinition](README.md#booleanfielddefinition)
- [CircleFunction](README.md#circlefunction)
- [CommonFieldDefinition](README.md#commonfielddefinition)
- [DataStructure](README.md#datastructure)
- [EntityConstructor](README.md#entityconstructor)
- [DateFieldDefinition](README.md#datefielddefinition)
- [Entity](README.md#entity)
- [EntityData](README.md#entitydata)
- [EntityValue](README.md#entityvalue)
- [EntityDataValue](README.md#entitydatavalue)
- [FieldDefinition](README.md#fielddefinition)
- [FieldType](README.md#fieldtype)
- [IdStrategy](README.md#idstrategy)
- [NumberFieldDefinition](README.md#numberfielddefinition)
- [Point](README.md#point)
- [PointFieldDefinition](README.md#pointfielddefinition)
- [RedisClientConnection](README.md#redisclientconnection)
- [RedisClusterConnection](README.md#redisclusterconnection)
- [RedisConnection](README.md#redisconnection)
- [SchemaDefinition](README.md#schemadefinition)
- [SchemaFieldType](README.md#schemafieldtype)
- [SchemaOptions](README.md#schemaoptions)
- [SearchDataStructure](README.md#searchdatastructure)
- [StopWordOptions](README.md#stopwordoptions)
- [StringArrayFieldDefinition](README.md#stringarrayfielddefinition)
- [StringFieldDefinition](README.md#stringfielddefinition)
- [SubSearchFunction](README.md#subsearchfunction)
- [TextFieldDefinition](README.md#textfielddefinition)
### Variables
- [EntityId](README.md#entityid)
- [EntityKeyName](README.md#entitykeyname)
## Type Aliases
### AllFieldDefinition
Ƭ **AllFieldDefinition**: `Object`
All configuration properties that any field might have, regardless of type.
#### Type declaration
| Name | Type | Description |
| :------ | :------ | :------ |
| `alias?` | `string` | The default field name in Redis is the property name defined in the [SchemaDefinition](README.md#schemadefinition). Overrides the field name for a Hash to this value or in the case of JSON documents, sets the JSONPath to this value preceded by `$.`. Overridden by [field](README.md#field) and/or [path](README.md#path) settings. **`Deprecated`** |
| `caseSensitive?` | `boolean` | Is the original case of this field indexed with Redis OM. Defaults to false. |
| `field?` | `string` | The field name used to store this in a Redis Hash. Defaults to the name used in the [SchemaDefinition](README.md#schemadefinition) or the [alias](README.md#alias) property. |
| `indexed?` | `boolean` | Is this field indexed and thus searchable with Redis OM. Defaults to true. |
| `matcher?` | ``"dm:en"`` \| ``"dm:fr"`` \| ``"dm:pt"`` \| ``"dm:es"`` | Enables setting the phonetic matcher to use, supported matchers are: dm:en - Double Metaphone for English dm:fr - Double Metaphone for French dm:pt - Double Metaphone for Portuguese dm:es - Double Metaphone for Spanish |
| `normalized?` | `boolean` | Is this (sortable) field normalized when indexed. Defaults to true. |
| `path?` | `string` | The JSONPath expression this field references. Used only by search and only for JSON documents. Defaults to the name used in the [SchemaDefinition](README.md#schemadefinition) or the [alias](README.md#alias) property prefixed with `$.` . |
| `separator?` | `string` | Due to how RediSearch works, strings and arrays are sometimes stored the same in Redis, as a simple string. This is the separator used to split those strings when it is an array. If your StringField contains this separator, this can cause problems. You can change it here to avoid those problems. Defaults to `\|`. |
| `sortable?` | `boolean` | Enables sorting by this field. |
| `stemming?` | `boolean` | Is word stemming applied to this field with Redis OM. Defaults to true. |
| `type` | [`FieldType`](README.md#fieldtype) | The type of the field (i.e. string, number, boolean, etc.) |
| `weight?` | `number` | Enables setting the weight to apply to a text field |
#### Defined in
[lib/schema/definitions.ts:5](https://github.com/redis/redis-om-node/blob/5777b6c/lib/schema/definitions.ts#L5)
___
### BooleanFieldDefinition
Ƭ **BooleanFieldDefinition**: { `type`: ``"boolean"`` } & [`CommonFieldDefinition`](README.md#commonfielddefinition) & `Pick`<[`AllFieldDefinition`](README.md#allfielddefinition), ``"sortable"``\>
A field representing a boolean.
#### Defined in
[lib/schema/definitions.ts:78](https://github.com/redis/redis-om-node/blob/5777b6c/lib/schema/definitions.ts#L78)
___
### CircleFunction

@@ -81,6 +135,18 @@

[lib/search/where-point.ts:9](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/where-point.ts#L9)
[lib/search/where-point.ts:8](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/where-point.ts#L8)
___
### CommonFieldDefinition
Ƭ **CommonFieldDefinition**: `Pick`<[`AllFieldDefinition`](README.md#allfielddefinition), ``"type"`` \| ``"alias"`` \| ``"indexed"`` \| ``"field"`` \| ``"path"``\>
The configuration properties that all fields have in common.
#### Defined in
[lib/schema/definitions.ts:75](https://github.com/redis/redis-om-node/blob/5777b6c/lib/schema/definitions.ts#L75)
___
### DataStructure

@@ -94,33 +160,27 @@

[lib/schema/options/data-structure.ts:2](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/schema/options/data-structure.ts#L2)
[lib/schema/options.ts:2](https://github.com/redis/redis-om-node/blob/5777b6c/lib/schema/options.ts#L2)
___
### EntityConstructor
### DateFieldDefinition
Ƭ **EntityConstructor**<`TEntity`\>: (`schema`: [`Schema`](classes/Schema.md)<`any`\>, `id`: `string`, `data?`: [`EntityData`](README.md#entitydata)) => `TEntity`
Ƭ **DateFieldDefinition**: { `type`: ``"date"`` } & [`CommonFieldDefinition`](README.md#commonfielddefinition) & `Pick`<[`AllFieldDefinition`](README.md#allfielddefinition), ``"sortable"``\>
#### Type parameters
A field representing a date/time.
| Name | Description |
| :------ | :------ |
| `TEntity` | The [Entity](classes/Entity.md) type. |
#### Defined in
#### Type declaration
[lib/schema/definitions.ts:83](https://github.com/redis/redis-om-node/blob/5777b6c/lib/schema/definitions.ts#L83)
• (`schema`, `id`, `data?`)
___
A constructor that creates an [Entity](classes/Entity.md) of type TEntity.
### Entity
##### Parameters
Ƭ **Entity**: [`EntityData`](README.md#entitydata) & { `[EntityId]?`: `string` ; `[EntityKeyName]?`: `string` }
| Name | Type |
| :------ | :------ |
| `schema` | [`Schema`](classes/Schema.md)<`any`\> |
| `id` | `string` |
| `data?` | [`EntityData`](README.md#entitydata) |
Defines the objects returned from calls to [repositories](classes/Repository.md).
#### Defined in
[lib/entity/entity-constructor.ts:8](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/entity/entity-constructor.ts#L8)
[lib/entity/entity.ts:8](https://github.com/redis/redis-om-node/blob/5777b6c/lib/entity/entity.ts#L8)

@@ -131,21 +191,25 @@ ___

Ƭ **EntityData**: `Record`<`string`, [`EntityValue`](README.md#entityvalue)\>
Ƭ **EntityData**: `Object`
A JavaScript object containing the underlying data of an [Entity](classes/Entity.md).
The free-form data associated with an [Entity](README.md#entity).
#### Index signature
▪ [key: `string`]: [`EntityDataValue`](README.md#entitydatavalue) \| [`EntityData`](README.md#entitydata) \| ([`EntityDataValue`](README.md#entitydatavalue) \| [`EntityData`](README.md#entitydata))[]
#### Defined in
[lib/entity/entity-data.ts:6](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/entity/entity-data.ts#L6)
[lib/entity/entity.ts:18](https://github.com/redis/redis-om-node/blob/5777b6c/lib/entity/entity.ts#L18)
___
### EntityValue
### EntityDataValue
Ƭ **EntityValue**: `string` \| `number` \| `boolean` \| [`Point`](README.md#point) \| `Date` \| `any`[] \| ``null``
Ƭ **EntityDataValue**: `string` \| `number` \| `boolean` \| `Date` \| [`Point`](README.md#point) \| ``null`` \| `undefined`
Valid types for properties on an [Entity](classes/Entity.md).
Valid types for values in an [Entity](README.md#entity).
#### Defined in
[lib/entity/entity-value.ts:6](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/entity/entity-value.ts#L6)
[lib/entity/entity.ts:23](https://github.com/redis/redis-om-node/blob/5777b6c/lib/entity/entity.ts#L23)

@@ -156,32 +220,56 @@ ___

Ƭ **FieldDefinition**: [`StringFieldDefinition`](interfaces/StringFieldDefinition.md) \| [`TextFieldDefinition`](interfaces/TextFieldDefinition.md) \| [`NumberFieldDefinition`](interfaces/NumberFieldDefinition.md) \| [`BooleanFieldDefinition`](interfaces/BooleanFieldDefinition.md) \| [`PointFieldDefinition`](interfaces/PointFieldDefinition.md) \| [`DateFieldDefinition`](interfaces/DateFieldDefinition.md) \| [`StringArrayFieldDefinition`](interfaces/StringArrayFieldDefinition.md)
Ƭ **FieldDefinition**: [`BooleanFieldDefinition`](README.md#booleanfielddefinition) \| [`DateFieldDefinition`](README.md#datefielddefinition) \| [`NumberFieldDefinition`](README.md#numberfielddefinition) \| [`PointFieldDefinition`](README.md#pointfielddefinition) \| [`StringArrayFieldDefinition`](README.md#stringarrayfielddefinition) \| [`StringFieldDefinition`](README.md#stringfielddefinition) \| [`TextFieldDefinition`](README.md#textfielddefinition)
Contains instructions telling how to map a property on an [Entity](classes/Entity.md) to Redis.
Contains instructions telling how to map a property on an [Entity](README.md#entity) to Redis.
#### Defined in
[lib/schema/definition/field-definition.ts:10](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/schema/definition/field-definition.ts#L10)
[lib/schema/definitions.ts:112](https://github.com/redis/redis-om-node/blob/5777b6c/lib/schema/definitions.ts#L112)
___
### FieldType
Ƭ **FieldType**: ``"boolean"`` \| ``"date"`` \| ``"number"`` \| ``"point"`` \| ``"string"`` \| ``"string[]"`` \| ``"text"``
Valid field types for a [FieldDefinition](README.md#fielddefinition).
#### Defined in
[lib/schema/definitions.ts:2](https://github.com/redis/redis-om-node/blob/5777b6c/lib/schema/definitions.ts#L2)
___
### IdStrategy
Ƭ **IdStrategy**: () => `string`
Ƭ **IdStrategy**: () => `Promise`<`string`\>
#### Type declaration
▸ (): `string`
▸ (): `Promise`<`string`\>
A function that generates random [Entity IDs](classes/Entity.md#entityid).
A function that generates random entityIds.
##### Returns
`string`
`Promise`<`string`\>
#### Defined in
[lib/schema/options/id-strategy.ts:2](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/schema/options/id-strategy.ts#L2)
[lib/schema/options.ts:5](https://github.com/redis/redis-om-node/blob/5777b6c/lib/schema/options.ts#L5)
___
### NumberFieldDefinition
Ƭ **NumberFieldDefinition**: { `type`: ``"number"`` } & [`CommonFieldDefinition`](README.md#commonfielddefinition) & `Pick`<[`AllFieldDefinition`](README.md#allfielddefinition), ``"sortable"``\>
A field representing a number.
#### Defined in
[lib/schema/definitions.ts:88](https://github.com/redis/redis-om-node/blob/5777b6c/lib/schema/definitions.ts#L88)
___
### Point

@@ -202,30 +290,66 @@

[lib/entity/point.ts:2](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/entity/point.ts#L2)
[lib/entity/entity.ts:26](https://github.com/redis/redis-om-node/blob/5777b6c/lib/entity/entity.ts#L26)
___
### SchemaDefinition
### PointFieldDefinition
Ƭ **SchemaDefinition**: `Record`<`string`, [`FieldDefinition`](README.md#fielddefinition)\>
Ƭ **PointFieldDefinition**: { `type`: ``"point"`` } & [`CommonFieldDefinition`](README.md#commonfielddefinition)
Group of [FieldDefinition](README.md#fielddefinition)s that define the schema for an [Entity](classes/Entity.md).
A field representing a point on the globe.
#### Defined in
[lib/schema/definition/schema-definition.ts:6](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/schema/definition/schema-definition.ts#L6)
[lib/schema/definitions.ts:93](https://github.com/redis/redis-om-node/blob/5777b6c/lib/schema/definitions.ts#L93)
___
### SchemaFieldType
### RedisClientConnection
Ƭ **SchemaFieldType**: ``"string"`` \| ``"number"`` \| ``"boolean"`` \| ``"text"`` \| ``"date"`` \| ``"point"`` \| ``"string[]"``
Ƭ **RedisClientConnection**: `ReturnType`<typeof `createClient`\>
Valid types a [FieldDefinition](README.md#fielddefinition).
A conventional Redis connection.
#### Defined in
[lib/schema/definition/schema-field-type.ts:4](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/schema/definition/schema-field-type.ts#L4)
[lib/client/client.ts:8](https://github.com/redis/redis-om-node/blob/5777b6c/lib/client/client.ts#L8)
___
### RedisClusterConnection
Ƭ **RedisClusterConnection**: `ReturnType`<typeof `createCluster`\>
A clustered Redis connection.
#### Defined in
[lib/client/client.ts:11](https://github.com/redis/redis-om-node/blob/5777b6c/lib/client/client.ts#L11)
___
### RedisConnection
Ƭ **RedisConnection**: [`RedisClientConnection`](README.md#redisclientconnection) \| [`RedisClusterConnection`](README.md#redisclusterconnection)
A Redis connection, clustered or conventional.
#### Defined in
[lib/client/client.ts:14](https://github.com/redis/redis-om-node/blob/5777b6c/lib/client/client.ts#L14)
___
### SchemaDefinition
Ƭ **SchemaDefinition**: `Record`<`string`, [`FieldDefinition`](README.md#fielddefinition)\>
Group of [FieldDefinition](README.md#fielddefinition)s that define the schema for an [Entity](README.md#entity).
#### Defined in
[lib/schema/definitions.ts:118](https://github.com/redis/redis-om-node/blob/5777b6c/lib/schema/definitions.ts#L118)
___
### SchemaOptions

@@ -241,8 +365,6 @@

| :------ | :------ | :------ |
| `dataStructure?` | [`DataStructure`](README.md#datastructure) | The data structure used to store the [Entity](classes/Entity.md) in Redis. Can be set to either `JSON` or `HASH`. Defaults to JSON. |
| `idStrategy?` | [`IdStrategy`](README.md#idstrategy) | A function that generates a random [Entity ID](classes/Entity.md#entityid). Defaults to a function that generates [ULIDs](https://github.com/ulid/spec). Combined with prefix to generate a Redis key. If prefix is `Foo` and idStratgey returns `12345` then the generated key would be `Foo:12345`. |
| `dataStructure?` | [`DataStructure`](README.md#datastructure) | The data structure used to store the [Entity](README.md#entity) in Redis. Can be set to either `JSON` or `HASH`. Defaults to JSON. |
| `idStrategy?` | [`IdStrategy`](README.md#idstrategy) | A function that generates a random entityId. Defaults to a function that generates [ULIDs](https://github.com/ulid/spec). Combined with prefix to generate a Redis key. If prefix is `Foo` and idStratgey returns `12345` then the generated key would be `Foo:12345`. |
| `indexHashName?` | `string` | The name used by Redis OM to store the hash of the index for this [Schema](classes/Schema.md). Defaults to prefix followed by `:index:hash`. So, for a prefix of `Foo`, it would use `Foo:index:hash`. |
| `indexName?` | `string` | The name used by RediSearch to store the index for this [Schema](classes/Schema.md). Defaults to prefix followed by `:index`. So, for a prefix of `Foo`, it would use `Foo:index`. |
| `indexedDefault?` | `boolean` | Whether fields are indexed by default |
| `prefix?` | `string` | The string that comes before the ID when creating Redis keys for [Entities](classes/Entity.md). Defaults to the class name of the [Entity](classes/Entity.md). Combined with the results of idStrategy to generate a key. If prefix is `Foo` and idStrategy returns `12345` then the generated key would be `Foo:12345`. |
| `stopWords?` | `string`[] | Stop words to be used by this schema. If `useStopWords` is anything other than `CUSTOM`, this option is ignored. |

@@ -253,43 +375,49 @@ | `useStopWords?` | [`StopWordOptions`](README.md#stopwordoptions) | Configures the usage of stop words. Valid values are `OFF`, `DEFAULT`, and `CUSTOM`. Setting this to `OFF` disables all stop words. Setting this to `DEFAULT` uses the stop words intrinsic to RediSearch. Setting this to `CUSTOM` tells RediSearch to use the stop words in `stopWords`. |

[lib/schema/options/schema-options.ts:9](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/schema/options/schema-options.ts#L9)
[lib/schema/options.ts:11](https://github.com/redis/redis-om-node/blob/5777b6c/lib/schema/options.ts#L11)
___
### SearchDataStructure
### StopWordOptions
Ƭ **SearchDataStructure**: ``"HASH"`` \| ``"JSON"``
Ƭ **StopWordOptions**: ``"OFF"`` \| ``"DEFAULT"`` \| ``"CUSTOM"``
The type of data structure in Redis to map objects to.
Valid values for how to use stop words for a given [Schema](classes/Schema.md).
#### Defined in
[lib/client.ts:23](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/client.ts#L23)
[lib/schema/options.ts:8](https://github.com/redis/redis-om-node/blob/5777b6c/lib/schema/options.ts#L8)
___
### StopWordOptions
### StringArrayFieldDefinition
Ƭ **StopWordOptions**: ``"OFF"`` \| ``"DEFAULT"`` \| ``"CUSTOM"``
Ƭ **StringArrayFieldDefinition**: { `type`: ``"string[]"`` } & [`CommonFieldDefinition`](README.md#commonfielddefinition) & `Pick`<[`AllFieldDefinition`](README.md#allfielddefinition), ``"sortable"`` \| ``"caseSensitive"`` \| ``"normalized"`` \| ``"separator"``\>
Valid values for how to use stop words for a given [Schema](classes/Schema.md).
A field representing an array of strings.
#### Defined in
[lib/schema/options/stop-word-options.ts:2](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/schema/options/stop-word-options.ts#L2)
[lib/schema/definitions.ts:97](https://github.com/redis/redis-om-node/blob/5777b6c/lib/schema/definitions.ts#L97)
___
### SubSearchFunction
### StringFieldDefinition
Ƭ **SubSearchFunction**<`TEntity`\>: (`search`: [`Search`](classes/Search.md)<`TEntity`\>) => [`Search`](classes/Search.md)<`TEntity`\>
Ƭ **StringFieldDefinition**: { `type`: ``"string"`` } & [`CommonFieldDefinition`](README.md#commonfielddefinition) & `Pick`<[`AllFieldDefinition`](README.md#allfielddefinition), ``"sortable"`` \| ``"caseSensitive"`` \| ``"normalized"`` \| ``"separator"``\>
#### Type parameters
A field representing a whole string.
| Name | Type | Description |
| :------ | :------ | :------ |
| `TEntity` | extends [`Entity`](classes/Entity.md) | The type of [Entity](classes/Entity.md) being sought. |
#### Defined in
[lib/schema/definitions.ts:102](https://github.com/redis/redis-om-node/blob/5777b6c/lib/schema/definitions.ts#L102)
___
### SubSearchFunction
Ƭ **SubSearchFunction**: (`search`: [`Search`](classes/Search.md)) => [`Search`](classes/Search.md)
#### Type declaration
▸ (`search`): [`Search`](classes/Search.md)<`TEntity`\>
▸ (`search`): [`Search`](classes/Search.md)

@@ -302,10 +430,46 @@ A function that takes a [Search](classes/Search.md) and returns a [Search](classes/Search.md). Used in nested queries.

| :------ | :------ |
| `search` | [`Search`](classes/Search.md)<`TEntity`\> |
| `search` | [`Search`](classes/Search.md) |
##### Returns
[`Search`](classes/Search.md)<`TEntity`\>
[`Search`](classes/Search.md)
#### Defined in
[lib/search/search.ts:26](https://github.com/redis/redis-om-node/blob/f2d3aed/lib/search/search.ts#L26)
[lib/search/search.ts:26](https://github.com/redis/redis-om-node/blob/5777b6c/lib/search/search.ts#L26)
___
### TextFieldDefinition
Ƭ **TextFieldDefinition**: { `type`: ``"text"`` } & [`CommonFieldDefinition`](README.md#commonfielddefinition) & `Pick`<[`AllFieldDefinition`](README.md#allfielddefinition), ``"sortable"`` \| ``"normalized"`` \| ``"matcher"`` \| ``"stemming"`` \| ``"weight"``\>
A field representing searchable text.
#### Defined in
[lib/schema/definitions.ts:107](https://github.com/redis/redis-om-node/blob/5777b6c/lib/schema/definitions.ts#L107)
## Variables
### EntityId
• `Const` **EntityId**: typeof [`EntityId`](README.md#entityid)
The Symbol used to access the entity ID of an [Entity](README.md#entity).
#### Defined in
[lib/entity/entity.ts:2](https://github.com/redis/redis-om-node/blob/5777b6c/lib/entity/entity.ts#L2)
___
### EntityKeyName
• `Const` **EntityKeyName**: typeof [`EntityKeyName`](README.md#entitykeyname)
The Symbol used to access the keyname of an [Entity](README.md#entity).
#### Defined in
[lib/entity/entity.ts:5](https://github.com/redis/redis-om-node/blob/5777b6c/lib/entity/entity.ts#L5)
{
"name": "redis-om",
"version": "0.3.6",
"version": "0.4.0-beta.1",
"description": "Object mapping, and more, for Redis and Node.js. Written in TypeScript.",

@@ -19,3 +19,3 @@ "main": "dist/index.js",

"test": "vitest",
"test:coverage": "vitest --coverage",
"test:coverage": "vitest run --coverage",
"test:ui": "vitest --ui",

@@ -48,3 +48,3 @@ "test:unit": "vitest --dir ./spec/unit",

"@types/node": "^18.0.0",
"@vitest/ui": "^0.17.0",
"@vitest/ui": "^0.17.1",
"c8": "^7.11.3",

@@ -55,8 +55,10 @@ "tsup": "^6.1.2",

"typescript": "^4.7.2",
"vitest": "^0.17.0"
"vitest": "^0.20.0"
},
"dependencies": {
"redis": "^4.0.4",
"jsonpath-plus": "^7.2.0",
"just-clone": "^6.1.1",
"redis": "^4.6.4",
"ulid": "^2.3.0"
}
}

@@ -25,3 +25,3 @@ <div align="center">

**Redis OM Node.js** makes it easy to model Redis data in your Node.js applications.
**Redis OM for Node.js** makes it easy to model Redis data in your Node.js applications.

@@ -33,13 +33,14 @@ [Redis OM .NET][redis-om-dotnet] | **Redis OM Node.js** | [Redis OM Python][redis-om-python] | [Redis OM Spring][redis-om-spring]

- 💡 [Redis OM for Node.js](#-redis-om-for-nodejs)
- 🏁 [Getting Started](#-getting-started)
- 🔌 [Connect to Redis with a Client](#-connect-to-redis-with-a-client)
- [Redis OM for Node.js](#redis-om-for-nodejs)
- [Getting Started](#getting-started)
- [Connect to Redis with Node Redis](#connect-to-redis-with-node-redis)
- [Redis Connection Strings](#redis-connection-strings)
- 📇 [Define an Entity and a Schema](#-define-an-entity-and-a-schema)
- 🖋 [Reading, Writing, and Removing with Repository](#-reading-writing-and-removing-with-repository)
- [Entities and Schemas](#entities-and-schemas)
- [JSON and Hashes](#json-and-hashes)
- [Configuring JSON](#configuring-json)
- [Configuring Hashes](#configuring-hashes)
- [Reading, Writing, and Removing with Repository](#reading-writing-and-removing-with-repository)
- [Creating Entities](#creating-entities)
- [Missing Entities and Null Values](#missing-entities-and-null-values)
- [A Note for TypeScript Users](#a-note-for-typescript-users)
- 🧮 [Embedding Your Own Logic into Entities](#-embedding-your-own-logic-into-entities)
- 📄 [Using Hashes](#-using-hashes)
- 🔎 [Using RediSearch](#-using-redisearch)
- [Searching](#searching)
- [Build the Index](#build-the-index)

@@ -61,30 +62,32 @@ - [Finding All The Things (and Returning Them)](#finding-all-the-things-and-returning-them)

- [Sorting Search Results](#sorting-search-results)
- 📚 [Documentation](#-documentation)
- ⛏️ [Troubleshooting](#%EF%B8%8F-troubleshooting)
- ❤️ [Contributing](#%EF%B8%8F-contributing)
- [Advanced Stuff](#advanced-stuff)
- [Schema Options](#schema-options)
- [Documentation](#documentation)
- [Troubleshooting](#troubleshooting)
- [Contributing](#contributing)
</details>
## 💡 Redis OM for Node.js
## Redis OM for Node.js
Redis OM (pronounced _REDiss OHM_) makes it easy to add Redis to your Node.js application by mapping the Redis data structures you know and love to classes that you define. No more pesky, low-level commands, just pure code with a fluent interface.
Redis OM (pronounced _REDiss OHM_) makes it easy to add Redis to your Node.js application by mapping the Redis data structures you know and love to simple JavaScript objects. No more pesky, low-level commands, just pure code with a fluent interface.
Define an entity:
Define a schema:
```javascript
class Album extends Entity {}
const schema = new Schema(Album, {
const schema = new Schema('album', {
artist: { type: 'string' },
title: { type: 'text' },
year: { type: 'number' }
});
})
```
Create a new entity and save it:
Create a JavaScript object and save it:
```javascript
const album = repository.createEntity()
album.artist = "Mushroomhead"
album.title = "The Righteous & The Butterfly"
album.year = 2014
const album = {
artist: "Mushroomhead",
title: "The Righteous & The Butterfly",
year: 2014
}
await repository.save(album)

@@ -99,3 +102,4 @@ ```

.and('title').matches('butterfly')
.and('year').is.greaterThan(2000).return.all()
.and('year').is.greaterThan(2000)
.return.all()
```

@@ -105,3 +109,3 @@

## 🏁 Getting Started
## Getting Started

@@ -114,6 +118,10 @@ First things first, get yourself a Node.js project. There are lots of ways to do this, but I'm gonna go with a classic:

$ npm install redis-om --save
$ npm install redis-om
Of course, you'll need some Redis, preferably [Redis Stack][redis-stack-url] as it comes with [RediSearch][redisearch-url] and [RedisJSON][redis-json-url] ready to go. The easiest way to do this is to set up a free [Redis Cloud][redis-cloud-url] instance. But, you can also use Docker:
Redis OM for Node.js uses [Node Redis](https://github.com/redis/node-redis). So you should install that too:
$ npm install redis
And, of course, you'll need some Redis, preferably [Redis Stack][redis-stack-url] as it comes with [RediSearch][redisearch-url] and [RedisJSON][redis-json-url] ready to go. The easiest way to do this is to set up a free [Redis Cloud][redis-cloud-url] instance. But, you can also use Docker:
$ docker run -d --name redis-stack -p 6379:6379 -p 8001:8001 redis/redis-stack:latest

@@ -123,94 +131,59 @@

## 🔌 Connect to Redis with a Client
## Connect to Redis with Node Redis
You connect to Redis using a [*client*](docs/classes/Client.md). The `Client` class has methods to open, close, and execute raw commands against Redis.
Before you can use Redis OM, you need to connect to Redis with Node Redis. Here's how you do that, stolen straight from the top of the Node Redis [README](https://github.com/redis/node-redis):
```javascript
import { Client } from 'redis-om'
import { createClient } from 'redis'
const client = new Client()
await client.open('redis://localhost:6379')
const redis = createClient()
redis.on('error', (err) => console.log('Redis Client Error', err));
await redis.connect()
```
const aString = await client.execute(['PING'])
// 'PONG'
Node Redis is a powerful piece of software with lots and lots of capabilities. Its details are *way* beyond the scope of this README. But, if you're curious—or if you need that power—you can find all the info in the Node Redis [documentation](https://github.com/redis/node-redis).
const aNumber = await client.execute(['HSET', 'foo', 'bar', 'baz', 'qux', 42])
// 2
Regardless, once you have a connection to Redis you can use it to execute Redis commands:
const anArray = await client.execute(['HGETALL', 'foo'])
// [ 'bar', 'baz', 'qux', '42' ]
```javascript
await client.close()
const aString = await redis.ping() // 'PONG'
const aNumber = await redis.hSet('foo', 'alfa', '42', 'bravo', '23') // 2
const aHash = await redis.hGetAll('foo') // { alfa: '42', bravo: '23' }
```
<details>
<summary>Or, in TypeScript:</summary>
You might not need to do this, but it's always handy to have the option. When you're done with a Redis connection, you can let the server know by calling `.quit`:
In Typescript you should type cast the returning type.
Typecasts can be done in 2 ways, casting it before the returning value `client.execute(["PING"])` or after using the `as` keyword `client.execute(["PING"]) as string`.
```typescript
import { Client } from 'redis-om';
let client = await new Client().open('redis://localhost:6379');
let aString = await <string>client.execute(['PING']);
// 'PONG'
let aNumber = await <number>client.execute(['HSET', 'foo', 'bar', 'baz', 'qux', 42]);
// 2
let anArray = await <Array<string>>client.execute(['HGETALL', 'foo']);
// [ 'bar', 'baz', 'qux', '42' ]
await client.close();
```javascript
await redis.quit()
```
</details>
Mostly you'll use `.open`, `.close`, and `.fetchRepository` (which we'll talk about soon enough). But, on occasion, you might need to talk to Redis directly. The `.execute` method allows you to do that.
### Redis Connection Strings
If you find you need to talk to Redis directly a *lot* or you need more than just a basic connection to Redis, you'll want to take a look at the `.use` method on `Client`. It will allow you to bind an existing [Node Redis](https://github.com/redis/node-redis) connection to your Redis OM Client:
By default, Node Redis connects to `localhost` on port `6379`. This is, of course, configurable. Just pass in a *url* with the hostname and port that you want to use:
```javascript
import { createClient } from 'redis'
import { Client } from 'redis-om'
const redis = createClient('redis://localhost:6379')
await redis.connect()
const client = await new Client().use(redis)
await redis.set('foo', 'bar')
const value = await client.execute(['GET', 'foo'])
const redis = createClient({ url: 'redis://alice:foobared@awesome.redis.server:6380' })
```
Use `.use` to take advantage of things like [clustering](https://github.com/redis/node-redis#clustering). Details on all that stuff are way beyond the scope of this README. You can read about it in the Node Redis [documentation](https://github.com/redis/node-redis).
The basic format for this URL is:
### Redis Connection Strings
When you open a Redis client, you hand it a URL. The basic format for this URL is:
redis://username:password@host:port
This is the bulk of what you will need, but if you want more, the full specification for the URL is [defined with the IANA](https://www.iana.org/assignments/uri-schemes/prov/redis). And yes, there is a [TLS version](https://www.iana.org/assignments/uri-schemes/prov/rediss) as well.
This will probably cover most scenarios, but if you want something more, the full specification for the URL is [defined with the IANA](https://www.iana.org/assignments/uri-schemes/prov/redis). And yes, there is a [TLS version](https://www.iana.org/assignments/uri-schemes/prov/rediss) as well.
If you don't provide a URL, it defaults to `redis://localhost:6379`.
Node Redis has lots of other ways you can create a connection. You can use discrete parameters, UNIX sockets, and all sorts of cool things. Details can be found in the [client configuration guide](https://github.com/redis/node-redis/blob/master/docs/client-configuration.md) for Node Redis and the [clusterting guide](https://github.com/redis/node-redis/blob/master/docs/clustering.md).
## 📇 Define an Entity and a Schema
## Entities and Schemas
Ok. Let's start doing some object mapping. We'll start by defining an [*entity*](docs/classes/Entity.md) and a [*schema*](docs/classes/Schema.md).
Redis OM is all about saving, reading, and deleting *entities*. An [Entity](docs/README.md#entity) is just data in a JavaScript object that you want to save or retrieve from Redis. Almost any JavaScript object is a valid `Entity`.
```javascript
import { Entity, Schema } from 'redis-om'
```
[Schemas](docs/classes/Schema.md) define fields that might be on an `Entity`. It includes a field's type, how it is stored internally in Redis, and how to search on it if you are using RediSearch. By default, they are mapped to JSON documents using RedisJSON, but you can change it to use Hashes if want (more on that later).
[Entities](docs/classes/Entity.md) are the classes that you work with. The things being created, read, updated, and deleted. Any class that extends `Entity` is an entity. Usually, you'll define an entity with a single line of code:
Ok. Let's start doing some object mapping and create a `Schema`:
```javascript
class Album extends Entity {}
class Studio extends Entity {}
```
import { Schema } from 'redis-om'
[Schemas](docs/classes/Schema.md) define the fields on your entity, their types, and how they are mapped internally to Redis. By default, entities map to JSON documents using RedisJSON, but you can change it to use Hashes if want (more on that later):
```javascript
const albumSchema = new Schema(Album, {
const albumSchema = new Schema('album', {
artist: { type: 'string' },

@@ -223,3 +196,3 @@ title: { type: 'text' },

const studioSchema = new Schema(Studio, {
const studioSchema = new Schema('studio', {
name: { type: 'string' },

@@ -233,10 +206,12 @@ city: { type: 'string' },

When you create a `Schema`, it modifies the entity you handed it, adding getters and setters for the properties you define. The type those getters and setters accept and return are defined with the type parameter above. Valid values are: `string`, `number`, `boolean`, `string[]`, `date`, `point`, or `text`.
The *first argument* is the `Schema` name. It defines the key name prefix that entities stored in Redis will have. It should be unique for your particular instance of Redis and probably meaningful to what you're doing. Here we have selected `album` for our album data and `studio` for data on recording studios. Imaginative, I know.
The first three do exactly what you think—they define a property that is a [String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String), a [Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number), or a [Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean). `string[]` does what you'd think as well, specifically defining an [Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array) of Strings.
The *second argument* defines fields that might be stored in that key. The property name is the name of the field that you'll be referencing in your Redis OM queries. The type property tells Redis OM what sort of data is in that field. Valid types are: `string`, `number`, `boolean`, `string[]`, `date`, `point`, and `text`.
`date` is a little different, but still more or less what you'd expect. It defines a property that returns a [Date](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date) and can be set using not only a Date but also a String containing an [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) date or a number with the [UNIX epoch time](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date#the_ecmascript_epoch_and_timestamps) in *seconds* (NOTE: the JavaScript Date object is specified in *milliseconds*).
The first three types do exactly what you think—they define a field that is a [String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String), a [Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number), or a [Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean). `string[]` does what you'd think as well, specifically describing an [Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array) of Strings.
A `point` defines a point somewhere on the globe as a longitude and a latitude. It defines a property that returns and accepts a simple object with `longitude` and `latitude` properties. Like this:
`date` is a little different, but still more or less what you'd expect. It describes a property that contains a [Date](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date) and can be set using not only a Date but also a String containing an [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) date or a number with the [UNIX epoch time](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date#the_ecmascript_epoch_and_timestamps) in *seconds* (NOTE: the JavaScript Date object is specified in *milliseconds*).
A `point` defines a point somewhere on the globe as a longitude and a latitude. It is expressed as a simple object with `longitude` and `latitude` properties. Like this:
```javascript

@@ -246,244 +221,269 @@ const point = { longitude: 12.34, latitude: 56.78 }

A `text` field is a lot like a `string`. If you're just reading and writing objects, they are identical. But if you want to *search* on them, they are very, very different. I'll cover that in detail when I talk about [using RediSearch](#-using-redisearch) but the tl;dr is that `string` fields can only be matched on their whole value—no partial matches—and are best for keys while `text` fields have full-text search enabled on them and are optimized for human-readable text.
A `text` field is a lot like a `string`. If you're just reading and writing objects, they are identical. But if you want to *search* on them, **they are very, very different**. I'll cover that in detail when I talk about [searching](#searching) but the tl;dr is that `string` fields can only be matched on their exact value and are best for keys and discrete data—like postal codes or status indicators—while `text` fields have full-text search enabled on them, are optimized for human-readable text, and can take advantage of [stemming](https://redis.io/docs/stack/search/reference/stemming/) and [stop words](https://redis.io/docs/stack/search/reference/stopwords/).
Additional field options can be set depending on the field type. These correspond to the [Field Options](https://redis.io/commands/ft.create/#field-options) available when creating a RediSearch full-text index. Other than the `separator` option, these only affect how content is indexed and searched.
### JSON and Hashes
| schema type | RediSearch type | `indexed` | `sortable` | `normalized` | `stemming` | `phonetic` | `weight` | `separator` | `caseSensitive` |
| -------------- | :-------------: | :-------: | :--------: | :----------: | :--------: | :--------: | :------: | :---------: | :-------------: |
| `string` | TAG | yes | HASH Only | HASH Only | - | - | - | yes | yes |
| `number` | NUMERIC | yes | yes | - | - | - | - | - | - |
| `boolean` | TAG | yes | HASH Only | - | - | - | - | - | - |
| `string[]` | TAG | yes | HASH Only | HASH Only | - | - | - | yes | yes |
| `date` | NUMERIC | yes | yes | - | | - | - | - | - |
| `point` | GEO | yes | - | - | | - | - | - | - |
| `text` | TEXT | yes | yes | yes | yes | yes | yes | - | - |
As I mentioned earlier, by default Redis OM stores your entities in JSON documents using RedisJSON. You can make this explicit in code if you like:
* `indexed`: true | false, whether this field is indexed by RediSearch (default true)
* `sortable`: true | false, whether to create an additional index to optmize sorting (default false)
* `normalized`: true | false, whether to apply normalization for sorting (default true)
* `matcher`: string defining phonetic matcher which can be one of 'dm:en' for English | 'dm:fr' for French | 'dm:pt' for Portugese)| 'dm:es' for Spanish (default none)
* `stemming`: true | false, whether word stemming is applied to text fields (default true)
* `weight`: number, the importance weighting to use when ranking results (default 1)
* `separator`: string, the character to delimit multiple tags (default '|')
* `caseSensitive`: true | false, whether original letter casing is kept for search (default false)
```javascript
const albumSchema = new Schema('album', {
artist: { type: 'string' },
title: { type: 'string' },
year: { type: 'number' },
genres: { type: 'string[]' },
outOfPublication: { type: 'boolean' }
}, {
dataStructure: 'JSON'
})
```
Example showing additional options:
But you can also store your entities as Hashes instead. Just change the `dataStructure` property to reflect it:
```javascript
const commentSchema = new Schema(Comment, {
name: { type: 'text', stemming: false, matcher: 'dm:en' },
email: { type: 'string', normalized: false, },
posted: { type: 'date', sortable: true },
title: { type: 'text', weight: 2 },
comment: { type: 'text', weight: 1 },
approved: { type: 'boolean', indexed: false },
iphash: { type: 'string', caseSensitive: true },
notes: { type: 'string', indexed: false },
const albumSchema = new Schema('album', {
artist: { type: 'string' },
title: { type: 'string' },
year: { type: 'number' },
genres: { type: 'string[]' },
outOfPublication: { type: 'boolean' }
}, {
dataStructure: 'HASH'
})
```
There are several other options available when defining a schema for your entity. Check them out in the [detailed documentation](docs/classes/Schema.md) for the `Schema` class.
And that's it.
## 🖋 Reading, Writing, and Removing with Repository
Of course, Hashes and JSON are somewhat different data structures. Hashes are flat with fields containing values. JSON documents, however, are trees and can have depth and—most excitingly—can be nested. This difference is reflected in how Redis OM maps data to entities and how you configure your Schema.
Now that we have a client and a schema, we have what we need to make a [*repository*](docs/classes/Repository.md). A repository provides the means to read, write, and remove entities. Creating a repository is pretty straightforward—just ask the client for it:
#### Configuring JSON
```javascript
import { Repository } from 'redis-om'
When you store your entities as JSON, the path to the properties in your JSON document and your JavaScript object default to the name of your property in the schema. In the above example, this would result in a document that looks like this:
const albumRepository = client.fetchRepository(albumSchema)
const studioRepository = client.fetchRepository(studioSchema)
```json
{
"artist": "Mushroomhead",
"title": "The Righteous & The Butterfly",
"year": 2014,
"genres": [ "metal" ],
"outOfPublication": true
}
```
Once we have a repository, we can use it to create entities:
However, you might not want your JavaScript object and your JSON to map this way. So, you can provide a `path` option in your schema that contains a [JSONPath](https://redis.io/docs/stack/json/path/#jsonpath-syntax) pointing to where that field *actually* exists in the JSON and your entity. For example, we might want to store some of the album's data inside of an album property like this:
```javascript
const album = albumRepository.createEntity()
album.entityId // '01FJYWEYRHYFT8YTEGQBABJ43J'
```json
{
"album": {
"artist": "Mushroomhead",
"title": "The Righteous & The Butterfly",
"year": 2014,
"genres": [ "metal" ]
},
"outOfPublication": true
}
```
Note that entities created by `.createEntity` are not saved to Redis (at least not yet). They've only been instantiated and populated with an entity ID. This ID is a [ULID](https://github.com/ulid/spec) and is a unique id representing that object. To create a new entity *and* save it to Redis, we need to set all the properties on the entity that we care about, and call `.save`:
To do this, we'll need to specify the `path` property for the nested fields in the schema:
```javascript
const album = albumRepository.createEntity()
album.artist = "Mushroomhead"
album.title = "The Righteous & The Butterfly"
album.year = 2014
album.genres = [ 'metal' ]
album.outOfPublication = true
const id = await albumRepository.save(album) // '01FJYWEYRHYFT8YTEGQBABJ43J'
const albumSchema = new Schema('album', {
artist: { type: 'string', path: '$.album.artist' },
title: { type: 'string', path: '$.album.title' },
year: { type: 'number', path: '$.album.year' },
genres: { type: 'string[]', path: '$.album.genres[*]' },
outOfPublication: { type: 'boolean' }
})
```
As a convenience, you can pass in the values for the entity in the constructor:
There are two things to note here:
1. We haven't specified a path for `outOfPublication` as it's still in the root of the document. It defaults to `$.outOfPublication`.
2. Our `genres` field points to a `string[]`. When using a `string[]`, the JSONPath must return an array. If it doesn't, an error will be generated.
#### Configuring Hashes
When you store your entities as Hashes there is no nesting—all the entities are flat. In Redis, the properties on your entity are stored in fields inside a Hash. The default name for each field is the name of the property in your schema and this is the name that will be used in your entities. So, for the following schema:
```javascript
const studio = studioRepository.createEntity({
name: "Bad Racket Recording Studio",
city: "Cleveland",
state: "Ohio",
location: { longitude: -81.6764187, latitude: 41.5080462 },
established: new Date('2010-12-27')
const albumSchema = new Schema('album', {
artist: { type: 'string' },
title: { type: 'string' },
year: { type: 'number' },
genres: { type: 'string[]' },
outOfPublication: { type: 'boolean' }
}, {
dataStructure: 'HASH'
})
```
const id = await studioRepository.save(studio) // '01FVDN241NGTPHSAV0DFDBXC90'
In your code, your entities would look like this:
```javascript
{
artist: 'Mushroomhead',
title: 'The Righteous & The Butterfly',
year: 2014,
genres: [ 'metal' ],
outOfPublication: true
}
```
And for even *more* convenience, you can create and save in a single call:
Inside Redis, your Hash would be stored like this:
| Field | Value |
|------------------|:----------------------------------------|
| artist | Mushroomhead |
| title | The Righteous & The Butterfly |
| year | 2014 |
| genres | metal |
| outOfPublication | 1 |
However, you might not want the names of your fields and the names of the properties on your entity to be exactly the same. Maybe you've got some existing data with existing names or something.
Fear not! You can change the name of the field used by Redis with the `field` property:
```javascript
const studio = studioRepository.createAndSave({
name: "Bad Racket Recording Studio",
city: "Cleveland",
state: "Ohio",
location: { longitude: -81.6764187, latitude: 41.5080462 },
established: new Date('2010-12-27')
const albumSchema = new Schema('album', {
artist: { type: 'string', field: 'album_artist' },
title: { type: 'string', field: 'album_title' },
year: { type: 'number', field: 'album_year' },
genres: { type: 'string[]' },
outOfPublication: { type: 'boolean' }
}, {
dataStructure: 'HASH'
})
```
You also use `.save` to update an existing entity:
With this configuration, your entities will remain unchanged and will still have properties for `artist`, `title`, `year`, `genres`, and `outOfPublication`. But inside Redis, the field will have changed:
| Field | Value |
|------------------|:----------------------------------------|
| album_artist | Mushroomhead |
| album_title | The Righteous & The Butterfly |
| album_year | 2014 |
| genres | metal |
| outOfPublication | 1 |
## Reading, Writing, and Removing with Repository
Now that we have a client and a schema, we have what we need to make a [*repository*](docs/classes/Repository.md). A repository provides the means to write, read, and remove entities. Creating a repository is pretty straightforward—just instantiate one with a schema and a client:
```javascript
album.genres = [ 'metal', 'nu metal', 'avantgarde' ]
album.outOfPublication = false
import { Repository } from 'redis-om'
const id = await albumRepository.save(album) // '01FJYWEYRHYFT8YTEGQBABJ43J'
const albumRepository = new Repository(albumSchema, redis)
const studioRepository = new Repository(studioSchema, redis)
```
If you know an object's entity ID you can `.fetch` it:
Once we have a repository, we can use `.save` to, well, save entities:
```javascript
const album = await albumRepository.fetch('01FJYWEYRHYFT8YTEGQBABJ43J')
album.artist // "Mushroomhead"
album.title // "The Righteous & The Butterfly"
album.year // 2014
album.genres // [ 'metal', 'nu metal', 'avantgarde' ]
album.outOfPublication // false
let album = {
artist: "Mushroomhead",
title: "The Righteous & The Butterfly",
year: 2014,
genres: [ 'metal' ],
outOfPublication: true
}
album = await albumRepository.save(album)
```
Or `.remove` it:
This saves your entity and returns a copy, a copy with some additional properties. The primary property we care about right now is the entity ID, which Redis OM will generate for you. However, this isn't stored and accessed like a typical property. After all, you might have a property in your data with a name that conflicts with the name Redis OM uses and that would create all sorts of problems.
So, Redis OM uses a [Symbol](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol) to access it instead. You'll need to import this symbol from Redis OM:
```javascript
await studioRepository.remove('01FVDN241NGTPHSAV0DFDBXC90')
import { EntityId } from 'redis-om'
```
You can also set an entity to expire after a certain number of seconds. Redis will automatically remove that entity when the time's up. Use the `.expire` method to do this:
Then you can access the entity ID using that symbol:
```javascript
const ttlInSeconds = 12 * 60 * 60 // 12 hours
await studioRepository.expire('01FVDN241NGTPHSAV0DFDBXC90', ttlInSeconds)
album = await albumRepository.save(album)
album[EntityId] // '01FJYWEYRHYFT8YTEGQBABJ43J'
```
### Missing Entities and Null Values
The entity ID that Redis OM generates is a [ULID](https://github.com/ulid/spec) and is a unique id representing that object. If you don't like using generated IDs for some reason and instead want to provide your own, you can totally do that:
Redis, and by extension Redis OM, doesn't differentiate between missing and null. Missing fields in Redis are returned as `null`, and missing keys return `null`. So, if you fetch an entity that doesn't exist, it will happily return you an entity full of nulls:
```javascript
const album = await albumRepository.fetch('DOES_NOT_EXIST')
album.artist // null
album.title // null
album.year // null
album.genres // null
album.outOfPublication // null
album = await albumRepository.save('BWOMP', album)
```
Conversely, if you set all the properties on an entity to `null` and then save it, it will remove the entity from Redis:
Regardless, once you have an object's entity ID you can `.fetch` with it:
```javascript
const album = await albumRepository.fetch('01FJYWEYRHYFT8YTEGQBABJ43J')
album.artist = null
album.title = null
album.year = null
album.genres = null
album.outOfPublication = null
album.artist // "Mushroomhead"
album.title // "The Righteous & The Butterfly"
album.year // 2014
album.genres // [ 'metal' ]
album.outOfPublication // true
```
const id = await albumRepository.save(album)
If you call `.save` with an entity that *already* has an entity ID, probably because you *fetched* it, `.save` will update it instead of creating a new `Entity`:
const exists = await client.execute(['EXISTS', 'Album:01FJYWEYRHYFT8YTEGQBABJ43J']) // 0
```javascript
let album = await albumRepository.fetch('01FJYWEYRHYFT8YTEGQBABJ43J')
album.genres = [ 'metal', 'nu metal', 'avantgarde' ]
album.outOfPublication = false
album = await albumRepository.save(album)
```
It does this because Redis—particularly Redis Hashes—doesn't distinguish between missing and null. You could have an entity that is all nulls. Or you could not. Redis doesn't know which is your intention, and so always returns *something* when you call `.fetch`.
You can even use `.save` to clone an `Entity`. Just pass in a new entity ID to `.save` and it'll save the data to that entity ID:
### A Note for TypeScript Users
```javascript
const album = await albumRepository.fetch('01FJYWEYRHYFT8YTEGQBABJ43J')
album.genres = [ 'metal', 'nu metal', 'avantgarde' ]
album.outOfPublication = false
When you define an entity and schema in TypeScript, all is well. But when you go to *use* that entity, you might have a problem. You'll get an error accessing the properties that the schema added to the entity. This code won't work:
```typescript
const album = albumRepository.createEntity()
album.artist = "Mushroomhead" // Property 'artist' does not exist on type 'Album'
album.title = "The Righteous & The Butterfly" // Property 'title' does not exist on type 'Album'
album.year = 2014 // Property 'year' does not exist on type 'Album'
album.genres = [ 'metal' ] // Property 'genres' does not exist on type 'Album'
album.outOfPublication = true // Property 'outOfPublication' does not exist on type 'Album'
const clonedEntity = await albumRepository.save('BWOMP', album)
```
To fix this—without resorting to `// @ts-ignore`—add an interface with the same name as your entity. On that interface, add all the properties you provided to the schema:
And, of course, you need to be able to delete things. Use `.remove` to do that:
```typescript
interface Album {
artist: string;
title: string;
year: number;
genres: string[];
outOfPublication: boolean;
}
```javascript
await albumRepository.remove('01FJYWEYRHYFT8YTEGQBABJ43J')
```
class Album extends Entity {}
You can also set an entity to expire after a certain number of seconds. Redis will automatically remove that entity when the time's up. Use the `.expire` method to do this:
const albumSchema = new Schema(Album, {
artist: { type: 'string' },
title: { type: 'string' },
year: { type: 'number' },
genres: { type: 'string[]' },
outOfPublication: { type: 'boolean' }
})
```javascript
const ttlInSeconds = 12 * 60 * 60 // 12 hours
await albumRepository.expire('01FJYWEYRHYFT8YTEGQBABJ43J', ttlInSeconds)
```
## 🧮 Embedding Your Own Logic into Entities
### Missing Entities and Null Values
You might be looking at how you define an entity and think it's a bit odd. Just an empty class? Really? Well, this class can contain additional logic that works with the data it retrieves from Redis. Which can be pretty useful.
Redis, and by extension Redis OM, doesn't differentiate between missing and null—particularly for Hashes. Missing fields in Redis Hashes are returned as `null`. Missing keys also return `null`. So, if you fetch an entity that doesn't exist, it will happily return you an empty entity, complete with the provided entity ID:
You can use this to create computed fields and add domain logic:
```javascript
class Album extends Entity {
get is70sRock() {
return this.year >= 1970 && this.year < 1980 && this.genres.includes('rock')
}
makeItRock() {
this.genres.push('rock');
}
}
const album = await albumRepository.fetch('TOTALLY_BOGUS')
album[EntityId] // 'TOTALLY_BOGUS'
album.artist // undefined
album.title // undefined
album.year // undefined
album.genres // undefined
album.outOfPublication // undefined
```
Or even use more Redis OM to find related entities:
Conversely, if you remove all the properties on an entity and then save it, it will remove the entity from Redis:
```javascript
class Album extends Entity {
async recordedAt() {
return await studioRepository.fetch(this.studioId)
}
}
```
const album = await albumRepository.fetch('01FJYWEYRHYFT8YTEGQBABJ43J')
delete album.artist
delete album.title
delete album.year
delete album.genres
delete album.outOfPublication
## 📄 Using Hashes
const entityId = await albumRepository.save(album)
By default, Redis OM stores your entities in JSON documents. But if you're not using [RedisJSON][redis-json-url], you can instead choose to store your entities as Hashes. It works exactly the same as using JSON, but when you define your schema, just pass in an option telling it to use Hashes:
```javascript
const albumSchema = new Schema(Album, {
artist: { type: 'string' },
title: { type: 'string' },
year: { type: 'number' },
genres: { type: 'string[]' },
outOfPublication: { type: 'boolean' }
}, {
dataStructure: 'HASH'
})
const exists = await redis.exists('album:01FJYWEYRHYFT8YTEGQBABJ43J') // 0
```
Everything else is the same.
It does this because Redis doesn't distinguish between missing and null. You could have an entity that is empty. Or you could not have an entity at all. Redis doesn't know which is your intention, and so always returns *something* when you call `.fetch`.
## 🔎 Using RediSearch
## Searching

@@ -512,3 +512,3 @@ Using [RediSearch][redisearch-url] with Redis OM is where the power of this fully armed and operational battle station starts to become apparent. If you have RediSearch installed on your Redis server you can use the search capabilities of Redis OM. This enables commands like:

However, if you have a *lot* of data, rebuilding an index can take some time. So, you might want to explicitly manage the building and rebuilding of your indices in some sort of deployment code script thing. To support those devops sorts of things, Redis OM includes a `.dropIndex` method to explicit remove an index without rebuilding it:
However, if you have a *lot* of data, rebuilding an index can take some time. So, you might want to explicitly manage the building and rebuilding of your indices in some sort of deployment code script thing. To support those devops sorts of things, Redis OM includes a `.dropIndex` method to explicitly remove an index without rebuilding it:

@@ -549,3 +549,3 @@ ```javascript

Note: If you have *no* albums, this will return `null`.
Note: If you have *no* albums, this will return `null`. And I feel sorry for you.

@@ -568,3 +568,3 @@ #### Counting

When you set the field type in your schema to `string`, you can search for a whole string. This syntax will not search for partial strings or words within a string. It only matches the *entire* string. If you want to search for words or partial words within text you need to use the `text` type and search it using the [Full-Text Search](#full-text-search) syntax.
When you set the field type in your schema to `string`, you can search for a particular value in that string. You can also search for partial strings (no shorter than two characters) that occur at the beginning, middle, or end of a string. If you need to search strings in a more sophisticated manner, you'll want to look at the `text` type and search it using the [Full-Text Search](#full-text-search) syntax.

@@ -580,2 +580,7 @@ ```javascript

// find all albums using wildcards
albums = await albumRepository.search().where('artist').eq('Mush*').return.all()
albums = await albumRepository.search().where('artist').eq('*head').return.all()
albums = await albumRepository.search().where('artist').eq('*room*').return.all()
// fluent alternatives that do the same thing

@@ -603,3 +608,3 @@ albums = await albumRepository.search().where('artist').equals('Mushroomhead').return.all()

// find all albums where year is between 1980 and 1989 inclusive
// find all albums where the year is between 1980 and 1989 inclusive
albums = await albumRepository.search().where('year').between(1980, 1989).return.all()

@@ -690,3 +695,3 @@

If you have a field type of `date` in your schema, you can search on it using [Dates](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date), [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) formated strings, or the [UNIX epoch time](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date#the_ecmascript_epoch_and_timestamps) in *seconds*:
If you have a field type of `date` in your schema, you can search on it using [Dates](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date), [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) formatted strings, or the [UNIX epoch time](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date#the_ecmascript_epoch_and_timestamps) in *seconds*:

@@ -811,7 +816,13 @@ ```javascript

Wildcards work here too:
```javascript
albums = await albumRepository.search().where('genres').contain('*rock*').return.all()
```
#### Full-Text Search
If you've defined a field with a type of `text` in your schema, you can store text in it and perform full-text searches against it. Full-text search is different from how a `string` is searched, which can only match the entire string. With full-text search, you can look for words, partial words, and exact phrases within a body of text.
If you've defined a field with a type of `text` in your schema, you can store text in it and perform full-text searches against it. Full-text search is different from how a `string` is searched. With full-text search, you can look for words, partial words, and exact phrases within a body of text.
Full-text search is optimized for human-readable text and it's pretty clever. It understands that certain words (like *a*, *an*, or *the*) are common and ignores them. It understands how words relate to each other and so if you search for *give*, it matches *gives*, *given*, *giving*, and *gave* too. It ignores punctuation.
Full-text search is optimized for human-readable text and it's pretty clever. It understands that certain words (like *a*, *an*, or *the*) are common and ignores them. It understands how words relate to each other and so if you search for *give*, it matches *gives*, *given*, *giving*, and *gave* too. It ignores punctuation and whitespace.

@@ -826,3 +837,3 @@ Here are some examples of doing full-text search against some album titles:

// finds all albums where the title contains the the words 'beautiful' and 'children'
// finds all albums where the title contains the words 'beautiful' and 'children'
albums = await albumRepository.search().where('title').match('beautiful children').return.all()

@@ -834,23 +845,12 @@

If you want to search for a part of a word, you can do that too, but only the front part of a word. To do it, just tack a `*` on the end of your partial word and it'll match accordingly:
If you want to search for a part of a word. To do it, just tack a `*` on the beginning or end (or both) of your partial word and it'll match accordingly:
```javascript
// finds all albums where the title contains a word that starts with 'right'
albums = await albumRepository.search().where('title').match('right*').return.all()
// finds all albums where the title contains a word that contains 'right'
albums = await albumRepository.search().where('title').match('*right*').return.all()
```
However, this only works for the front part of a word. And you need to provide *at least* two characters. So, for example, the following queries will *not* work:
Do not combine partial-word searches with exact matches. Partial-word searches and exact matches are not compatible in RediSearch. If you try to exactly match a partial-word search, you'll get an error.
```javascript
// INVALID: Wildcard must be at the end of the word
albums = await albumRepository.search().where('title').match('*fly').return.all()
albums = await albumRepository.search().where('title').match('*hild*').return.all()
// INVALID: At least two characters required before wildcard
albums = await albumRepository.search().where('title').match('b*').return.all()
```
Also, do not combine partial-word searches with exact matches. Partial-word searches and exact matches are not compatible in RediSearch. If you try to exactly match a partial-word search, you'll get an error.
```javascript
// THIS WILL ERROR

@@ -897,7 +897,7 @@ albums = await albumRepository.search().where('title').matchExact('beautiful sto*').return.all()

```javascript
// finds all the studios with 50 miles of downtown Cleveland using a point
// finds all the studios within 50 miles of downtown Cleveland using a point
studios = await studioRepository.search().where('location').inRadius(
circle => circle.origin({ longitude: -81.7758995, latitude: 41.4976393 }).radius(50).miles).return.all()
// finds all the studios with 50 miles of downtown Cleveland using longitude and latitude
// finds all the studios within 50 miles of downtown Cleveland using longitude and latitude
studios = await studioRepository.search().where('location').inRadius(

@@ -1063,3 +1063,3 @@ circle => circle.longitude(-81.7758995).latitude(41.4976393).radius(50).miles).return.all()

If your schema is for a JSON data structure (the default), you can mark `number`, `date`, and `text` fields as sortable. You can also mark `string` and `boolean` field sortable, but this will have no effect and will generate a warning.
If your schema is for a JSON data structure (the default), you can mark `number`, `date`, and `text` fields as sortable. You can also mark `string` and `boolean` fields as sortable, but this will have no effect and will generate a warning.

@@ -1070,14 +1070,57 @@ If your schema is for a Hash, you can mark `string`, `number`, `boolean`, `date`, and `text` fields as sortable.

If this seems like a confusion flowchart to parse, don't worry. If you call `.sortBy` on a field in the Schema that's not marked as `sortable` and it *could* be, Redis OM will log a warning to let you know.
If this seems like a confusing flowchart to parse, don't worry. If you call `.sortBy` on a field in the Schema that's not marked as `sortable` and it *could* be, Redis OM will log a warning to let you know.
## Advanced Stuff
## 📚 Documentation
This is a bit of a catch-all for some of the more advanced stuff you can do with Redis OM.
### Schema Options
Additional field options can be set depending on the field type. These correspond to the [Field Options](https://redis.io/commands/ft.create/#field-options) available when creating a RediSearch full-text index. Other than the `separator` option, these only affect how content is indexed and searched.
| schema type | RediSearch type | `indexed` | `sortable` | `normalized` | `stemming` | `phonetic` | `weight` | `separator` | `caseSensitive` |
| -------------- | :-------------: | :-------: | :--------: | :----------: | :--------: | :--------: | :------: | :---------: | :-------------: |
| `string` | TAG | yes | HASH Only | HASH Only | - | - | - | yes | yes |
| `number` | NUMERIC | yes | yes | - | - | - | - | - | - |
| `boolean` | TAG | yes | HASH Only | - | - | - | - | - | - |
| `string[]` | TAG | yes | HASH Only | HASH Only | - | - | - | yes | yes |
| `date` | NUMERIC | yes | yes | - | | - | - | - | - |
| `point` | GEO | yes | - | - | | - | - | - | - |
| `text` | TEXT | yes | yes | yes | yes | yes | yes | - | - |
* `indexed`: true | false, whether this field is indexed by RediSearch (default true)
* `sortable`: true | false, whether to create an additional index to optimize sorting (default false)
* `normalized`: true | false, whether to apply normalization for sorting (default true)
* `matcher`: string defining phonetic matcher which can be one of: 'dm:en' for English, 'dm:fr' for French, 'dm:pt' for Portugese, 'dm:es' for Spanish (default none)
* `stemming`: true | false, whether word-stemming is applied to text fields (default true)
* `weight`: number, the importance weighting to use when ranking results (default 1)
* `separator`: string, the character to delimit multiple tags (default '|')
* `caseSensitive`: true | false, whether original letter casing is kept for search (default false)
Example showing additional options:
```javascript
const commentSchema = new Schema(Comment, {
name: { type: 'text', stemming: false, matcher: 'dm:en' },
email: { type: 'string', normalized: false, },
posted: { type: 'date', sortable: true },
title: { type: 'text', weight: 2 },
comment: { type: 'text', weight: 1 },
approved: { type: 'boolean', indexed: false },
iphash: { type: 'string', caseSensitive: true },
notes: { type: 'string', indexed: false },
})
```
There are several other options available when defining a schema for your entity. Check them out in the [detailed documentation](docs/classes/Schema.md) for the `Schema` class.
## Documentation
This README is pretty extensive, but if you want to check out every last corner of Redis OM for Node.js, take a look at the complete [API documentation](/docs).
## ⛏️ Troubleshooting
## Troubleshooting
I'll eventually have a FAQ full of answered questions, but since this is a new library, nobody has asked anything yet, frequently or otherwise. So, if you run into a problem, open an issue. Even cooler, dive into the code and send a pull request. If you just want to ping somebody, hit me up on the [Redis Discord server][discord-url].
## ❤️ Contributing
## Contributing

@@ -1084,0 +1127,0 @@ Contributions are always appreciated. I take PayPal and Bitcoin. Just kidding, I would sincerely appreciate your help in making this software better. Here are a couple of ways to help:

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc