@twin.org/entity-storage-connector-postgresql 0.0.1-next.21 → 0.0.1-next.22
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.
package/dist/cjs/index.cjs
CHANGED
|
@@ -189,8 +189,7 @@ class PostgreSqlEntityStorageConnector {
|
|
|
189
189
|
*/
|
|
190
190
|
async set(entity$1, conditions) {
|
|
191
191
|
core.Guards.object(this.CLASS_NAME, "entity", entity$1);
|
|
192
|
-
|
|
193
|
-
this.entitySqlVerification(entity$1);
|
|
192
|
+
entity.EntitySchemaHelper.validateEntity(entity$1, this.getSchema());
|
|
194
193
|
const primaryKey = entity.EntitySchemaHelper.getPrimaryKey(this.getSchema());
|
|
195
194
|
const id = entity$1[primaryKey.property];
|
|
196
195
|
try {
|
|
@@ -523,34 +522,6 @@ class PostgreSqlEntityStorageConnector {
|
|
|
523
522
|
const primaryKeyDefinition = primaryKeys.length > 0 ? `, PRIMARY KEY (${primaryKeys.join(", ")})` : "";
|
|
524
523
|
return columnDefinitions + primaryKeyDefinition;
|
|
525
524
|
}
|
|
526
|
-
/**
|
|
527
|
-
* Validate that the entity matches the schema.
|
|
528
|
-
* @param entity The entity to validate.
|
|
529
|
-
* @throws GeneralError if the entity schema properties are undefined or if the entity does not match the schema.
|
|
530
|
-
*/
|
|
531
|
-
entitySqlVerification(entity) {
|
|
532
|
-
// Validate that the entity matches the schema
|
|
533
|
-
if (!this._entitySchema.properties) {
|
|
534
|
-
throw new core.GeneralError(this.CLASS_NAME, "entitySchemaPropertiesUndefined");
|
|
535
|
-
}
|
|
536
|
-
for (const prop of this._entitySchema.properties) {
|
|
537
|
-
const value = entity[prop.property];
|
|
538
|
-
if (value === undefined || value === null) {
|
|
539
|
-
if (!prop.optional) {
|
|
540
|
-
throw new core.GeneralError(this.CLASS_NAME, "invalidEntity", {
|
|
541
|
-
entity,
|
|
542
|
-
entitySchema: this._entitySchema
|
|
543
|
-
});
|
|
544
|
-
}
|
|
545
|
-
}
|
|
546
|
-
else if (typeof value !== prop.type && (prop.type !== "array" || !core.Is.array(value))) {
|
|
547
|
-
throw new core.GeneralError(this.CLASS_NAME, "invalidEntity", {
|
|
548
|
-
entity,
|
|
549
|
-
entitySchema: this._entitySchema
|
|
550
|
-
});
|
|
551
|
-
}
|
|
552
|
-
}
|
|
553
|
-
}
|
|
554
525
|
}
|
|
555
526
|
|
|
556
527
|
exports.PostgreSqlEntityStorageConnector = PostgreSqlEntityStorageConnector;
|
package/dist/esm/index.mjs
CHANGED
|
@@ -187,8 +187,7 @@ class PostgreSqlEntityStorageConnector {
|
|
|
187
187
|
*/
|
|
188
188
|
async set(entity, conditions) {
|
|
189
189
|
Guards.object(this.CLASS_NAME, "entity", entity);
|
|
190
|
-
|
|
191
|
-
this.entitySqlVerification(entity);
|
|
190
|
+
EntitySchemaHelper.validateEntity(entity, this.getSchema());
|
|
192
191
|
const primaryKey = EntitySchemaHelper.getPrimaryKey(this.getSchema());
|
|
193
192
|
const id = entity[primaryKey.property];
|
|
194
193
|
try {
|
|
@@ -521,34 +520,6 @@ class PostgreSqlEntityStorageConnector {
|
|
|
521
520
|
const primaryKeyDefinition = primaryKeys.length > 0 ? `, PRIMARY KEY (${primaryKeys.join(", ")})` : "";
|
|
522
521
|
return columnDefinitions + primaryKeyDefinition;
|
|
523
522
|
}
|
|
524
|
-
/**
|
|
525
|
-
* Validate that the entity matches the schema.
|
|
526
|
-
* @param entity The entity to validate.
|
|
527
|
-
* @throws GeneralError if the entity schema properties are undefined or if the entity does not match the schema.
|
|
528
|
-
*/
|
|
529
|
-
entitySqlVerification(entity) {
|
|
530
|
-
// Validate that the entity matches the schema
|
|
531
|
-
if (!this._entitySchema.properties) {
|
|
532
|
-
throw new GeneralError(this.CLASS_NAME, "entitySchemaPropertiesUndefined");
|
|
533
|
-
}
|
|
534
|
-
for (const prop of this._entitySchema.properties) {
|
|
535
|
-
const value = entity[prop.property];
|
|
536
|
-
if (value === undefined || value === null) {
|
|
537
|
-
if (!prop.optional) {
|
|
538
|
-
throw new GeneralError(this.CLASS_NAME, "invalidEntity", {
|
|
539
|
-
entity,
|
|
540
|
-
entitySchema: this._entitySchema
|
|
541
|
-
});
|
|
542
|
-
}
|
|
543
|
-
}
|
|
544
|
-
else if (typeof value !== prop.type && (prop.type !== "array" || !Is.array(value))) {
|
|
545
|
-
throw new GeneralError(this.CLASS_NAME, "invalidEntity", {
|
|
546
|
-
entity,
|
|
547
|
-
entitySchema: this._entitySchema
|
|
548
|
-
});
|
|
549
|
-
}
|
|
550
|
-
}
|
|
551
|
-
}
|
|
552
523
|
}
|
|
553
524
|
|
|
554
525
|
export { PostgreSqlEntityStorageConnector };
|
|
@@ -85,10 +85,4 @@ export declare class PostgreSqlEntityStorageConnector<T = unknown> implements IE
|
|
|
85
85
|
* @throws GeneralError if the entity properties do not exist.
|
|
86
86
|
*/
|
|
87
87
|
private mapPostgreSqlProperties;
|
|
88
|
-
/**
|
|
89
|
-
* Validate that the entity matches the schema.
|
|
90
|
-
* @param entity The entity to validate.
|
|
91
|
-
* @throws GeneralError if the entity schema properties are undefined or if the entity does not match the schema.
|
|
92
|
-
*/
|
|
93
|
-
private entitySqlVerification;
|
|
94
88
|
}
|
package/docs/changelog.md
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@twin.org/entity-storage-connector-postgresql",
|
|
3
|
-
"version": "0.0.1-next.
|
|
3
|
+
"version": "0.0.1-next.22",
|
|
4
4
|
"description": "Entity Storage connector implementation using PostgreSql storage",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"dependencies": {
|
|
17
17
|
"@twin.org/core": "next",
|
|
18
18
|
"@twin.org/entity": "next",
|
|
19
|
-
"@twin.org/entity-storage-models": "0.0.1-next.
|
|
19
|
+
"@twin.org/entity-storage-models": "0.0.1-next.22",
|
|
20
20
|
"@twin.org/logging-models": "next",
|
|
21
21
|
"@twin.org/nameof": "next",
|
|
22
22
|
"postgres": "^3.4.5"
|