Skip to content

Commit

Permalink
add additional methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
wparad committed Feb 15, 2024
1 parent b2f080f commit b071f1f
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 26 deletions.
14 changes: 7 additions & 7 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ on:

jobs:
nodejs:
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v1
uses: actions/setup-node@v4
with:
node-version: 12.22.0
node-version: 16
registry-url: 'https://registry.npmjs.org'

- name: Install packages
Expand All @@ -27,18 +27,18 @@ jobs:
- name: Test
run: yarn lint && yarn validate-types && yarn test
- name: Deploy to NPM
if: github.ref != 'refs/heads/main' && github.event_name == 'push'
if: github.repository_owner == 'Authress-Engineering' && github.ref != 'refs/heads/main' && github.ref != 'refs/heads/master' && github.event_name == 'push'
run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NODE_AUTH_TOKEN }}

- name: After build
if: github.ref != 'refs/heads/main' && github.event_name == 'push'
if: github.repository_owner == 'Authress-Engineering' && github.ref != 'refs/heads/main' && github.ref != 'refs/heads/master' && github.event_name == 'push'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: node make.js after_build
- name: Create Github Release and Tag
if: github.ref != 'refs/heads/main' && github.event_name == 'push'
if: github.repository_owner == 'Authress-Engineering' && github.ref != 'refs/heads/main' && github.ref != 'refs/heads/master' && github.event_name == 'push'
run: |
git tag ${GITHUB_REF/refs\/heads\/release\//}.$GITHUB_RUN_NUMBER
git push origin ${GITHUB_REF/refs\/heads\/release\//}.$GITHUB_RUN_NUMBER
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
12
16
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,6 @@
},
"homepage": "https://rhosys.ch",
"engines": {
"node": ">=12.22"
"node": ">=16"
}
}
115 changes: 98 additions & 17 deletions src/dynamoDbSafe.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ function parseExpression(expression, isMultiExpression) {
}, 'InvalidExpression');
}

// TODO: merge together repeated actions since DDB doesn't accept "SET operand SET operand"

