kinvey-flex-sdk
Advanced tools
Comparing version 3.3.0-alpha.2 to 3.3.0
@@ -16,4 +16,6 @@ /** | ||
const BaseStore = require('./baseStore'); | ||
const async = require('async'); | ||
const BASE_ROUTE = 'appdata'; | ||
const SAVE_BATCH_SIZE = 100; | ||
@@ -37,2 +39,50 @@ // Initialize the DataStore; initializes to current User Context, unless useMasterSecret = true | ||
_makeAppdataBatchRequest(requestOptions, entities, collectionName, callback) { | ||
if (this._taskMetadata.objectName === collectionName && (this._useBl === true || this._useUserContext === true)) { | ||
const error = new Error('DataStoreError'); | ||
error.description = 'Not Allowed'; | ||
error.debug = 'Recursive data operations to the same collection cannot use user context or use BL.'; | ||
return callback ? setImmediate(() => callback(error)) : Promise.reject(error); | ||
} | ||
// send multi-insert request in batches | ||
const entitiesInBatches = []; | ||
let start = 0; | ||
while (start < entities.length) { | ||
entitiesInBatches.push(entities.slice(start, start + SAVE_BATCH_SIZE)); | ||
start += SAVE_BATCH_SIZE; | ||
} | ||
const totalEntities = []; | ||
const totalErrors = []; | ||
return new Promise((resolve, reject) => { | ||
async.eachOfSeries(entitiesInBatches, (batch, i, cb) => { | ||
requestOptions.body = batch; | ||
this._makeRequest(requestOptions, (err, resBody) => { | ||
if (err) return cb(err); | ||
totalEntities.push(...resBody.entities); | ||
// change batch-specific index to absolute index | ||
resBody.errors.forEach((e) => { | ||
e.index = (SAVE_BATCH_SIZE * i) + e.index; | ||
}); | ||
totalErrors.push(...resBody.errors); | ||
cb(); | ||
}); | ||
}, (err) => { | ||
if (err) { | ||
return callback ? callback(err) : reject(err); | ||
} | ||
// form the result | ||
const resBody = { | ||
entities: totalEntities, | ||
errors: totalErrors | ||
}; | ||
return callback ? callback(null, resBody) : resolve(resBody); | ||
}); | ||
}); | ||
} | ||
collection(collectionName) { | ||
@@ -56,4 +106,7 @@ const save = (entity, callback) => { | ||
if (Array.isArray(entity) && entity.length > SAVE_BATCH_SIZE) { | ||
return this._makeAppdataBatchRequest(requestOptions, entity, collectionName, callback); | ||
} | ||
requestOptions.body = entity; | ||
return this._makeAppdataRequest(requestOptions, collectionName, callback); | ||
@@ -60,0 +113,0 @@ }; |
{ | ||
"name": "kinvey-flex-sdk", | ||
"version": "3.3.0-alpha.2", | ||
"version": "3.3.0", | ||
"description": "SDK for creating Kinvey Flex Services", | ||
@@ -19,2 +19,3 @@ "engines": { | ||
"dependencies": { | ||
"async": "3.1.0", | ||
"bson": "0.4.23", | ||
@@ -21,0 +22,0 @@ "kinvey-code-task-runner": "2.4.0", |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
692150
15818
1
7
+ Addedasync@3.1.0
+ Addedasync@3.1.0(transitive)