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

@appbaseio/reactivecore

Package Overview
Dependencies
Maintainers
6
Versions
289
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@appbaseio/reactivecore - npm Package Compare versions

Comparing version 10.0.0-alpha.2 to 10.0.0-alpha.3

2

lib/utils/server.js

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

Object.defineProperty(exports,"__esModule",{value:true});var _extends=Object.assign||function(target){for(var i=1;i<arguments.length;i++){var source=arguments[i];for(var key in source){if(Object.prototype.hasOwnProperty.call(source,key)){target[key]=source[key];}}}return target;};var _constants=require('./constants');var _utils=require('../actions/utils');var _transform=require('./transform');var _valueReducer=require('../reducers/valueReducer');var _valueReducer2=_interopRequireDefault(_valueReducer);var _helper=require('./helper');function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj};}function _toConsumableArray(arr){if(Array.isArray(arr)){for(var i=0,arr2=Array(arr.length);i<arr.length;i++){arr2[i]=arr[i];}return arr2;}else{return Array.from(arr);}}function _objectWithoutProperties(obj,keys){var target={};for(var i in obj){if(keys.indexOf(i)>=0)continue;if(!Object.prototype.hasOwnProperty.call(obj,i))continue;target[i]=obj[i];}return target;}function _defineProperty(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true});}else{obj[key]=value;}return obj;}function getValue(state,id,defaultValue){if(state&&state[id]){try{var parsedValue=JSON.parse(state[id]);return _extends({},typeof parsedValue==='object'&&parsedValue.value?_extends({value:parsedValue.value},parsedValue.category?{category:parsedValue.category}:{}):{value:parsedValue},{reference:'URL'});}catch(error){return{value:state[id],reference:'URL'};}}return{value:defaultValue,reference:'DEFAULT'};}function parseQuery(str){if(str instanceof Object){return str;}if(typeof str!=='string'||str.length===0)return{};var s=void 0;if(str.split('/?')[1]){s=str.split('/?')[1].split('&');}if(str.split('?')[1]){s=str.split('?')[1].split('&');}if(!s)return{};var sLength=s.length;var bit=void 0;var query={};var first=void 0;var second=void 0;for(var i=0;i<sLength;i+=1){bit=s[i].split('=');first=decodeURIComponent(bit[0]);if(first.length===0)continue;second=decodeURIComponent(bit[1]);if(typeof query[first]==='undefined')query[first]=second;else if(query[first]instanceof Array)query[first].push(second);else query[first]=[query[first],second];}return query;}var getServerResults=function getServerResults(){var storeReference=null;return function(App){var queryString=arguments.length>1&&arguments[1]!==undefined?arguments[1]:'';var ssrRenderFunc=arguments[2];try{var parsedQueryString=parseQuery(queryString);if(!storeReference){var newSelectedValues={};var contextCollector=function contextCollector(params){if(params.ctx){storeReference=params.ctx;Object.keys(parsedQueryString).forEach(function(componentId){var _getValue=getValue(parsedQueryString,componentId,null),value=_getValue.value,reference=_getValue.reference;if(value){newSelectedValues=(0,_valueReducer2.default)(newSelectedValues,{type:'PATCH_VALUE',component:componentId,payload:{value:value,reference:reference}});}});}return{selectedValues:newSelectedValues};};var output=ssrRenderFunc(App({contextCollector:contextCollector}));var promiseFunc=void 0;if(!output.then){promiseFunc=Promise.resolve(promiseFunc);}else{promiseFunc=output;}return promiseFunc.then(function(){if(storeReference){var extractedState=storeReference.getState();var components=extractedState.components,config=extractedState.config,appbaseRef=extractedState.appbaseRef,queryOptions=extractedState.queryOptions,internalValues=extractedState.internalValues,props=extractedState.props,queryList=extractedState.queryList,dependencyTree=extractedState.dependencyTree;var queryLog=extractedState.queryLog;var finalQuery=[];var appbaseQuery={};var orderOfQueries=[];var hits={};var aggregations={};var state=_extends({},extractedState);components.filter(function(t){return!t.endsWith('__internal');}).forEach(function(componentId){var _buildQuery=(0,_helper.buildQuery)(componentId,dependencyTree,queryList,queryOptions),queryObj=_buildQuery.queryObj,options=_buildQuery.options;if(!queryObj&&!options){return;}var query=(0,_transform.getRSQuery)(componentId,(0,_transform.extractPropsFromState)(state,componentId,queryOptions&&queryOptions[componentId]?{from:queryOptions[componentId].from}:null));if(query&&!!Object.keys(query).length){var currentQuery=query;var dependentQueries=(0,_transform.getDependentQueries)(state,componentId,orderOfQueries);var queryToLog=_extends(_defineProperty({},componentId,currentQuery),Object.keys(dependentQueries).reduce(function(acc,q){return _extends({},acc,_defineProperty({},q,_extends({},dependentQueries[q],{execute:false},dependentQueries[q].type===_constants.queryTypes.suggestion?{type:'search'}:{})));},{}));if([_constants.queryTypes.range,_constants.queryTypes.term].includes(_transform.componentToTypeMap[props[componentId].componentType])){var value=currentQuery.value,rest=_objectWithoutProperties(currentQuery,['value']);queryToLog=_extends(_defineProperty({},componentId,rest),Object.keys(dependentQueries).reduce(function(acc,q){return _extends({},acc,_defineProperty({},q,_extends({},dependentQueries[q],{execute:false},dependentQueries[q].type===_constants.queryTypes.suggestion?{type:'search'}:{})));},{}));}orderOfQueries=[].concat(_toConsumableArray(orderOfQueries),[componentId]);queryLog=_extends({},queryLog,_defineProperty({},componentId,queryToLog));if(query){var dependentQueriesToAppend=(0,_transform.getDependentQueries)(state,componentId,orderOfQueries);appbaseQuery=_extends({},appbaseQuery,_defineProperty({},componentId,query));Object.keys(dependentQueriesToAppend).forEach(function(cId){if(appbaseQuery[cId]){appbaseQuery[cId+Math.random()]=dependentQueriesToAppend[cId];}else{appbaseQuery[cId]=dependentQueriesToAppend[cId];}});}}});var handleRSResponse=function handleRSResponse(res){var promotedResults={};var rawData={};var customData={};var allPromises=orderOfQueries.map(function(component){return new Promise(function(responseResolve,responseReject){(0,_utils.handleTransformResponse)(res[component],config,component).then(function(response){if(response){if(response.promoted){promotedResults[component]=response.promoted.map(function(promoted){return _extends({},promoted.doc,{_position:promoted.position});});}rawData[component]=response;if(response.customData){customData[component]=response.customData;}if(response.aggregations){aggregations=_extends({},aggregations,_defineProperty({},component,response.aggregations));}var hitsObj=response.hits||{};hits=_extends({},hits,_defineProperty({},component,{hits:hitsObj.hits,total:typeof hitsObj.total==='object'?hitsObj.total.value:hitsObj.total,time:response.took}));responseResolve();}}).catch(function(err){responseReject(err);});});});return Promise.all(allPromises).then(function(){state={queryList:queryList,queryOptions:queryOptions,selectedValues:newSelectedValues,internalValues:internalValues,queryLog:queryLog,hits:hits,aggregations:aggregations,promotedResults:promotedResults,customData:customData,rawData:rawData,dependencyTree:dependencyTree};return Promise.resolve(JSON.parse(JSON.stringify(state)));});};if(Object.keys(appbaseQuery).length){finalQuery=Object.values(appbaseQuery);var rsAPISettings={};if(config.analyticsConfig){rsAPISettings.recordAnalytics=(0,_utils.isPropertyDefined)(config.analyticsConfig.recordAnalytics)?config.analyticsConfig.recordAnalytics:undefined;rsAPISettings.userId=(0,_utils.isPropertyDefined)(config.analyticsConfig.userId)?config.analyticsConfig.userId:undefined;rsAPISettings.enableQueryRules=(0,_utils.isPropertyDefined)(config.analyticsConfig.enableQueryRules)?config.analyticsConfig.enableQueryRules:undefined;rsAPISettings.customEvents=(0,_utils.isPropertyDefined)(config.analyticsConfig.customEvents)?config.analyticsConfig.customEvents:undefined;}return appbaseRef.reactiveSearchv3(finalQuery,rsAPISettings).then(function(res){return handleRSResponse(res);}).catch(function(err){return Promise.reject(err);});}throw new Error('Could not compute server-side initial state of the app!');}else{return null;}});}return null;}catch(error){return Promise.reject(error);}};};exports.default=getServerResults;
Object.defineProperty(exports,"__esModule",{value:true});exports.getServerResults=undefined;var _extends=Object.assign||function(target){for(var i=1;i<arguments.length;i++){var source=arguments[i];for(var key in source){if(Object.prototype.hasOwnProperty.call(source,key)){target[key]=source[key];}}}return target;};var _constants=require('./constants');var _utils=require('../actions/utils');var _transform=require('./transform');var _valueReducer=require('../reducers/valueReducer');var _valueReducer2=_interopRequireDefault(_valueReducer);var _helper=require('./helper');function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj};}function _toConsumableArray(arr){if(Array.isArray(arr)){for(var i=0,arr2=Array(arr.length);i<arr.length;i++){arr2[i]=arr[i];}return arr2;}else{return Array.from(arr);}}function _objectWithoutProperties(obj,keys){var target={};for(var i in obj){if(keys.indexOf(i)>=0)continue;if(!Object.prototype.hasOwnProperty.call(obj,i))continue;target[i]=obj[i];}return target;}function _defineProperty(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true});}else{obj[key]=value;}return obj;}function getValue(state,id,defaultValue){if(state&&state[id]){try{var parsedValue=JSON.parse(state[id]);return _extends({},typeof parsedValue==='object'&&parsedValue.value?_extends({value:parsedValue.value},parsedValue.category?{category:parsedValue.category}:{}):{value:parsedValue},{reference:'URL'});}catch(error){return{value:state[id],reference:'URL'};}}return{value:defaultValue,reference:'DEFAULT'};}function parseQuery(str){if(str instanceof Object){return str;}if(typeof str!=='string'||str.length===0)return{};var s=void 0;if(str.split('/?')[1]){s=str.split('/?')[1].split('&');}if(str.split('?')[1]){s=str.split('?')[1].split('&');}if(!s)return{};var sLength=s.length;var bit=void 0;var query={};var first=void 0;var second=void 0;for(var i=0;i<sLength;i+=1){bit=s[i].split('=');first=decodeURIComponent(bit[0]);if(first.length===0)continue;second=decodeURIComponent(bit[1]);if(typeof query[first]==='undefined')query[first]=second;else if(query[first]instanceof Array)query[first].push(second);else query[first]=[query[first],second];}return query;}var getServerResults=function getServerResults(){var storeReference=null;return function(App){var queryString=arguments.length>1&&arguments[1]!==undefined?arguments[1]:'';var ssrRenderFunc=arguments[2];try{var parsedQueryString=parseQuery(queryString);if(!storeReference){var newSelectedValues={};var contextCollector=function contextCollector(params){if(params.ctx){storeReference=params.ctx;Object.keys(parsedQueryString).forEach(function(componentId){var _getValue=getValue(parsedQueryString,componentId,null),value=_getValue.value,reference=_getValue.reference;if(value){newSelectedValues=(0,_valueReducer2.default)(newSelectedValues,{type:'PATCH_VALUE',component:componentId,payload:{value:value,reference:reference}});}});}return{selectedValues:newSelectedValues};};var output=ssrRenderFunc(App({contextCollector:contextCollector}));var promiseFunc=void 0;if(!output.then){promiseFunc=Promise.resolve(promiseFunc);}else{promiseFunc=output;}return promiseFunc.then(function(){if(storeReference){var extractedState=storeReference.getState();var components=extractedState.components,config=extractedState.config,appbaseRef=extractedState.appbaseRef,queryOptions=extractedState.queryOptions,internalValues=extractedState.internalValues,props=extractedState.props,queryList=extractedState.queryList,dependencyTree=extractedState.dependencyTree;var queryLog=extractedState.queryLog;var finalQuery=[];var appbaseQuery={};var orderOfQueries=[];var hits={};var aggregations={};var state=_extends({},extractedState);components.filter(function(t){return!t.endsWith('__internal');}).forEach(function(componentId){var _buildQuery=(0,_helper.buildQuery)(componentId,dependencyTree,queryList,queryOptions),queryObj=_buildQuery.queryObj,options=_buildQuery.options;if(!queryObj&&!options){return;}var query=(0,_transform.getRSQuery)(componentId,(0,_transform.extractPropsFromState)(state,componentId,queryOptions&&queryOptions[componentId]?{from:queryOptions[componentId].from}:null));if(query&&!!Object.keys(query).length){var currentQuery=query;var dependentQueries=(0,_transform.getDependentQueries)(state,componentId,orderOfQueries);var queryToLog=_extends(_defineProperty({},componentId,currentQuery),Object.keys(dependentQueries).reduce(function(acc,q){return _extends({},acc,_defineProperty({},q,_extends({},dependentQueries[q],{execute:false},dependentQueries[q].type===_constants.queryTypes.suggestion?{type:'search'}:{})));},{}));if([_constants.queryTypes.range,_constants.queryTypes.term].includes(_transform.componentToTypeMap[props[componentId].componentType])){var value=currentQuery.value,rest=_objectWithoutProperties(currentQuery,['value']);queryToLog=_extends(_defineProperty({},componentId,rest),Object.keys(dependentQueries).reduce(function(acc,q){return _extends({},acc,_defineProperty({},q,_extends({},dependentQueries[q],{execute:false},dependentQueries[q].type===_constants.queryTypes.suggestion?{type:'search'}:{})));},{}));}orderOfQueries=[].concat(_toConsumableArray(orderOfQueries),[componentId]);queryLog=_extends({},queryLog,_defineProperty({},componentId,queryToLog));if(query){var dependentQueriesToAppend=(0,_transform.getDependentQueries)(state,componentId,orderOfQueries);appbaseQuery=_extends({},appbaseQuery,_defineProperty({},componentId,query));Object.keys(dependentQueriesToAppend).forEach(function(cId){if(appbaseQuery[cId]){appbaseQuery[cId+Math.random()]=dependentQueriesToAppend[cId];}else{appbaseQuery[cId]=dependentQueriesToAppend[cId];}});}}});var handleRSResponse=function handleRSResponse(res){var promotedResults={};var rawData={};var customData={};var allPromises=orderOfQueries.map(function(component){return new Promise(function(responseResolve,responseReject){(0,_utils.handleTransformResponse)(res[component],config,component).then(function(response){if(response){if(response.promoted){promotedResults[component]=response.promoted.map(function(promoted){return _extends({},promoted.doc,{_position:promoted.position});});}rawData[component]=response;if(response.customData){customData[component]=response.customData;}if(response.aggregations){aggregations=_extends({},aggregations,_defineProperty({},component,response.aggregations));}var hitsObj=response.hits||{};hits=_extends({},hits,_defineProperty({},component,{hits:hitsObj.hits,total:typeof hitsObj.total==='object'?hitsObj.total.value:hitsObj.total,time:response.took}));responseResolve();}}).catch(function(err){responseReject(err);});});});return Promise.all(allPromises).then(function(){state={queryList:queryList,queryOptions:queryOptions,selectedValues:newSelectedValues,internalValues:internalValues,queryLog:queryLog,hits:hits,aggregations:aggregations,promotedResults:promotedResults,customData:customData,rawData:rawData,dependencyTree:dependencyTree};return Promise.resolve(JSON.parse(JSON.stringify(state)));});};if(Object.keys(appbaseQuery).length){finalQuery=Object.values(appbaseQuery);var rsAPISettings={};if(config.analyticsConfig){rsAPISettings.recordAnalytics=(0,_utils.isPropertyDefined)(config.analyticsConfig.recordAnalytics)?config.analyticsConfig.recordAnalytics:undefined;rsAPISettings.userId=(0,_utils.isPropertyDefined)(config.analyticsConfig.userId)?config.analyticsConfig.userId:undefined;rsAPISettings.enableQueryRules=(0,_utils.isPropertyDefined)(config.analyticsConfig.enableQueryRules)?config.analyticsConfig.enableQueryRules:undefined;rsAPISettings.customEvents=(0,_utils.isPropertyDefined)(config.analyticsConfig.customEvents)?config.analyticsConfig.customEvents:undefined;}return appbaseRef.reactiveSearchv3(finalQuery,rsAPISettings).then(function(res){return handleRSResponse(res);}).catch(function(err){return Promise.reject(err);});}throw new Error('Could not compute server-side initial state of the app!');}else{return null;}}).catch(Promise.reject);}return null;}catch(error){return Promise.reject(error);}};};exports.getServerResults=getServerResults;
{
"name": "@appbaseio/reactivecore",
"version": "10.0.0-alpha.2",
"version": "10.0.0-alpha.3",
"description": "Core architecture of reactive UI libraries",

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

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