const setExpression = partialExpressions.find(e => e.match(/^SET/i));
if (setExpression) {
// validate the set expression
Expand Down Expand Up @@ -66,10 +64,104 @@ class DynamoDB extends DynamoDbOriginal.DocumentClient {
this.logger = args && args.logger || (() => {});
}

// get
// query
// delete
// put
get(originalParams) {
if (!originalParams || !originalParams.TableName) { throw new DynamoDbError({ error: 'TableName not specified', parameters: originalParams }, 'InvalidParameters'); }
if (!originalParams.Key) { throw new DynamoDbError({ error: 'Key not specified', parameters: originalParams }, 'InvalidParameters'); }

const params = originalParams;
const capturedStack = { name: 'DynamoDB.update() Error:' };
Error.captureStackTrace(capturedStack);
const resultAsync = super.get(params).promise().catch(error => {
const wrappedError = new DynamoDbError({ message: error.message, method: 'Get', parameters: originalParams, dynamoDbStack: error.stack }, error.code);
wrappedError.stack = capturedStack;
throw wrappedError;
});
resultAsync.promise = () => resultAsync;
// Prevent unhandled promise rejections
resultAsync.catch(() => {});
return resultAsync;
}

query(originalParams) {
if (!originalParams || !originalParams.TableName) { throw new DynamoDbError({ error: 'TableName not specified', parameters: originalParams }, 'InvalidParameters'); }
if (!originalParams.Key) { throw new DynamoDbError({ error: 'Key not specified', parameters: originalParams }, 'InvalidParameters'); }

const params = originalParams;
const capturedStack = { name: 'DynamoDB.update() Error:' };
Error.captureStackTrace(capturedStack);
const resultAsync = super.delete(params).promise().catch(error => {
const wrappedError = new DynamoDbError({ message: error.message, method: 'Query', parameters: originalParams, dynamoDbStack: error.stack }, error.code);
wrappedError.stack = capturedStack;
throw wrappedError;
});
resultAsync.promise = () => resultAsync;
// Prevent unhandled promise rejections
resultAsync.catch(() => {});
return resultAsync;
}

delete(originalParams) {
if (!originalParams || !originalParams.TableName) { throw new DynamoDbError({ error: 'TableName not specified', parameters: originalParams }, 'InvalidParameters'); }
if (!originalParams.Key) { throw new DynamoDbError({ error: 'Key not specified', parameters: originalParams }, 'InvalidParameters'); }

const conditionExpressionTokens = parseExpression(originalParams.ConditionExpression);
if (conditionExpressionTokens) {
// Validate the tokens
}

const params = originalParams;
const capturedStack = { name: 'DynamoDB.update() Error:' };
Error.captureStackTrace(capturedStack);
const resultAsync = super.delete(params).promise().catch(error => {
const wrappedError = new DynamoDbError({ message: error.message, method: 'Delete', parameters: originalParams, dynamoDbStack: error.stack }, error.code);
wrappedError.stack = capturedStack;
throw wrappedError;
});
resultAsync.promise = () => resultAsync;
// Prevent unhandled promise rejections
resultAsync.catch(() => {});
return resultAsync;
}

put(originalParams) {
if (!originalParams || !originalParams.TableName) { throw new DynamoDbError({ error: 'TableName not specified', parameters: originalParams }, 'InvalidParameters'); }
if (!originalParams.Key) { throw new DynamoDbError({ error: 'Key not specified', parameters: originalParams }, 'InvalidParameters'); }

const conditionExpressionTokens = parseExpression(originalParams.ConditionExpression);
if (conditionExpressionTokens) {
// Validate the tokens
}

const params = originalParams;
const capturedStack = { name: 'DynamoDB.update() Error:' };
Error.captureStackTrace(capturedStack);
const resultAsync = super.put(params).promise().catch(error => {
const wrappedError = new DynamoDbError({ message: error.message, method: 'Put', parameters: originalParams, dynamoDbStack: error.stack }, error.code);
wrappedError.stack = capturedStack;
throw wrappedError;
});
resultAsync.promise = () => resultAsync;
// Prevent unhandled promise rejections
resultAsync.catch(() => {});
return resultAsync;
}

scan(originalParams) {
if (!originalParams || !originalParams.TableName) { throw new DynamoDbError({ error: 'TableName not specified', parameters: originalParams }, 'InvalidParameters'); }

const params = originalParams;
const capturedStack = { name: 'DynamoDB.update() Error:' };
Error.captureStackTrace(capturedStack);
const resultAsync = super.scan(params).promise().catch(error => {
const wrappedError = new DynamoDbError({ message: error.message, method: 'Scan', parameters: originalParams, dynamoDbStack: error.stack }, error.code);
wrappedError.stack = capturedStack;
throw wrappedError;
});
resultAsync.promise = () => resultAsync;
// Prevent unhandled promise rejections
resultAsync.catch(() => {});
return resultAsync;
}

update(originalParams) {
if (!originalParams || !originalParams.TableName) { throw new DynamoDbError({ error: 'TableName not specified', parameters: originalParams }, 'InvalidParameters'); }
Expand All @@ -82,17 +174,6 @@ class DynamoDB extends DynamoDbOriginal.DocumentClient {
if (updateExpressionTokens || conditionExpressionTokens) {
// Validate the tokens
}

// query related
// const keyExpressionTokens = parseExpression(originalParams.KeyConditionExpression);
// const filterExpressionTokens = parseExpression(originalParams.FilterExpression);
// const matchingFilterExpressionKey = Object.keys(filterExpressionTokens.keys).some(filterKey => Object.keys(keyExpressionTokens.keys)
// .some(keyKey => originalParams.ExpressionAttributeNames[keyKey] === originalParams.ExpressionAttributeNames[filterKey]));

// // TODO: convert this from a error generation to in memory filtering
// if (matchingFilterExpressionKey) {
// throw new DynamoDbError({ title: 'DynamoDB disallows having a FilterExpression contain ', key: matchingFilterExpressionKey, parameters: originalParams }, 'InvalidExpression');
// }

const params = originalParams;
const capturedStack = { name: 'DynamoDB.update() Error:' };
Expand Down

0 comments on commit b071f1f

Please sign in to comment.