elastic-dsl-typescript
Advanced tools
Comparing version 1.0.5 to 1.0.6
"use strict"; | ||
var __rest = (this && this.__rest) || function (s, e) { | ||
var t = {}; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) | ||
t[p] = s[p]; | ||
if (s != null && typeof Object.getOwnPropertySymbols === "function") | ||
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { | ||
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) | ||
t[p[i]] = s[p[i]]; | ||
} | ||
return t; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -10,2 +21,14 @@ const AbstractBuilder_1 = require("../../Abstract/AbstractBuilder"); | ||
add(aggType, name, d) { | ||
const _a = d.params, { filter } = _a, all = __rest(_a, ["filter"]); | ||
if (filter) { | ||
this._data[name] = { | ||
filter, | ||
aggs: { | ||
[`${name}_filtered`]: { | ||
[aggType]: Object.assign(Object.assign({}, all), (d.opts || {})), | ||
}, | ||
}, | ||
}; | ||
return this; | ||
} | ||
this._data[name] = { | ||
@@ -12,0 +35,0 @@ [aggType]: Object.assign(Object.assign({}, d.params), (d.opts || {})), |
@@ -15,15 +15,15 @@ "use strict"; | ||
Should(filter, data) { | ||
this.add('should', filter, data); | ||
this.add("should", filter, data); | ||
return this; | ||
} | ||
Filter(filter, data) { | ||
this.add('filter', filter, data); | ||
this.add("filter", filter, data); | ||
return this; | ||
} | ||
Must(filter, data) { | ||
this.add('must', filter, data); | ||
this.add("must", filter, data); | ||
return this; | ||
} | ||
Must_Not(filter, data) { | ||
this.add('must_not', filter, data); | ||
this.add("must_not", filter, data); | ||
return this; | ||
@@ -61,12 +61,12 @@ } | ||
switch (filter) { | ||
case 'exists': { | ||
case "exists": { | ||
(_a = this._query[type]) === null || _a === void 0 ? void 0 : _a.push({ | ||
[filter]: { field: data.params.fieldName }, | ||
[filter]: { field: data.params.fieldName } | ||
}); | ||
break; | ||
} | ||
case 'term': | ||
case 'terms': { | ||
case "term": | ||
case "terms": { | ||
(_b = this._query[type]) === null || _b === void 0 ? void 0 : _b.push({ | ||
[filter]: Object.assign({ [data['field']]: data.params['value'] }, data.opts), | ||
[filter]: Object.assign({ [data["field"]]: data.params["value"] }, data.opts) | ||
}); | ||
@@ -81,3 +81,3 @@ break; | ||
(_c = this._query[type]) === null || _c === void 0 ? void 0 : _c.push({ | ||
[filter]: { [data['field']]: payload }, | ||
[filter]: { [data["field"]]: payload } | ||
}); | ||
@@ -84,0 +84,0 @@ } |
@@ -16,3 +16,3 @@ import { AbstractBulder } from '../..'; | ||
*/ | ||
add<K extends keyof BASE_SCHEMA>(filter: K, data: BASE_SCHEMA[K]): Omit<this, 'add'>; | ||
add<K extends keyof BASE_SCHEMA>(filter: K, data: BASE_SCHEMA[K]): Omit<this, "add">; | ||
/** | ||
@@ -19,0 +19,0 @@ * Generate Json |
@@ -26,4 +26,4 @@ "use strict"; | ||
[filter]: { | ||
[data.field]: Object.assign(Object.assign({}, data.params), data.opts), | ||
}, | ||
[data.field]: Object.assign(Object.assign({}, data.params), data.opts) | ||
} | ||
}; | ||
@@ -33,3 +33,3 @@ } | ||
this._query = { | ||
[filter]: Object.assign(Object.assign({}, data.params), data.opts), | ||
[filter]: Object.assign(Object.assign({}, data.params), data.opts) | ||
}; | ||
@@ -36,0 +36,0 @@ } |
{ | ||
"name": "elastic-dsl-typescript", | ||
"version": "1.0.5", | ||
"version": "1.0.6", | ||
"description": "Node.js ElasticSearch search query builder", | ||
@@ -10,3 +10,2 @@ "main": "./", | ||
"build": "rm -rf ./dist && ./node_modules/.bin/tsc", | ||
"pub": "npm run build && npm run copyData && cd ./dist && npm publish" | ||
@@ -13,0 +12,0 @@ }, |
@@ -56,6 +56,6 @@ "use strict"; | ||
switch (prop) { | ||
case 'query': { | ||
case "query": { | ||
break; | ||
} | ||
case 'aggs': { | ||
case "aggs": { | ||
obj[prop] = val.build(); | ||
@@ -71,3 +71,2 @@ break; | ||
for (const [prop, val] of Object.entries(this._query)) { | ||
console.log(prop); | ||
if (val instanceof AbstractBuilder_1.AbstractBulder) { | ||
@@ -74,0 +73,0 @@ query = Object.assign(Object.assign({}, query), val.build()); |
@@ -14,5 +14,5 @@ import { Aggregation } from '../../Builders/Aggregation'; | ||
params: {}, | ||
source: 'doc.my_avg.value * 2' | ||
} | ||
} | ||
source: 'doc.my_avg.value * 2', | ||
}, | ||
}, | ||
}); | ||
@@ -26,6 +26,6 @@ | ||
params: {}, | ||
source: 'doc.my_avg.value * 2' | ||
} | ||
} | ||
} | ||
source: 'doc.my_avg.value * 2', | ||
}, | ||
}, | ||
}, | ||
}); | ||
@@ -41,5 +41,5 @@ }); | ||
params: {}, | ||
source: 'doc.my_max.value * 2' | ||
} | ||
} | ||
source: 'doc.my_max.value * 2', | ||
}, | ||
}, | ||
}) | ||
@@ -52,5 +52,5 @@ .add('min', 'my_min', { | ||
params: {}, | ||
source: 'doc.my_min.value * 2' | ||
} | ||
} | ||
source: 'doc.my_min.value * 2', | ||
}, | ||
}, | ||
}); | ||
@@ -64,5 +64,5 @@ | ||
params: {}, | ||
source: 'doc.my_max.value * 2' | ||
} | ||
} | ||
source: 'doc.my_max.value * 2', | ||
}, | ||
}, | ||
}, | ||
@@ -74,6 +74,6 @@ my_min: { | ||
params: {}, | ||
source: 'doc.my_min.value * 2' | ||
} | ||
} | ||
} | ||
source: 'doc.my_min.value * 2', | ||
}, | ||
}, | ||
}, | ||
}); | ||
@@ -85,3 +85,3 @@ }); | ||
params: { | ||
field: 'color' | ||
field: 'color', | ||
}, | ||
@@ -92,4 +92,4 @@ opts: { | ||
min_doc_count: 2, | ||
size: 100 | ||
} | ||
size: 100, | ||
}, | ||
}); | ||
@@ -104,5 +104,5 @@ | ||
min_doc_count: 2, | ||
size: 100 | ||
} | ||
} | ||
size: 100, | ||
}, | ||
}, | ||
}); | ||
@@ -117,9 +117,9 @@ }); | ||
{ | ||
from: 100 | ||
from: 100, | ||
}, | ||
{ | ||
to: 1000 | ||
} | ||
] | ||
} | ||
to: 1000, | ||
}, | ||
], | ||
}, | ||
}); | ||
@@ -133,10 +133,10 @@ | ||
{ | ||
from: 100 | ||
from: 100, | ||
}, | ||
{ | ||
to: 1000 | ||
} | ||
] | ||
} | ||
} | ||
to: 1000, | ||
}, | ||
], | ||
}, | ||
}, | ||
}); | ||
@@ -153,9 +153,9 @@ }); | ||
{ | ||
from: 100 | ||
from: 100, | ||
}, | ||
{ | ||
to: 1000 | ||
} | ||
] | ||
} | ||
to: 1000, | ||
}, | ||
], | ||
}, | ||
}); | ||
@@ -165,2 +165,25 @@ | ||
}); | ||
test('Create filtered terms agg', async () => { | ||
const a = new Aggregation().add('terms', 'availStoreSizes', { | ||
params: { | ||
field: 'availSizes.sizes.keyword', | ||
filter: { terms: { 'availSizes.IStoreId.keyword': ['0000'] } }, | ||
}, | ||
opts: { | ||
size: 50, | ||
}, | ||
}); | ||
// availStoreSizes: { | ||
// aggs: { sizes: { terms: { field: 'availSizes.sizes.keyword', size: 50 } } }, | ||
// filter: { terms: { 'availSizes.IStoreId.keyword': ['0000'] } }, | ||
// }, | ||
expect(a.build()).toEqual({ | ||
availStoreSizes: { | ||
aggs: { availStoreSizes_filtered: { terms: { field: 'availSizes.sizes.keyword', size: 50 } } }, | ||
filter: { terms: { 'availSizes.IStoreId.keyword': ['0000'] } }, | ||
}, | ||
}); | ||
}); | ||
}); |
@@ -22,14 +22,3 @@ import { Bool } from '../../Builders/Bool'; | ||
'bool', | ||
expect.objectContaining({ | ||
must: [ | ||
{ | ||
term: { | ||
articul: { | ||
boost: 1, | ||
value: '00001851', | ||
}, | ||
}, | ||
}, | ||
], | ||
}), | ||
expect.objectContaining({"must": [{"term": {"articul": "00001851", "boost": 1}}]}), | ||
); | ||
@@ -81,4 +70,4 @@ }); | ||
expect(b.build()).toHaveProperty( | ||
'bool', | ||
expect.objectContaining({ filter: [{ terms: { articul:['00001851'] , boost: 2, } }] }), | ||
"bool", | ||
expect.objectContaining({ filter: [{ terms: { articul: ["00001851"], boost: 2 } }] }) | ||
); | ||
@@ -99,16 +88,16 @@ }); | ||
.add('must', 'range', { | ||
field: 'price', | ||
field: "price", | ||
params: { | ||
gte: 0, | ||
lte: Number.MAX_VALUE, | ||
lte: Number.MAX_VALUE | ||
}, | ||
opts: { | ||
boost: 120, | ||
}, | ||
boost: 120 | ||
} | ||
}) | ||
.add('should', 'notExistsFilter', { | ||
field: 'test', | ||
field: "test", | ||
params: { | ||
someParams: 'some data', | ||
}, | ||
someParams: "some data" | ||
} | ||
}); | ||
@@ -124,3 +113,3 @@ | ||
gte: 0, | ||
lte: 1.7976931348623157e308, | ||
lte: 1.7976931348623157e308 | ||
}, | ||
@@ -134,7 +123,7 @@ }, | ||
test: { | ||
someParams: 'some data', | ||
}, | ||
}, | ||
}, | ||
], | ||
someParams: "some data" | ||
} | ||
} | ||
} | ||
] | ||
}, | ||
@@ -144,26 +133,26 @@ }); | ||
test('Create mutlti query', async () => { | ||
test("Create mutlti query", async () => { | ||
const b = new Bool() | ||
.add('must', 'fuzzy', { | ||
field: 'f', | ||
.add("must", "fuzzy", { | ||
field: "f", | ||
params: { | ||
value: 'some text', | ||
value: "some text" | ||
}, | ||
opts: { | ||
fuzziness: '1', | ||
fuzziness: "1", | ||
max_expansions: 1, | ||
prefix_length: 3, | ||
rewrite: 'constant_score', | ||
transpositions: true, | ||
}, | ||
rewrite: "constant_score", | ||
transpositions: true | ||
} | ||
}) | ||
.add('must', 'regexp', { | ||
field: 'f', | ||
.add("must", "regexp", { | ||
field: "f", | ||
opts: { | ||
rewrite: 'constant_score', | ||
rewrite: "constant_score" | ||
}, | ||
params: { | ||
flags: 'ALL', | ||
value: 'qqqqq', | ||
}, | ||
flags: "ALL", | ||
value: "qqqqq" | ||
} | ||
}); | ||
@@ -177,10 +166,10 @@ | ||
f: { | ||
fuzziness: '1', | ||
fuzziness: "1", | ||
max_expansions: 1, | ||
prefix_length: 3, | ||
rewrite: 'constant_score', | ||
rewrite: "constant_score", | ||
transpositions: true, | ||
value: 'some text', | ||
}, | ||
}, | ||
value: "some text" | ||
} | ||
} | ||
}, | ||
@@ -190,24 +179,24 @@ { | ||
f: { | ||
flags: 'ALL', | ||
rewrite: 'constant_score', | ||
value: 'qqqqq', | ||
}, | ||
}, | ||
}, | ||
], | ||
}, | ||
flags: "ALL", | ||
rewrite: "constant_score", | ||
value: "qqqqq" | ||
} | ||
} | ||
} | ||
] | ||
} | ||
}); | ||
}); | ||
test('Setters', async () => { | ||
test("Setters", async () => { | ||
const testTerm = { | ||
params: { | ||
value: '11', | ||
value: "11" | ||
}, | ||
field: 'test', | ||
field: "test" | ||
}; | ||
const b = new Bool() | ||
.Filter('term', testTerm) | ||
.Should('term', testTerm) | ||
.Must('term', testTerm) | ||
.Must_Not('term', testTerm); | ||
.Filter("term", testTerm) | ||
.Should("term", testTerm) | ||
.Must("term", testTerm) | ||
.Must_Not("term", testTerm); | ||
@@ -219,7 +208,6 @@ expect(b.build()).toEqual({ | ||
term: { | ||
test: { | ||
value: '11', | ||
}, | ||
}, | ||
}, | ||
test: "11" | ||
} | ||
} | ||
], | ||
@@ -229,7 +217,6 @@ must: [ | ||
term: { | ||
test: { | ||
value: '11', | ||
}, | ||
}, | ||
}, | ||
test: "11" | ||
} | ||
} | ||
], | ||
@@ -239,7 +226,6 @@ must_not: [ | ||
term: { | ||
test: { | ||
value: '11', | ||
}, | ||
}, | ||
}, | ||
test: "11" | ||
} | ||
} | ||
], | ||
@@ -249,11 +235,10 @@ should: [ | ||
term: { | ||
test: { | ||
value: '11', | ||
}, | ||
}, | ||
}, | ||
], | ||
}, | ||
test: "11" | ||
} | ||
} | ||
] | ||
} | ||
}); | ||
}); | ||
}); |
@@ -68,5 +68,4 @@ import { Aggregation, Bool, Query } from '../../index'; | ||
term: { | ||
articul: { | ||
value: '111', | ||
}, | ||
articul: '111', | ||
}, | ||
@@ -73,0 +72,0 @@ }, |
@@ -33,2 +33,3 @@ import { TEXT } from '../../Builders/Text'; | ||
fuzzy_transpositions: true, | ||
max_expansions: 1, | ||
operator: 'AND', | ||
@@ -35,0 +36,0 @@ prefix_length: 15, |
@@ -8,2 +8,15 @@ import { AbstractBulder } from '../../Abstract/AbstractBuilder'; | ||
public add<Type extends keyof SCHEMA>(aggType: Type, name: string, d: SCHEMA[Type]) { | ||
const { filter, ...all } = d.params as { filter?: any }; | ||
if (filter) { | ||
this._data[name] = { | ||
filter, | ||
aggs: { | ||
[`${name}_filtered`]: { | ||
[aggType]: { ...(all as object), ...((d.opts as object) || {}) }, | ||
}, | ||
}, | ||
}; | ||
return this; | ||
} | ||
this._data[name] = { | ||
@@ -10,0 +23,0 @@ [aggType]: { ...(d.params as object), ...((d.opts as object) || {}) }, |
@@ -7,3 +7,3 @@ import { AbstractBulder } from '../../Abstract/AbstractBuilder'; | ||
export class Bool<BASE_SCHEMA extends BoolSchema= BoolSchema> extends AbstractBulder { | ||
export class Bool<BASE_SCHEMA extends BoolSchema = BoolSchema> extends AbstractBulder { | ||
private _query: BoolQueryData = {}; | ||
@@ -18,3 +18,3 @@ | ||
public Should<K extends keyof BASE_SCHEMA>(filter: K, data: BASE_SCHEMA[K]) { | ||
this.add('should', filter, data); | ||
this.add("should", filter, data); | ||
return this; | ||
@@ -24,3 +24,3 @@ } | ||
public Filter<K extends keyof BASE_SCHEMA>(filter: K, data: BASE_SCHEMA[K]) { | ||
this.add('filter', filter, data); | ||
this.add("filter", filter, data); | ||
return this; | ||
@@ -30,3 +30,3 @@ } | ||
public Must<K extends keyof BASE_SCHEMA>(filter: K, data: BASE_SCHEMA[K]) { | ||
this.add('must', filter, data); | ||
this.add("must", filter, data); | ||
return this; | ||
@@ -36,3 +36,3 @@ } | ||
public Must_Not<K extends keyof BASE_SCHEMA>(filter: K, data: BASE_SCHEMA[K]) { | ||
this.add('must_not', filter, data); | ||
this.add("must_not", filter, data); | ||
return this; | ||
@@ -72,12 +72,12 @@ } | ||
switch (filter) { | ||
case 'exists': { | ||
case "exists": { | ||
this._query[type]?.push({ | ||
[filter]: { field: (data.params as BASE_SCHEMA['exists']['params']).fieldName }, | ||
[filter]: { field: (data.params as BASE_SCHEMA["exists"]["params"]).fieldName } | ||
}); | ||
break; | ||
} | ||
case 'term': | ||
case 'terms': { | ||
case "term": | ||
case "terms": { | ||
this._query[type]?.push({ | ||
[filter]: { [data['field']!]: (data.params as object)['value'], ...(data.opts as object) }, | ||
[filter]: { [data["field"]!]: (data.params as object)["value"], ...(data.opts as object) } | ||
}); | ||
@@ -94,3 +94,3 @@ break; | ||
this._query[type]?.push({ | ||
[filter]: { [data['field']!]: payload }, | ||
[filter]: { [data["field"]!]: payload } | ||
}); | ||
@@ -97,0 +97,0 @@ } |
@@ -18,3 +18,3 @@ import { Schema } from '../../Abstract/Schema'; | ||
MinimumShouldMatch, | ||
ZeroTermsQuery, | ||
ZeroTermsQuery | ||
} from '../../Types/QueryOptions'; | ||
@@ -21,0 +21,0 @@ |
@@ -21,12 +21,12 @@ import { AbstractBulder } from '../..'; | ||
*/ | ||
public add<K extends keyof BASE_SCHEMA>(filter: K, data: BASE_SCHEMA[K]): Omit<this, 'add'> { | ||
public add<K extends keyof BASE_SCHEMA>(filter: K, data: BASE_SCHEMA[K]): Omit<this, "add"> { | ||
if (data.field) { | ||
this._query = { | ||
[filter]: { | ||
[data.field]: { ...(data.params as object), ...(data.opts as object) }, | ||
}, | ||
[data.field]: { ...(data.params as object), ...(data.opts as object) } | ||
} | ||
}; | ||
} else { | ||
this._query = { | ||
[filter]: { ...(data.params as object), ...(data.opts as object) }, | ||
[filter]: { ...(data.params as object), ...(data.opts as object) } | ||
}; | ||
@@ -33,0 +33,0 @@ } |
@@ -17,3 +17,3 @@ import { Schema } from '../../Abstract/Schema'; | ||
Fuzziness, | ||
FuzzyPrefixLength, | ||
FuzzyPrefixLength | ||
} from '../../Types/QueryOptions'; | ||
@@ -20,0 +20,0 @@ |
@@ -59,6 +59,6 @@ import { AbstractBulder } from '../Abstract/AbstractBuilder'; | ||
switch (prop) { | ||
case 'query': { | ||
case "query": { | ||
break; | ||
} | ||
case 'aggs': { | ||
case "aggs": { | ||
obj[prop] = (val as AbstractBulder).build(); | ||
@@ -74,3 +74,2 @@ break; | ||
for (const [prop, val] of Object.entries(this._query)) { | ||
console.log(prop); | ||
if (val instanceof AbstractBulder) { | ||
@@ -77,0 +76,0 @@ query = { ...query, ...(val as AbstractBulder).build() }; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
301031
2450