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.3 to 3.3.4

13

gulpfile.js
/*eslint no-process-env: "off"*/
const path = require('path');
const gulp = require('gulp');

@@ -7,3 +6,2 @@ const mocha = require('gulp-mocha');

const istanbul = require('gulp-istanbul');
const coveralls = require('gulp-coveralls');
const gulpIf = require('gulp-if');

@@ -75,11 +73,2 @@

gulp.task('test', ['test:lint']);
gulp.task('coveralls', ['test'], () => {
if (!process.env.CI) {
return;
}
return gulp.src(path.join(__dirname, 'coverage/lcov.info'))
.pipe(coveralls());
});
gulp.task('test', ['test:lint']);

15

index.js

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

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

@@ -84,3 +83,3 @@ if (mapping.properties) {

if (options[schemaType].all.maxLength && mapping.type === 'string') {
if (options[schemaType].all.maxLength && mapping.type === 'string' && schema.type !== 'array') {
schema.maxLength = options[schemaType].all.maxLength;

@@ -91,3 +90,3 @@ }

// because schema.type may not be populated if we don't want type coercion
if (options[schemaType].all.rules && mapping.type === 'string') {
if (options[schemaType].all.rules && mapping.type === 'string' && schema.type !== 'array') {
schema.rules = options[schemaType].all.rules;

@@ -99,2 +98,10 @@ }

schema.type = type;
if (options[schemaType].all.minLength && mapping.type === 'string' && schema.type !== 'array') {
schema.minLength = options[schemaType].all.minLength;
}
if (options[schemaType].all.maxLength && mapping.type === 'string' && schema.type !== 'array') {
schema.maxLength = options[schemaType].all.maxLength;
}
}

@@ -101,0 +108,0 @@

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

type: 'boolean'
},
minLength: {
optional: true,
type: 'integer'
}

@@ -33,0 +37,0 @@ }

{
"name": "es-mapping-to-schema",
"version": "3.3.3",
"version": "3.3.4",
"description": "Convert Elasticsearch mappings to Schema Inspector schemas",
"main": "index.js",
"scripts": {
"test": "mocha test.js",
"patch": "npm version patch && git push && git push --tags && npm publish",
"minor": "npm version minor && git push && git push --tags && npm publish",
"major": "npm version major && git push && git push --tags && npm publish"
"test": "gulp test",
"coverage:codacy": "cat ./coverage/lcov.info | codacy-coverage"
},

@@ -37,2 +35,3 @@ "repository": {

"chai": "^3.5.0",
"codacy-coverage": "^2.0.0",
"coveralls": "^2.11.11",

@@ -39,0 +38,0 @@ "gulp": "^3.9.1",

@@ -1366,2 +1366,135 @@ const chai = require('chai');

});
it('should nest sanitization in array', () => {
const mapping = {
properties: {
someString: {
type: 'string'
}
}
};
const expectedSchema = {
type: 'object',
properties: {
someString: {
type: 'array',
items: {
type: 'string',
rules: [
'trim',
'lower'
]
}
}
}
};
const schemas = MappingToSchema(mapping, {
arrayPaths: [
'someString'
],
sanitization: {
all: {
types: [
'object',
'integer',
'string',
'number',
'array',
'boolean',
'date'
],
rules: [
'trim',
'lower'
]
}
}
});
expect(schemas.sanitization).to.eql(expectedSchema);
});
it('should nest validation in array', () => {
const mapping = {
properties: {
someString: {
type: 'string'
}
}
};
const expectedSchema = {
type: 'object',
properties: {
someString: {
type: 'array',
items: {
type: 'string'
}
}
}
};
const schemas = MappingToSchema(mapping, {
arrayPaths: [
'someString'
],
validation: {
all: {
types: [
'object',
'integer',
'string',
'number',
'array',
'boolean',
'date'
]
}
}
});
expect(schemas.validation).to.eql(expectedSchema);
});
it('should apply minLength validation', () => {
const mapping = {
properties: {
someString: {
type: 'string'
}
}
};
const expectedSchema = {
type: 'object',
properties: {
someString: {
type: 'string',
minLength: 1
}
}
};
const schemas = MappingToSchema(mapping, {
validation: {
all: {
minLength: 1,
types: [
'object',
'integer',
'string',
'number',
'array',
'boolean',
'date'
]
}
}
});
expect(schemas.validation).to.eql(expectedSchema);
});
});

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