{"_id":"redis-type-xyz","_rev":"3-c72a9d6784d27401f04779de3ed095b2","name":"redis-type-xyz","dist-tags":{"latest":"2.1.1"},"versions":{"1.10.5":{"name":"redis-type-xyz","version":"1.10.5","keywords":["redis","redis-om","orm","typescript","object-mapping","redisearch","redisjson"],"author":{"url":"http://guyroyse.com/","name":"Guy Royse","email":"guy@guyroyse.com"},"license":"MIT","_id":"redis-type-xyz@1.10.5","maintainers":[{"name":"qmtijao982","email":"qmtijao982@ufiwi.site"}],"homepage":"https://github.com/redis/redis-om-node#readme","bugs":{"url":"https://github.com/redis/redis-om-node/issues"},"dist":{"shasum":"f1b827610da1810f87c14dbae00b07a847e4a89a","tarball":"https://registry.npmjs.org/redis-type-xyz/-/redis-type-xyz-1.10.5.tgz","fileCount":33,"integrity":"sha512-QMAjybe+wMgjwwpWRf4FmdfcBz2y49wrJNOvnkS5qg91lLw5ayVrpt9JUencqdrJrabfgrhW9Ajt1Zmp7BDQbQ==","signatures":[{"sig":"MEUCIQDePM3qTh1qI3vgrbQS5YPXBfZ06vNiXZVcA5LxLiv3JwIgcPe61gth1/cylHVDA2Uf7onWbRDIePLRY0megZiR2ZY=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":276562},"main":"dist/index.js","tsup":{"dts":true,"clean":true,"entry":["lib/index.ts"],"noExternal":["ulid"]},"types":"./dist/index.d.ts","engines":{"node":">= 14"},"scripts":{"docs":"rm -rf ./docs && typedoc","test":"vitest","build":"tsup","test:ui":"vitest --ui","test:unit":"vitest --dir ./spec/unit","test:coverage":"vitest run --coverage","test:functional":"vitest --dir ./spec/functional"},"_npmUser":{"name":"qmtijao982","email":"qmtijao982@ufiwi.site"},"repository":{"url":"git+https://github.com/redis/redis-om-node.git","type":"git"},"_npmVersion":"11.9.0","description":"TypeScript-based Node.js library for Redis with object mapping and additional utilities.","directories":{},"_nodeVersion":"24.14.0","dependencies":{"redis":"^4.6.4","just-clone":"^6.1.1","jsonpath-plus":"^7.2.0"},"_hasShrinkwrap":false,"devDependencies":{"c8":"^7.11.3","tsup":"^6.1.2","vitest":"^0.20.0","typedoc":"^0.24.8","@vitest/ui":"^0.17.1","typescript":"^4.7.2","@types/node":"^18.0.0","typedoc-plugin-markdown":"^3.13.1"},"_npmOperationalInternal":{"tmp":"tmp/redis-type-xyz_1.10.5_1781676443894_0.6458448163530035","host":"s3://npm-registry-packages-npm-production"}},"1.10.6":{"name":"redis-type-xyz","version":"1.10.6","keywords":["redis","redis-om","orm","typescript","object-mapping","redisearch","redisjson"],"author":{"url":"http://guyroyse.com/","name":"Guy Royse","email":"guy@guyroyse.com"},"license":"MIT","_id":"redis-type-xyz@1.10.6","maintainers":[{"name":"qmtijao982","email":"qmtijao982@ufiwi.site"}],"homepage":"https://github.com/redis/redis-om-node#readme","bugs":{"url":"https://github.com/redis/redis-om-node/issues"},"dist":{"shasum":"2b2a0b0fe287e146746bb2d1f8c0bfe815b9dee4","tarball":"https://registry.npmjs.org/redis-type-xyz/-/redis-type-xyz-1.10.6.tgz","fileCount":33,"integrity":"sha512-ftmh6iA2ffuDaKwdQDOQJOzYAHI4cfbNI8Sb0oTHbx/bTv6KIaqlHcNi12HhHLHNh6bnqYG7ylOGU77MW2WNGg==","signatures":[{"sig":"MEUCIQDRvAbd7B6poC2nfnznZJJQAxlFbJirlFkg4Omv9a7hrwIgdAbyGmluwtPUq2gRezIgewi9GpNMkREJgEw8FdmbaOg=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":276590},"main":"dist/index.js","tsup":{"dts":true,"clean":true,"entry":["lib/index.ts"],"noExternal":["ulid"]},"types":"./dist/index.d.ts","engines":{"node":">= 14"},"scripts":{"docs":"rm -rf ./docs && typedoc","test":"vitest","build":"tsup","test:ui":"vitest --ui","test:unit":"vitest --dir ./spec/unit","test:coverage":"vitest run --coverage","test:functional":"vitest --dir ./spec/functional"},"_npmUser":{"name":"qmtijao982","email":"qmtijao982@ufiwi.site"},"repository":{"url":"git+https://github.com/redis/redis-om-node.git","type":"git"},"_npmVersion":"11.9.0","description":"TypeScript-based Node.js library for Redis with object mapping and additional utilities.","directories":{},"_nodeVersion":"24.14.0","dependencies":{"redis":"^4.6.4","ulid-xyz":"^2.12.2","just-clone":"^6.1.1","jsonpath-plus":"^7.2.0"},"_hasShrinkwrap":false,"devDependencies":{"c8":"^7.11.3","tsup":"^6.1.2","vitest":"^0.20.0","typedoc":"^0.24.8","@vitest/ui":"^0.17.1","typescript":"^4.7.2","@types/node":"^18.0.0","typedoc-plugin-markdown":"^3.13.1"},"_npmOperationalInternal":{"tmp":"tmp/redis-type-xyz_1.10.6_1781683004592_0.608786061890757","host":"s3://npm-registry-packages-npm-production"}},"2.1.1":{"name":"redis-type-xyz","version":"2.1.1","description":"TypeScript-based Node.js library for Redis with object mapping and additional utilities.","main":"dist/index.js","types":"./dist/index.d.ts","scripts":{"build":"tsup","docs":"rm -rf ./docs && typedoc","test":"vitest","test:coverage":"vitest run --coverage","test:ui":"vitest --ui","test:unit":"vitest --dir ./spec/unit","test:functional":"vitest --dir ./spec/functional"},"tsup":{"entry":["lib/index.ts"],"clean":true,"dts":true,"noExternal":["ulid"]},"repository":{"type":"git","url":"git+https://github.com/redis/redis-om-node.git"},"homepage":"https://github.com/redis/redis-om-node#readme","keywords":["redis","redis-om","orm","typescript","object-mapping","redisearch","redisjson"],"license":"MIT","author":{"name":"Guy Royse","email":"guy@guyroyse.com","url":"http://guyroyse.com/"},"engines":{"node":">= 14"},"devDependencies":{"@types/node":"^18.0.0","@vitest/ui":"^0.17.1","c8":"^7.11.3","tsup":"^6.1.2","typedoc":"^0.24.8","typedoc-plugin-markdown":"^3.13.1","typescript":"^4.7.2","vitest":"^0.20.0"},"dependencies":{"jsonpath-plus":"^7.2.0","just-clone":"^6.1.1","ulid-xyz":"^3.2.0","redis":"^4.6.4"},"_id":"redis-type-xyz@2.1.1","bugs":{"url":"https://github.com/redis/redis-om-node/issues"},"_nodeVersion":"24.14.0","_npmVersion":"11.9.0","dist":{"integrity":"sha512-2uLvPvZSY9sAHI6pPQ0WEwoxlHNxX5Lj2vr55qPQAlfcCsRgkswiy0yP6HnzRAiQ7IiDNGw9SlqLhWxq/2Vr+A==","shasum":"3f0c7fcfd9170e0a12b5095ab89ec8411eb4f5f4","tarball":"https://registry.npmjs.org/redis-type-xyz/-/redis-type-xyz-2.1.1.tgz","fileCount":33,"unpackedSize":276588,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQCsD5rQXKTh2kFJeoAXx2rjOFUp+bW9Bp49jrb1yFmHlQIhAIfI1qm+DOqwapBpW81omIjWKBrId/rVnTHAbkoSgeTF"}]},"_npmUser":{"name":"qmtijao982","email":"qmtijao982@ufiwi.site"},"directories":{},"maintainers":[{"name":"qmtijao982","email":"qmtijao982@ufiwi.site"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/redis-type-xyz_2.1.1_1781683071737_0.6981092135609948"},"_hasShrinkwrap":false}},"time":{"created":"2026-06-17T06:07:23.833Z","modified":"2026-06-17T07:57:51.974Z","1.10.5":"2026-06-17T06:07:24.026Z","1.10.6":"2026-06-17T07:56:44.752Z","2.1.1":"2026-06-17T07:57:51.853Z"},"bugs":{"url":"https://github.com/redis/redis-om-node/issues"},"author":{"name":"Guy Royse","email":"guy@guyroyse.com","url":"http://guyroyse.com/"},"license":"MIT","homepage":"https://github.com/redis/redis-om-node#readme","keywords":["redis","redis-om","orm","typescript","object-mapping","redisearch","redisjson"],"repository":{"type":"git","url":"git+https://github.com/redis/redis-om-node.git"},"description":"TypeScript-based Node.js library for Redis with object mapping and additional utilities.","maintainers":[{"name":"qmtijao982","email":"qmtijao982@ufiwi.site"}],"readme":"<div align=\"center\">\r\n  <br/>\r\n  <br/>\r\n  <img width=\"360\" src=\"logo.svg\" alt=\"Redis OM\" />\r\n  <br/>\r\n  <br/>\r\n</div>\r\n\r\n<p align=\"center\">\r\n  TypeScript-based Node.js library for Redis with object mapping and additional utilities.\r\n</p>\r\n\r\n---\r\n\r\n[![Discord][discord-shield]][discord-url]\r\n[![Twitch][twitch-shield]][twitch-url]\r\n[![YouTube][youtube-shield]][youtube-url]\r\n[![Twitter][twitter-shield]][twitter-url]\r\n\r\n[![NPM][package-shield]][package-url]\r\n[![Build][build-shield]][build-url]\r\n[![License][license-shield]][license-url]\r\n\r\n**redis-type-os** implements schemas, repositories, and fluent search over Redis. It follows the same model as [Redis OM for Node.js](https://github.com/redis/redis-om-node), with TypeScript declarations and tooling for Node.js applications.\r\n\r\nRelated Redis OM clients: [Redis OM .NET][redis-om-dotnet] · [Redis OM Node.js (upstream)](https://github.com/redis/redis-om-node) · [Redis OM Python][redis-om-python] · [Redis OM Spring][redis-om-spring]\r\n\r\n<details>\r\n  <summary><strong>Table of contents</strong></summary>\r\n\r\n  - [Overview](#overview)\r\n  - [Getting Started](#getting-started)\r\n  - [Connect to Redis with Node Redis](#connect-to-redis-with-node-redis)\r\n    - [Redis Connection Strings](#redis-connection-strings)\r\n  - [Entities and Schemas](#entities-and-schemas)\r\n    - [JSON and Hashes](#json-and-hashes)\r\n      - [Configuring JSON](#configuring-json)\r\n      - [Configuring Hashes](#configuring-hashes)\r\n  - [Reading, Writing, and Removing with Repository](#reading-writing-and-removing-with-repository)\r\n    - [Creating Entities](#creating-entities)\r\n    - [Missing Entities and Null Values](#missing-entities-and-null-values)\r\n  - [Searching](#searching)\r\n    - [Build the Index](#build-the-index)\r\n    - [Finding All The Things (and Returning Them)](#finding-all-the-things-and-returning-them)\r\n      - [Pagination](#pagination)\r\n      - [First Things First](#first-things-first)\r\n      - [Counting](#counting)\r\n    - [Finding Specific Things](#finding-specific-things)\r\n      - [Searching on Strings](#searching-on-strings)\r\n      - [Searching on Numbers](#searching-on-numbers)\r\n      - [Searching on Booleans](#searching-on-booleans)\r\n      - [Searching on Dates](#searching-on-dates)\r\n      - [Searching String Arrays](#searching-string-arrays)\r\n      - [Searching Arrays of Numbers](#searching-arrays-of-numbers)\r\n      - [Full-Text Search](#full-text-search)\r\n      - [Searching on Points](#searching-on-points)\r\n      - [Chaining Searches](#chaining-searches)\r\n      - [Running Raw Searches](#running-raw-searches)\r\n    - [Sorting Search Results](#sorting-search-results)\r\n  - [Advanced usage](#advanced-usage)\r\n    - [Schema Options](#schema-options)\r\n  - [Documentation](#documentation)\r\n  - [Troubleshooting](#troubleshooting)\r\n  - [Contributing](#contributing)\r\n</details>\r\n\r\n## Overview\r\n\r\nRedis OM (often pronounced “redis-ohm”) maps Redis data to plain JavaScript objects so you can persist and query entities without hand-writing low-level commands. The API is fluent and composable, with strong TypeScript support in this package.\r\n\r\nDefine a schema:\r\n\r\n```javascript\r\nconst schema = new Schema('album', {\r\n  artist: { type: 'string' },\r\n  title: { type: 'text' },\r\n  year: { type: 'number' }\r\n})\r\n```\r\n\r\nCreate a JavaScript object and save it:\r\n\r\n```javascript\r\nconst album = {\r\n  artist: \"Mushroomhead\",\r\n  title: \"The Righteous & The Butterfly\",\r\n  year: 2014\r\n}\r\n\r\nawait repository.save(album)\r\n```\r\n\r\nSearch for matching entities:\r\n\r\n```javascript\r\nconst albums = await repository.search()\r\n  .where('artist').equals('Mushroomhead')\r\n  .and('title').matches('butterfly')\r\n  .and('year').is.greaterThan(2000)\r\n    .return.all()\r\n```\r\n\r\nThe sections below describe schemas, repositories, and search in full.\r\n\r\n> ## Migrating from Redis OM 0.3.x\r\n>\r\n> Version 0.4 introduced breaking changes relative to 0.3.6. If you are new to this API, follow this README from top to bottom.\r\n>\r\n> If you already use **redis-om** on npm, read this document and [CHANGELOG](CHANGELOG) before upgrading. The [redis-om 0.3.6 README](https://www.npmjs.com/package/redis-om/v/0.3.6) remains available for comparison. Later 0.4.x releases add requested improvements; further non-breaking changes are expected.\r\n\r\n## Getting Started\r\n\r\nCreate or use an existing Node.js project (for example `npm init`).\r\n\r\nInstall this package and the Redis client:\r\n\r\n```bash\r\nnpm install redis-type-os redis\r\n```\r\n\r\nUse [Redis Stack][redis-stack-url] (includes [RediSearch][redisearch-url] and [RedisJSON][redis-json-url]) or [Redis Cloud][redis-cloud-url]. With Docker:\r\n\r\n```bash\r\ndocker run -d --name redis-stack -p 6379:6379 -p 8001:8001 redis/redis-stack:latest\r\n```\r\n\r\n## Connect to Redis with Node Redis\r\n\r\nBefore using **redis-type-os**, connect to Redis with [Node Redis](https://github.com/redis/node-redis). Minimal setup (from the Node Redis [README](https://github.com/redis/node-redis)):\r\n\r\n```javascript\r\nimport { createClient } from 'redis'\r\n\r\nconst redis = createClient()\r\nredis.on('error', (err) => console.log('Redis Client Error', err));\r\nawait redis.connect()\r\n```\r\n\r\nFor advanced connection options, clustering, and tuning, see the Node Redis [documentation](https://github.com/redis/node-redis).\r\n\r\nWith a connected client you can run ordinary Redis commands when needed:\r\n\r\n```javascript\r\n\r\nconst aString = await redis.ping() // 'PONG'\r\nconst aNumber = await redis.hSet('foo', 'alfa', '42', 'bravo', '23') // 2\r\nconst aHash = await redis.hGetAll('foo') // { alfa: '42', bravo: '23' }\r\n```\r\n\r\nWhen you are finished with a connection, close it with `.quit`:\r\n\r\n```javascript\r\nawait redis.quit()\r\n```\r\n\r\n### Redis Connection Strings\r\n\r\nBy default, Node Redis connects to `localhost:6379`. Override this with a URL:\r\n\r\n```javascript\r\nconst redis = createClient({ url: 'redis://alice:foobared@awesome.redis.server:6380' })\r\n```\r\n\r\nThe basic format for this URL is:\r\n\r\n    redis://username:password@host:port\r\n\r\nThe full URI scheme is [registered with IANA](https://www.iana.org/assignments/uri-schemes/prov/redis); TLS uses [`rediss://`](https://www.iana.org/assignments/uri-schemes/prov/rediss).\r\n\r\nFor sockets, clustering, and other options, see the Node Redis [client configuration](https://github.com/redis/node-redis/blob/master/docs/client-configuration.md) and [clustering](https://github.com/redis/node-redis/blob/master/docs/clustering.md) guides.\r\n\r\n## Entities and Schemas\r\n\r\nThis library is concerned with saving, reading, and deleting *entities*. An [Entity](docs/README.md#entity) is plain JavaScript object data you persist or load from Redis. Almost any object shape can serve as an `Entity`.\r\n\r\n[Schemas](docs/classes/Schema.md) declare which fields an entity may have: each field’s type, how it is stored in Redis, and how it participates in RediSearch when indexing is enabled. By default, entities are stored as JSON (RedisJSON); you can opt into Redis Hashes instead (see below).\r\n\r\nDefine a `Schema` as follows:\r\n\r\n```javascript\r\nimport { Schema } from 'redis-type-os'\r\n\r\nconst albumSchema = new Schema('album', {\r\n  artist: { type: 'string' },\r\n  title: { type: 'text' },\r\n  year: { type: 'number' },\r\n  genres: { type: 'string[]' },\r\n  songDurations: { type: 'number[]' },\r\n  outOfPublication: { type: 'boolean' }\r\n})\r\n\r\nconst studioSchema = new Schema('studio', {\r\n  name: { type: 'string' },\r\n  city: { type: 'string' },\r\n  state: { type: 'string' },\r\n  location: { type: 'point' },\r\n  established: { type: 'date' }\r\n})\r\n```\r\n\r\nThe first argument is the schema name. It becomes part of the Redis key prefix for entities using this schema. Choose a name that is unique on your Redis instance and meaningful to your domain (here, `album` and `studio`).\r\n\r\nThe second argument lists fields that may appear on entities. Object keys are the names you use in queries; each field’s `type` must be one of: `string`, `number`, `boolean`, `string[]`, `number[]`, `date`, `point`, or `text`.\r\n\r\nThe 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[]` and `number[]` do 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 or Numbers respectively.\r\n\r\n`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*).\r\n\r\nA `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:\r\n\r\n```javascript\r\nconst point = { longitude: 12.34, latitude: 56.78 }\r\n```\r\n\r\nA `text` field behaves like a `string` for plain read and write operations. For search, the two diverge: `string` fields support exact and tag-style matching (good for codes and identifiers), while `text` fields use RediSearch full-text indexing ([stemming](https://redis.io/docs/stack/search/reference/stemming/), [stop words](https://redis.io/docs/stack/search/reference/stopwords/), and related features). See [Searching](#searching).\r\n\r\n### JSON and Hashes\r\n\r\nBy default, entities are stored as JSON documents (RedisJSON). You can set this explicitly:\r\n\r\n```javascript\r\nconst albumSchema = new Schema('album', {\r\n  artist: { type: 'string' },\r\n  title: { type: 'string' },\r\n  year: { type: 'number' },\r\n  genres: { type: 'string[]' },\r\n  songDurations: { type: 'number[]' },\r\n  outOfPublication: { type: 'boolean' }\r\n}, {\r\n  dataStructure: 'JSON'\r\n})\r\n```\r\n\r\nTo store entities as Redis Hashes, set `dataStructure` to `'HASH'`:\r\n\r\n```javascript\r\nconst albumSchema = new Schema('album', {\r\n  artist: { type: 'string' },\r\n  title: { type: 'string' },\r\n  year: { type: 'number' },\r\n  genres: { type: 'string[]' },\r\n  outOfPublication: { type: 'boolean' }\r\n}, {\r\n  dataStructure: 'HASH'\r\n})\r\n```\r\n\r\nHashes and JSON differ: hashes are flat field/value maps; JSON documents are trees and may be nested. That affects how you configure paths and fields.\r\n\r\n> Hash-backed schemas cannot use `number[]`; that type is JSON-only. Omit it from hash schemas or use JSON.\r\n\r\n#### Configuring JSON\r\n\r\nWhen 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:\r\n\r\n```json\r\n{\r\n  \"artist\": \"Mushroomhead\",\r\n  \"title\": \"The Righteous & The Butterfly\",\r\n  \"year\": 2014,\r\n  \"genres\": [ \"metal\" ],\r\n  \"songDurations\": [ 204, 290, 196, 210, 211, 105, 244, 245, 209, 252, 259, 200, 215, 219 ],\r\n  \"outOfPublication\": true\r\n}\r\n```\r\n\r\nHowever, 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:\r\n\r\n```json\r\n{\r\n  \"album\": {\r\n    \"artist\": \"Mushroomhead\",\r\n    \"title\": \"The Righteous & The Butterfly\",\r\n    \"year\": 2014,\r\n    \"genres\": [ \"metal\" ],\r\n    \"songDurations\": [ 204, 290, 196, 210, 211, 105, 244, 245, 209, 252, 259, 200, 215, 219 ]\r\n  },\r\n  \"outOfPublication\": true\r\n}\r\n```\r\n\r\nTo do this, we'll need to specify the `path` property for the nested fields in the schema:\r\n\r\n```javascript\r\nconst albumSchema = new Schema('album', {\r\n  artist: { type: 'string', path: '$.album.artist' },\r\n  title: { type: 'string', path: '$.album.title' },\r\n  year: { type: 'number', path: '$.album.year' },\r\n  genres: { type: 'string[]', path: '$.album.genres[*]' },\r\n  songDurations: { type: 'number[]', path: '$.album.songDurations[*]' },\r\n  outOfPublication: { type: 'boolean' }\r\n})\r\n```\r\n\r\nThere are two things to note here:\r\n\r\n  1. We haven't specified a path for `outOfPublication` as it's still in the root of the document. It defaults to `$.outOfPublication`.\r\n  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.\r\n  3. Same for our `songDurations`.\r\n\r\n#### Configuring Hashes\r\n\r\nWhen 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:\r\n\r\n```javascript\r\nconst albumSchema = new Schema('album', {\r\n  artist: { type: 'string' },\r\n  title: { type: 'string' },\r\n  year: { type: 'number' },\r\n  genres: { type: 'string[]' },\r\n  outOfPublication: { type: 'boolean' }\r\n}, {\r\n  dataStructure: 'HASH'\r\n})\r\n```\r\n\r\nIn your code, your entities would look like this:\r\n\r\n```javascript\r\n{\r\n  artist: 'Mushroomhead',\r\n  title: 'The Righteous & The Butterfly',\r\n  year: 2014,\r\n  genres: [ 'metal' ],\r\n  outOfPublication: true\r\n}\r\n```\r\n\r\nInside Redis, your Hash would be stored like this:\r\n\r\n| Field            | Value                                   |\r\n|------------------|:----------------------------------------|\r\n| artist           | Mushroomhead                            |\r\n| title            | The Righteous & The Butterfly           |\r\n| year             | 2014                                    |\r\n| genres           | metal                                   |\r\n| outOfPublication | 1                                       |\r\n\r\nHowever, 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.\r\n\r\nFear not! You can change the name of the field used by Redis with the `field` property:\r\n\r\n```javascript\r\nconst albumSchema = new Schema('album', {\r\n  artist: { type: 'string', field: 'album_artist' },\r\n  title: { type: 'string', field: 'album_title' },\r\n  year: { type: 'number', field: 'album_year' },\r\n  genres: { type: 'string[]' },\r\n  outOfPublication: { type: 'boolean' }\r\n}, {\r\n  dataStructure: 'HASH'\r\n})\r\n```\r\n\r\nWith 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:\r\n\r\n| Field            | Value                                   |\r\n|------------------|:----------------------------------------|\r\n| album_artist     | Mushroomhead                            |\r\n| album_title      | The Righteous & The Butterfly           |\r\n| album_year       | 2014                                    |\r\n| genres           | metal                                   |\r\n| outOfPublication | 1                                       |\r\n\r\n## Reading, Writing, and Removing with Repository\r\n\r\nGiven a connected Redis client and a schema, create a [*repository*](docs/classes/Repository.md) to create, read, update, delete, and search entities:\r\n\r\n```javascript\r\nimport { Repository } from 'redis-type-os'\r\n\r\nconst albumRepository = new Repository(albumSchema, redis)\r\nconst studioRepository = new Repository(studioSchema, redis)\r\n```\r\n\r\nCall `.save` to persist entities:\r\n\r\n```javascript\r\nlet album = {\r\n  artist: \"Mushroomhead\",\r\n  title: \"The Righteous & The Butterfly\",\r\n  year: 2014,\r\n  genres: [ 'metal' ],\r\n  songDurations: [ 204, 290, 196, 210, 211, 105, 244, 245, 209, 252, 259, 200, 215, 219 ],\r\n  outOfPublication: true\r\n}\r\n\r\nalbum = await albumRepository.save(album)\r\n```\r\n\r\n`.save` returns the persisted entity, including a generated entity ID. The ID is not a normal string property (to avoid collisions with your own fields); it is exposed through a [Symbol](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol). Import `EntityId` from **redis-type-os** and read the ID with `entity[EntityId]`:\r\n\r\n```javascript\r\nimport { EntityId } from 'redis-type-os'\r\n\r\nalbum = await albumRepository.save(album)\r\nalbum[EntityId] // '01FJYWEYRHYFT8YTEGQBABJ43J'\r\n```\r\n\r\nGenerated IDs are [ULIDs](https://github.com/ulid/spec). To use your own ID, pass it as the first argument to `.save`:\r\n\r\n```javascript\r\nalbum = await albumRepository.save('BWOMP', album)\r\n```\r\n\r\nLoad an entity by ID with `.fetch`:\r\n\r\n```javascript\r\nconst album = await albumRepository.fetch('01FJYWEYRHYFT8YTEGQBABJ43J')\r\nalbum.artist // \"Mushroomhead\"\r\nalbum.title // \"The Righteous & The Butterfly\"\r\nalbum.year // 2014\r\nalbum.genres // [ 'metal' ]\r\nalbum.songDurations // [ 204, 290, 196, 210, 211, 105, 244, 245, 209, 252, 259, 200, 215, 219 ]\r\nalbum.outOfPublication // true\r\n```\r\n\r\nIf the entity already has an ID (for example after a `.fetch`), `.save` updates the existing record:\r\n\r\n```javascript\r\nlet album = await albumRepository.fetch('01FJYWEYRHYFT8YTEGQBABJ43J')\r\nalbum.genres = [ 'metal', 'nu metal', 'avantgarde' ]\r\nalbum.outOfPublication = false\r\n\r\nalbum = await albumRepository.save(album)\r\n```\r\n\r\nTo copy data to a new ID, call `.save` with a new entity ID as the first argument:\r\n\r\n```javascript\r\nconst album = await albumRepository.fetch('01FJYWEYRHYFT8YTEGQBABJ43J')\r\nalbum.genres = [ 'metal', 'nu metal', 'avantgarde' ]\r\nalbum.outOfPublication = false\r\n\r\nconst clonedEntity = await albumRepository.save('BWOMP', album)\r\n```\r\n\r\nDelete entities with `.remove`:\r\n\r\n```javascript\r\nawait albumRepository.remove('01FJYWEYRHYFT8YTEGQBABJ43J')\r\n```\r\n\r\nSet a TTL in seconds with `.expire` (Redis removes the key when it elapses):\r\n\r\n```javascript\r\nconst ttlInSeconds = 12 * 60 * 60  // 12 hours\r\nawait albumRepository.expire('01FJYWEYRHYFT8YTEGQBABJ43J', ttlInSeconds)\r\n```\r\n\r\n### Missing Entities and Null Values\r\n\r\nRedis (and this library) do not fully distinguish “missing field” from “null,” especially for hashes. Fetching a non-existent key still yields an object whose fields are empty and whose `[EntityId]` is the ID you requested:\r\n\r\n```javascript\r\nconst album = await albumRepository.fetch('TOTALLY_BOGUS')\r\nalbum[EntityId] // 'TOTALLY_BOGUS'\r\nalbum.artist // undefined\r\nalbum.title // undefined\r\nalbum.year // undefined\r\nalbum.genres // undefined\r\nalbum.outOfPublication // undefined\r\n```\r\n\r\nIf you strip all schema fields and save, the key may be removed from Redis:\r\n\r\n```javascript\r\nconst album = await albumRepository.fetch('01FJYWEYRHYFT8YTEGQBABJ43J')\r\ndelete album.artist\r\ndelete album.title\r\ndelete album.year\r\ndelete album.genres\r\ndelete album.outOfPublication\r\n\r\nconst entityId = await albumRepository.save(album)\r\n\r\nconst exists = await redis.exists('album:01FJYWEYRHYFT8YTEGQBABJ43J') // 0\r\n```\r\n\r\nBecause of that, `.fetch` always returns an object shape; treat empty fields as “no data” for that ID.\r\n\r\n## Searching\r\n\r\nWith [RediSearch][redisearch-url] available on your server, repositories support indexed search—for example:\r\n\r\n```javascript\r\nconst albums = await albumRepository.search()\r\n  .where('artist').equals('Mushroomhead')\r\n  .and('title').matches('butterfly')\r\n  .and('year').is.greaterThan(2000)\r\n    .return.all()\r\n```\r\n\r\n### Build the Index\r\n\r\nSearch requires a RediSearch index. Create (or update) it with `.createIndex` on the repository:\r\n\r\n```javascript\r\nawait albumRepository.createIndex();\r\n```\r\n\r\nAfter schema changes, call `.createIndex` again; the library rebuilds the index only when the schema definition changes, so it is safe to invoke during application startup.\r\n\r\nRebuilding can be slow on large datasets—plan that in deployment scripts if needed. To drop an index without immediately rebuilding, use `.dropIndex`:\r\n\r\n```javascript\r\nawait albumRepository.dropIndex();\r\n```\r\n\r\n### Finding All The Things (and Returning Them)\r\n\r\nReturn every entity matching the (possibly empty) query:\r\n\r\n```javascript\r\nconst albums = await albumRepository.search().return.all()\r\n```\r\n\r\n#### Pagination\r\n\r\nRequest a slice with a zero-based offset and page size:\r\n\r\n```javascript\r\nconst offset = 100\r\nconst count = 25\r\nconst albums = await albumRepository.search().return.page(offset, count)\r\n```\r\n\r\nIf the offset is past the end of the result set, you get an empty array.\r\n\r\n#### First Things First\r\n\r\nReturn the first match, or `null` if none:\r\n\r\n```javascript\r\nconst firstAlbum = await albumRepository.search().return.first();\r\n```\r\n\r\n#### Counting\r\n\r\nReturn the number of matches without loading documents:\r\n\r\n```javascript\r\nconst count = await albumRepository.search().return.count()\r\n```\r\n\r\n### Finding Specific Things\r\n\r\nNarrow results using [strings](#searching-on-strings), [numbers](#searching-on-numbers), [booleans](#searching-on-booleans), [string arrays](#searching-string-arrays), [numeric arrays](#searching-arrays-of-numbers), [full-text](#full-text-search), [dates](#searching-on-dates), and [geo radius](#searching-on-points). The fluent API offers several equivalent phrasings for the same predicate; the sections below list common patterns.\r\n\r\n#### Searching on Strings\r\n\r\nWhen 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.\r\n\r\n```javascript\r\nlet albums\r\n\r\n// find all albums where the artist is 'Mushroomhead'\r\nalbums = await albumRepository.search().where('artist').eq('Mushroomhead').return.all()\r\n\r\n// find all albums where the artist is *not* 'Mushroomhead'\r\nalbums = await albumRepository.search().where('artist').not.eq('Mushroomhead').return.all()\r\n\r\n// find all albums using wildcards\r\nalbums = await albumRepository.search().where('artist').eq('Mush*').return.all()\r\nalbums = await albumRepository.search().where('artist').eq('*head').return.all()\r\nalbums = await albumRepository.search().where('artist').eq('*room*').return.all()\r\n\r\n// fluent alternatives that do the same thing\r\nalbums = await albumRepository.search().where('artist').equals('Mushroomhead').return.all()\r\nalbums = await albumRepository.search().where('artist').does.equal('Mushroomhead').return.all()\r\nalbums = await albumRepository.search().where('artist').is.equalTo('Mushroomhead').return.all()\r\nalbums = await albumRepository.search().where('artist').does.not.equal('Mushroomhead').return.all()\r\nalbums = await albumRepository.search().where('artist').is.not.equalTo('Mushroomhead').return.all()\r\n```\r\n\r\n#### Searching on Numbers\r\n\r\nWhen you set the field type in your schema to `number`, you can store both integers and floating-point numbers. And you can search against it with all the comparisons you'd expect to see:\r\n\r\n```javascript\r\nlet albums\r\n\r\n// find all albums where the year is ===, >, >=, <, and <= 1984\r\nalbums = await albumRepository.search().where('year').eq(1984).return.all()\r\nalbums = await albumRepository.search().where('year').gt(1984).return.all()\r\nalbums = await albumRepository.search().where('year').gte(1984).return.all()\r\nalbums = await albumRepository.search().where('year').lt(1984).return.all()\r\nalbums = await albumRepository.search().where('year').lte(1984).return.all()\r\n\r\n// find all albums where the year is between 1980 and 1989 inclusive\r\nalbums = await albumRepository.search().where('year').between(1980, 1989).return.all()\r\n\r\n// find all albums where the year is *not* ===, >, >=, <, and <= 1984\r\nalbums = await albumRepository.search().where('year').not.eq(1984).return.all()\r\nalbums = await albumRepository.search().where('year').not.gt(1984).return.all()\r\nalbums = await albumRepository.search().where('year').not.gte(1984).return.all()\r\nalbums = await albumRepository.search().where('year').not.lt(1984).return.all()\r\nalbums = await albumRepository.search().where('year').not.lte(1984).return.all()\r\n\r\n// find all albums where year is *not* between 1980 and 1989 inclusive\r\nalbums = await albumRepository.search().where('year').not.between(1980, 1989);\r\n\r\n// fluent alternatives that do the same thing\r\nalbums = await albumRepository.search().where('year').equals(1984).return.all()\r\nalbums = await albumRepository.search().where('year').does.equal(1984).return.all()\r\nalbums = await albumRepository.search().where('year').does.not.equal(1984).return.all()\r\nalbums = await albumRepository.search().where('year').is.equalTo(1984).return.all()\r\nalbums = await albumRepository.search().where('year').is.not.equalTo(1984).return.all()\r\n\r\nalbums = await albumRepository.search().where('year').greaterThan(1984).return.all()\r\nalbums = await albumRepository.search().where('year').is.greaterThan(1984).return.all()\r\nalbums = await albumRepository.search().where('year').is.not.greaterThan(1984).return.all()\r\n\r\nalbums = await albumRepository.search().where('year').greaterThanOrEqualTo(1984).return.all()\r\nalbums = await albumRepository.search().where('year').is.greaterThanOrEqualTo(1984).return.all()\r\nalbums = await albumRepository.search().where('year').is.not.greaterThanOrEqualTo(1984).return.all()\r\n\r\nalbums = await albumRepository.search().where('year').lessThan(1984).return.all()\r\nalbums = await albumRepository.search().where('year').is.lessThan(1984).return.all()\r\nalbums = await albumRepository.search().where('year').is.not.lessThan(1984).return.all()\r\n\r\nalbums = await albumRepository.search().where('year').lessThanOrEqualTo(1984).return.all()\r\nalbums = await albumRepository.search().where('year').is.lessThanOrEqualTo(1984).return.all()\r\nalbums = await albumRepository.search().where('year').is.not.lessThanOrEqualTo(1984).return.all()\r\n\r\nalbums = await albumRepository.search().where('year').is.between(1980, 1989).return.all()\r\nalbums = await albumRepository.search().where('year').is.not.between(1980, 1989).return.all()\r\n```\r\n\r\n#### Searching on Booleans\r\n\r\nYou can search against fields that contain booleans if you defined a field type of `boolean` in your schema:\r\n\r\n```javascript\r\nlet albums\r\n\r\n// find all albums where outOfPublication is true\r\nalbums = await albumRepository.search().where('outOfPublication').true().return.all()\r\n\r\n// find all albums where outOfPublication is false\r\nalbums = await albumRepository.search().where('outOfPublication').false().return.all()\r\n```\r\n\r\nYou can negate boolean searches. This might seem odd, but if your field is `null`, then it would match on a `.not` query:\r\n\r\n```javascript\r\n// find all albums where outOfPublication is false or null\r\nalbums = await albumRepository.search().where('outOfPublication').not.true().return.all()\r\n\r\n// find all albums where outOfPublication is true or null\r\nalbums = await albumRepository.search().where('outOfPublication').not.false().return.all()\r\n```\r\n\r\nAnd, of course, there's lots of syntactic sugar to make this fluent:\r\n\r\n```javascript\r\nalbums = await albumRepository.search().where('outOfPublication').eq(true).return.all()\r\nalbums = await albumRepository.search().where('outOfPublication').equals(true).return.all()\r\nalbums = await albumRepository.search().where('outOfPublication').does.equal(true).return.all()\r\nalbums = await albumRepository.search().where('outOfPublication').is.equalTo(true).return.all()\r\n\r\nalbums = await albumRepository.search().where('outOfPublication').true().return.all()\r\nalbums = await albumRepository.search().where('outOfPublication').false().return.all()\r\nalbums = await albumRepository.search().where('outOfPublication').is.true().return.all()\r\nalbums = await albumRepository.search().where('outOfPublication').is.false().return.all()\r\n\r\nalbums = await albumRepository.search().where('outOfPublication').not.eq(true).return.all()\r\nalbums = await albumRepository.search().where('outOfPublication').does.not.equal(true).return.all()\r\nalbums = await albumRepository.search().where('outOfPublication').is.not.equalTo(true).return.all()\r\nalbums = await albumRepository.search().where('outOfPublication').is.not.true().return.all()\r\nalbums = await albumRepository.search().where('outOfPublication').is.not.false().return.all()\r\n```\r\n\r\n#### Searching on Dates\r\n\r\nIf 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*:\r\n\r\n```javascript\r\nstudios = await studioRepository.search().where('established').on(new Date('2010-12-27')).return.all()\r\nstudios = await studioRepository.search().where('established').on('2010-12-27').return.all()\r\nstudios = await studioRepository.search().where('established').on(1293408000).return.all()\r\n```\r\n\r\nThere are several date comparison methods to use. And they can be negated:\r\n\r\n```javascript\r\nconst date = new Date('2010-12-27')\r\nconst laterDate = new Date('2020-12-27')\r\n\r\nstudios = await studioRepository.search().where('established').on(date).return.all()\r\nstudios = await studioRepository.search().where('established').not.on(date).return.all()\r\nstudios = await studioRepository.search().where('established').before(date).return.all()\r\nstudios = await studioRepository.search().where('established').not.before(date).return.all()\r\nstudios = await studioRepository.search().where('established').after(date).return.all()\r\nstudios = await studioRepository.search().where('established').not.after(date).return.all()\r\nstudios = await studioRepository.search().where('established').onOrBefore(date).return.all()\r\nstudios = await studioRepository.search().where('established').not.onOrBefore(date).return.all()\r\nstudios = await studioRepository.search().where('established').onOrAfter(date).return.all()\r\nstudios = await studioRepository.search().where('established').not.onOrAfter(date).return.all()\r\nstudios = await studioRepository.search().where('established').between(date, laterDate).return.all()\r\nstudios = await studioRepository.search().where('established').not.between(date, laterDate).return.all()\r\n```\r\n\r\nMore fluent variations work too:\r\n\r\n```javascript\r\nconst date = new Date('2010-12-27')\r\nconst laterDate = new Date('2020-12-27')\r\n\r\nstudios = await studioRepository.search().where('established').is.on(date).return.all()\r\nstudios = await studioRepository.search().where('established').is.not.on(date).return.all()\r\n\r\nstudios = await studioRepository.search().where('established').is.before(date).return.all()\r\nstudios = await studioRepository.search().where('established').is.not.before(date).return.all()\r\n\r\nstudios = await studioRepository.search().where('established').is.onOrBefore(date).return.all()\r\nstudios = await studioRepository.search().where('established').is.not.onOrBefore(date).return.all()\r\n\r\nstudios = await studioRepository.search().where('established').is.after(date).return.all()\r\nstudios = await studioRepository.search().where('established').is.not.after(date).return.all()\r\n\r\nstudios = await studioRepository.search().where('established').is.onOrAfter(date).return.all()\r\nstudios = await studioRepository.search().where('established').is.not.onOrAfter(date).return.all()\r\n\r\nstudios = await studioRepository.search().where('established').is.between(date, laterDate).return.all()\r\nstudios = await studioRepository.search().where('established').is.not.between(date, laterDate).return.all()\r\n```\r\n\r\nAnd, since dates are really just numbers, all the numeric comparisons work too:\r\n\r\n```javascript\r\nconst date = new Date('2010-12-27')\r\nconst laterDate = new Date('2020-12-27')\r\n\r\nstudios = await studioRepository.search().where('established').eq(date).return.all()\r\nstudios = await studioRepository.search().where('established').not.eq(date).return.all()\r\nstudios = await studioRepository.search().where('established').equals(date).return.all()\r\nstudios = await studioRepository.search().where('established').does.equal(date).return.all()\r\nstudios = await studioRepository.search().where('established').does.not.equal(date).return.all()\r\nstudios = await studioRepository.search().where('established').is.equalTo(date).return.all()\r\nstudios = await studioRepository.search().where('established').is.not.equalTo(date).return.all()\r\n\r\nstudios = await studioRepository.search().where('established').gt(date).return.all()\r\nstudios = await studioRepository.search().where('established').not.gt(date).return.all()\r\nstudios = await studioRepository.search().where('established').greaterThan(date).return.all()\r\nstudios = await studioRepository.search().where('established').is.greaterThan(date).return.all()\r\nstudios = await studioRepository.search().where('established').is.not.greaterThan(date).return.all()\r\n\r\nstudios = await studioRepository.search().where('established').gte(date).return.all()\r\nstudios = await studioRepository.search().where('established').not.gte(date).return.all()\r\nstudios = await studioRepository.search().where('established').greaterThanOrEqualTo(date).return.all()\r\nstudios = await studioRepository.search().where('established').is.greaterThanOrEqualTo(date).return.all()\r\nstudios = await studioRepository.search().where('established').is.not.greaterThanOrEqualTo(date).return.all()\r\n\r\nstudios = await studioRepository.search().where('established').lt(date).return.all()\r\nstudios = await studioRepository.search().where('established').not.lt(date).return.all()\r\nstudios = await studioRepository.search().where('established').lessThan(date).return.all()\r\nstudios = await studioRepository.search().where('established').is.lessThan(date).return.all()\r\nstudios = await studioRepository.search().where('established').is.not.lessThan(date).return.all()\r\n\r\nstudios = await studioRepository.search().where('established').lte(date).return.all()\r\nstudios = await studioRepository.search().where('established').not.lte(date).return.all()\r\nstudios = await studioRepository.search().where('established').lessThanOrEqualTo(date).return.all()\r\nstudios = await studioRepository.search().where('established').is.lessThanOrEqualTo(date).return.all()\r\nstudios = await studioRepository.search().where('established').is.not.lessThanOrEqualTo(date).return.all()\r\n```\r\n\r\n#### Searching String Arrays\r\n\r\nIf you have a field type of `string[]` you can search for *whole strings* that are in that array:\r\n\r\n```javascript\r\nlet albums\r\n\r\n// find all albums where genres contains the string 'rock'\r\nalbums = await albumRepository.search().where('genres').contain('rock').return.all()\r\n\r\n// find all albums where genres contains the string 'rock', 'metal', or 'blues'\r\nalbums = await albumRepository.search().where('genres').containOneOf('rock', 'metal', 'blues').return.all()\r\n\r\n// find all albums where genres does *not* contain the string 'rock'\r\nalbums = await albumRepository.search().where('genres').not.contain('rock').return.all()\r\n\r\n// find all albums where genres does *not* contain the string 'rock', 'metal', and 'blues'\r\nalbums = await albumRepository.search().where('genres').not.containOneOf('rock', 'metal', 'blues').return.all()\r\n\r\n// alternative syntaxes\r\nalbums = await albumRepository.search().where('genres').contains('rock').return.all()\r\nalbums = await albumRepository.search().where('genres').containsOneOf('rock', 'metal', 'blues').return.all()\r\nalbums = await albumRepository.search().where('genres').does.contain('rock').return.all()\r\nalbums = await albumRepository.search().where('genres').does.not.contain('rock').return.all()\r\nalbums = await albumRepository.search().where('genres').does.containOneOf('rock', 'metal', 'blues').return.all()\r\nalbums = await albumRepository.search().where('genres').does.not.containOneOf('rock', 'metal', 'blues').return.all()\r\n```\r\n\r\nWildcards work here too:\r\n\r\n```javascript\r\nalbums = await albumRepository.search().where('genres').contain('*rock*').return.all()\r\n```\r\n\r\n### Searching Arrays of Numbers\r\n\r\nIf you have a field of type `number[]`, you can search on it just like a `number`. If any number in the array matches your criteria, then it'll match and the document will be returned.\r\n\r\n```javascript\r\nlet albums\r\n\r\n// find all albums where at least one song is at least 3 minutes long\r\nalbums = await albumRepository.search().where('songDurations').gte(180).return.all()\r\n\r\n// find all albums where at least one song is at exactly 3 minutes long\r\nalbums = await albumRepository.search().where('songDurations').eq(180).return.all()\r\n\r\n// find all albums where at least one song is between 3 and 4 minutes long\r\nalbums = await albumRepository.search().where('songDurations').between(180, 240).return.all()\r\n```\r\n\r\nThe same numeric predicates as in [Searching on numbers](#searching-on-numbers) apply to `number[]` fields (any array element may satisfy the predicate).\r\n\r\n#### Full-Text Search\r\n\r\nIf 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, fuzzy matches, and exact phrases within a body of text.\r\n\r\nFull-text search treats natural language: common words (*a*, *an*, *the*, …) may be skipped; related forms (*give*, *gives*, *given*) may match via stemming; punctuation and extra whitespace are normalized.\r\n\r\nHere are some examples of doing full-text search against some album titles:\r\n\r\n```javascript\r\nlet albums\r\n\r\n// finds all albums where the title contains the word 'butterfly'\r\nalbums = await albumRepository.search().where('title').match('butterfly').return.all()\r\n\r\n// finds all albums using fuzzy matching where the title contains a word which is within 3 Levenshtein distance of the word 'buterfly'\r\nalbums = await albumRepository.search().where('title').match('buterfly', { fuzzyMatching: true, levenshteinDistance: 3 }).return.all()\r\n\r\n// finds all albums where the title contains the words 'beautiful' and 'children'\r\nalbums = await albumRepository.search().where('title').match('beautiful children').return.all()\r\n\r\n// finds all albums where the title contains the exact phrase 'beautiful stories'\r\nalbums = await albumRepository.search().where('title').matchExact('beautiful stories').return.all()\r\n```\r\n\r\nFor prefix, suffix, or infix word fragments, add `*` where needed:\r\n\r\n```javascript\r\n// finds all albums where the title contains a word that contains 'right'\r\nalbums = await albumRepository.search().where('title').match('*right*').return.all()\r\n```\r\n\r\nDo not combine partial-word searches or fuzzy matches with exact matches. Partial-word searches and fuzzy matches with exact matches are not compatible in RediSearch. If you try to exactly match a partial-word search or fuzzy match a partial-word search, you'll get an error.\r\n\r\n```javascript\r\n// THESE WILL ERROR\r\nalbums = await albumRepository.search().where('title').matchExact('beautiful sto*').return.all()\r\nalbums = await albumRepository.search().where('title').matchExact('*buterfly', { fuzzyMatching: true, levenshteinDistance: 3 }).return.all()\r\n```\r\n\r\nAs always, there are several alternatives to make this a bit more fluent and, of course, negation is available:\r\n\r\n```javascript\r\nalbums = await albumRepository.search().where('title').not.match('butterfly').return.all()\r\nalbums = await albumRepository.search().where('title').matches('butterfly').return.all()\r\nalbums = await albumRepository.search().where('title').does.match('butterfly').return.all()\r\nalbums = await albumRepository.search().where('title').does.not.match('butterfly').return.all()\r\n\r\nalbums = await albumRepository.search().where('title').exact.match('beautiful stories').return.all()\r\nalbums = await albumRepository.search().where('title').not.exact.match('beautiful stories').return.all()\r\nalbums = await albumRepository.search().where('title').exactly.matches('beautiful stories').return.all()\r\nalbums = await albumRepository.search().where('title').does.exactly.match('beautiful stories').return.all()\r\nalbums = await albumRepository.search().where('title').does.not.exactly.match('beautiful stories').return.all()\r\n\r\nalbums = await albumRepository.search().where('title').not.matchExact('beautiful stories').return.all()\r\nalbums = await albumRepository.search().where('title').matchesExactly('beautiful stories').return.all()\r\nalbums = await albumRepository.search().where('title').does.matchExactly('beautiful stories').return.all()\r\nalbums = await albumRepository.search().where('title').does.not.matchExactly('beautiful stories').return.all()\r\n```\r\n\r\n#### Searching on Points\r\n\r\nRediSearch supports geographic queries: supply a point and a radius to return entities within that area:\r\n\r\n```javascript\r\nlet studios\r\n\r\n// finds all the studios with 50 miles of downtown Cleveland\r\nstudios = await studioRepository.search().where('location').inRadius(\r\n  circle => circle.origin(-81.7758995, 41.4976393).radius(50).miles).return.all()\r\n```\r\n\r\nNote that coordinates are specified with the longitude *first*, and then the latitude. This might be the opposite of what you expect but is consistent with how Redis implements coordinates in [RediSearch](https://oss.redis.com/redisearch/Query_Syntax/) and with [GeoSets](https://redis.io/commands#geo).\r\n\r\nIf you don't want to rely on argument order, you can also specify longitude and latitude more explicitly:\r\n\r\n```javascript\r\n// finds all the studios within 50 miles of downtown Cleveland using a point\r\nstudios = await studioRepository.search().where('location').inRadius(\r\n  circle => circle.origin({ longitude: -81.7758995, latitude: 41.4976393 }).radius(50).miles).return.all()\r\n\r\n// finds all the studios within 50 miles of downtown Cleveland using longitude and latitude\r\nstudios = await studioRepository.search().where('location').inRadius(\r\n  circle => circle.longitude(-81.7758995).latitude(41.4976393).radius(50).miles).return.all()\r\n```\r\n\r\nRadius can be in *miles*, *feet*, *kilometers*, and *meters* in all the spelling variations you could ever want:\r\n\r\n```javascript\r\n// finds all the studios within 50 miles\r\nstudios = await studioRepository.search().where('location').inRadius(\r\n  circle => circle.origin(-81.7758995, 41.4976393).radius(50).miles).return.all()\r\n\r\nstudios = await studioRepository.search().where('location').inRadius(\r\n  circle => circle.origin(-81.7758995, 41.4976393).radius(50).mile).return.all()\r\n\r\nstudios = await studioRepository.search().where('location').inRadius(\r\n  circle => circle.origin(-81.7758995, 41.4976393).radius(50).mi).return.all()\r\n\r\n// finds all the studios within 50 feet\r\nstudios = await studioRepository.search().where('location').inRadius(\r\n  circle => circle.origin(-81.7758995, 41.4976393).radius(50).feet).return.all()\r\n\r\nstudios = await studioRepository.search().where('location').inRadius(\r\n  circle => circle.origin(-81.7758995, 41.4976393).radius(50).foot).return.all()\r\n\r\nstudios = await studioRepository.search().where('location').inRadius(\r\n  circle => circle.origin(-81.7758995, 41.4976393).radius(50).ft).return.all()\r\n\r\n// finds all the studios within 50 kilometers\r\nstudios = await studioRepository.search().where('location').inRadius(\r\n  circle => circle.origin(-81.7758995, 41.4976393).radius(50).kilometers).return.all()\r\n\r\nstudios = await studioRepository.search().where('location').inRadius(\r\n  circle => circle.origin(-81.7758995, 41.4976393).radius(50).kilometer).return.all()\r\n\r\nstudios = await studioRepository.search().where('location').inRadius(\r\n  circle => circle.origin(-81.7758995, 41.4976393).radius(50).km).return.all()\r\n\r\n// finds all the studios within 50 meters\r\nstudios = await studioRepository.search().where('location').inRadius(\r\n  circle => circle.origin(-81.7758995, 41.4976393).radius(50).meters).return.all()\r\n\r\nstudios = await studioRepository.search().where('location').inRadius(\r\n  circle => circle.origin(-81.7758995, 41.4976393).radius(50).meter).return.all()\r\n\r\nstudios = await studioRepository.search().where('location').inRadius(\r\n  circle => circle.origin(-81.7758995, 41.4976393).radius(50).m).return.all()\r\n```\r\n\r\nIf you omit the origin, the library defaults to longitude `0` and latitude `0` ([Null Island](https://en.wikipedia.org/wiki/Null_Island)):\r\n\r\n```javascript\r\n// finds all the studios within 50 miles of Null Island (probably ain't much there)\r\nstudios = await studioRepository.search().where('location').inRadius(\r\n  circle => circle.radius(50).miles).return.all()\r\n```\r\n\r\nIf you don't specify the radius, it defaults to *1* and if you don't provide units, it defaults to *meters*:\r\n\r\n```javascript\r\n// finds all the studios within 1 meter of downtown Cleveland\r\nstudios = await studioRepository.search().where('location').inRadius(\r\n  circle => circle.origin(-81.7758995, 41.4976393)).return.all()\r\n\r\n// finds all the studios within 1 kilometer of downtown Cleveland\r\nstudios = await studioRepository.search().where('location').inRadius(\r\n  circle => circle.origin(-81.7758995, 41.4976393).kilometers).return.all()\r\n\r\n// finds all the studios within 50 meters of downtown Cleveland\r\nstudios = await studioRepository.search().where('location').inRadius(\r\n  circle => circle.origin(-81.7758995, 41.4976393).radius(50)).return.all()\r\n```\r\n\r\nEquivalent fluent spellings include:\r\n\r\n```javascript\r\nstudios = await studioRepository.search().where('location').not.inRadius(\r\n  circle => circle.longitude(-81.7758995).latitude(41.4976393).radius(50).miles).return.all()\r\n\r\nstudios = await studioRepository.search().where('location').is.inRadius(\r\n  circle => circle.longitude(-81.7758995).latitude(41.4976393).radius(50).miles).return.all()\r\n\r\nstudios = await studioRepository.search().where('location').is.not.inRadius(\r\n  circle => circle.longitude(-81.7758995).latitude(41.4976393).radius(50).miles).return.all()\r\n\r\nstudios = await studioRepository.search().where('location').not.inCircle(\r\n  circle => circle.longitude(-81.7758995).latitude(41.4976393).radius(50).miles).return.all()\r\n\r\nstudios = await studioRepository.search().where('location').is.inCircle(\r\n  circle => circle.longitude(-81.7758995).latitude(41.4976393).radius(50).miles).return.all()\r\n\r\nstudios = await studioRepository.search().where('location').is.not.inCircle(\r\n  circle => circle.longitude(-81.7758995).latitude(41.4976393).radius(50).miles).return.all()\r\n```\r\n\r\n#### Chaining Searches\r\n\r\nSo far we've been doing searches that match on a single field. However, we often want to query on multiple fields. Not a problem:\r\n\r\n```javascript\r\nconst albums = await albumRepository.search()\r\n  .where('artist').equals('Mushroomhead')\r\n  .or('title').matches('butterfly')\r\n  .and('year').is.greaterThan(1990).return.all()\r\n```\r\n\r\nThese are executed in order from left to right, and ignore any order of operations. So this query will match an artist of \"Mushroomhead\" OR a title matching \"butterfly\" before it goes on to match that the year is greater than 1990.\r\n\r\nIf you'd like to change this you can nest your queries:\r\n\r\n```javascript\r\nconst albums = await albumRepository.search()\r\n  .or(search => search\r\n    .where('artist').equals('Mushroomhead')\r\n    .and('year').is.greaterThan(1990)\r\n  )\r\n  .or(search => search.where('title').matches('butterfly'))\r\n  .return.all()\r\n```\r\n\r\nThis matches albums where `(artist is Mushroomhead and year > 1990)` **or** the title matches `butterfly`. Adjust grouping with nested callbacks if you need different precedence; see [Chaining Searches](#chaining-searches).\r\n\r\n#### Running Raw Searches\r\n\r\nFor queries that are easier to express in RediSearch’s native syntax, use `.searchRaw` with a query string. See the [RediSearch query syntax](https://oss.redis.com/redisearch/Query_Syntax/).\r\n\r\n```javascript\r\n// finds all the Mushroomhead albums with the word 'beautiful' in the title from 1990 and beyond\r\nconst query = \"@artist:{Mushroomhead} @title:beautiful @year:[1990 +inf]\"\r\nconst albums = albumRepository.searchRaw(query).return.all();\r\n```\r\n\r\nResults are the same entity objects as with the fluent builder.\r\n\r\n### Sorting Search Results\r\n\r\nSort by a single field with `.sortBy`, `.sortAscending`, or `.sortDescending` on these types: `string`, `number`, `boolean`, `date`, and `text`.\r\n\r\n```javascript\r\nconst albumsByYear = await albumRepository.search()\r\n  .where('artist').equals('Mushroomhead')\r\n    .sortAscending('year').return.all()\r\n\r\nconst albumsByTitle = await albumRepository.search()\r\n  .where('artist').equals('Mushroomhead')\r\n    .sortBy('title', 'DESC').return.all()\r\n```\r\n\r\nMark fields as `sortable` in the schema so RediSearch can maintain a sortable side index where supported (not every field type benefits):\r\n\r\n```javascript\r\nconst albumSchema = new Schema('album', {\r\n  artist: { type: 'string' },\r\n  title: { type: 'text', sortable: true },\r\n  year: { type: 'number', sortable: true },\r\n  genres: { type: 'string[]' },\r\n  outOfPublication: { type: 'boolean' }\r\n})\r\n```\r\n\r\nIf 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.\r\n\r\nIf your schema is for a Hash, you can mark `string`, `number`, `boolean`, `date`, and `text` fields as sortable.\r\n\r\nFields of the types `point` and `string[]` are never sortable.\r\n\r\nCalling `.sortBy` on a field that could be `sortable` but is not may produce a runtime warning.\r\n\r\n## Advanced usage\r\n\r\nAdditional configuration for RediSearch-backed schemas:\r\n\r\n### Schema Options\r\n\r\nAdditional 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.\r\n\r\n|  schema type   | RediSearch type | `indexed` | `sortable` | `normalized` | `stemming` | `matcher` | `weight` | `separator` | `caseSensitive` |\r\n| -------------- | :-------------: | :-------: | :--------: | :----------: | :--------: | :--------: | :------: | :---------: | :-------------: |\r\n| `string`       |       TAG       |    yes    |  HASH Only |   HASH Only  |      -     |      -     |     -    |     yes     |        yes      |\r\n| `number`       |     NUMERIC     |    yes    |    yes     |       -      |      -     |      -     |     -    |      -      |         -       |\r\n| `boolean`      |       TAG       |    yes    |  HASH Only |       -      |      -     |      -     |     -    |      -      |         -       |\r\n| `string[]`     |       TAG       |    yes    |  HASH Only |   HASH Only  |      -     |      -     |     -    |     yes     |        yes      |\r\n| `number[]`     |     NUMERIC     |    yes    |    yes     |       -      |      -     |      -     |     -    |      -      |         -       |\r\n| `date`         |     NUMERIC     |    yes    |    yes     |       -      |            |      -     |     -    |      -      |         -       |\r\n| `point`        |       GEO       |    yes    |     -      |       -      |            |      -     |     -    |      -      |         -       |\r\n| `text`         |       TEXT      |    yes    |    yes     |      yes     |     yes    |     yes    |    yes   |      -      |         -       |\r\n\r\n* `indexed`: true | false, whether this field is indexed by RediSearch (default true)\r\n* `sortable`: true | false, whether to create an additional index to optimize sorting (default false)\r\n* `normalized`: true | false, whether to apply normalization for sorting (default true)\r\n* `matcher`: string defining phonetic matcher which can be one of: 'dm:en' for English, 'dm:fr' for French, 'dm:pt' for Portuguese, 'dm:es' for Spanish (default none)\r\n* `stemming`: true | false, whether word-stemming is applied to text fields (default true)\r\n* `weight`: number, the importance weighting to use when ranking results (default 1)\r\n* `separator`: string, the character to delimit multiple tags (default '|')\r\n* `caseSensitive`: true | false, whether original letter casing is kept for search (default false)\r\n\r\nExample showing additional options:\r\n\r\n```javascript\r\nconst commentSchema = new Schema('comment', {\r\n  name: { type: 'text', stemming: false, matcher: 'dm:en' },\r\n  email: { type: 'string', normalized: false, },\r\n  posted: { type: 'date', sortable: true },\r\n  title: { type: 'text', weight: 2 },\r\n  comment: { type: 'text', weight: 1 },\r\n  approved: { type: 'boolean', indexed: false },\r\n  iphash: { type: 'string', caseSensitive: true },\r\n  notes: { type: 'string', indexed: false },\r\n})\r\n```\r\n\r\nSee [docs/classes/Schema.md](docs/classes/Schema.md) for additional `Schema` options.\r\n\r\n## Documentation\r\n\r\nGenerated TypeDoc output lives under [`docs/`](docs/). This README covers day-to-day usage; the class reference fills in edge cases and full method signatures.\r\n\r\n## Troubleshooting\r\n\r\nIf something fails, confirm Redis Stack (RediSearch + RedisJSON) is available, indices are created, and your schema matches stored data. For upstream **redis-om** behavior, see issues on [redis-om-node](https://github.com/redis/redis-om-node). Community help is available on the [Redis Discord][discord-url].\r\n\r\n## Contributing\r\n\r\nContributions are welcome: reproducible bug reports, documentation fixes, and pull requests that include or update tests when behavior changes.\r\n\r\n<!-- Links, Badges, and Whatnot -->\r\n\r\n[package-shield]: https://img.shields.io/npm/v/redis-type-os?logo=npm\r\n[build-shield]: https://img.shields.io/github/workflow/status/redis/redis-om-node/CI/main\r\n[license-shield]: https://img.shields.io/npm/l/redis-type-os\r\n[discord-shield]: https://img.shields.io/discord/697882427875393627?style=social&logo=discord\r\n[twitch-shield]: https://img.shields.io/twitch/status/redisinc?style=social\r\n[twitter-shield]: https://img.shields.io/twitter/follow/redisinc?style=social\r\n[youtube-shield]: https://img.shields.io/youtube/channel/views/UCD78lHSwYqMlyetR0_P4Vig?style=social\r\n\r\n[package-url]: https://www.npmjs.com/package/redis-type-os\r\n[build-url]: https://github.com/redis/redis-om-node/actions/workflows/ci.yml\r\n[license-url]: LICENSE\r\n[discord-url]: http://discord.gg/redis\r\n[twitch-url]: https://www.twitch.tv/redisinc\r\n[twitter-url]: https://twitter.com/redisinc\r\n[youtube-url]: https://www.youtube.com/redisinc\r\n\r\n[redis-cloud-url]: https://redis.com/try-free/\r\n[redis-stack-url]: https://redis.io/docs/stack/\r\n[redisearch-url]: https://oss.redis.com/redisearch/\r\n[redis-json-url]: https://oss.redis.com/redisjson/\r\n[redis-om-dotnet]: https://github.com/redis/redis-om-dotnet\r\n[redis-om-python]: https://github.com/redis/redis-om-python\r\n[redis-om-spring]: https://github.com/redis/redis-om-spring\r\n","readmeFilename":"README.md"}