Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@middy/dynamodb

Package Overview
Dependencies
Maintainers
3
Versions
65
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@middy/dynamodb - npm Package Compare versions

Comparing version 5.0.0-alpha.1 to 5.0.0-alpha.2

134

index.js

@@ -1,82 +0,64 @@

import {
canPrefetch,
createPrefetchClient,
createClient,
getCache,
getInternal,
processCache,
modifyCache
} from '@middy/util'
import { DynamoDBClient, GetItemCommand } from '@aws-sdk/client-dynamodb'
import { marshall, unmarshall } from '@aws-sdk/util-dynamodb'
import { canPrefetch, createPrefetchClient, createClient, getCache, getInternal, processCache, modifyCache } from '@middy/util';
import { DynamoDBClient, GetItemCommand } from '@aws-sdk/client-dynamodb';
import { marshall, unmarshall } from '@aws-sdk/util-dynamodb';
const defaults = {
AwsClient: DynamoDBClient,
awsClientOptions: {},
awsClientAssumeRole: undefined,
awsClientCapture: undefined,
fetchData: {},
disablePrefetch: false,
cacheKey: 'dynamodb',
cacheKeyExpiry: {},
cacheExpiry: -1,
setToContext: false
}
const dynamodbMiddleware = (opts = {}) => {
const options = {
...defaults,
...opts
}
// force marshall of Key during cold start
for (const internalKey in options.fetchData) {
options.fetchData[internalKey].Key = marshall(
options.fetchData[internalKey].Key
)
}
const fetch = (request, cachedValues = {}) => {
const values = {}
for (const internalKey in options.fetchData) {
if (cachedValues[internalKey]) continue
const inputParameters = options.fetchData[internalKey]
values[internalKey] = client
.send(new GetItemCommand(inputParameters))
.then((resp) => unmarshall(resp.Item))
.catch((e) => {
const value = getCache(options.cacheKey).value ?? {}
value[internalKey] = undefined
modifyCache(options.cacheKey, value)
throw e
})
AwsClient: DynamoDBClient,
awsClientOptions: {},
awsClientAssumeRole: undefined,
awsClientCapture: undefined,
fetchData: {},
disablePrefetch: false,
cacheKey: 'dynamodb',
cacheKeyExpiry: {},
cacheExpiry: -1,
setToContext: false
};
const dynamodbMiddleware = (opts = {})=>{
const options = {
...defaults,
...opts
};
// force marshall of Key during cold start
for(const internalKey in options.fetchData){
options.fetchData[internalKey].Key = marshall(options.fetchData[internalKey].Key);
}
return values
}
let client
if (canPrefetch(options)) {
client = createPrefetchClient(options)
processCache(options, fetch)
}
const dynamodbMiddlewareBefore = async (request) => {
if (!client) {
client = await createClient(options, request)
const fetch = (request, cachedValues = {})=>{
const values = {};
for(const internalKey in options.fetchData){
if (cachedValues[internalKey]) continue;
const inputParameters = options.fetchData[internalKey];
values[internalKey] = client.send(new GetItemCommand(inputParameters)).then((resp)=>unmarshall(resp.Item)).catch((e)=>{
const value = getCache(options.cacheKey).value ?? {};
value[internalKey] = undefined;
modifyCache(options.cacheKey, value);
throw e;
});
}
return values;
};
let client;
if (canPrefetch(options)) {
client = createPrefetchClient(options);
processCache(options, fetch);
}
const { value } = processCache(options, fetch, request)
Object.assign(request.internal, value)
if (options.setToContext) {
const data = await getInternal(Object.keys(options.fetchData), request)
Object.assign(request.context, data)
}
}
return {
before: dynamodbMiddlewareBefore
}
}
const dynamodbMiddlewareBefore = async (request)=>{
if (!client) {
client = await createClient(options, request);
}
const { value } = processCache(options, fetch, request);
Object.assign(request.internal, value);
if (options.setToContext) {
const data = await getInternal(Object.keys(options.fetchData), request);
Object.assign(request.context, data);
}
};
return {
before: dynamodbMiddlewareBefore
};
};
// used for TS type inference (see index.d.ts)
export function dynamoDbReq (req) {
return req
export function dynamoDbReq(req) {
return req;
}
export default dynamodbMiddleware;
export default dynamodbMiddleware
{
"name": "@middy/dynamodb",
"version": "5.0.0-alpha.1",
"version": "5.0.0-alpha.2",
"description": "DynamoDB middleware for the middy framework",

@@ -61,3 +61,3 @@ "type": "module",

"dependencies": {
"@middy/util": "5.0.0-alpha.1"
"@middy/util": "5.0.0-alpha.2"
},

@@ -67,3 +67,3 @@ "devDependencies": {

"@aws-sdk/util-dynamodb": "^3.245.0",
"@middy/core": "5.0.0-alpha.1",
"@middy/core": "5.0.0-alpha.2",
"@types/aws-lambda": "^8.10.101",

@@ -70,0 +70,0 @@ "aws-xray-sdk": "^3.3.3"

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc