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

wappsto-redux

Package Overview
Dependencies
Maintainers
1
Versions
52
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

wappsto-redux - npm Package Compare versions

Comparing version 1.1.7 to 2.0.0

32

actions/request.js
import querystring from 'querystring';
import config from '../config';
import { isUUID, getUrlInfo } from '../util/helpers';
import { getUrlInfo } from '../util/helpers';
import { addEntities, removeEntities } from './entities';

@@ -48,3 +48,3 @@ import { addSession, invalidSession, removeSession } from './session';

if(Object.keys(query).length > 0){
result += result.indexOf('?') === -1 ? '?': '&';
result += result.indexOf('?') === -1 ? '?': '&';
result += querystring.stringify(query);

@@ -100,3 +100,3 @@ }

function dispatchEntitiesAction(dispatch, method, url, json, options){
let { service, id, parent } = getUrlInfo(url);
let { service, parent } = getUrlInfo(url);
switch(method){

@@ -114,2 +114,4 @@ case 'GET':

break;
default:
break;
}

@@ -169,9 +171,9 @@ }

let state = getState();
if(state.request[url] && state.request[url].status === 'pending'){
let requestOptions = getOptions(method, url, data, options, state.session);
let urlKey = method === 'GET' ? requestOptions.url.replace(config.baseUrl, '') : url;
if(state.request[urlKey] && state.request[urlKey].status === 'pending'){
console.log('a request with the same url is already pending');
return;
}
dispatch(requestPending(method, url, data, options));
let requestOptions = getOptions(method, url, data, options, state.session);
// console.log(requestOptions);
dispatch(requestPending(method, urlKey, data, options));
let response;

@@ -184,4 +186,4 @@ try{

if(response.ok){
dispatchMethodAction(dispatch, method, url, response.json, options);
dispatch(requestSuccess(method, url, response.status, response.json, options));
dispatchMethodAction(dispatch, method, urlKey, response.json, options);
dispatch(requestSuccess(method, urlKey, response.status, response.json, options));
} else {

@@ -191,3 +193,3 @@ if(response.json && response.json.code === 9900025){

}
dispatch(requestError(method, url, response.status, response.json, options));
dispatch(requestError(method, urlKey, response.status, response.json, options));
}

@@ -197,6 +199,7 @@ };

export function removeRequest(url, method){
export function removeRequest(url, method, query){
const urlKey = getUrlWithQuery(url, query);
return {
type: REMOVE_REQUEST,
url,
url: urlKey,
method

@@ -206,6 +209,7 @@ }

export function removeRequestError(url, method){
export function removeRequestError(url, method, query){
const urlKey = getUrlWithQuery(url, query);
return {
type: REMOVE_REQUEST_ERROR,
url,
url: urlKey,
method

@@ -212,0 +216,0 @@ }

{
"name": "wappsto-redux",
"version": "1.1.7",
"version": "2.0.0",
"description": "",

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

@@ -8,3 +8,2 @@ import { normalize } from 'normalizr';

import schemas from "../util/schemas";
import schemaTree from "../util/schemaTree";
import { parse } from "../util/parser";

@@ -26,6 +25,3 @@ import reducerRegistry from "../util/reducerRegistry";

function addEntities(state, type, data){
if(!schemas.hasOwnProperty(type)){
schemas.generateGenericSchema(type);
}
data = normalize(data, [schemas[type]]);
data = normalize(data, [schemas.getSchema(type)]);
for(let key in data.entities){

@@ -46,6 +42,3 @@ state[key] = Object.assign({}, state[key], data.entities[key]);

function removeAllEntities(state, type){
if(!schemas.hasOwnProperty(type)){
schemas.generateGenericSchema(type);
}
let def = schemaTree[type];
let def = schemas.getSchemaTree(type);
let entities = state[def.name];

@@ -61,3 +54,3 @@ if(entities){

let newData, result;
let def = schemaTree[type];
let def = schemas.getSchemaTree(type);
let element = state[def.name] && state[def.name][id];

@@ -84,3 +77,3 @@ if(element){

let result, newData;
let def = schemaTree[type];
let def = schemas.getSchemaTree(type);
let element = state[def.name] && state[def.name][id];

@@ -108,6 +101,3 @@ if(element){

function addEntity(state, type, data){
if(!schemas.hasOwnProperty(type)){
schemas.generateGenericSchema(type);
}
data = normalize(data, schemas[type]);
data = normalize(data, schemas.getSchema(type));
for(let key in data.entities){

@@ -120,3 +110,3 @@ state[key] = Object.assign({}, state[key], data.entities[key]);

function removeEntity(state, type, id){
let def = schemaTree[type];
let def = schemas.getSchemaTree(type);
let element = state[def.name] && state[def.name][id];

@@ -165,3 +155,3 @@ if(element){

if(!action.ids){
let def = schemaTree[action.service];
let def = schemas.getSchemaTree(action.service);
action.ids = Object.keys(state[def.name] || {});

@@ -173,6 +163,7 @@ }

return state;
default:
return state;
}
return state;
}
reducerRegistry.register("entities", reducer);

@@ -78,4 +78,13 @@ import schemaTree from "../util/schemaTree";

if(found){
if(options.filter && matchObject(found, filter)){
result.push(found);
if(options.filter){
let filters = options.filter;
if(!(filters instanceof Array)){
filters = [filters];
}
for(let i = 0; i < filters.length; i++){
if(matchObject(found, filters[i])){
result.push(found);
break;
}
}
} else {

@@ -89,9 +98,16 @@ result.push(found);

if(options.filter){
let filters = options.filter;
result = [];
for(let key in state.entities[name]){
let val = state.entities[name][key];
if(matchObject(val, options.filter)){
result.push(val);
if(!(filters instanceof Array)){
filters = [filters];
}
filters.forEach(filter => {
for(let key in state.entities[name]){
const val = state.entities[name][key];
if(matchObject(val, filter)){
result.push(val);
break;
}
}
}
});
} else {

@@ -98,0 +114,0 @@ result = Object.values(state.entities[name]);

@@ -1,10 +0,24 @@

export const getRequestError = (state, url, method) => {
return state.request.errors[method + "_" + url];
import querystring from 'querystring';
function getUrlKey(url, method, query){
if(method === 'GET'){
const qs = querystring.stringify(query);
if(qs){
url += '?' + qs;
}
}
return url;
}
export const getRequestAndError = (state, url, method) => {
const getRequestError = (state, url, method, query) => {
const urlKey = getUrlKey(url, method, query);
return state.request.errors[method + "_" + urlKey];
}
const getRequestAndError = (state, url, method, query) => {
let request;
let error = state.request.errors[method + "_" + url];
if(state.request[url] && state.request[url].method === method){
request = state.request[url];
const error = getRequestError(state, url, method, query);
const urlKey = getUrlKey(url, method, query);
if(state.request[urlKey] && state.request[urlKey].method === method){
request = state.request[urlKey];
}

@@ -17,5 +31,6 @@ return {

export const getRequest = (state, url, method) => {
export const getRequest = (state, url, method, query) => {
method = method.toUpperCase();
if(method){
let result = getRequestAndError(state, url, method);
let result = getRequestAndError(state, url, method, query);
return result.error || result.request;

@@ -22,0 +37,0 @@ } else {

@@ -29,2 +29,16 @@ import { schema } from "normalizr";

schemas.getSchema = (type) => {
if(!schemas.hasOwnProperty(type)){
schemas.generateGenericSchema(type);
}
return schemas[type];
}
schemas.getSchemaTree = (type) => {
if(!schemas.hasOwnProperty(type)){
schemas.generateGenericSchema(type);
}
return schemaTree[type];
}
export default schemas;
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