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

@google/dscc

Package Overview
Dependencies
Maintainers
2
Versions
40
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@google/dscc - npm Package Compare versions

Comparing version 0.3.21 to 0.3.22

25

__tests__/impl.test.ts

@@ -342,3 +342,4 @@ /*!

numStyle: number,
numDateRange: number
numDateRange: number,
hasColorMap?: boolean
): sut.Message => {

@@ -350,2 +351,5 @@ const dimensionFields = testDimensionFields(numDimensions);

const dateRanges = testDateRange(numDateRange);
const colorMap = hasColorMap
? {California: '#6bcfdc', Seattle: '#beafc2'}
: undefined;
return {

@@ -432,2 +436,3 @@ type: sut.MessageType.RENDER,

dateRanges,
colorMap,
},

@@ -562,2 +567,3 @@ };

theme,
colorMap: {},
};

@@ -606,2 +612,3 @@ const actual = sut.tableTransform(testMessage(2, 2, 0, 0));

theme,
colorMap: {},
dateRanges: {},

@@ -678,2 +685,3 @@ fields: expectedFields,

dateRanges: {},
colorMap: {},
fields: {

@@ -866,2 +874,17 @@ dimensions: [

test('If there is no color map in the input, it returns the correct value', () => {
const actual: sut.ObjectFormat = sut.objectTransform(
testMessage(2, 2, 2, 0, false)
);
expect(actual.colorMap).toEqual({});
});
test('If there is a color map in the input, it returns the correct value', () => {
const expectedColorMap = {California: '#6bcfdc', Seattle: '#beafc2'};
const actual: sut.ObjectFormat = sut.objectTransform(
testMessage(2, 2, 2, 1, true)
);
expect(actual.colorMap).toEqual(expectedColorMap);
});
test('If elements are dim met dim dim, they have to be sorted specially.', () => {

@@ -868,0 +891,0 @@ const messageDimMetDimDim: sut.Message = {

2

_bundles/dscc.min.js

@@ -22,3 +22,3 @@ !function(e,R){"object"==typeof exports&&"object"==typeof module?module.exports=R():"function"==typeof define&&define.amd?define("dscc",[],R):"object"==typeof exports?exports.dscc=R():e.dscc=R()}(window,function(){return C={},n.m=t={"./src/index.ts":

*/
var _=R(/*! ./types */"./src/types.ts");!function(e){for(var R in e)N.hasOwnProperty(R)||(N[R]=e[R])}(R(/*! ./types */"./src/types.ts")),N.getWidth=function(){return document.body.clientWidth},N.getHeight=function(){return document.documentElement.clientHeight},N.getComponentId=function(){var e=new URLSearchParams(window.location.search);if(null!==e.get("dscId"))return e.get("dscId");throw new Error("dscId must be in the query parameters. This is a bug in ds-component, please file a bug: https://github.com/googledatastudio/ds-component/issues/new")};function E(e){return e.type===_.ConfigDataElementType.DIMENSION||e.type===_.ConfigDataElementType.METRIC}function r(e){return e===_.ConfigDataElementType.DIMENSION?-1:1}function a(e){var R=[];e.config.data.forEach(function(e){e.elements.filter(E).forEach(function(e){R.push(e)})});var t,C=(t=function(e,R){return r(e.type)-r(R.type)},R.map(function(e,R){return{item:e,index:R}}).sort(function(e,R){return t(e.item,R.item)||e.index-R.index}).map(function(e){return e.item})),n=[];return C.forEach(function(e){e.value.forEach(function(){return n.push(e.id)})}),n}function o(R){return function(e){var t,C,n={};return C=R,((t=e).length<C.length?t.map(function(e,R){return[e,C[R]]}):C.map(function(e,R){return[t[R],e]})).forEach(function(e){var R=e[0],t=e[1];void 0===n[t]&&(n[t]=[]),n[t].push(R)},{}),n}}N.fieldsByConfigId=function(e){var R=e.fields.reduce(function(e,R){return e[R.id]=R,e},{}),t={};return e.config.data.forEach(function(e){e.elements.filter(E).forEach(function(e){t[e.id]=e.value.map(function(e){return R[e]})})}),t};function U(e){var R={};return(e.config.style||[]).forEach(function(e){e.elements.forEach(function(e){if(void 0!==R[e.id])throw new Error("styleIds must be unique. Your styleId: '"+e.id+"' is used more than once.");R[e.id]={value:e.value,defaultValue:e.defaultValue}})},{}),R}function Y(e){return e.config.themeStyle}function n(e){switch(e){case _.DSInteractionType.FILTER:return _.InteractionType.FILTER}}function s(e){var R=e.config.interactions;return void 0===R?{}:R.reduce(function(e,R){var t=R.supportedActions.map(n),C={type:n(R.value.type),data:R.value.data};return e[R.id]={value:C,supportedActions:t},e},{})}function u(e){return(e.dataResponse.dateRanges||[]).reduce(function(e,R){return e[R.id]={start:R.start,end:R.end},e},{})}N.tableTransform=function(e){return{tables:(R=e,C=N.fieldsByConfigId(R),n=a(R),E={},r=n.map(function(e){void 0===E[e]?E[e]=0:E[e]++;var R=E[e],t=C[e][R];return i(i({},t),{configId:e})}),(t={})[_.TableType.DEFAULT]={headers:[],rows:[]},o=t,R.dataResponse.tables.forEach(function(e){o[e.id]={headers:r,rows:e.rows}}),o),dateRanges:u(e),fields:N.fieldsByConfigId(e),style:U(e),theme:Y(e),interactions:s(e)};var R,t,C,n,E,r,o},N.objectTransform=function(e){return{tables:(C=a(R=e),(t={})[_.TableType.DEFAULT]=[],n=t,R.dataResponse.tables.forEach(function(e){var R=e.rows.map(o(C));e.id===_.TableType.DEFAULT?n[e.id]=R:(void 0===n[e.id]&&(n[e.id]=[]),n[e.id]=n[e.id].concat(R))}),n),dateRanges:u(e),fields:N.fieldsByConfigId(e),style:U(e),theme:Y(e),interactions:s(e)};var R,t,C,n};function T(e){var R,t=!1;return e===N.tableTransform||e===N.objectTransform?t=!0:(R=!1,"identity"===e("identity")&&(R=!0,console.warn("This is an unsupported data format. Please use one of the supported transforms:\n dscc.objectFormat or dscc.tableFormat.")),R&&(t=!0)),t}N.subscribeToData=function(R,t){if(T(t.transform)){var e=function(e){e.data.type===_.MessageType.RENDER?R(t.transform(e.data)):console.error("MessageType: "+e.data.type+" is not supported by this version of the library.")};window.addEventListener("message",e);var C={componentId:N.getComponentId(),type:_.ToDSMessageType.VIZ_READY};return window.parent.postMessage(C,"*"),function(){return window.removeEventListener("message",e)}}throw new Error("Only the built in transform functions are supported.")},N.sendInteraction=function(e,R,t){var C=N.getComponentId(),n={type:_.ToDSMessageType.INTERACTION,id:e,data:t,componentId:C};window.parent.postMessage(n,"*")},N.clearInteraction=function(e,R){N.sendInteraction(e,R,void 0)}},"./src/types.ts":
var a=R(/*! ./types */"./src/types.ts");!function(e){for(var R in e)N.hasOwnProperty(R)||(N[R]=e[R])}(R(/*! ./types */"./src/types.ts")),N.getWidth=function(){return document.body.clientWidth},N.getHeight=function(){return document.documentElement.clientHeight},N.getComponentId=function(){var e=new URLSearchParams(window.location.search);if(null!==e.get("dscId"))return e.get("dscId");throw new Error("dscId must be in the query parameters. This is a bug in ds-component, please file a bug: https://github.com/googledatastudio/ds-component/issues/new")};function E(e){return e.type===a.ConfigDataElementType.DIMENSION||e.type===a.ConfigDataElementType.METRIC}function r(e){return e===a.ConfigDataElementType.DIMENSION?-1:1}function _(e){var R=[];e.config.data.forEach(function(e){e.elements.filter(E).forEach(function(e){R.push(e)})});var t,C=(t=function(e,R){return r(e.type)-r(R.type)},R.map(function(e,R){return{item:e,index:R}}).sort(function(e,R){return t(e.item,R.item)||e.index-R.index}).map(function(e){return e.item})),n=[];return C.forEach(function(e){e.value.forEach(function(){return n.push(e.id)})}),n}function o(R){return function(e){var t,C,n={};return C=R,((t=e).length<C.length?t.map(function(e,R){return[e,C[R]]}):C.map(function(e,R){return[t[R],e]})).forEach(function(e){var R=e[0],t=e[1];void 0===n[t]&&(n[t]=[]),n[t].push(R)},{}),n}}N.fieldsByConfigId=function(e){var R=e.fields.reduce(function(e,R){return e[R.id]=R,e},{}),t={};return e.config.data.forEach(function(e){e.elements.filter(E).forEach(function(e){t[e.id]=e.value.map(function(e){return R[e]})})}),t};function U(e){var R={};return(e.config.style||[]).forEach(function(e){e.elements.forEach(function(e){if(void 0!==R[e.id])throw new Error("styleIds must be unique. Your styleId: '"+e.id+"' is used more than once.");R[e.id]={value:e.value,defaultValue:e.defaultValue}})},{}),R}function Y(e){return e.config.themeStyle}function n(e){switch(e){case a.DSInteractionType.FILTER:return a.InteractionType.FILTER}}function s(e){var R=e.config.interactions;return void 0===R?{}:R.reduce(function(e,R){var t=R.supportedActions.map(n),C={type:n(R.value.type),data:R.value.data};return e[R.id]={value:C,supportedActions:t},e},{})}function u(e){return(e.dataResponse.dateRanges||[]).reduce(function(e,R){return e[R.id]={start:R.start,end:R.end},e},{})}function T(e){var R=e.dataResponse.colorMap||{};return i({},R)}N.tableTransform=function(e){return{tables:(R=e,C=N.fieldsByConfigId(R),n=_(R),E={},r=n.map(function(e){void 0===E[e]?E[e]=0:E[e]++;var R=E[e],t=C[e][R];return i(i({},t),{configId:e})}),(t={})[a.TableType.DEFAULT]={headers:[],rows:[]},o=t,R.dataResponse.tables.forEach(function(e){o[e.id]={headers:r,rows:e.rows}}),o),dateRanges:u(e),fields:N.fieldsByConfigId(e),style:U(e),theme:Y(e),interactions:s(e),colorMap:T(e)};var R,t,C,n,E,r,o},N.objectTransform=function(e){return{tables:(C=_(R=e),(t={})[a.TableType.DEFAULT]=[],n=t,R.dataResponse.tables.forEach(function(e){var R=e.rows.map(o(C));e.id===a.TableType.DEFAULT?n[e.id]=R:(void 0===n[e.id]&&(n[e.id]=[]),n[e.id]=n[e.id].concat(R))}),n),dateRanges:u(e),fields:N.fieldsByConfigId(e),style:U(e),theme:Y(e),interactions:s(e),colorMap:T(e)};var R,t,C,n};function c(e){var R,t=!1;return e===N.tableTransform||e===N.objectTransform?t=!0:(R=!1,"identity"===e("identity")&&(R=!0,console.warn("This is an unsupported data format. Please use one of the supported transforms:\n dscc.objectFormat or dscc.tableFormat.")),R&&(t=!0)),t}N.subscribeToData=function(R,t){if(c(t.transform)){var e=function(e){e.data.type===a.MessageType.RENDER?R(t.transform(e.data)):console.error("MessageType: "+e.data.type+" is not supported by this version of the library.")};window.addEventListener("message",e);var C={componentId:N.getComponentId(),type:a.ToDSMessageType.VIZ_READY};return window.parent.postMessage(C,"*"),function(){return window.removeEventListener("message",e)}}throw new Error("Only the built in transform functions are supported.")},N.sendInteraction=function(e,R,t){var C=N.getComponentId(),n={type:a.ToDSMessageType.INTERACTION,id:e,data:t,componentId:C};window.parent.postMessage(n,"*")},N.clearInteraction=function(e,R){N.sendInteraction(e,R,void 0)}},"./src/types.ts":
/*!**********************!*\

@@ -25,0 +25,0 @@ !*** ./src/types.ts ***!

@@ -283,2 +283,7 @@ "use strict";

};
/* Transform for color maps */
var toColorsByDimension = function (message) {
var colors = message.dataResponse.colorMap || {};
return __assign({}, colors);
};
/**

@@ -294,2 +299,3 @@ * The transform to use for data in a Table format. i.e. `[[1, 2, 3], [4, 5, 6]]`

interactions: transformDSInteraction(message),
colorMap: toColorsByDimension(message),
}); };

@@ -306,2 +312,3 @@ /**

interactions: transformDSInteraction(message),
colorMap: toColorsByDimension(message),
}); };

@@ -308,0 +315,0 @@ /**

@@ -65,2 +65,5 @@ export interface PostMessage extends MessageEvent {

}
export interface DSColorMap {
[dimension: string]: string;
}
export interface DataResponse {

@@ -72,2 +75,3 @@ /**

dateRanges?: DSDateRange[];
colorMap?: DSColorMap;
}

@@ -618,2 +622,3 @@ export declare enum MessageType {

interactions: InteractionsById;
colorMap: ColorsByDimension;
}

@@ -643,2 +648,5 @@ export declare type TableTransform = (message: Message) => TableFormat;

}
export interface ColorsByDimension {
[dimension: string]: string;
}
export interface ObjectFormat {

@@ -651,2 +659,3 @@ fields: FieldsByConfigId;

interactions: InteractionsById;
colorMap: ColorsByDimension;
}

@@ -653,0 +662,0 @@ export declare type ComponentId = string;

{
"name": "@google/dscc",
"libraryName": "dscc",
"version": "0.3.21",
"version": "0.3.22",
"main": "lib/index.js",

@@ -6,0 +6,0 @@ "license": "Apache-2.0",

@@ -19,2 +19,3 @@ /*!

ClearInteraction,
ColorsByDimension,
ConfigData,

@@ -36,3 +37,2 @@ ConfigDataElement,

FieldsById,
Interaction,
InteractionMessage,

@@ -46,3 +46,2 @@ InteractionsById,

ObjectTransform,
ParsedImage,
PostMessage,

@@ -354,2 +353,8 @@ Row,

};
/* Transform for color maps */
const toColorsByDimension = (message: Message): ColorsByDimension => {
const colors = message.dataResponse.colorMap || {};
return {...colors};
};
/**

@@ -367,2 +372,3 @@ * The transform to use for data in a Table format. i.e. `[[1, 2, 3], [4, 5, 6]]`

interactions: transformDSInteraction(message),
colorMap: toColorsByDimension(message),
});

@@ -380,2 +386,3 @@

interactions: transformDSInteraction(message),
colorMap: toColorsByDimension(message),
});

@@ -388,5 +395,5 @@

*/
const isProbablyIdentityFunction = (transform): boolean => {
const isProbablyIdentityFunction = <T, U>(transform: (t: T) => U): boolean => {
let isIdentity: boolean = false;
if (transform('identity') === 'identity') {
if ((transform as any)('identity') === 'identity') {
isIdentity = true;

@@ -401,3 +408,3 @@ console.warn(

const isValidTransform = (transform): boolean => {
const isValidTransform = <T, U>(transform: (t: T) => U): boolean => {
let isValid = false;

@@ -404,0 +411,0 @@ if (

@@ -89,2 +89,6 @@ /*!

export interface DSColorMap {
[dimension: string]: string;
}
export interface DataResponse {

@@ -96,2 +100,3 @@ /**

dateRanges?: DSDateRange[];
colorMap?: DSColorMap;
}

@@ -681,2 +686,3 @@

interactions: InteractionsById;
colorMap: ColorsByDimension;
}

@@ -713,2 +719,7 @@

/* A map of dimension values to hex string colors */
export interface ColorsByDimension {
[dimension: string]: string;
}
export interface ObjectFormat {

@@ -721,2 +732,3 @@ fields: FieldsByConfigId;

interactions: InteractionsById;
colorMap: ColorsByDimension;
}

@@ -723,0 +735,0 @@

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

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