redis-om
Advanced tools
Comparing version 0.4.0-beta.3 to 0.4.0-beta.4
@@ -658,2 +658,4 @@ import { createClient, createCluster, RediSearchSchema, SearchOptions } from 'redis'; | ||
protected buildQuery(valuePortion: string): string; | ||
/** @internal */ | ||
protected escapePunctuation(value: string): string; | ||
} | ||
@@ -660,0 +662,0 @@ |
@@ -212,3 +212,3 @@ "use strict"; | ||
constructor(field) { | ||
const message = `Null or undefined found in field '${field.name}' of type '${field.type}' in JSON at "${field.jsonPath}".`; | ||
const message = `Null or undefined found in field '${field.name}' of type '${field.type}' in JSON at '${field.jsonPath}'.`; | ||
super(message); | ||
@@ -230,3 +230,3 @@ this.#field = field; | ||
constructor(field) { | ||
const message = `Unexpected value for field '${field.name}' of type '${field.type}' in JSON at "${field.jsonPath}".`; | ||
const message = `Unexpected value for field '${field.name}' of type '${field.type}' in JSON at '${field.jsonPath}'.`; | ||
super(message); | ||
@@ -292,3 +292,3 @@ this.#field = field; | ||
constructor(field) { | ||
const message = `Null or undefined found in field '${field.name}' of type '${field.type}' from JSON path "${field.jsonPath}" in Redis.`; | ||
const message = `Null or undefined found in field '${field.name}' of type '${field.type}' from JSON path '${field.jsonPath}' in Redis.`; | ||
super(message); | ||
@@ -310,3 +310,3 @@ this.#field = field; | ||
constructor(field) { | ||
const message = `Unexpected value for field '${field.name}' of type '${field.type}' from JSON path "${field.jsonPath}" in Redis.`; | ||
const message = `Unexpected value for field '${field.name}' of type '${field.type}' from JSON path '${field.jsonPath}' in Redis.`; | ||
super(message); | ||
@@ -328,3 +328,3 @@ this.#field = field; | ||
constructor(field) { | ||
const message = `Unexpected value for field '${field.name}' of type '${field.type}' from Hash field "${field.hashField}" read from Redis.`; | ||
const message = `Unexpected value for field '${field.name}' of type '${field.type}' from Hash field '${field.hashField}' read from Redis.`; | ||
super(message); | ||
@@ -378,2 +378,3 @@ this.#field = field; | ||
var isUndefined = (value) => value === void 0; | ||
var isNullish = (value) => value === void 0 || value === null; | ||
var isNotNullish = (value) => value !== void 0 && value !== null; | ||
@@ -428,4 +429,7 @@ var isBoolean = (value) => typeof value === "boolean"; | ||
const value = hashData[field.hashField]; | ||
if (isNotNullish(value)) | ||
if (isNotNullish(value)) { | ||
data[field.name] = convertKnownValueFromString(field, value); | ||
} else if (isNullish(value) && field.type === "string[]") { | ||
data[field.name] = []; | ||
} | ||
}); | ||
@@ -538,3 +542,6 @@ return data; | ||
const hashField = field ? field.hashField : key; | ||
hashData[hashField] = field ? convertKnownValueToString2(field, value) : convertUnknownValueToString(key, value); | ||
if (field && field.type === "string[]" && isArray(value) && value.length === 0) { | ||
} else { | ||
hashData[hashField] = field ? convertKnownValueToString2(field, value) : convertUnknownValueToString(key, value); | ||
} | ||
} | ||
@@ -797,5 +804,9 @@ }); | ||
const negationPortion = this.negated ? "-" : ""; | ||
const fieldPortion = this.field.name; | ||
const fieldPortion = this.escapePunctuation(this.field.name); | ||
return `(${negationPortion}@${fieldPortion}:${valuePortion})`; | ||
} | ||
escapePunctuation(value) { | ||
const matchPunctuation = /[,.<>{}[\]"':;!@#$%^&()\-+=~|/\\ ]/g; | ||
return value.replace(matchPunctuation, "\\$&"); | ||
} | ||
}; | ||
@@ -1060,4 +1071,3 @@ | ||
toString() { | ||
const matchPunctuation = /[,.<>{}[\]"':;!@#$%^&()\-+=~|/\\ ]/g; | ||
const escapedValue = this.value.replace(matchPunctuation, "\\$&"); | ||
const escapedValue = this.escapePunctuation(this.value); | ||
return this.buildQuery(`{${escapedValue}}`); | ||
@@ -1757,4 +1767,4 @@ } | ||
return this.#definition.path; | ||
const alias = this.#definition.alias ?? this.name; | ||
return this.type === "string[]" ? `$.${alias}[*]` : `$.${alias}`; | ||
const alias = (this.#definition.alias ?? this.name).replace(/"/g, '\\"'); | ||
return this.type === "string[]" ? `$["${alias}"][*]` : `$["${alias}"]`; | ||
} | ||
@@ -1761,0 +1771,0 @@ get separator() { |
{ | ||
"name": "redis-om", | ||
"version": "0.4.0-beta.3", | ||
"version": "0.4.0-beta.4", | ||
"description": "Object mapping, and more, for Redis and Node.js. Written in TypeScript.", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -988,3 +988,3 @@ <div align="center"> | ||
```javascript | ||
const albums = await albumRepository.search | ||
const albums = await albumRepository.search() | ||
.where('artist').equals('Mushroomhread') | ||
@@ -1000,3 +1000,3 @@ .or('title').matches('butterfly') | ||
```javascript | ||
const albums = await albumRepository.search | ||
const albums = await albumRepository.search() | ||
.where('title').matches('butterfly').return.all() | ||
@@ -1006,3 +1006,3 @@ .or(search => search | ||
.and('year').is.greaterThan(1990) | ||
) | ||
).return.all() | ||
``` | ||
@@ -1031,7 +1031,7 @@ | ||
```javascript | ||
const albumsByYear = await albumRepository.search | ||
const albumsByYear = await albumRepository.search() | ||
.where('artist').equals('Mushroomhread') | ||
.sortAscending('year').return.all() | ||
const albumsByTitle = await albumRepository.search | ||
const albumsByTitle = await albumRepository.search() | ||
.where('artist').equals('Mushroomhread') | ||
@@ -1038,0 +1038,0 @@ .sortBy('title', 'DESC').return.all() |
Sorry, the diff of this file is not supported yet
374003
3289