jxp-helper 1.3.13 → 1.4.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.
Files changed (2) hide show
  1. package/jxp-helper.js +36 -13
  2. package/package.json +2 -2
package/jxp-helper.js CHANGED
@@ -147,7 +147,7 @@ class JXPHelper {
147
147
 
148
148
  async bulk_postput(type, key, data) {
149
149
  try {
150
- if (!Array.isArray(data)) return await JXPHelper.postput(type, key, data);
150
+ if (!Array.isArray(data)) return await this.postput(type, key, data);
151
151
  const updates = data.map(item => {
152
152
  const updateQuery = {
153
153
  "updateOne": {
@@ -156,7 +156,13 @@ class JXPHelper {
156
156
  }
157
157
  updateQuery.updateOne.update = item;
158
158
  updateQuery.updateOne.filter = {};
159
- updateQuery.updateOne.filter[key] = item[key];
159
+ if (Array.isArray(key)) {
160
+ key.forEach(k => {
161
+ updateQuery.updateOne.filter[k] = item[k];
162
+ });
163
+ } else {
164
+ updateQuery.updateOne.filter[key] = item[key];
165
+ }
160
166
  return updateQuery;
161
167
  });
162
168
  const url = `${this.server}/bulkwrite/${type}?apikey=${this.apikey}`;
@@ -188,6 +194,34 @@ class JXPHelper {
188
194
  }
189
195
  }
190
196
 
197
+ async bulk_post(type, data) {
198
+ try {
199
+ const updates = data.map(item => {
200
+ return {
201
+ "insertOne": {
202
+ "document": item
203
+ }
204
+ }
205
+ });
206
+ const url = `${this.server}/bulkwrite/${type}?apikey=${this.apikey}`;
207
+ return (await axios.post(url, updates)).data;
208
+ } catch (err) {
209
+ this._displayError(err);
210
+ throw (err.response ? err.response.data : err);
211
+ }
212
+ }
213
+
214
+ async bulk(type, query) {
215
+ try {
216
+ if (this.debug) console.log("bulk", type);
217
+ const url = `${this.server}/bulkwrite/${type}?apikey=${this.apikey}`;
218
+ return (await axios.post(url, query)).data;
219
+ } catch(err) {
220
+ this._displayError(err);
221
+ throw(err.response ? err.response.data : err);
222
+ }
223
+ }
224
+
191
225
  // A very fast way to update ALL rows in a collection, with no seatbelts
192
226
  async put_all(type, data) {
193
227
  try {
@@ -209,17 +243,6 @@ class JXPHelper {
209
243
  }
210
244
  }
211
245
 
212
- async bulk(type, query) {
213
- try {
214
- if (this.debug) console.log("bulk", type);
215
- const url = `${this.server}/bulkwrite/${type}?apikey=${this.apikey}`;
216
- return (await axios.post(url, query)).data;
217
- } catch(err) {
218
- this._displayError(err);
219
- throw(err.response ? err.response.data : err);
220
- }
221
- }
222
-
223
246
  async count(type, opts) {
224
247
  const label = `count.${type}-${this._randomString()}`;
225
248
  if (this.debug) console.time(label);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jxp-helper",
3
- "version": "1.3.13",
3
+ "version": "1.4.0",
4
4
  "description": "A bunch of helpful functions for talking to a JXP API server ",
5
5
  "main": "jxp-helper.js",
6
6
  "scripts": {
@@ -17,6 +17,6 @@
17
17
  },
18
18
  "homepage": "https://github.com/j-norwood-young/jxp-helper#readme",
19
19
  "dependencies": {
20
- "axios": "^0.21.1"
20
+ "axios": "^1.1.3"
21
21
  }
22
22
  }