@searchspring/snap-client 0.27.8 → 0.28.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"Recommend.d.ts","sourceRoot":"","sources":["../../../../src/Client/apis/Recommend.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,gBAAgB,EAAe,MAAM,YAAY,CAAC;AAIhE,OAAO,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AAgBvH,qBAAa,YAAa,SAAQ,GAAG;IACpC,OAAO,CAAC,OAAO,CAOb;gBAEU,MAAM,EAAE,gBAAgB;IAK9B,UAAU,CAAC,eAAe,EAAE,mBAAmB,GAAG,OAAO,CAAC,oBAAoB,CAAC;IAgB/E,oBAAoB,CAAC,UAAU,EAAE,qBAAqB,GAAG,OAAO,CAAC,sBAAsB,CAAC;IAgFxF,kBAAkB,CAAC,eAAe,EAAE,qBAAqB,GAAG,OAAO,CAAC,sBAAsB,CAAC;IAmB3F,mBAAmB,CAAC,iBAAiB,EAAE,qBAAqB,GAAG,OAAO,CAAC,sBAAsB,CAAC;CAmBpG"}
1
+ {"version":3,"file":"Recommend.d.ts","sourceRoot":"","sources":["../../../../src/Client/apis/Recommend.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,gBAAgB,EAAe,MAAM,YAAY,CAAC;AAIhE,OAAO,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AAqBvH,qBAAa,YAAa,SAAQ,GAAG;IACpC,OAAO,CAAC,OAAO,CAMb;gBAEU,MAAM,EAAE,gBAAgB;IAK9B,UAAU,CAAC,eAAe,EAAE,mBAAmB,GAAG,OAAO,CAAC,oBAAoB,CAAC;IAgB/E,oBAAoB,CAAC,UAAU,EAAE,qBAAqB,GAAG,OAAO,CAAC,sBAAsB,CAAC;IA+ExF,kBAAkB,CAAC,eAAe,EAAE,qBAAqB,GAAG,OAAO,CAAC,sBAAsB,CAAC;IAmB3F,mBAAmB,CAAC,iBAAiB,EAAE,qBAAqB,GAAG,OAAO,CAAC,sBAAsB,CAAC;CAmBpG"}
@@ -116,11 +116,10 @@ var RecommendAPI = /** @class */ (function (_super) {
116
116
  });
117
117
  };
