@xapp/dynamo-service
Advanced tools
Comparing version 0.0.61 to 0.0.62
@@ -13,2 +13,5 @@ export declare type DynamoType = "S" | "N" | "M" | "L"; | ||
} | ||
export interface SlugifyParams { | ||
remove?: RegExp; | ||
} | ||
export interface DynamoStringSchema extends DynamoSchema { | ||
@@ -18,2 +21,3 @@ type: "S"; | ||
enum?: string[]; | ||
slugify?: boolean | SlugifyParams; | ||
} | ||
@@ -20,0 +24,0 @@ export declare type DateFormat = "ISO-8601" | "Timestamp"; |
@@ -22,2 +22,3 @@ import { ConditionExpression, DynamoService, QueryParams, QueryResult, ScanParams, ScanResult, UpdateBody, UpdateReturnType } from "./DynamoService"; | ||
private readonly enumKeys; | ||
private readonly slugKeys; | ||
private readonly db; | ||
@@ -46,2 +47,3 @@ private readonly props; | ||
delete(key: Partial<T> | Partial<T>[]): Promise<void>; | ||
private convertObjectToPutObject(obj); | ||
private convertObjFromDynamo(dynamoObj); | ||
@@ -48,0 +50,0 @@ private convertObjFromDynamo<P>(dynamoObj); |
@@ -8,2 +8,3 @@ "use strict"; | ||
const Converters_1 = require("./Converters"); | ||
const slugify = require("slugify"); | ||
function getConverter(schema) { | ||
@@ -25,2 +26,3 @@ if (schema.type === "Date") { | ||
this.enumKeys = {}; | ||
this.slugKeys = {}; | ||
this.tableName = tableName; | ||
@@ -30,2 +32,6 @@ this.db = db; | ||
this.props = props; | ||
this.convertObjectToPutObject = this.convertObjectToPutObject.bind(this); | ||
this.convertObjectsFromDynamo = this.convertObjectsFromDynamo.bind(this); | ||
this.convertObjFromDynamo = this.convertObjFromDynamo.bind(this); | ||
this.convertObjToDynamo = this.convertObjToDynamo.bind(this); | ||
let primaryKeys = []; | ||
@@ -61,2 +67,5 @@ let sortKeys = []; | ||
} | ||
if (v.slugify) { | ||
this.slugKeys[key] = v.slugify; | ||
} | ||
} | ||
@@ -80,3 +89,6 @@ } | ||
ensureEnums(this.enumKeys, obj); | ||
const putObj = (this.props.trimUnknown) ? Object_1.subset(obj, this.knownKeys) : obj; | ||
let putObj = slugifyKeys(this.slugKeys, obj); | ||
if (this.props.trimUnknown) { | ||
putObj = Object_1.subset(putObj, this.knownKeys); | ||
} | ||
ensureNoExtraKeys(this.knownKeys, putObj); | ||
@@ -96,6 +108,5 @@ const primaryExistsQuery = (this.sortKey) ? | ||
}); | ||
const putObjs = (this.props.trimUnknown) ? | ||
obj.map(o => Object_1.subset(o, this.knownKeys)) : | ||
obj; | ||
const converted = putObjs.map(p => this.convertObjToDynamo(p)); | ||
const putObjs = obj.map(this.convertObjectToPutObject); | ||
putObjs.forEach(o => ensureNoExtraKeys(this.knownKeys, o)); | ||
const converted = putObjs.map(this.convertObjToDynamo); | ||
return this.db.put(this.tableName, converted).then(unprocessed => { | ||
@@ -108,5 +119,8 @@ return { | ||
update(key, obj, conditionExpression, returnType) { | ||
const set = (this.props.trimConstants) ? Object_1.removeItems(obj.set, this.constantKeys) : obj.set; | ||
const remove = (this.props.trimConstants) ? Object_1.removeItems(obj.remove, this.constantKeys) : obj.remove; | ||
const append = (this.props.trimConstants) ? Object_1.removeItems(obj.append, this.constantKeys) : obj.append; | ||
let set = slugifyKeys(this.slugKeys, obj.set); | ||
if (this.props.trimConstants) { | ||
set = Object_1.removeItems(obj.set, this.constantKeys); | ||
} | ||
ensureDoesNotHaveConstantKeys(this.constantKeys.concat(this.requiredKeys), remove); | ||
@@ -132,2 +146,9 @@ ensureDoesNotHaveConstantKeys(this.constantKeys, append); | ||
} | ||
convertObjectToPutObject(obj) { | ||
let putObj = slugifyKeys(this.slugKeys, obj); | ||
if (this.props.trimUnknown) { | ||
putObj = Object_1.subset(putObj, this.knownKeys); | ||
} | ||
return putObj; | ||
} | ||
convertObjFromDynamo(dynamoObj) { | ||
@@ -199,1 +220,13 @@ for (let key in this.keyConverters) { | ||
} | ||
function slugifyKeys(keysToSlug, obj) { | ||
const copy = Object.assign({}, obj); | ||
for (let key in keysToSlug) { | ||
const value = obj[key]; | ||
if (typeof value === "string") { | ||
const slugParams = (typeof keysToSlug[key] === "object") ? keysToSlug[key] : undefined; | ||
console.log("SLUG PARAMS", slugParams); | ||
copy[key] = slugify(value, slugParams); | ||
} | ||
} | ||
return copy; | ||
} |
{ | ||
"name": "@xapp/dynamo-service", | ||
"version": "0.0.61", | ||
"version": "0.0.62", | ||
"description": "A dynamo help class which will help maintain data integrity.", | ||
@@ -45,3 +45,5 @@ "main": "dist/index.js", | ||
}, | ||
"dependencies": {} | ||
"dependencies": { | ||
"slugify": "1.2.9" | ||
} | ||
} |
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
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 1 instance in 1 package
142289
3825
1
+ Addedslugify@1.2.9
+ Addedslugify@1.2.9(transitive)