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

d2l-lms-launch-darkly-feature-converter-plugin

Package Overview
Dependencies
Maintainers
1
Versions
40
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

d2l-lms-launch-darkly-feature-converter-plugin - npm Package Compare versions

Comparing version 0.7.0 to 0.8.0

schemas/instance-multivariate/v2_0.json

2

package.json
{
"name": "d2l-lms-launch-darkly-feature-converter-plugin",
"version": "0.7.0",
"version": "0.8.0",
"description": "",

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

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

const instanceMultivariateSchemaV1_1 = require( '../schemas/instance-multivariate/v1_1.json' );
const instanceMultivariateSchemaV2_0 = require( '../schemas/instance-multivariate/v2_0.json' );

@@ -29,2 +30,3 @@ const orgBooleanSchemaV1_0 = require( '../schemas/org-boolean/v1_0.json' );

const orgMultivariateSchemaV1_1 = require( '../schemas/org-multivariate/v1_1.json' );
const orgMultivariateSchemaV2_0 = require( '../schemas/org-multivariate/v2_0.json' );

@@ -77,3 +79,4 @@ const booleanFeatureKind = 'boolean';

instanceMultivariateSchemaV1_0,
instanceMultivariateSchemaV1_1
instanceMultivariateSchemaV1_1,
instanceMultivariateSchemaV2_0
] ),

@@ -100,3 +103,4 @@ multiVariationMapper,

orgMultivariateSchemaV1_0,
orgMultivariateSchemaV1_1
orgMultivariateSchemaV1_1,
orgMultivariateSchemaV2_0
] ),

@@ -103,0 +107,0 @@ multiVariationMapper,