118
118
  RecommendAPI.prototype.batchRecommendations = function (parameters) {
119
- var _a;
120
119
  return __awaiter(this, void 0, void 0, function () {
121
120
  var tags, limits, categories, otherParams, getKey, key, batch, deferred;
122
121
  var _this = this;
123
- return __generator(this, function (_b) {
122
+ return __generator(this, function (_a) {
124
123
  tags = parameters.tags, limits = parameters.limits, categories = parameters.categories, otherParams = __rest(parameters, ["tags", "limits", "categories"]);
125
124
  getKey = function (parameters) {
126
125
  var key = (0, hashParams_1.hashParams)(parameters);
@@ -132,26 +131,26 @@ var RecommendAPI = /** @class */ (function (_super) {
132
131
  return key;
133
132
  };
134
133
  key = getKey(otherParams);
135
- batch = (this.batches[key] = this.batches[key] || { timeout: null, request: { tags: [], limits: [] }, requests: [], deferreds: [] });
134
+ batch = (this.batches[key] = this.batches[key] || { timeout: null, request: { tags: [], limits: [] }, entries: [] });
136
135
  deferred = new Deferred();
137
136
  // add each request to the list
138
- batch.requests.push(__assign({}, parameters));
139
- (_a = batch.deferreds) === null || _a === void 0 ? void 0 : _a.push(deferred);
137
+ batch.entries.push({ request: parameters, deferred: deferred });
140
138
  // wait for all of the requests to come in
141
139
  window.clearTimeout(batch.timeout);
142
140
  batch.timeout = window.setTimeout(function () { return __awaiter(_this, void 0, void 0, function () {
143
- var batchedRequests, response_1, err_1;
141
+ var response_1, err_1;
144
142
  var _a, _b;
145
143
  return __generator(this, function (_c) {
146
144
  switch (_c.label) {
147
145
  case 0:
148
146
  // delete the batch so a new one can take its place
149
147
  delete this.batches[key];
150
- batchedRequests = batch.requests.sort(sortRequests);
148
+ // reorder the requests by order value in context.
149
+ batch.entries.sort(sortBatchEntries);
151
150
  // now that the requests are in proper order, map through them
152
151
  // and build out the batches
153
- batchedRequests.map(function (request) {
154
- var tags = request.tags, limits = request.limits, categories = request.categories, otherParams = __rest(request, ["tags", "limits", "categories"]);
152
+ batch.entries.map(function (entry) {
153
+ var _a = entry.request, tags = _a.tags, limits = _a.limits, categories = _a.categories, otherParams = __rest(_a, ["tags", "limits", "categories"]);
155
154
  if (!limits)
156
155
  limits = 20;
157
156
  var tag = (tags || [])[0];
@@ -160,7 +159,7 @@ var RecommendAPI = /** @class */ (function (_super) {
160
159
  batch.request.tags.push(tag);
161
160
  if (categories) {
162
161
  if (!batch.request.categories) {
163
- batch.request.categories = categories;
162
+ batch.request.categories = Array.isArray(categories) ? categories : [categories];
164
163
  }
165
164
  else {
166
165
  batch.request.categories = batch.request.categories.concat(categories);
@@ -185,14 +184,14 @@ var RecommendAPI = /** @class */ (function (_super) {
185
184
  response_1 = _c.sent();
186
185
  _c.label = 5;
187
186
  case 5:
188
- (_a = batch.deferreds) === null || _a === void 0 ? void 0 : _a.forEach(function (def, index) {
189
- def.resolve([response_1[index]]);
187
+ (_a = batch.entries) === null || _a === void 0 ? void 0 : _a.forEach(function (entry, index) {
188
+ entry.deferred.resolve([response_1[index]]);
190
189
  });
191
190
  return [3 /*break*/, 7];
192
191
  case 6:
193
192
  err_1 = _c.sent();
194
- (_b = batch.deferreds) === null || _b === void 0 ? void 0 : _b.forEach(function (def) {
195
- def.reject(err_1);
193
+ (_b = batch.entries) === null || _b === void 0 ? void 0 : _b.forEach(function (entry) {
194
+ entry.deferred.reject(err_1);
196
195
  });
197
196
  return [3 /*break*/, 7];
198
197
  case 7: return [2 /*return*/];
@@ -251,21 +250,21 @@ var RecommendAPI = /** @class */ (function (_super) {
251
250
  return RecommendAPI;
252
251
  }(Abstract_1.API));
253
252
  exports.RecommendAPI = RecommendAPI;
254
- function sortRequests(a, b) {
253
+ function sortBatchEntries(a, b) {
255
254
  // undefined order goes last
256
- if (a.order == undefined && b.order == undefined) {
255
+ if (a.request.order == undefined && b.request.order == undefined) {
257
256
  return 0;
258
257
  }
259
- if (a.order == undefined && b.order != undefined) {
258
+ if (a.request.order == undefined && b.request.order != undefined) {
260
259
  return 1;
261
260
  }
262
- if (b.order == undefined && a.order != undefined) {
261
+ if (b.request.order == undefined && a.request.order != undefined) {
263
262
  return -1;
264
263
  }
265
- if (a.order < b.order) {
264
+ if (a.request.order < b.request.order) {
266
265
  return -1;
267
266
  }
268
- if (a.order > b.order) {
267
+ if (a.request.order > b.request.order) {
269
268
  return 1;
270
269
  }
271
270
  return 0;
@@ -1 +1 @@
1
- {"version":3,"file":"Recommend.d.ts","sourceRoot":"","sources":["../../../../src/Client/apis/Recommend.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,gBAAgB,EAAe,MAAM,YAAY,CAAC;AAIhE,OAAO,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AAgBvH,qBAAa,YAAa,SAAQ,GAAG;IACpC,OAAO,CAAC,OAAO,CAOb;gBAEU,MAAM,EAAE,gBAAgB;IAK9B,UAAU,CAAC,eAAe,EAAE,mBAAmB,GAAG,OAAO,CAAC,oBAAoB,CAAC;IAgB/E,oBAAoB,CAAC,UAAU,EAAE,qBAAqB,GAAG,OAAO,CAAC,sBAAsB,CAAC;IAgFxF,kBAAkB,CAAC,eAAe,EAAE,qBAAqB,GAAG,OAAO,CAAC,sBAAsB,CAAC;IAmB3F,mBAAmB,CAAC,iBAAiB,EAAE,qBAAqB,GAAG,OAAO,CAAC,sBAAsB,CAAC;CAmBpG"}
1
+ {"version":3,"file":"Recommend.d.ts","sourceRoot":"","sources":["../../../../src/Client/apis/Recommend.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,gBAAgB,EAAe,MAAM,YAAY,CAAC;AAIhE,OAAO,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AAqBvH,qBAAa,YAAa,SAAQ,GAAG;IACpC,OAAO,CAAC,OAAO,CAMb;gBAEU,MAAM,EAAE,gBAAgB;IAK9B,UAAU,CAAC,eAAe,EAAE,mBAAmB,GAAG,OAAO,CAAC,oBAAoB,CAAC;IAgB/E,oBAAoB,CAAC,UAAU,EAAE,qBAAqB,GAAG,OAAO,CAAC,sBAAsB,CAAC;IA+ExF,kBAAkB,CAAC,eAAe,EAAE,qBAAqB,GAAG,OAAO,CAAC,sBAAsB,CAAC;IAmB3F,mBAAmB,CAAC,iBAAiB,EAAE,qBAAqB,GAAG,OAAO,CAAC,sBAAsB,CAAC;CAmBpG"}
@@ -38,22 +38,21 @@ export class RecommendAPI extends API {
38
38
  };
39
39
  // set up batch keys and deferred promises
40
40
  const key = getKey(otherParams);
41
- const batch = (this.batches[key] = this.batches[key] || { timeout: null, request: { tags: [], limits: [] }, requests: [], deferreds: [] });
41
+ const batch = (this.batches[key] = this.batches[key] || { timeout: null, request: { tags: [], limits: [] }, entries: [] });
42
42
  const deferred = new Deferred();
43
43
  // add each request to the list
44
- batch.requests.push({ ...parameters });
45
- batch.deferreds?.push(deferred);
44
+ batch.entries.push({ request: parameters, deferred: deferred });
46
45
  // wait for all of the requests to come in
47
46
  window.clearTimeout(batch.timeout);
48
47
  batch.timeout = window.setTimeout(async () => {
49
48
  // delete the batch so a new one can take its place
50
49
  delete this.batches[key];
51
50
  // reorder the requests by order value in context.
52
- const batchedRequests = batch.requests.sort(sortRequests);
51
+ batch.entries.sort(sortBatchEntries);
53
52
  // now that the requests are in proper order, map through them
54
53
  // and build out the batches
55
- batchedRequests.map((request) => {
56
- let { tags, limits, categories, ...otherParams } = request;
54
+ batch.entries.map((entry) => {
55
+ let { tags, limits, categories, ...otherParams } = entry.request;
57
56
  if (!limits)
58
57
  limits = 20;
59
58
  const [tag] = tags || [];
@@ -62,7 +61,7 @@ export class RecommendAPI extends API {
62
61
  batch.request.tags.push(tag);
63
62
  if (categories) {
64
63
  if (!batch.request.categories) {
65
- batch.request.categories = categories;
64
+ batch.request.categories = Array.isArray(categories) ? categories : [categories];
66
65
  }
67
66
  else {
68
67
  batch.request.categories = batch.request.categories.concat(categories);
@@ -82,13 +81,13 @@ export class RecommendAPI extends API {
82
81
  else {
83
82
  response = await this.getRecommendations(batch.request);
84
83
  }
85
- batch.deferreds?.forEach((def, index) => {
86
- def.resolve([response[index]]);
84
+ batch.entries?.forEach((entry, index) => {
85
+ entry.deferred.resolve([response[index]]);
87
86
  });
88
87
  }
89
88
  catch (err) {
90
- batch.deferreds?.forEach((def) => {
91
- def.reject(err);
89
+ batch.entries?.forEach((entry) => {
90
+ entry.deferred.reject(err);
92
91
  });
93
92
  }
94
93
  }, BATCH_TIMEOUT);
@@ -120,21 +119,21 @@ export class RecommendAPI extends API {
120
119
  return response;
121
120
  }
122
121
  }
123
- function sortRequests(a, b) {
122
+ function sortBatchEntries(a, b) {
124
123
  // undefined order goes last
125
- if (a.order == undefined && b.order == undefined) {
124
+ if (a.request.order == undefined && b.request.order == undefined) {
126
125
  return 0;
127
126
  }
128
- if (a.order == undefined && b.order != undefined) {
127
+ if (a.request.order == undefined && b.request.order != undefined) {
129
128
  return 1;
130
129
  }
131
- if (b.order == undefined && a.order != undefined) {
130
+ if (b.request.order == undefined && a.request.order != undefined) {
132
131
  return -1;
133
132
  }
134
- if (a.order < b.order) {
133
+ if (a.request.order < b.request.order) {
135
134
  return -1;
136
135
  }
137
- if (a.order > b.order) {
136
+ if (a.request.order > b.request.order) {
138
137
  return 1;
139
138
  }
140
139
  return 0;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@searchspring/snap-client",
3
- "version": "0.27.8",
3
+ "version": "0.28.0",
4
4
  "description": "Snap Client",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",
@@ -20,12 +20,12 @@
20
20
  "test:watch": "jest --watch"
21
21
  },
22
22
  "dependencies": {
23
- "@searchspring/snap-toolbox": "^0.27.8",
23
+ "@searchspring/snap-toolbox": "^0.28.0",
24
24
  "deepmerge": "4.2.2"
25
25
  },
26
26
  "sideEffects": false,
27
27
  "files": [
28
28
  "dist/**/*"
29
29
  ],
30
- "gitHead": "cfbe6d18899fb4944ec397e2419d8409d4ab0065"
30
+ "gitHead": "050a3e8e94678c61db77c597e20bab6e9492bc4f"
31
31
  }