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

@searchkit/client

Package Overview
Dependencies
Maintainers
2
Versions
56
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@searchkit/client - npm Package Compare versions

Comparing version 3.0.0-canary.46 to 3.0.0-canary.47

8

CHANGELOG.md

@@ -6,2 +6,10 @@ # Change Log

# [3.0.0-canary.47](https://github.com/searchkit/searchkit/compare/v3.0.0-canary.46...v3.0.0-canary.47) (2022-01-29)
**Note:** Version bump only for package @searchkit/client
# [3.0.0-canary.46](https://github.com/searchkit/searchkit/compare/v3.0.0-canary.27...v3.0.0-canary.46) (2021-11-01)

@@ -8,0 +16,0 @@

4

lib/cjs/history.d.ts

@@ -8,3 +8,3 @@ import qs from 'qs';

read(): RouteState;
write(route: RouteState): void;
write(route: RouteState, shouldPushToHistory: boolean): void;
createURL(state: RouteState): string;

@@ -37,3 +37,3 @@ dispose(): void;

read(): RouteState;
write(routeState: RouteState): void;
write(routeState: RouteState, shouldPushToHistory?: boolean): void;
onUpdate(callback: (routeState: RouteState) => void): void;

@@ -40,0 +40,0 @@ createURL(routeState: RouteState): string;

@@ -34,3 +34,3 @@ "use strict";

}
write(routeState) {
write(routeState, shouldPushToHistory = true) {
const url = this.createURL(routeState);

@@ -41,3 +41,5 @@ if (this.writeTimer) {

this.writeTimer = window.setTimeout(() => {
window.history.pushState(routeState, null, url);
if (shouldPushToHistory) {
window.history.pushState(routeState, null, url);
}
this.writeTimer = undefined;

@@ -76,3 +78,3 @@ }, this.writeDelay);

}
this.write({});
this.write({}, false);
}

@@ -79,0 +81,0 @@ }

@@ -27,3 +27,3 @@ import React from 'react';

query: string;
filters: Array<Filter>;
filters: Filter[];
sortBy: string;

@@ -55,3 +55,3 @@ page: PageOptions;

baseSearchState: SearchState;
constructor({}?: SearchkitClientConfig);
constructor({ itemsPerPage }?: SearchkitClientConfig);
updateBaseSearchState(updates: Partial<SearchState>): void;

@@ -58,0 +58,0 @@ private performSearch;

@@ -21,5 +21,9 @@ "use strict";

};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.useSearchkitQuery = exports.useSearchkitQueryValue = exports.useSearchkitRoutingOptions = exports.useSearchkit = exports.useSearchkitVariables = exports.SearchkitProvider = exports.SearchkitRoutingOptionsContext = exports.SearchkitVariablesContext = exports.SearchkitContext = exports.SearchkitClient = exports.createSearchState = exports.searchStateEqual = void 0;
const react_1 = __importStar(require("react"));
const fast_deep_equal_1 = __importDefault(require("fast-deep-equal"));
const lodash_1 = require("lodash");

@@ -46,24 +50,3 @@ const client_1 = require("@apollo/client");

};
const searchStateEqual = (a, b) => {
if (a.query !== b.query)
return false;
if (a.sortBy !== b.sortBy)
return false;
if (a.page.from !== b.page.from)
return false;
if (a.page.size !== b.page.size)
return false;
if (a.filters.length !== b.filters.length)
return false;
const filterDiffs = a.filters.find((filter) => {
const filterSelectorA = filterSelector(filter);
if (!b.filters.find(filterSelectorA)) {
return true;
}
return false;
});
if (filterDiffs)
return false;
return true;
};
const searchStateEqual = (a, b) => fast_deep_equal_1.default(a, b);
exports.searchStateEqual = searchStateEqual;

