Security News
pnpm 10.0.0 Blocks Lifecycle Scripts by Default
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
es-mapping-to-schema
Advanced tools
This allows you to convert an elasticsearch mapping, defined in JSON into a schema that works with Schema Inspector.
3.2 - Fix bug preventing usage of 'type' or 'properties' as field names. May be a breaking change depending on previous use.
3.1 - Add ability to wildcard paths
3.0 - Completely changed the API and output. Now offers more options, and generates separate schemas for validation and sanitization. Previous version combined validation and sanitization into a single schema, with occasionally bad results.
npm install --save es-mapping-to-schema
Pass in the elasticsearch mapping and the options you want. It will return two schemas, one for validation, and one for sanitization.
const MappingToSchema = require('es-mapping-to-schema');
const mapping = {
properties: {
booleanThing: {
type: 'boolean'
},
selectors: {
properties: {
selector: {
properties: {
name: {
type: 'string'
},
value: {
type: 'string'
}
}
}
}
}
}
};
const expectedSchema = {
type: 'object',
properties: {
booleanThing: {
type: 'boolean'
},
selectors: {
type: 'array',
items: {
selector: {
type: 'object',
properties: {
name: {
type: 'string'
},
value: {
type: 'string'
}
}
}
}
}
}
};
// Explicity specify the types to be added to sanitization schema.
const schemas = MappingToSchema(mapping, {
arrayPaths: [
'selectors'
],
sanitization: {
all: {
types: [
'object',
'string',
'integer',
'number',
'array',
'boolean',
'date'
]
}
}
});
expect(schemas.validation).to.eql(expectedSchema);
expect(schemas.sanitization).to.eql(expectedSchema);
const Options = {
// Do not display warnings when an unknown type is encountered
disableWarnings: false,
// 'arrayPaths' are used to define properties in the mapping that appear as objects but should be validated as arrays
// This is because elasticsearch does not explicitly support arrays, but schema inspector does
arrayPaths: [],
// These are the rules and options that will apply only to validation schema generation
validation: {
// 'all' fields are applied recursively to all appropriate fields
// Currently supports 'strict' and 'optional' for validation
all: {
strict: false,
optional: false
},
// 'paths' are specific path overrides.
// For 'paths', any field, value, and path combination is allowed
// In this case field 'pattern' is applied with value '/must be this/' to property 'path.to.some.property'
paths: {
pattern: [
{
path: 'path.to.some.property',
value: /must be this/
}
]
}
},
// These are the rules and options that will apply only to sanitization schema generation
sanitization: {
// 'all' fields are applied recursively to all appropriate fields.
// Currently supports 'strict', 'rules', and 'maxLength' for sanitization.
// The 'types' field is special, in that you must explicitly list the types you want to sanitize
// otherwise none will sanitized.
all: {
strict: false,
rules: [],
maxLength: 10,
types: []
},
// 'paths' are specific path overrides.
// For 'paths', any field, value, and path combination is allowed
// In this case field 'def' is applied with value 'default to this' to property 'path.to.some.property'
paths: {
def: [
{
path: 'path.to.some.property',
value: 'default to this'
},
{
path: 'path.to.all.properties.*',
value: 'default to this'
}
]
}
}
};
FAQs
Convert Elasticsearch mappings to Schema Inspector schemas
We found that es-mapping-to-schema demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
Product
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.
Research
Security News
Socket researchers have discovered multiple malicious npm packages targeting Solana private keys, abusing Gmail to exfiltrate the data and drain Solana wallets.