New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@searchspring/snap-controller

Package Overview
Dependencies
Maintainers
3
Versions
117
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@searchspring/snap-controller - npm Package Compare versions

Comparing version 0.38.0 to 0.38.1

118

dist/cjs/Search/SearchController.js

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

_this.search = function () { return __awaiter(_this, void 0, void 0, function () {
var params, err_1, stringyParams, prevStringyParams, searchProfile, meta_1, response_1, preventBackfill, dontBackfill, previousResults, backfills, pageSize, pagesNeeded1, totalResultsNeeded, apiLimit, backfillParams, pagesNeeded, lastPageCount, i, backfillParams, backfillResults_1, backfillResponses, afterSearchProfile, err_2, afterStoreProfile, err_3, err_4;
var params, err_1, stringyParams, prevStringyParams, searchProfile, meta_1, response_1, preventBackfill, dontBackfill, previousResults, backfills, pageSize, meta_2, pagesNeeded1, totalResultsNeeded, apiLimit, backfillParams, pagesNeeded, lastPageCount, i, backfillParams, backfillResults_1, backfillResponses, afterSearchProfile, err_2, afterStoreProfile, err_3, err_4;
var _a, _b;

@@ -154,3 +154,3 @@ var _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t;

case 3:
_u.trys.push([3, 23, , 24]);
_u.trys.push([3, 26, , 27]);
_u.label = 4;

@@ -185,3 +185,3 @@ case 4:

searchProfile = this.profiler.create({ type: 'event', name: 'search', context: params }).start();
if (!(((_c = this.config.settings) === null || _c === void 0 ? void 0 : _c.infinite) && ((_d = params.pagination) === null || _d === void 0 ? void 0 : _d.page) > 1)) return [3 /*break*/, 12];
if (!(((_c = this.config.settings) === null || _c === void 0 ? void 0 : _c.infinite) && ((_d = params.pagination) === null || _d === void 0 ? void 0 : _d.page) > 1)) return [3 /*break*/, 15];
preventBackfill = ((_e = this.config.settings.infinite) === null || _e === void 0 ? void 0 : _e.backfill) && !this.store.results.length && ((_f = params.pagination) === null || _f === void 0 ? void 0 : _f.page) > this.config.settings.infinite.backfill;

@@ -197,28 +197,36 @@ dontBackfill = !((_g = this.config.settings.infinite) === null || _g === void 0 ? void 0 : _g.backfill) && !this.store.results.length && ((_h = params.pagination) === null || _h === void 0 ? void 0 : _h.page) > 1;

backfills = [];
if (((_j = this.config.settings) === null || _j === void 0 ? void 0 : _j.infinite.backfill) && !previousResults.length) {
pageSize = ((_k = params.pagination) === null || _k === void 0 ? void 0 : _k.pageSize) || this.store.pagination.pageSize || this.store.pagination.defaultPageSize;
pagesNeeded1 = ((_l = params.pagination) === null || _l === void 0 ? void 0 : _l.page) && ((_m = params.pagination) === null || _m === void 0 ? void 0 : _m.page) > ((_o = this.config.settings) === null || _o === void 0 ? void 0 : _o.infinite.backfill)
? (_p = this.config.settings) === null || _p === void 0 ? void 0 : _p.infinite.backfill
: (_q = params.pagination) === null || _q === void 0 ? void 0 : _q.page;
totalResultsNeeded = pageSize * (pagesNeeded1 || 1);
apiLimit = 500;
// our search api is limited to a certain amount per request.
//so we will need to make more than one request if totalresultsneeded is greater.
if (totalResultsNeeded < apiLimit) {
backfillParams = (0, deepmerge_1.default)(__assign({}, params), { pagination: { pageSize: totalResultsNeeded, page: 1 } });
pageSize = ((_j = params.pagination) === null || _j === void 0 ? void 0 : _j.pageSize) || this.store.pagination.pageSize || this.store.pagination.defaultPageSize;
if (!(((_k = this.config.settings) === null || _k === void 0 ? void 0 : _k.infinite.backfill) && !previousResults.length)) return [3 /*break*/, 10];
if (!!pageSize) return [3 /*break*/, 9];
return [4 /*yield*/, this.client.meta()];
case 8:
meta_2 = _u.sent();
pageSize = (_l = meta_2.pagination) === null || _l === void 0 ? void 0 : _l.defaultPageSize;
_u.label = 9;
case 9:
pagesNeeded1 = ((_m = params.pagination) === null || _m === void 0 ? void 0 : _m.page) && ((_o = params.pagination) === null || _o === void 0 ? void 0 : _o.page) > ((_p = this.config.settings) === null || _p === void 0 ? void 0 : _p.infinite.backfill)
? (_q = this.config.settings) === null || _q === void 0 ? void 0 : _q.infinite.backfill
: (_r = params.pagination) === null || _r === void 0 ? void 0 : _r.page;
totalResultsNeeded = pageSize * (pagesNeeded1 || 1);
apiLimit = 500;
// our search api is limited to a certain amount per request.
//so we will need to make more than one request if totalresultsneeded is greater.
if (totalResultsNeeded < apiLimit) {
backfillParams = (0, deepmerge_1.default)(__assign({}, params), { pagination: { pageSize: totalResultsNeeded, page: 1 } });
backfills.push(this.client.search(backfillParams));
}
else {
pagesNeeded = Math.ceil(totalResultsNeeded / apiLimit);
lastPageCount = apiLimit - (pagesNeeded * apiLimit - totalResultsNeeded);
for (i = 1; i <= pagesNeeded; i++) {
backfillParams = (0, deepmerge_1.default)(__assign({}, params), { pagination: { pageSize: i < pagesNeeded ? apiLimit : lastPageCount, page: i } });
backfills.push(this.client.search(backfillParams));
}
else {
pagesNeeded = Math.ceil(totalResultsNeeded / apiLimit);
lastPageCount = apiLimit - (pagesNeeded * apiLimit - totalResultsNeeded);
for (i = 1; i <= pagesNeeded; i++) {
backfillParams = (0, deepmerge_1.default)(__assign({}, params), { pagination: { pageSize: i < pagesNeeded ? apiLimit : lastPageCount, page: i } });
backfills.push(this.client.search(backfillParams));
}
}
}
if (!(backfills && backfills.length)) return [3 /*break*/, 9];
_u.label = 10;
case 10:
if (!(backfills && backfills.length)) return [3 /*break*/, 12];
backfillResults_1 = [];
return [4 /*yield*/, Promise.all(backfills)];
case 8:
case 11:
backfillResponses = _u.sent();

@@ -247,9 +255,10 @@ backfillResponses.map(function (_a) {

//we need to overwrite the pagination params so the ui doesnt get confused.
response_1.pagination.pageSize = ((_r = params.pagination) === null || _r === void 0 ? void 0 : _r.pageSize) || this.store.pagination.pageSize || this.store.pagination.defaultPageSize;
response_1.pagination.pageSize = pageSize;
response_1.pagination.totalPages = Math.ceil(response_1.pagination.totalResults / response_1.pagination.pageSize);
response_1.pagination.page = (_s = params.pagination) === null || _s === void 0 ? void 0 : _s.page;
//set the response results after all backfill promises are resolved.
response_1.results = backfillResults_1;
return [3 /*break*/, 11];
case 9: return [4 /*yield*/, this.client.search(params)];
case 10:
return [3 /*break*/, 14];
case 12: return [4 /*yield*/, this.client.search(params)];
case 13:
// infinite with no backfills.

@@ -268,6 +277,6 @@ _a = _u.sent(), meta_1 = _a[0], response_1 = _a[1];

response_1.results = __spreadArray(__spreadArray([], previousResults, true), (response_1.results || []), true);
_u.label = 11;
case 11: return [3 /*break*/, 14];
case 12: return [4 /*yield*/, this.client.search(params)];
case 13:
_u.label = 14;
case 14: return [3 /*break*/, 17];
case 15: return [4 /*yield*/, this.client.search(params)];
case 16:
//standard.

@@ -284,10 +293,10 @@ _b = _u.sent(), meta_1 = _b[0], response_1 = _b[1];

}
_u.label = 14;
case 14:
_u.label = 17;
case 17:
searchProfile.stop();
this.log.profile(searchProfile);
afterSearchProfile = this.profiler.create({ type: 'event', name: 'afterSearch', context: params }).start();
_u.label = 15;
case 15:
_u.trys.push([15, 17, , 18]);
_u.label = 18;
case 18:
_u.trys.push([18, 20, , 21]);
return [4 /*yield*/, this.eventManager.fire('afterSearch', {

@@ -298,6 +307,6 @@ controller: this,

})];
case 16:
case 19:
_u.sent();
return [3 /*break*/, 18];
case 17:
return [3 /*break*/, 21];
case 20:
err_2 = _u.sent();

@@ -313,6 +322,7 @@ if ((err_2 === null || err_2 === void 0 ? void 0 : err_2.message) == 'cancelled') {

}
return [3 /*break*/, 18];
case 18:
return [3 /*break*/, 21];
case 21:
afterSearchProfile.stop();
this.log.profile(afterSearchProfile);
// store previous results for infinite usage
if ((_t = this.config.settings) === null || _t === void 0 ? void 0 : _t.infinite) {

@@ -324,5 +334,5 @@ this.previousResults = JSON.parse(JSON.stringify(response_1.results));

afterStoreProfile = this.profiler.create({ type: 'event', name: 'afterStore', context: params }).start();
_u.label = 19;
case 19:
_u.trys.push([19, 21, , 22]);
_u.label = 22;
case 22:
_u.trys.push([22, 24, , 25]);
return [4 /*yield*/, this.eventManager.fire('afterStore', {

@@ -333,6 +343,6 @@ controller: this,

})];
case 20:
case 23:
_u.sent();
return [3 /*break*/, 22];
case 21:
return [3 /*break*/, 25];
case 24:
err_3 = _u.sent();

@@ -348,8 +358,8 @@ if ((err_3 === null || err_3 === void 0 ? void 0 : err_3.message) == 'cancelled') {

}
return [3 /*break*/, 22];
case 22:
return [3 /*break*/, 25];
case 25:
afterStoreProfile.stop();
this.log.profile(afterStoreProfile);
return [3 /*break*/, 24];
case 23:
return [3 /*break*/, 27];
case 26:
err_4 = _u.sent();

@@ -381,4 +391,4 @@ if (err_4) {

}
return [3 /*break*/, 24];
case 24: return [2 /*return*/];
return [3 /*break*/, 27];
case 27: return [2 /*return*/];
}

@@ -385,0 +395,0 @@ });

@@ -100,5 +100,10 @@ import deepmerge from 'deepmerge';

const backfills = [];
let pageSize = params.pagination?.pageSize || this.store.pagination.pageSize || this.store.pagination.defaultPageSize;
if (this.config.settings?.infinite.backfill && !previousResults.length) {
// figure out how many pages of results to backfill and wait on all responses
const pageSize = params.pagination?.pageSize || this.store.pagination.pageSize || this.store.pagination.defaultPageSize;
if (!pageSize) {
//unfortunatly we need to fetch meta to know the default pagesize before we can continue.
const meta = await this.client.meta();
pageSize = meta.pagination?.defaultPageSize;
}
let pagesNeeded1 = params.pagination?.page && params.pagination?.page > this.config.settings?.infinite.backfill

@@ -152,3 +157,4 @@ ? this.config.settings?.infinite.backfill

//we need to overwrite the pagination params so the ui doesnt get confused.
response.pagination.pageSize = params.pagination?.pageSize || this.store.pagination.pageSize || this.store.pagination.defaultPageSize;
response.pagination.pageSize = pageSize;
response.pagination.totalPages = Math.ceil(response.pagination.totalResults / response.pagination.pageSize);
response.pagination.page = params.pagination?.page;

@@ -210,2 +216,3 @@ //set the response results after all backfill promises are resolved.

this.log.profile(afterSearchProfile);
// store previous results for infinite usage
if (this.config.settings?.infinite) {

@@ -212,0 +219,0 @@ this.previousResults = JSON.parse(JSON.stringify(response.results));

{
"name": "@searchspring/snap-controller",
"version": "0.38.0",
"version": "0.38.1",
"description": "Snap Controllers",

@@ -23,13 +23,13 @@ "main": "dist/cjs/index.js",

"dependencies": {
"@searchspring/snap-toolbox": "^0.38.0",
"@searchspring/snap-toolbox": "^0.38.1",
"deepmerge": "4.2.2"
},
"devDependencies": {
"@searchspring/snap-client": "^0.38.0",
"@searchspring/snap-event-manager": "^0.38.0",
"@searchspring/snap-logger": "^0.38.0",
"@searchspring/snap-profiler": "^0.38.0",
"@searchspring/snap-store-mobx": "^0.38.0",
"@searchspring/snap-tracker": "^0.38.0",
"@searchspring/snap-url-manager": "^0.38.0"
"@searchspring/snap-client": "^0.38.1",
"@searchspring/snap-event-manager": "^0.38.1",
"@searchspring/snap-logger": "^0.38.1",
"@searchspring/snap-profiler": "^0.38.1",
"@searchspring/snap-store-mobx": "^0.38.1",
"@searchspring/snap-tracker": "^0.38.1",
"@searchspring/snap-url-manager": "^0.38.1"
},

@@ -40,3 +40,3 @@ "sideEffects": false,

],
"gitHead": "88f7d1f065081f9691f26563666320e198c45ca9"
"gitHead": "c7f130f994a310eb4fefc9806ea102194981bed0"
}

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