@@ -153,3 +136,3 @@ class SearchkitClientState {

class SearchkitClient extends SearchkitClientState {
constructor({} = {}) {
constructor({ itemsPerPage } = {}) {
super();

@@ -160,3 +143,3 @@ this.baseSearchState = {

page: {
size: 10,
size: itemsPerPage || 10,
from: 0

@@ -163,0 +146,0 @@ },

@@ -15,3 +15,3 @@ /// <reference types="react" />

};
export default function withSearchkitRouting(Page: any, { stateToRoute, routeToState, createURL, parseURL }?: {
export default function withSearchkitRouting(Page: any, { stateToRoute, routeToState, createURL, parseURL, router }?: {
stateToRoute?: (searchState: any) => {};

@@ -36,2 +36,3 @@ routeToState?: (routeState: any) => {

}) => RouteState;
router?: any;
}): {

@@ -38,0 +39,0 @@ (props: any): JSX.Element;

@@ -36,7 +36,16 @@ "use strict";

const react_1 = __importStar(require("react"));
const lodash_1 = require("lodash");
const fast_deep_equal_1 = __importDefault(require("fast-deep-equal"));
const qs_1 = __importDefault(require("qs"));
const history_1 = __importStar(require("./history"));
const searchkit_1 = require("./searchkit");
const routeStateEqual = (a, b) => Object.entries(a).toString() === Object.entries(b).toString();
const sanitiseRouteState = (routeState) => {
const intKeys = ['size', 'from'];
for (const key of intKeys) {
if (routeState[key] !== undefined && typeof routeState[key] === 'string') {
routeState[key] = parseInt(routeState[key]);
}
}
return routeState;
};
const routeStateEqual = (a, b) => fast_deep_equal_1.default(sanitiseRouteState(a), sanitiseRouteState(b));
exports.routeStateEqual = routeStateEqual;

@@ -49,8 +58,8 @@ const stateToRouteFn = (searchState) => {

filters: searchState.filters,
size: Number((_a = searchState.page) === null || _a === void 0 ? void 0 : _a.size),
from: Number((_b = searchState.page) === null || _b === void 0 ? void 0 : _b.from)
size: parseInt((_a = searchState.page) === null || _a === void 0 ? void 0 : _a.size),
from: parseInt((_b = searchState.page) === null || _b === void 0 ? void 0 : _b.from)
};
return Object.keys(routeState).reduce((sum, key) => {
if ((lodash_1.isArray(routeState[key]) && routeState[key].length > 0) ||
(!lodash_1.isArray(routeState[key]) && !!routeState[key])) {
if ((Array.isArray(routeState[key]) && routeState[key].length > 0) ||
(!Array.isArray(routeState[key]) && !!routeState[key])) {
sum[key] = routeState[key];

@@ -72,4 +81,4 @@ }

exports.routeToStateFn = routeToStateFn;
function withSearchkitRouting(Page, { stateToRoute = exports.stateToRouteFn, routeToState = exports.routeToStateFn, createURL = history_1.defaultCreateURL, parseURL = history_1.defaultParseURL } = {}) {
let routingInstance = undefined;
function withSearchkitRouting(Page, { stateToRoute = exports.stateToRouteFn, routeToState = exports.routeToStateFn, createURL = history_1.defaultCreateURL, parseURL = history_1.defaultParseURL, router = null } = {}) {
let routingInstance = router;
const getRouting = () => {

@@ -94,8 +103,9 @@ if (routingInstance)

react_1.useEffect(() => {
var _a;
const router = getRouting();
if (router) {
const routeState = stateToRoute(searchkitVariables);
const currentRouteState = router.read();
const currentRouteState = Object.assign({ size: (_a = api.baseSearchState.page) === null || _a === void 0 ? void 0 : _a.size }, router.read());
if (!exports.routeStateEqual(currentRouteState, routeState)) {
router.write(routeState);
router.write(routeState, true);
}

@@ -102,0 +112,0 @@ }

@@ -8,3 +8,3 @@ import qs from 'qs';

read(): RouteState;
write(route: RouteState): void;
write(route: RouteState, shouldPushToHistory: boolean): void;
createURL(state: RouteState): string;

@@ -37,3 +37,3 @@ dispose(): void;

read(): RouteState;
write(routeState: RouteState): void;
write(routeState: RouteState, shouldPushToHistory?: boolean): void;
onUpdate(callback: (routeState: RouteState) => void): void;

@@ -40,0 +40,0 @@ createURL(routeState: RouteState): string;

@@ -26,3 +26,3 @@ import qs from 'qs';

}
write(routeState) {
write(routeState, shouldPushToHistory = true) {
const url = this.createURL(routeState);

@@ -33,3 +33,5 @@ if (this.writeTimer) {

this.writeTimer = window.setTimeout(() => {
window.history.pushState(routeState, null, url);
if (shouldPushToHistory) {
window.history.pushState(routeState, null, url);
}
this.writeTimer = undefined;

@@ -68,3 +70,3 @@ }, this.writeDelay);

}
this.write({});
this.write({}, false);
}

@@ -71,0 +73,0 @@ }

@@ -27,3 +27,3 @@ import React from 'react';

query: string;
filters: Array<Filter>;
filters: Filter[];
sortBy: string;

@@ -55,3 +55,3 @@ page: PageOptions;

baseSearchState: SearchState;
constructor({}?: SearchkitClientConfig);
constructor({ itemsPerPage }?: SearchkitClientConfig);
updateBaseSearchState(updates: Partial<SearchState>): void;

@@ -58,0 +58,0 @@ private performSearch;

import React, { createContext, useContext, useEffect, useState } from 'react';
import isEqual from 'fast-deep-equal';
import { isUndefined } from 'lodash';

@@ -23,24 +24,3 @@ import { useQuery } from '@apollo/client';

};
export const searchStateEqual = (a, b) => {
if (a.query !== b.query)
return false;
if (a.sortBy !== b.sortBy)
return false;
if (a.page.from !== b.page.from)
return false;
if (a.page.size !== b.page.size)
return false;
if (a.filters.length !== b.filters.length)
return false;
const filterDiffs = a.filters.find((filter) => {
const filterSelectorA = filterSelector(filter);
if (!b.filters.find(filterSelectorA)) {
return true;
}
return false;
});
if (filterDiffs)
return false;
return true;
};
export const searchStateEqual = (a, b) => isEqual(a, b);
class SearchkitClientState {

@@ -128,3 +108,3 @@ getSearchState() {

export class SearchkitClient extends SearchkitClientState {
constructor({} = {}) {
constructor({ itemsPerPage } = {}) {
super();

@@ -135,3 +115,3 @@ this.baseSearchState = {

page: {
size: 10,
size: itemsPerPage || 10,
from: 0

@@ -138,0 +118,0 @@ },

@@ -15,3 +15,3 @@ /// <reference types="react" />

};
export default function withSearchkitRouting(Page: any, { stateToRoute, routeToState, createURL, parseURL }?: {
export default function withSearchkitRouting(Page: any, { stateToRoute, routeToState, createURL, parseURL, router }?: {
stateToRoute?: (searchState: any) => {};

@@ -36,2 +36,3 @@ routeToState?: (routeState: any) => {

}) => RouteState;
router?: any;
}): {

@@ -38,0 +39,0 @@ (props: any): JSX.Element;

@@ -11,7 +11,16 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {

import React, { useEffect } from 'react';
import { isArray } from 'lodash';
import isEqual from 'fast-deep-equal';
import qs from 'qs';
import history, { defaultParseURL, defaultCreateURL } from './history';
import { useSearchkitVariables, useSearchkit, searchStateEqual, SearchkitRoutingOptionsContext } from './searchkit';
export const routeStateEqual = (a, b) => Object.entries(a).toString() === Object.entries(b).toString();
const sanitiseRouteState = (routeState) => {
const intKeys = ['size', 'from'];
for (const key of intKeys) {
if (routeState[key] !== undefined && typeof routeState[key] === 'string') {
routeState[key] = parseInt(routeState[key]);
}
}
return routeState;
};
export const routeStateEqual = (a, b) => isEqual(sanitiseRouteState(a), sanitiseRouteState(b));
export const stateToRouteFn = (searchState) => {

@@ -23,8 +32,8 @@ var _a, _b;

filters: searchState.filters,
size: Number((_a = searchState.page) === null || _a === void 0 ? void 0 : _a.size),
from: Number((_b = searchState.page) === null || _b === void 0 ? void 0 : _b.from)
size: parseInt((_a = searchState.page) === null || _a === void 0 ? void 0 : _a.size),
from: parseInt((_b = searchState.page) === null || _b === void 0 ? void 0 : _b.from)
};
return Object.keys(routeState).reduce((sum, key) => {
if ((isArray(routeState[key]) && routeState[key].length > 0) ||
(!isArray(routeState[key]) && !!routeState[key])) {
if ((Array.isArray(routeState[key]) && routeState[key].length > 0) ||
(!Array.isArray(routeState[key]) && !!routeState[key])) {
sum[key] = routeState[key];

@@ -44,4 +53,4 @@ }

});
export default function withSearchkitRouting(Page, { stateToRoute = stateToRouteFn, routeToState = routeToStateFn, createURL = defaultCreateURL, parseURL = defaultParseURL } = {}) {
let routingInstance = undefined;
export default function withSearchkitRouting(Page, { stateToRoute = stateToRouteFn, routeToState = routeToStateFn, createURL = defaultCreateURL, parseURL = defaultParseURL, router = null } = {}) {
let routingInstance = router;
const getRouting = () => {

@@ -66,8 +75,9 @@ if (routingInstance)

useEffect(() => {
var _a;
const router = getRouting();
if (router) {
const routeState = stateToRoute(searchkitVariables);
const currentRouteState = router.read();
const currentRouteState = Object.assign({ size: (_a = api.baseSearchState.page) === null || _a === void 0 ? void 0 : _a.size }, router.read());
if (!routeStateEqual(currentRouteState, routeState)) {
router.write(routeState);
router.write(routeState, true);
}

@@ -74,0 +84,0 @@ }

{
"name": "@searchkit/client",
"version": "3.0.0-canary.46",
"version": "3.0.0-canary.47",
"main": "./lib/cjs/index.js",

@@ -51,6 +51,7 @@ "module": "./lib/esm/index.js",

"dependencies": {
"fast-deep-equal": "^3.1.3",
"lodash": "^4.17.21",
"qs": "^6.10.1"
},
"gitHead": "b1e693587d76761685b17e959d6fd419b36c8b01"
"gitHead": "a5f7bf3c51fabc358cc521a53ae110cf0079bb8e"
}

@@ -10,3 +10,3 @@ import qs from 'qs'

read(): RouteState
write(route: RouteState): void
write(route: RouteState, shouldPushToHistory: boolean): void
createURL(state: RouteState): string

@@ -80,3 +80,3 @@ dispose(): void

public write(routeState: RouteState): void {
public write(routeState: RouteState, shouldPushToHistory = true): void {
const url = this.createURL(routeState)

@@ -89,3 +89,5 @@

this.writeTimer = window.setTimeout(() => {
window.history.pushState(routeState, null, url)
if (shouldPushToHistory) {
window.history.pushState(routeState, null, url)
}
this.writeTimer = undefined

@@ -131,3 +133,3 @@ }, this.writeDelay)

this.write({})
this.write({}, false)
}

@@ -134,0 +136,0 @@ }

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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