kinvey-js-sdk
Advanced tools
Comparing version 4.1.0 to 4.2.0
@@ -17,5 +17,5 @@ import { Aggregation } from '../aggregation'; | ||
findById(id: string, options?: any): any; | ||
create(doc: any, options?: any): Promise<any>; | ||
create(docs: any, options?: any): Promise<any>; | ||
update(doc: any, options?: any): Promise<any>; | ||
save(doc: any, options?: any): Promise<any>; | ||
save(docs: any, options?: any): Promise<any>; | ||
remove(query: Query, options?: any): Promise<any>; | ||
@@ -22,0 +22,0 @@ removeById(id: string, options?: any): Promise<any>; |
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var tslib_1 = require("tslib"); | ||
var isArray_1 = tslib_1.__importDefault(require("lodash/isArray")); | ||
var cloneDeep_1 = tslib_1.__importDefault(require("lodash/cloneDeep")); | ||
var rxjs_1 = require("rxjs"); | ||
@@ -12,2 +13,3 @@ var device_1 = require("../device"); | ||
var live_1 = require("../live"); | ||
var kmd_1 = require("../kmd"); | ||
function createRequest(method, url, body) { | ||
@@ -217,16 +219,43 @@ return new http_1.KinveyHttpRequest({ | ||
}; | ||
NetworkStore.prototype.create = function (doc, options) { | ||
NetworkStore.prototype.create = function (docs, options) { | ||
if (options === void 0) { options = {}; } | ||
return tslib_1.__awaiter(this, void 0, void 0, function () { | ||
var _a, rawResponse, timeout, properties, trace, skipBL, queryObject, url, request, response; | ||
var batchSize, apiVersion, i_1, batchCreate_1, _a, rawResponse, timeout, properties, trace, skipBL, queryObject, url, request, response; | ||
var _this = this; | ||
return tslib_1.__generator(this, function (_b) { | ||
switch (_b.label) { | ||
case 0: | ||
if (isArray_1.default(doc)) { | ||
batchSize = 100; | ||
apiVersion = kinvey_2.getApiVersion(); | ||
if (apiVersion !== 5 && isArray_1.default(docs)) { | ||
throw new kinvey_1.KinveyError('Unable to create an array of entities. Please create entities one by one.'); | ||
} | ||
if (isArray_1.default(docs) && docs.length > batchSize) { | ||
i_1 = 0; | ||
batchCreate_1 = function (createResults) { | ||
if (createResults === void 0) { createResults = []; } | ||
return tslib_1.__awaiter(_this, void 0, void 0, function () { | ||
var batch, result; | ||
return tslib_1.__generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
if (i_1 >= docs.length) { | ||
return [2 /*return*/, createResults]; | ||
} | ||
batch = docs.slice(i_1, i_1 + batchSize); | ||
i_1 += batchSize; | ||
return [4 /*yield*/, this.create(batch, options)]; | ||
case 1: | ||
result = _a.sent(); | ||
return [2 /*return*/, batchCreate_1(createResults.concat(result))]; | ||
} | ||
}); | ||
}); | ||
}; | ||
return [2 /*return*/, batchCreate_1()]; | ||
} | ||
_a = options.rawResponse, rawResponse = _a === void 0 ? false : _a, timeout = options.timeout, properties = options.properties, trace = options.trace, skipBL = options.skipBL; | ||
queryObject = {}; | ||
url = http_1.formatKinveyBaasUrl(http_1.KinveyBaasNamespace.AppData, this.pathname, queryObject); | ||
request = createRequest(http_1.HttpRequestMethod.POST, url, doc); | ||
request = createRequest(http_1.HttpRequestMethod.POST, url, docs); | ||
request.headers.setCustomRequestProperties(properties); | ||
@@ -275,7 +304,10 @@ request.timeout = timeout; | ||
}; | ||
NetworkStore.prototype.save = function (doc, options) { | ||
if (doc._id) { | ||
return this.update(doc, options); | ||
NetworkStore.prototype.save = function (docs, options) { | ||
if (!isArray_1.default(docs)) { | ||
var kmd = new kmd_1.Kmd(cloneDeep_1.default(docs)); | ||
if (docs._id && !kmd.isLocal()) { | ||
return this.update(docs, options); | ||
} | ||
} | ||
return this.create(doc, options); | ||
return this.create(docs, options); | ||
}; | ||
@@ -282,0 +314,0 @@ NetworkStore.prototype.remove = function (query, options) { |
@@ -11,3 +11,3 @@ export declare class HttpHeaders { | ||
}); | ||
readonly contentType: string; | ||
contentType: string; | ||
has(name: string): boolean; | ||
@@ -14,0 +14,0 @@ get(name: string): string | undefined; |
@@ -42,2 +42,5 @@ Object.defineProperty(exports, "__esModule", { value: true }); | ||
}, | ||
set: function (value) { | ||
this.set('Content-Type', value); | ||
}, | ||
enumerable: true, | ||
@@ -127,3 +130,3 @@ configurable: true | ||
if (!_this.has('X-Kinvey-Api-Version')) { | ||
_this.set('X-Kinvey-Api-Version', '4'); | ||
_this.set('X-Kinvey-Api-Version', String(kinvey_2.getApiVersion())); | ||
} | ||
@@ -130,0 +133,0 @@ // Add global Kinvey headers |
@@ -9,2 +9,3 @@ export interface KinveyConfig { | ||
encryptionKey?: string; | ||
apiVersion?: number; | ||
} | ||
@@ -21,1 +22,2 @@ export declare function getAppKey(): string; | ||
export declare function getEncryptionKey(): string; | ||
export declare function getApiVersion(): number; |
@@ -61,2 +61,10 @@ Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getEncryptionKey = getEncryptionKey; | ||
function getApiVersion() { | ||
var config = config_1.getConfig(config_1.ConfigKey.KinveyConfig); | ||
if (isNumber(config.apiVersion) && config.apiVersion >= 3) { | ||
return config.apiVersion; | ||
} | ||
return 4; | ||
} | ||
exports.getApiVersion = getApiVersion; | ||
//# sourceMappingURL=kinvey.js.map |
{ | ||
"name": "kinvey-js-sdk", | ||
"description": "Kinvey JavaScript SDK for JavaScript applications.", | ||
"version": "4.1.0", | ||
"version": "4.2.0", | ||
"license": "Apache-2.0", | ||
@@ -26,3 +26,4 @@ "homepage": "https://github.com/Kinvey/js-sdk/tree/master/packages/js-sdk", | ||
"build": "tsc -p tsconfig.json", | ||
"test": "mocha --require ts-node/register test/**/*.spec.ts" | ||
"test": "mocha --require ts-node/register test/**/*.spec.ts", | ||
"test:watch": "mocha --require ts-node/register test/**/*.spec.ts --watch --watch-extensions ts" | ||
}, | ||
@@ -29,0 +30,0 @@ "dependencies": { |
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
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
526327
7853