Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

es-mapping-to-schema

Package Overview
Dependencies
Maintainers
1
Versions
34
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

es-mapping-to-schema - npm Package Compare versions

Comparing version 3.3.2 to 3.3.3

21

gulpfile.js

@@ -8,4 +8,10 @@ /*eslint no-process-env: "off"*/

const coveralls = require('gulp-coveralls');
const gulpIf = require('gulp-if');
gulp.task('test:dirty', ()=> {
const isFixed = (file) => {
// Has ESLint fixed the file contents?
return file.eslint != null && file.eslint.fixed;
};
gulp.task('test:dirty', () => {
return gulp.src('test.js')

@@ -15,3 +21,3 @@ .pipe(mocha({reporter: 'spec'}));

gulp.task('pre-test', ()=> {
gulp.task('pre-test', () => {
return gulp.src([

@@ -25,3 +31,3 @@ 'index.js',

gulp.task('test:coverage', ['pre-test'], ()=> {
gulp.task('test:coverage', ['pre-test'], () => {
return gulp.src(['test.js'])

@@ -43,3 +49,3 @@ .pipe(mocha({reporter: 'spec'}))

const lint = ()=> {
const lint = () => {
return gulp.src([

@@ -58,10 +64,13 @@ '**/*.js',

process.exit(1);
}).pipe(gulpIf(isFixed, gulp.dest('.')))
.once('end', () => {
process.exit();
});
};
gulp.task('test:lint', ['test:coverage'], ()=> {
gulp.task('test:lint', ['test:coverage'], () => {
return lint();
});
gulp.task('lint', ()=> {
gulp.task('lint', () => {
return lint();

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

@@ -24,6 +24,6 @@ const _ = require('lodash');

nextOptions[schemaType].paths = nextPaths(nextOptions[schemaType].paths);
nextOptions.arrayPaths = shortenArrayPaths(nextOptions.arrayPaths);
nextOptions.arrayPaths = shortenArrayPaths(nextOptions.arrayPaths);
const nextLocalOptions = getLocalOptions(options[schemaType].paths, name);
nextOptions.isArray = _.includes(options.arrayPaths, name);
nextOptions.isArray = _.includes(options.arrayPaths, name);

@@ -43,3 +43,3 @@ schema[name] = determineType(mapping[name], {}, schemaType, nextOptions);

if (options.isArray) {
schema.items = {};
schema.items = {};
schema.items.type = determineType(mapping, {}, schemaType, Object.assign({}, options, {isArray: false})).type;

@@ -104,3 +104,3 @@

const getLocalOptions = (currentPathObjects, name) => _.reduce(currentPathObjects, (result, currentPathObject, field) => {
_.forEach(currentPathObject, specificPath => {
_.forEach(currentPathObject, (specificPath) => {
if (specificPath.path === name || specificPath.path === '*') {

@@ -121,3 +121,3 @@ result[field] = specificPath.value;

const nextPaths = currentPathObjects => _.reduce(currentPathObjects, (result, currentPathObject, field) => {
const nextPaths = (currentPathObjects) => _.reduce(currentPathObjects, (result, currentPathObject, field) => {
result[field] = shortenPaths(currentPathObject);

@@ -127,3 +127,3 @@ return result;

const shortenPaths = currentPaths => _.reduce(currentPaths, (result, currentPath) => {
const shortenPaths = (currentPaths) => _.reduce(currentPaths, (result, currentPath) => {
const nextPath = _.join(_.drop(_.split(currentPath.path, '.'), 1), '.');

@@ -139,3 +139,3 @@ if (nextPath.length > 0) {

const shortenArrayPaths = currentPaths => _.reduce(currentPaths, (result, currentPath) => {
const shortenArrayPaths = (currentPaths) => _.reduce(currentPaths, (result, currentPath) => {
const nextPath = _.join(_.drop(_.split(currentPath, '.'), 1), '.');

@@ -150,3 +150,3 @@ if (nextPath.length > 0) {

if (!_.isString(mapping.type) && !_.isObject(mapping.properties)) {
throw new Error(`root of mapping must have 'type' or 'properties' fields`);
throw new Error('root of mapping must have \'type\' or \'properties\' fields');
}

@@ -174,16 +174,16 @@

switch (type) {
case 'nested':
return isArray ? 'array' : 'object';
case 'double':
case 'float':
return 'number';
case 'long':
case 'short':
case 'byte':
return 'integer';
case undefined:
return null;
default:
console.warn(`mapping type: ${_.isObject(type) ? JSON.stringify(type, null, 2) : type} is unsupported and will be ignored`);
return null;
case 'nested':
return isArray ? 'array' : 'object';
case 'double':
case 'float':
return 'number';
case 'long':
case 'short':
case 'byte':
return 'integer';
case undefined:
return null;
default:
console.warn(`mapping type: ${_.isObject(type) ? JSON.stringify(type, null, 2) : type} is unsupported and will be ignored`);
return null;
}

@@ -194,5 +194,5 @@ }

const DEFAULTS = {
arrayPaths: [],
validation: {
all: {
arrayPaths: [],
validation: {
all: {
strict: false,

@@ -204,3 +204,3 @@ optional: false

sanitization: {
all: {
all: {
strict: false

@@ -212,6 +212,6 @@ },

MappingToSchema.__pickPaths = pickPaths;
MappingToSchema.__nextPaths = nextPaths;
MappingToSchema.__pickPaths = pickPaths;
MappingToSchema.__nextPaths = nextPaths;
MappingToSchema.__getLocalOptions = getLocalOptions;
module.exports = MappingToSchema;

@@ -8,3 +8,3 @@ const _ = require('lodash');

properties: {
arrayPaths: {
arrayPaths: {
optional: true,

@@ -16,3 +16,3 @@ type: 'array',

},
validation: {
validation: {
optional: true,

@@ -22,7 +22,7 @@ type: 'object',

properties: {
all: {
all: {
optional: true,
type: 'object',
properties: {
strict: {
strict: {
optional: true,

@@ -46,3 +46,3 @@ type: 'boolean'

properties: {
path: {
path: {
type: 'string'

@@ -65,3 +65,3 @@ },

properties: {
all: {
all: {
optional: true,

@@ -71,7 +71,7 @@ type: 'object',

properties: {
strict: {
strict: {
optional: true,
type: 'boolean'
},
rules: {
rules: {
optional: true,

@@ -85,3 +85,3 @@ type: 'array'

},
types: {
types: {
optional: true,

@@ -104,3 +104,3 @@ type: 'array',

properties: {
path: {
path: {
type: 'string'

@@ -123,3 +123,3 @@ },

const self = this;
params = _.cloneDeep(params);
params = _.cloneDeep(params);

@@ -126,0 +126,0 @@ const result = inspector.validate(VALIDATION_SCHEMA, params);

{
"name": "es-mapping-to-schema",
"version": "3.3.2",
"version": "3.3.3",
"description": "Convert Elasticsearch mappings to Schema Inspector schemas",

@@ -41,2 +41,3 @@ "main": "index.js",

"gulp-eslint": "^2.0.0",
"gulp-if": "^2.0.1",
"gulp-istanbul": "^0.10.4",

@@ -43,0 +44,0 @@ "gulp-mocha": "^2.2.0",

@@ -1,2 +0,2 @@

[![Coverage Status](https://coveralls.io/repos/github/groupby/es-mapping-to-schema/badge.svg?branch=master)](https://coveralls.io/github/groupby/es-mapping-to-schema?branch=master) [![CircleCI](https://circleci.com/gh/groupby/es-mapping-to-schema.svg?style=svg)](https://circleci.com/gh/groupby/es-mapping-to-schema)
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/637529966f1248808adb9fa263e98385)](https://www.codacy.com/app/GroupByInc/es-mapping-to-schema?utm_source=github.com&utm_medium=referral&utm_content=groupby/es-mapping-to-schema&utm_campaign=Badge_Grade) [![Coverage Status](https://coveralls.io/repos/github/groupby/es-mapping-to-schema/badge.svg?branch=master)](https://coveralls.io/github/groupby/es-mapping-to-schema?branch=master) [![CircleCI](https://circleci.com/gh/groupby/es-mapping-to-schema.svg?style=svg)](https://circleci.com/gh/groupby/es-mapping-to-schema)

@@ -3,0 +3,0 @@ ## Elasticsearch Mapping to Schema Inspector schema

@@ -7,31 +7,31 @@ const chai = require('chai');

describe('es-mapping-to-schema tests', ()=> {
describe('es-mapping-to-schema tests', () => {
it('should convert a mapping into a validation and sanitization schemas', () => {
const mapping = {
_all: {
_all: {
enabled: false
},
properties: {
booleanThing: {
booleanThing: {
type: 'boolean'
},
stringThing: {
stringThing: {
type: 'string'
},
integerThing: {
integerThing: {
type: 'integer'
},
longThing: {
longThing: {
type: 'long'
},
shortThing: {
shortThing: {
type: 'short'
},
byteThing: {
byteThing: {
type: 'byte'
},
floatThing: {
floatThing: {
type: 'float'
},
doubleThing: {
doubleThing: {
type: 'double'

@@ -43,6 +43,6 @@ },

},
variousTerm: {
variousTerm: {
type: 'string',
fields: {
raw: {
raw: {
type: 'string',

@@ -52,7 +52,7 @@ index: 'not_analyzed',

},
normalized: {
normalized: {
type: 'string',
analyzer: 'facet_analyzer'
},
lang_en: {
lang_en: {
type: 'string',

@@ -67,3 +67,3 @@ analyzer: 'english'

},
customer: {
customer: {
type: 'object',

@@ -75,7 +75,7 @@ properties: {

},
projectId: {
projectId: {
type: 'string',
index: 'not_analyzed'
},
localTime: {
localTime: {
type: 'date',

@@ -86,3 +86,3 @@ format: 'dateOptionalTime'

},
selectors: {
selectors: {
type: 'nested',

@@ -93,6 +93,6 @@ include_in_parent: true,

properties: {
name: {
name: {
type: 'string',
fields: {
raw: {
raw: {
type: 'string',

@@ -128,24 +128,24 @@ index: 'not_analyzed',

properties: {
booleanThing: {
booleanThing: {
type: 'boolean'
},
stringThing: {
stringThing: {
type: 'string'
},
integerThing: {
integerThing: {
type: 'integer'
},
longThing: {
longThing: {
type: 'integer'
},
shortThing: {
shortThing: {
type: 'integer'
},
byteThing: {
byteThing: {
type: 'integer'
},
floatThing: {
floatThing: {
type: 'number'
},
doubleThing: {
doubleThing: {
type: 'number'

@@ -156,6 +156,6 @@ },

},
variousTerm: {
variousTerm: {
type: 'string'
},
customer: {
customer: {
type: 'object',

@@ -166,6 +166,6 @@ properties: {

},
projectId: {
projectId: {
type: 'string'
},
localTime: {
localTime: {
type: 'date'

@@ -175,3 +175,3 @@ }

},
selectors: {
selectors: {
type: 'object',

@@ -182,3 +182,3 @@ properties: {

properties: {
name: {
name: {
type: 'string'

@@ -218,3 +218,3 @@ },

it('should convert a mapping with an array non-objects', ()=> {
it('should convert a mapping with an array non-objects', () => {
const mapping = {

@@ -225,5 +225,5 @@ properties: {

},
selectors: {
selectors: {
properties: {
name: {
name: {
type: 'string'

@@ -246,3 +246,3 @@ },

},
selectors: {
selectors: {
type: 'array',

@@ -253,3 +253,3 @@ items: {

properties: {
name: {
name: {
type: 'string'

@@ -267,3 +267,3 @@ },

const schemas = MappingToSchema(mapping, {
arrayPaths: [
arrayPaths: [
'selectors'

@@ -285,3 +285,3 @@ ],

},
validation: {
validation: {
all: {

@@ -328,7 +328,7 @@ strict: true

},
selectors: {
selectors: {
properties: {
selector: {
properties: {
name: {
name: {
type: 'string'

@@ -353,3 +353,3 @@ },

},
selectors: {
selectors: {
type: 'array',

@@ -364,3 +364,3 @@ items: {

properties: {
name: {
name: {
type: 'string'

@@ -380,3 +380,3 @@ },

const schemas = MappingToSchema(mapping, {
arrayPaths: [
arrayPaths: [
'selectors'

@@ -398,3 +398,3 @@ ],

},
validation: {
validation: {
all: {

@@ -431,3 +431,3 @@ strict: true

},
extra: 'this'
extra: 'this'
}

@@ -446,7 +446,7 @@ ]

},
selectors: {
selectors: {
properties: {
selector: {
properties: {
name: {
name: {
type: 'string'

@@ -470,3 +470,3 @@ },

},
selectors: {
selectors: {
type: 'object',

@@ -477,3 +477,3 @@ properties: {

properties: {
name: {
name: {
type: 'string',

@@ -494,3 +494,3 @@ optional: true

const schemas = MappingToSchema(mapping, {
validation: {
validation: {
paths: {

@@ -510,3 +510,3 @@ optional: [

sanitization: {
all: {
all: {
types: [

@@ -547,7 +547,7 @@ 'object',

},
selectors: {
selectors: {
properties: {
selector: {
properties: {
name: {
name: {
type: 'string'

@@ -572,3 +572,3 @@ },

},
selectors: {
selectors: {
type: 'object',

@@ -581,3 +581,3 @@ strict: true,

properties: {
name: {
name: {
type: 'string'

@@ -596,3 +596,3 @@ },

const schemas = MappingToSchema(mapping, {
validation: {
validation: {
all: {

@@ -628,7 +628,7 @@ strict: true

},
selectors: {
selectors: {
properties: {
selector: {
properties: {
name: {
name: {
type: 'string'

@@ -652,3 +652,3 @@ },

},
selectors: {
selectors: {
type: 'object',

@@ -660,3 +660,3 @@ strict: true,

properties: {
name: {
name: {
type: 'string'

@@ -675,3 +675,3 @@ },

const schemas = MappingToSchema(mapping, {
validation: {
validation: {
paths: {

@@ -687,3 +687,3 @@ strict: [

sanitization: {
all: {
all: {
types: [

@@ -720,7 +720,7 @@ 'object',

},
selectors: {
selectors: {
properties: {
selector: {
properties: {
name: {
name: {
type: 'string'

@@ -745,3 +745,3 @@ },

},
selectors: {
selectors: {
type: 'object',

@@ -755,3 +755,3 @@ strict: true,

properties: {
name: {
name: {
type: 'string'

@@ -770,4 +770,4 @@ },

const schemas = MappingToSchema(mapping, {
validation: {
all: {
validation: {
all: {
strict: true

@@ -785,3 +785,3 @@ },

sanitization: {
all: {
all: {
strict: true,

@@ -819,7 +819,7 @@ types: [

},
selectors: {
selectors: {
properties: {
selector: {
properties: {
name: {
name: {
type: 'string'

@@ -843,3 +843,3 @@ },

},
selectors: {
selectors: {
type: 'object',

@@ -850,3 +850,3 @@ properties: {

properties: {
name: {
name: {
type: 'string'

@@ -870,3 +870,3 @@ },

},
selectors: {
selectors: {
type: 'object',

@@ -877,3 +877,3 @@ properties: {

properties: {
name: {
name: {
type: 'string',

@@ -925,3 +925,3 @@ rules: [

const paths = {
def: [
def: [
{

@@ -951,3 +951,3 @@ path: 'something.yo.this',

expect(shortenedPaths).to.eql({
def: [
def: [
{

@@ -971,5 +971,5 @@ path: 'yo.this',

it('should return the options applicable to a specific field', ()=> {
it('should return the options applicable to a specific field', () => {
const paths = {
def: [
def: [
{

@@ -1000,3 +1000,3 @@ path: 'something.yo.this',

it('should produce a schemas with empty objects for every property if nothing else is needed', ()=> {
it('should produce a schemas with empty objects for every property if nothing else is needed', () => {
const mapping = {

@@ -1007,7 +1007,7 @@ properties: {

},
selectors: {
selectors: {
properties: {
selector: {
properties: {
name: {
name: {
type: 'string'

@@ -1031,3 +1031,3 @@ },

},
selectors: {
selectors: {
type: 'object',

@@ -1038,3 +1038,3 @@ properties: {

properties: {
name: {
name: {
type: 'string'

@@ -1074,3 +1074,3 @@ },

it('should throw if the root object does not have a type or properties field', ()=> {
it('should throw if the root object does not have a type or properties field', () => {
const mapping = {

@@ -1085,6 +1085,6 @@ thing: {

it('should handle mappings with properties named "type" or "properties"', ()=> {
it('should handle mappings with properties named "type" or "properties"', () => {
const mapping = {
properties: {
type: {
type: {
type: 'string'

@@ -1095,3 +1095,3 @@ },

},
notType: {
notType: {
type: 'string'

@@ -1105,3 +1105,3 @@ }

properties: {
type: {
type: {
type: 'string'

@@ -1112,3 +1112,3 @@ },

},
notType: {
notType: {
type: 'string'

@@ -1133,3 +1133,3 @@ }

it('should apply path value to wildcarded path', ()=> {
it('should apply path value to wildcarded path', () => {
const mapping = {

@@ -1140,5 +1140,5 @@ properties: {

},
selectors: {
selectors: {
properties: {
name: {
name: {
type: 'string'

@@ -1167,6 +1167,6 @@ },

},
selectors: {
selectors: {
type: 'object',
properties: {
name: {
name: {
something: 'wildcard',

@@ -1187,3 +1187,3 @@ type: 'string'

},
type: 'object'
type: 'object'
}

@@ -1194,3 +1194,3 @@ }

const schemas = MappingToSchema(mapping, {
validation: {
validation: {
paths: {

@@ -1206,3 +1206,3 @@ something: [

sanitization: {
all: {
all: {
types: [

@@ -1235,3 +1235,3 @@ 'object',

const paths = {
strict: [
strict: [
{

@@ -1267,3 +1267,3 @@ path: 'selectors.something',

const expectedPicked = {
strict: [
strict: [
{

@@ -1309,3 +1309,3 @@ path: 'selectors.something',

const schemas = MappingToSchema(mapping, {
arrayPaths: [
arrayPaths: [
'arrayOfStrings'

@@ -1366,3 +1366,3 @@ ],

properties: {
someValue: {
someValue: {
type: 'integer'

@@ -1373,3 +1373,3 @@ },

},
deeper: {
deeper: {
properties: {

@@ -1379,3 +1379,3 @@ anotherString: {

},
aNumber: {
aNumber: {
type: 'double'

@@ -1391,3 +1391,3 @@ }

properties: {
someValue: {
someValue: {
type: 'integer'

@@ -1401,3 +1401,3 @@ },

},
deeper: {
deeper: {
type: 'object',

@@ -1411,3 +1411,3 @@ properties: {

},
aNumber: {
aNumber: {
type: 'number'

@@ -1414,0 +1414,0 @@ }

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc