You're Invited: Meet the Socket team at BSidesSF and RSAC - April 27 - May 1.RSVP

es-alchemy

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

es-alchemy - npm Package Compare versions

Comparing version

to
8.1.0

@@ -74,3 +74,3 @@ "use strict";

},
rest: rest(idx => get(indices[idx], 'fields', null), idx => get(indices[idx], 'rels', null), idx => get(indices[idx], 'mapping', null), versions, options)
rest: rest(idx => get(indices[idx], 'fields', null), idx => get(indices[idx], 'rels', null), idx => get(indices[idx], 'mapping', null), idx => get(indices[idx], 'specs', null), models, versions, options)
};

@@ -77,0 +77,0 @@ };

"use strict";
const mkFn = result => (...args) => args.reduce((prev, arg) => ({ ...prev,
...arg
}), result);
const identity = v => v;
const mkFn = (def, meta = {
marshall: identity,
unmarshall: identity
}) => {
const r = (...args) => args.reduce((prev, arg) => ({ ...prev,
...arg
}), def);
r.meta = meta;
return r;
};
module.exports = {

@@ -29,6 +39,35 @@ date: mkFn({

type: 'geo_point'
}, {
marshall: v => v ? [v[0], v[1]] : null,
unmarshall: identity
}),
shape: mkFn({
type: 'geo_shape'
}, {
marshall: v => v ? {
type: 'Polygon',
coordinates: [v]
} : null,
unmarshall: v => v !== null ? v.coordinates[0] : null
}),
polygon: mkFn({
type: 'geo_shape'
}, {
marshall: v => v ? {
type: 'Polygon',
coordinates: v
} : null,
unmarshall: v => v !== null ? v.coordinates : null
}),
polygons: mkFn({
type: 'geo_shape'
}, {
marshall: vs => vs ? vs.map(v => ({
type: 'Polygon',
coordinates: v
})) : null,
unmarshall: vs => vs !== null ? vs.map(({
coordinates
}) => coordinates) : null
}),
datetime: mkFn({

@@ -47,3 +86,6 @@ type: 'date',

enabled: false
}, {
marshall: v => [v],
unmarshall: v => v[0]
})
};

@@ -6,3 +6,3 @@ "use strict";

const fieldRemap = require('../resources/field-remap');
const fieldDefinitions = require('../resources/field-definitions');

@@ -25,3 +25,3 @@ const {

.map(field => typeof field === 'string' ? field : field.name).map(field => [field, origin[field]]).filter(kv => kv[1] !== undefined).reduce((prev, [key, value]) => Object.assign(prev, {
[key]: fieldRemap[fieldTypes[key].endsWith('[]') ? fieldTypes[key].slice(0, -2) : fieldTypes[key]](value)
[key]: fieldDefinitions[fieldTypes[key].endsWith('[]') ? fieldTypes[key].slice(0, -2) : fieldTypes[key]].meta.marshall(value)
}), entry);

@@ -28,0 +28,0 @@ Object.entries(specs.nested || {}) // handle nested

@@ -13,5 +13,5 @@ "use strict";

const resultRemap = require('../../../resources/result-remap');
const fieldDefinitions = require('../../../resources/field-definitions');
module.exports = (call, idx, rels, mapping, filter) => call('GET', idx, {
module.exports = (call, idx, rels, specs, models, filter) => call('GET', idx, {
body: (() => {

@@ -35,4 +35,17 @@ // PART 1: workaround for https://github.com/elastic/elasticsearch/issues/23796

// eslint-disable-next-line no-underscore-dangle
const resultRemaps = filter._source.map(f => [f, get(mapping, `mappings.properties.${f.split('.').join('.properties.')}.type`)]).filter(f => f[1] !== undefined).reduce((p, [field, fieldMapping]) => Object.assign(p, {
[field]: e => resultRemap[fieldMapping](e)
const resultRemaps = filter._source.map(f => {
if (specs === null || f === '_id' || f === '') {
return [f, undefined];
}
const pth = f.split('.');
const name = pth.pop();
const model = pth.length === 0 ? specs.model : get(specs, `nested.${pth.join('.nested.')}`).model;
const type = models[model.endsWith('[]') ? model.slice(0, -2) : model].specs.fields[name];
const {
meta
} = fieldDefinitions[type.endsWith('[]') ? type.slice(0, -2) : type];
return [f, meta];
}).filter(f => f[1] !== undefined).reduce((p, [field, meta]) => Object.assign(p, {
[field]: e => meta.unmarshall(e)
}), {});

@@ -39,0 +52,0 @@

@@ -55,3 +55,3 @@ "use strict";

module.exports = (getFields, getRels, getMapping, versions, options) => {
module.exports = (getFields, getRels, getMapping, getSpecs, models, versions, options) => {
const call = (method, idx, {

@@ -119,3 +119,3 @@ endpoint = '',

exists: (idx, id) => dataExists(call, idx, id),
query: (idx, filter) => dataQuery(call, idx, getRels(idx), getMapping(idx), filter),
query: (idx, filter) => dataQuery(call, idx, getRels(idx), getSpecs(idx), models, filter),
refresh: idx => dataRefresh(call, idx),

@@ -122,0 +122,0 @@ signature: (idx, id) => dataSignature(call, idx, getMapping(idx), id),

{
"name": "es-alchemy",
"version": "8.0.1",
"version": "8.1.0",
"description": "Simplification of Elasticsearch interactions",

@@ -5,0 +5,0 @@ "main": "lib/index.js",