const _ = require( 'lodash' );
const duplicatesDeep = require( '../utils.js' ).duplicatesDeep;
const VariationIndexMap = require( './VariationIndexMap.js' );
module.exports = class MultiVariationMapper {
function validateAllSameType( values ) {
mapVariations( definition ) {
let valueType;
let valueType;
const indexes = {};
const variations = [];
_.forEach( values, value => {
let index = 0;
if( _.isUndefined( valueType ) ) {
valueType = typeof ( value );
_.forIn( definition, ( variation, key ) => {
indexes[key] = index;
} else if( valueType !== typeof ( value ) ) {
throw new Error( 'Variation values must all be of the same type' );
}
} );
}
if( _.isUndefined( valueType ) ) {
valueType = typeof( variation.value );
function mapVariation( variation ) {
} else if( valueType !== typeof( variation.value ) ) {
throw new Error( 'Variation values must all be of the same type' );
}
const mappedVariation = _.pick( variation, [
'name',
'description',
'value'
] );
const mappedVariation = _.pick( variation, [
'name',
'description',
'value'
] );
return mappedVariation;
}
variations.push( mappedVariation );
index++;
} );
function mapVariationsFromObject( definition ) {
return {
indexes: new VariationIndexMap( indexes ),
variations
};
const allValues = _.map( _.values( definition ), d => d.value );
validateAllSameType( allValues );
const duplicateValues = duplicatesDeep( allValues );
if( duplicateValues.length > 0 ) {
const msg = `Duplicate variation values: ${ _.join( duplicateValues, ', ' ) }`;
throw new Error( msg );
}
const indexes = {};
const variations = [];
let index = 0;
_.forIn( definition, ( variation, key ) => {
indexes[ key ] = index;
const mappedVariation = mapVariation( variation );
variations.push( mappedVariation );
index++;
} );
return {
indexes: new VariationIndexMap( indexes ),
variations
};
}
function mapVariationsFromArray( definition ) {
const duplicateKeys = duplicatesDeep(
_.map( definition, d => d.key )
);
if( duplicateKeys.length > 0 ) {
const msg = `Duplicate variation keys: ${ _.join( duplicateKeys, ', ' ) }`;
throw new Error( msg );
}
const allValues = _.map( definition, d => d.value );
validateAllSameType( allValues );
const duplicateValues = duplicatesDeep( allValues );
if( duplicateValues.length > 0 ) {
const msg = `Duplicate variation values: ${ _.join( duplicateValues, ', ' ) }`;
throw new Error( msg );
}
const indexes = {};
const variations = [];
definition.forEach( ( variation, index ) => {
indexes[ variation.key ] = index;
const mappedVariation = mapVariation( variation );
variations.push( mappedVariation );
} );
return {
indexes: new VariationIndexMap( indexes ),
variations
};
}
module.exports = class MultiVariationMapper {
mapVariations( definition ) {
if( _.isArray( definition ) ) {
return mapVariationsFromArray( definition );
}
return mapVariationsFromObject( definition );
}
};

@@ -9,127 +9,324 @@ const assert = require( 'chai' ).assert;

it( 'should map variations', function() {
describe( 'object definition', function() {
it( 'should map variations', function() {
const result = mapper.mapVariations( {
red: {
name: 'Red',
description: 'Things are on fire',
value: 0
},
green: {
name: 'Green',
description: 'Things are all ok',
value: 1
},
blue: {
name: 'Blue',
description: 'Things are unknown',
value: 2
}
const result = mapper.mapVariations( {
red: {
name: 'Red',
description: 'Things are on fire',
value: 0
},
green: {
name: 'Green',
description: 'Things are all ok',
value: 1
},
blue: {
name: 'Blue',
description: 'Things are unknown',
value: 2
}
} );
assert.equal(
result.indexes.getIndex( 'red' ),
0,
'red should map to index 0'
);
assert.equal(
result.indexes.getIndex( 'green' ),
1,
'green should map to index 1'
);
assert.equal(
result.indexes.getIndex( 'blue' ),
2,
'blue should map to index 2'
);
assert.deepEqual( result.variations, [
{
name: 'Red',
description: 'Things are on fire',
value: 0
},
{
name: 'Green',
description: 'Things are all ok',
value: 1
},
{
name: 'Blue',
description: 'Things are unknown',
value: 2
}
] );
} );
assert.equal(
result.indexes.getIndex( 'red' ),
0,
'red should map to index 0'
);
it( 'should throw if value types mismatch', function() {
assert.equal(
result.indexes.getIndex( 'green' ),
1,
'green should map to index 1'
);
assert.throws(
() => {
mapper.mapVariations( {
off: {
name: 'Off',
description: 'The switch is off',
value: false
},
on: {
name: 'On',
description: 'The switch is on',
value: 'on'
}
} );
},
/Variation values must all be of the same type/
);
assert.equal(
result.indexes.getIndex( 'blue' ),
2,
'blue should map to index 2'
);
} );
assert.deepEqual( result.variations, [
{
name: 'Red',
description: 'Things are on fire',
value: 0
},
{
name: 'Green',
description: 'Things are all ok',
value: 1
},
{
name: 'Blue',
description: 'Things are unknown',
value: 2
}
] );
} );
it( 'should map just values', function() {
it( 'should throw if value types mismatch', function() {
const result = mapper.mapVariations( {
red: {
value: 0
},
green: {
value: 1
},
blue: {
value: 2
}
} );
assert.throws(
() => {
mapper.mapVariations( {
off: {
name: 'Off',
description: 'The switch is off',
value: false
},
on: {
name: 'On',
description: 'The switch is on',
value: 'on'
}
} );
},
/Variation values must all be of the same type/
);
assert.equal(
result.indexes.getIndex( 'red' ),
0,
'red should map to index 0'
);
assert.equal(
result.indexes.getIndex( 'green' ),
1,
'green should map to index 1'
);
assert.equal(
result.indexes.getIndex( 'blue' ),
2,
'blue should map to index 2'
);
assert.deepEqual( result.variations, [
{
value: 0
},
{
value: 1
},
{
value: 2
}
] );
} );
it( 'should throw if values duplicated', function() {
assert.throws(
() => {
mapper.mapVariations( {
off: {
name: 'Off',
value: 1
},
on: {
name: 'On',
value: 1
}
} );
},
/^Duplicate variation values: 1$/
);
} );
} );
it( 'should map just values', function() {
describe( 'array definition', function() {
it( 'should map variations', function() {
const result = mapper.mapVariations( {
red: {
value: 0
},
green: {
value: 1
},
blue: {
value: 2
}
const result = mapper.mapVariations( [
{
key: 'red',
name: 'Red',
description: 'Things are on fire',
value: 0
},
{
key: 'green',
name: 'Green',
description: 'Things are all ok',
value: 1
},
{
key: 'blue',
name: 'Blue',
description: 'Things are unknown',
value: 2
}
] );
assert.equal(
result.indexes.getIndex( 'red' ),
0,
'red should map to index 0'
);
assert.equal(
result.indexes.getIndex( 'green' ),
1,
'green should map to index 1'
);
assert.equal(
result.indexes.getIndex( 'blue' ),
2,
'blue should map to index 2'
);
assert.deepEqual( result.variations, [
{
name: 'Red',
description: 'Things are on fire',
value: 0
},
{
name: 'Green',
description: 'Things are all ok',
value: 1
},
{
name: 'Blue',
description: 'Things are unknown',
value: 2
}
] );
} );
assert.equal(
result.indexes.getIndex( 'red' ),
0,
'red should map to index 0'
);
it( 'should throw if value types mismatch', function() {
assert.equal(
result.indexes.getIndex( 'green' ),
1,
'green should map to index 1'
);
assert.throws(
() => {
mapper.mapVariations( [
{
key: 'off',
name: 'Off',
description: 'The switch is off',
value: false
},
{
key: 'on',
name: 'On',
description: 'The switch is on',
value: 'on'
}
] );
},
/Variation values must all be of the same type/
);
assert.equal(
result.indexes.getIndex( 'blue' ),
2,
'blue should map to index 2'
);
} );
assert.deepEqual( result.variations, [
{
value: 0
},
{
value: 1
},
{
value: 2
}
] );
it( 'should map just values', function() {
const result = mapper.mapVariations( [
{
key: 'red',
value: 0
},
{
key: 'green',
value: 1
},
{
key: 'blue',
value: 2
}
] );
assert.equal(
result.indexes.getIndex( 'red' ),
0,
'red should map to index 0'
);
assert.equal(
result.indexes.getIndex( 'green' ),
1,
'green should map to index 1'
);
assert.equal(
result.indexes.getIndex( 'blue' ),
2,
'blue should map to index 2'
);
assert.deepEqual( result.variations, [
{
value: 0
},
{
value: 1
},
{
value: 2
}
] );
} );
it( 'should throw if keys duplicated', function() {
assert.throws(
() => {
mapper.mapVariations( [
{
key: 'off',
name: 'Off',
value: 0
},
{
key: 'off',
name: 'On',
value: 1
}
] );
},
/^Duplicate variation keys: off$/
);
} );
it( 'should throw if values duplicated', function() {
assert.throws(
() => {
mapper.mapVariations( [
{
key: 'off',
name: 'Off',
value: 1
},
{
key: 'on',
name: 'On',
value: 1
}
] );
},
/^Duplicate variation values: 1$/
);
} );
} );
} );
} );
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