Skip to content

Commit

Permalink
feat: init db wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
alinarublea committed Oct 19, 2023
1 parent fabbd71 commit c15a214
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
28 changes: 17 additions & 11 deletions src/db-wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,21 @@ import createDynamoDBService from './db.js';
import serviceWrap from './service-wrap.js';

export default function dynamoDBWrapper(func) {
const region = process.env.AWS_REGION;
if (!region) {
throw Error('Please define region in secrets');
}
return (request, context) => serviceWrap(
func,
request,
{ ...context, region },
'__ow_dynamodb',
createDynamoDBService,
);
return async (...args) => {
let params = {};
let context;
[params, context = {}] = args;
const region = process.env.AWS_REGION;
if (!region) {
throw Error('Please define region in secrets');
}
context = { ...context, region };
serviceWrap(
params,
context,
'__ow_dynamodb',
createDynamoDBService,
);
return func(...args);
};
}
2 changes: 0 additions & 2 deletions src/service-wrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
* governing permissions and limitations under the License.
*/
export default function serviceWrap(
lambdaFn,
lambdaRequest,
lambdaContext,
paramName,
Expand All @@ -22,5 +21,4 @@ export default function serviceWrap(
// eslint-disable-next-line no-param-reassign
lambdaContext[paramName] = factoryFn(lambdaContext);
}
return lambdaFn(lambdaContext);
}

0 comments on commit c15a214

Please sign in to comment.