@xapp/dynamo-service
Advanced tools
Comparing version 1.0.0-alpha.8 to 1.0.0-alpha.9
@@ -8,3 +8,3 @@ "use strict"; | ||
super(key, schema, isTimestampFormat(schema.dateFormat) ? "number" : "string"); | ||
this.addProcessor(generateFormatProcessor(schema.dateFormat)); | ||
this.addJavascriptProcessor(generateFormatProcessor(schema.dateFormat)); | ||
this.addPutValidator(DateSchemaValidator_1.isDateObjValidator()); | ||
@@ -11,0 +11,0 @@ this.addUpdateBodyValidator(DateSchemaValidator_1.isDateObjUpdateBodyValidator()); |
@@ -14,6 +14,8 @@ import { Converter, NormalSchema, Processor } from "../../../KeySchema"; | ||
private readonly processors; | ||
private readonly javascriptProcessors; | ||
constructor(key: string, schema: T, valueType?: string); | ||
protected addProcessor(...processor: (Processor<any> | Converter<any, any>)[]): void; | ||
protected addPutValidator(...validators: Validator<any>[]): void; | ||
protected addUpdateBodyValidator(...validators: Validator<UpdateBody<any>, T>[]): void; | ||
addProcessor(...processor: (Processor<any> | Converter<any, any>)[]): void; | ||
protected addJavascriptProcessor(...processor: Converter<any, any>[]): void; | ||
addPutValidator(...validators: Validator<any>[]): void; | ||
addUpdateBodyValidator(...validators: Validator<UpdateBody<any>, T>[]): void; | ||
validateObjectAgainstSchema(obj: any): string[]; | ||
@@ -24,4 +26,6 @@ validateUpdateObjectAgainstSchema(updateBody: UpdateBody<any>): string[]; | ||
convertObjectFromSchema(dynamoBaseObject: any): any; | ||
convertObjectFromJavascript(baseObject: any): any; | ||
convertObjectToJavascript(dynamoBaseObject: any): any; | ||
private runValidators; | ||
} | ||
export default NormalSchemaBuilder; |
@@ -13,2 +13,3 @@ "use strict"; | ||
this.processors = [].concat(this.schema.process || []).map(convertToProcessor); | ||
this.javascriptProcessors = []; | ||
this.validators = [ | ||
@@ -30,2 +31,5 @@ IsRequiredValidator_1.isRequiredPutObjectValidator() | ||
} | ||
addJavascriptProcessor(...processor) { | ||
this.javascriptProcessors.push(...processor); | ||
} | ||
addPutValidator(...validators) { | ||
@@ -53,3 +57,3 @@ this.validators.push(...validators); | ||
} | ||
return Object.assign({}, baseObject, { [this.key]: current }); | ||
return this.convertObjectFromJavascript(Object.assign({}, baseObject, { [this.key]: current })); | ||
} | ||
@@ -71,2 +75,24 @@ convertUpdateObjectToSchema(baseObject) { | ||
} | ||
return this.convertObjectToJavascript(copy); | ||
} | ||
convertObjectFromJavascript(baseObject) { | ||
const hasProperty = baseObject.hasOwnProperty(this.key); | ||
const original = baseObject[this.key]; | ||
let current = original; | ||
for (const processor of this.javascriptProcessors) { | ||
current = processor.toObj(current); | ||
} | ||
if (!hasProperty && current == null) { | ||
return baseObject; | ||
} | ||
return Object.assign({}, baseObject, { [this.key]: current }); | ||
} | ||
convertObjectToJavascript(dynamoBaseObject) { | ||
if (!dynamoBaseObject.hasOwnProperty(this.key)) { | ||
return dynamoBaseObject; | ||
} | ||
const copy = Object.assign({}, dynamoBaseObject); | ||
for (const processor of this.javascriptProcessors) { | ||
copy[this.key] = processor.fromObj(copy[this.key]); | ||
} | ||
return copy; | ||
@@ -73,0 +99,0 @@ } |
@@ -10,4 +10,6 @@ import { KeySchema } from "../../KeySchema"; | ||
convertObjectFromSchema(dynamoBaseObject: any): any; | ||
convertObjectFromJavascript(baseObject: any): any; | ||
convertObjectToJavascript(baseObject: any): any; | ||
convertUpdateObjectToSchema(baseObject: UpdateBody<any>): UpdateBody<any>; | ||
} | ||
export declare function getSchemaBuilder(key: string, schema: KeySchema): DateSchemaBuilder | NormalSchemaBuilder<import("../../KeySchema").DynamoSchema<unknown>>; |
@@ -19,3 +19,5 @@ import { UpdateBody } from "../../DynamoService"; | ||
convertObjectToSchema(baseObject: any): any; | ||
convertObjectFromJavascript(baseObject: any): any; | ||
convertObjectToJavascript(baseObject: any): any; | ||
convertUpdateObjectToSchema(baseObject: UpdateBody<any>): UpdateBody<any>; | ||
} |
@@ -51,2 +51,18 @@ "use strict"; | ||
} | ||
convertObjectFromJavascript(baseObject) { | ||
const trimmed = (this.props.trimUnknown) ? trimUnknown(baseObject, this.knownKeys) : baseObject; | ||
let returnObj = Object.assign({}, trimmed); | ||
for (const builder of this.schemaBuilders) { | ||
returnObj = builder.convertObjectFromJavascript(returnObj); | ||
} | ||
return returnObj; | ||
} | ||
convertObjectToJavascript(baseObject) { | ||
const trimmed = (this.props.trimUnknown) ? trimUnknown(baseObject, this.knownKeys) : baseObject; | ||
let returnObj = Object.assign({}, trimmed); | ||
for (const builder of this.schemaBuilders) { | ||
returnObj = builder.convertObjectToJavascript(returnObj); | ||
} | ||
return returnObj; | ||
} | ||
convertUpdateObjectToSchema(baseObject) { | ||
@@ -53,0 +69,0 @@ let returnObj = Object.assign({}, baseObject); |
@@ -86,3 +86,3 @@ "use strict"; | ||
} | ||
return key; | ||
return this.schemaBuilder.convertObjectFromJavascript(key); | ||
} | ||
@@ -89,0 +89,0 @@ validateAndConvertObjectToPutObject(obj) { |
{ | ||
"name": "@xapp/dynamo-service", | ||
"version": "1.0.0-alpha.8", | ||
"version": "1.0.0-alpha.9", | ||
"description": "A dynamo help class which will help maintain data integrity.", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
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
Native code
Supply chain riskContains native code (e.g., compiled binaries or shared libraries). Including native code can obscure malicious behavior.
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
Native code
Supply chain riskContains native code (e.g., compiled binaries or shared libraries). Including native code can obscure malicious behavior.
Found 3 instances in 1 package
5276
2
291298
108