@remult/core
Advanced tools
Comparing version
{ | ||
"name": "@remult/core", | ||
"schematics": "./schematics/collection.json", | ||
"version": "3.1.2", | ||
"version": "3.1.4", | ||
"description": "remult core lib", | ||
"homepage": "https://remult-ts.github.io/", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/remult-ts/core" | ||
}, | ||
"license": "MIT", | ||
@@ -7,0 +11,0 @@ "author": { |
@@ -5,2 +5,4 @@ "use strict"; | ||
var tslib_1 = require("tslib"); | ||
var column_1 = require("../column"); | ||
var sort_1 = require("../sort"); | ||
var ArrayEntityDataProvider = /** @class */ (function () { | ||
@@ -143,10 +145,32 @@ function ArrayEntityDataProvider(entity, rows) { | ||
ArrayEntityDataProvider.prototype.insert = function (data) { | ||
if (data.id) | ||
this.rows.forEach(function (i) { | ||
if (data.id == i.id) | ||
throw Error("id already exists"); | ||
return tslib_1.__awaiter(this, void 0, void 0, function () { | ||
var idf, lastRow, j; | ||
return tslib_1.__generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
idf = this.entity.idMetadata.field; | ||
if (!!(idf instanceof column_1.CompoundIdField)) return [3 /*break*/, 3]; | ||
if (!this.entity.options.dbAutoIncrementId) return [3 /*break*/, 2]; | ||
return [4 /*yield*/, this.find({ orderBy: new sort_1.Sort({ field: idf, isDescending: true }) })]; | ||
case 1: | ||
lastRow = _a.sent(); | ||
if (lastRow.length > 0) | ||
data[idf.key] = lastRow[0][idf.key] + 1; | ||
else | ||
data[idf.key] = 1; | ||
_a.label = 2; | ||
case 2: | ||
if (data[idf.key]) | ||
this.rows.forEach(function (i) { | ||
if (data[idf.key] == i[idf.key]) | ||
throw Error("id already exists"); | ||
}); | ||
_a.label = 3; | ||
case 3: | ||
j = this.translateToJson(data); | ||
this.rows.push(j); | ||
return [2 /*return*/, Promise.resolve(this.translateFromJson(j))]; | ||
} | ||
}); | ||
var j = this.translateToJson(data); | ||
this.rows.push(j); | ||
return Promise.resolve(this.translateFromJson(j)); | ||
}); | ||
}; | ||
@@ -153,0 +177,0 @@ return ArrayEntityDataProvider; |
@@ -71,7 +71,11 @@ "use strict"; | ||
JsonEntityDataProvider.prototype.insert = function (data) { | ||
var _this = this; | ||
return this.p = this.p.then(function () { return _this.loadEntityData(function (dp, save) { return dp.insert(data).then(function (x) { | ||
save(); | ||
return x; | ||
}); }); }); | ||
return tslib_1.__awaiter(this, void 0, void 0, function () { | ||
var _this = this; | ||
return tslib_1.__generator(this, function (_a) { | ||
return [2 /*return*/, this.p = this.p.then(function () { return _this.loadEntityData(function (dp, save) { return dp.insert(data).then(function (x) { | ||
save(); | ||
return x; | ||
}); }); })]; | ||
}); | ||
}); | ||
}; | ||
@@ -78,0 +82,0 @@ return JsonEntityDataProvider; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
1339090
0.16%20696
0.14%2
-33.33%