electrodb
Advanced tools
Comparing version 2.6.1 to 2.7.0
{ | ||
"name": "electrodb", | ||
"version": "2.6.1", | ||
"version": "2.7.0", | ||
"description": "A library to more easily create and interact with multiple entities and heretical relationships in dynamodb", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -188,9 +188,13 @@ const { QueryTypes, MethodTypes, ItemOperations, ExpressionTypes, TransactionCommitSymbol, TransactionOperations, TerminalOperation, KeyTypes, IndexTypes } = require("./types"); | ||
const {pk, sk} = state.getCompositeAttributes(); | ||
const pkComposite = entity._expectFacets(facets, pk); | ||
state.addOption('_includeOnResponseItem', pkComposite); | ||
return state | ||
.setMethod(MethodTypes.delete) | ||
.setType(QueryTypes.eq) | ||
.setPK(entity._expectFacets(facets, pk)) | ||
.setPK(pkComposite) | ||
.ifSK(() => { | ||
entity._expectFacets(facets, sk); | ||
state.setSK(state.buildQueryComposites(facets, sk)); | ||
const skComposite = state.buildQueryComposites(facets, sk); | ||
state.setSK(skComposite); | ||
state.addOption('_includeOnResponseItem', {...skComposite, ...pkComposite}); | ||
}); | ||
@@ -219,9 +223,13 @@ } catch(err) { | ||
} | ||
const pkComposite = entity._expectFacets(facets, attributes.pk); | ||
state.addOption('_includeOnResponseItem', pkComposite); | ||
return state | ||
.setMethod(MethodTypes.delete) | ||
.setType(QueryTypes.eq) | ||
.setPK(entity._expectFacets(facets, attributes.pk)) | ||
.setPK(pkComposite) | ||
.ifSK(() => { | ||
entity._expectFacets(facets, attributes.sk); | ||
state.setSK(state.buildQueryComposites(facets, attributes.sk)); | ||
const skComposite = state.buildQueryComposites(facets, attributes.sk); | ||
state.setSK(skComposite); | ||
state.addOption('_includeOnResponseItem', {...skComposite, ...pkComposite}); | ||
}); | ||
@@ -244,2 +252,4 @@ } catch(err) { | ||
const attributes = state.getCompositeAttributes(); | ||
const pkComposite = entity._expectFacets(record, attributes.pk); | ||
state.addOption('_includeOnResponseItem', pkComposite); | ||
return state | ||
@@ -249,6 +259,8 @@ .setMethod(MethodTypes.upsert) | ||
.applyUpsert(record) | ||
.setPK(entity._expectFacets(record, attributes.pk)) | ||
.setPK(pkComposite) | ||
.ifSK(() => { | ||
entity._expectFacets(record, attributes.sk); | ||
state.setSK(entity._buildQueryFacets(record, attributes.sk)); | ||
const skComposite = entity._buildQueryFacets(record, attributes.sk); | ||
state.setSK(skComposite); | ||
state.addOption('_includeOnResponseItem', {...skComposite, ...pkComposite}); | ||
}) | ||
@@ -344,9 +356,13 @@ .whenOptions(({ state, options }) => { | ||
} | ||
const pkComposite = entity._expectFacets(facets, attributes.pk); | ||
state.addOption('_includeOnResponseItem', pkComposite); | ||
return state | ||
.setMethod(MethodTypes.update) | ||
.setType(QueryTypes.eq) | ||
.setPK(entity._expectFacets(facets, attributes.pk)) | ||
.setPK(pkComposite) | ||
.ifSK(() => { | ||
entity._expectFacets(facets, attributes.sk); | ||
state.setSK(state.buildQueryComposites(facets, attributes.sk)); | ||
const skComposite = state.buildQueryComposites(facets, attributes.sk); | ||
state.setSK(skComposite); | ||
state.addOption('_includeOnResponseItem', {...skComposite, ...pkComposite}); | ||
}); | ||
@@ -368,9 +384,13 @@ } catch(err) { | ||
const attributes = state.getCompositeAttributes(); | ||
const pkComposite = entity._expectFacets(facets, attributes.pk); | ||
state.addOption('_includeOnResponseItem', pkComposite); | ||
return state | ||
.setMethod(MethodTypes.update) | ||
.setType(QueryTypes.eq) | ||
.setPK(entity._expectFacets(facets, attributes.pk)) | ||
.setPK(pkComposite) | ||
.ifSK(() => { | ||
entity._expectFacets(facets, attributes.sk); | ||
state.setSK(state.buildQueryComposites(facets, attributes.sk)); | ||
const skComposite = state.buildQueryComposites(facets, attributes.sk); | ||
state.setSK(skComposite); | ||
state.addOption('_includeOnResponseItem', {...pkComposite, ...skComposite}); | ||
}); | ||
@@ -817,3 +837,4 @@ } catch(err) { | ||
upsert: { | ||
data: {} | ||
data: {}, | ||
ifNotExists: {}, | ||
}, | ||
@@ -1028,4 +1049,8 @@ keys: { | ||
applyUpsert(data = {}) { | ||
this.query.upsert.data = {...this.query.upsert.data, ...data}; | ||
applyUpsert(data = {}, { ifNotExists } = {}) { | ||
if (ifNotExists) { | ||
this.query.upsert.ifNotExists = {...this.query.upsert.ifNotExists, ...data}; | ||
} else { | ||
this.query.upsert.data = {...this.query.upsert.data, ...data}; | ||
} | ||
return this; | ||
@@ -1032,0 +1057,0 @@ } |
@@ -1432,3 +1432,3 @@ const { CastTypes, ValueTypes, KeyCasing, AttributeTypes, AttributeMutationMethods, AttributeWildCard, PathTypes, TableIndex, ItemOperations } = require("./types"); | ||
checkUpdate(payload = {}) { | ||
checkUpdate(payload = {}, { allowReadOnly } = {}) { | ||
let record = {}; | ||
@@ -1440,4 +1440,3 @@ for (let [path, attribute] of this.traverser.getAll()) { | ||
} | ||
if (attribute.readOnly) { | ||
// todo: #electroerror | ||
if (attribute.readOnly && !allowReadOnly) { | ||
throw new e.ElectroAttributeValidationError(attribute.path, `Attribute "${attribute.path}" is Read-Only and cannot be updated`); | ||
@@ -1444,0 +1443,0 @@ } else { |
@@ -220,2 +220,3 @@ const KeyTypes = { | ||
"append": "append", | ||
"ifNotExists": "ifNotExists" | ||
}; | ||
@@ -222,0 +223,0 @@ |
@@ -12,3 +12,3 @@ const {AttributeOperationProxy, ExpressionState} = require("./operations"); | ||
subtract: new Set(), | ||
delete: new Set() | ||
delete: new Set(), | ||
}; | ||
@@ -27,3 +27,7 @@ this.seen = new Map(); | ||
set(name, value, operation) { | ||
set(name, value, operation = ItemOperations.set) { | ||
let operationToApply = operation; | ||
if (operation === ItemOperations.ifNotExists) { | ||
operationToApply = ItemOperations.set; | ||
} | ||
const seen = this.seen.get(name); | ||
@@ -35,3 +39,4 @@ let n; | ||
v = seen.value; | ||
this.unadd(ItemOperations.set, seen.expression); | ||
this.unadd(operationToApply, seen.expression); | ||
} else { | ||
@@ -41,3 +46,6 @@ n = this.setName({}, name, name); | ||
} | ||
const expression = `${n.prop} = ${v}`; | ||
let expression = `${n.prop} = ${v}`; | ||
if (operation === ItemOperations.ifNotExists) { | ||
expression = `${n.prop} = if_not_exists(${n.prop}, ${v})`; | ||
} | ||
this.seen.set(name, { | ||
@@ -48,3 +56,3 @@ name: n, | ||
}); | ||
this.add(operation || ItemOperations.set, expression); | ||
this.add(operationToApply, expression); | ||
} | ||
@@ -51,0 +59,0 @@ |
Sorry, the diff of this file is too big to display
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
592715
25
11633
1