Skip to content

Commit

Permalink
fix: update deps, security fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ruicsh committed Jan 8, 2023
1 parent 8ae4c1b commit 688085a
Show file tree
Hide file tree
Showing 35 changed files with 1,635 additions and 1,438 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
- uses: actions/checkout@master
- uses: actions/setup-node@master
with:
node-version: 16
node-version: 18
- uses: actions/cache@v1
with:
path: node_modules
Expand All @@ -54,7 +54,7 @@ jobs:
- run: yarn install --frozen-lockfile
- run: yarn build
- name: Semantic Release
uses: cycjimmy/semantic-release-action@v2
uses: cycjimmy/semantic-release-action@main
with:
branch: main
env:
Expand Down
1 change: 0 additions & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"singleQuote": true,
"trailingComma": "es5",
"printWidth": 80,
"useTabs": true
Expand Down
22 changes: 11 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,24 +48,24 @@
},
"dependencies": {},
"devDependencies": {
"@types/jest": "29.2.3",
"@types/node": "18.11.9",
"@typescript-eslint/eslint-plugin": "5.45.0",
"@typescript-eslint/parser": "5.45.0",
"aws-sdk": "^2.1262.0",
"esbuild": "0.15.16",
"eslint": "8.28.0",
"@types/jest": "29.2.5",
"@types/node": "18.11.18",
"@typescript-eslint/eslint-plugin": "5.48.0",
"@typescript-eslint/parser": "5.48.0",
"aws-sdk": "^2.1290.0",
"esbuild": "0.16.15",
"eslint": "8.31.0",
"eslint-config-airbnb-base": "15.0.0",
"eslint-config-airbnb-typescript": "17.0.0",
"eslint-config-prettier": "8.5.0",
"eslint-config-prettier": "8.6.0",
"eslint-plugin-import": "2.26.0",
"eslint-plugin-jest": "27.1.6",
"eslint-plugin-jest": "27.2.1",
"jest": "29.3.1",
"nyc": "15.1.0",
"prettier": "2.8.0",
"prettier": "2.8.2",
"ts-jest": "29.0.3",
"tsx": "3.12.1",
"typescript": "4.9.3",
"typescript": "4.9.4",
"zx": "7.1.1"
},
"peerDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion sh/build.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'zx/globals';
import "zx/globals";

async function main() {
await $`rm -rf dist`;
Expand Down
2 changes: 1 addition & 1 deletion sh/coverage.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'zx/globals';
import "zx/globals";

async function main() {
await $`rm -rf ./node_modules/.cache`;
Expand Down
14 changes: 7 additions & 7 deletions sh/dev.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import 'zx/globals';
import "zx/globals";

async function main() {
const flags = [
'--bundle',
'--watch',
'--format=esm',
'--platform=node',
'--outfile=dist/index.js',
'--external:aws-sdk',
"--bundle",
"--watch",
"--format=esm",
"--platform=node",
"--outfile=dist/index.js",
"--external:aws-sdk",
];

await $`esbuild src/index.ts ${flags}`;
Expand Down
106 changes: 53 additions & 53 deletions src/bug-reports.test.ts
Original file line number Diff line number Diff line change
@@ -1,136 +1,136 @@
import dynoexpr from './index';
import type { FilterInput } from './dynoexpr.d';
import dynoexpr from "./index";
import type { FilterInput } from "./dynoexpr.d";

describe('bug reports', () => {
it('logical operator', () => {
const dateNowSpy = jest.spyOn(Date, 'now').mockReturnValue(1646249594000);
describe("bug reports", () => {
it("logical operator", () => {
const dateNowSpy = jest.spyOn(Date, "now").mockReturnValue(1646249594000);
const args = {
Update: {
modified: new Date(Date.now()).toJSON(),
GSI1_PK: 'OPEN',
GSI2_PK: 'REQUEST#STATUS#open#DATE#2022-03-01T13:58:09.242z',
GSI1_PK: "OPEN",
GSI2_PK: "REQUEST#STATUS#open#DATE#2022-03-01T13:58:09.242z",
},
Condition: {
status: ['IN_PROGRESS', 'OPEN'],
status: ["IN_PROGRESS", "OPEN"],
},
ConditionLogicalOperator: 'OR',
ConditionLogicalOperator: "OR",
};
const result = dynoexpr(args);

const expected = {
ConditionExpression:
'(#n44ec6258 = :va87bccc9) OR (#n44ec6258 = :v5ebbf5c3)',
"(#n44ec6258 = :va87bccc9) OR (#n44ec6258 = :v5ebbf5c3)",
ExpressionAttributeNames: {
'#n4b532461': 'GSI1_PK',
'#n44ec6258': 'status',
'#n4a4b98d5': 'modified',
'#nfbaeecf8': 'GSI2_PK',
"#n4b532461": "GSI1_PK",
"#n44ec6258": "status",
"#n4a4b98d5": "modified",
"#nfbaeecf8": "GSI2_PK",
},
ExpressionAttributeValues: {
':vd8444872': '2022-03-02T19:33:14.000Z',
':v879a6e2b': 'REQUEST#STATUS#open#DATE#2022-03-01T13:58:09.242z',
':va87bccc9': 'IN_PROGRESS',
':v5ebbf5c3': 'OPEN',
":vd8444872": "2022-03-02T19:33:14.000Z",
":v879a6e2b": "REQUEST#STATUS#open#DATE#2022-03-01T13:58:09.242z",
":va87bccc9": "IN_PROGRESS",
":v5ebbf5c3": "OPEN",
},
UpdateExpression:
'SET #n4a4b98d5 = :vd8444872, #n4b532461 = :v5ebbf5c3, #nfbaeecf8 = :v879a6e2b',
"SET #n4a4b98d5 = :vd8444872, #n4b532461 = :v5ebbf5c3, #nfbaeecf8 = :v879a6e2b",
};
expect(result).toStrictEqual(expected);

dateNowSpy.mockRestore();
});

it('supports if_not_exists on update expressions', () => {
it("supports if_not_exists on update expressions", () => {
const result = dynoexpr({
Update: { number: 'if_not_exists(420)' },
Update: { number: "if_not_exists(420)" },
});

const expected = {
UpdateExpression:
'SET #ne68615df = if_not_exists(#ne68615df, :v24592772)',
ExpressionAttributeNames: { '#ne68615df': 'number' },
ExpressionAttributeValues: { ':v24592772': '420' },
"SET #ne68615df = if_not_exists(#ne68615df, :v24592772)",
ExpressionAttributeNames: { "#ne68615df": "number" },
ExpressionAttributeValues: { ":v24592772": "420" },
};
expect(result).toStrictEqual(expected);
});

it('allows boolean values', () => {
it("allows boolean values", () => {
const Filter = {
a: '<> true',
b: '<> false',
a: "<> true",
b: "<> false",
};
const params: FilterInput = { Filter };
const actual = dynoexpr(params);

const expected = {
ExpressionAttributeNames: { '#n69772661': 'a', '#n7531578f': 'b' },
ExpressionAttributeValues: { ':v05902327': false, ':v7534cb09': true },
ExpressionAttributeNames: { "#n69772661": "a", "#n7531578f": "b" },
ExpressionAttributeValues: { ":v05902327": false, ":v7534cb09": true },
FilterExpression:
'(#n69772661 <> :v7534cb09) AND (#n7531578f <> :v05902327)',
"(#n69772661 <> :v7534cb09) AND (#n7531578f <> :v05902327)",
};
expect(actual).toStrictEqual(expected);
});

it('empty ExpressionAttributeValues on UpdateRemove with Condition', () => {
it("empty ExpressionAttributeValues on UpdateRemove with Condition", () => {
const params = {
UpdateRemove: { 'parent.item': 1 },
Condition: { 'parent.item': 'attribute_exists' },
UpdateRemove: { "parent.item": 1 },
Condition: { "parent.item": "attribute_exists" },
};
const actual = dynoexpr(params);

const expected = {
ConditionExpression: '(attribute_exists(#n7e86b602.#n95d67ebc))',
ConditionExpression: "(attribute_exists(#n7e86b602.#n95d67ebc))",
ExpressionAttributeNames: {
'#n95d67ebc': 'item',
'#n7e86b602': 'parent',
"#n95d67ebc": "item",
"#n7e86b602": "parent",
},
UpdateExpression: 'REMOVE #n7e86b602.#n95d67ebc',
UpdateExpression: "REMOVE #n7e86b602.#n95d67ebc",
};
expect(actual).toStrictEqual(expected);
});

it('pass undefined to UpdateRemove', () => {
it("pass undefined to UpdateRemove", () => {
const params = {
UpdateRemove: { 'parent.item': undefined },
Condition: { 'parent.item': 'attribute_exists' },
UpdateRemove: { "parent.item": undefined },
Condition: { "parent.item": "attribute_exists" },
};
const actual = dynoexpr(params);

const expected = {
ConditionExpression: '(attribute_exists(#n7e86b602.#n95d67ebc))',
ConditionExpression: "(attribute_exists(#n7e86b602.#n95d67ebc))",
ExpressionAttributeNames: {
'#n95d67ebc': 'item',
'#n7e86b602': 'parent',
"#n95d67ebc": "item",
"#n7e86b602": "parent",
},
UpdateExpression: 'REMOVE #n7e86b602.#n95d67ebc',
UpdateExpression: "REMOVE #n7e86b602.#n95d67ebc",
};
expect(actual).toStrictEqual(expected);
});

it('handles list_append', () => {
it("handles list_append", () => {
const params = {
Update: { numbersArray: 'list_append([1, 2], numbersArray)' },
Update: { numbersArray: "list_append([1, 2], numbersArray)" },
};
const actual = dynoexpr(params);

const expected = {
UpdateExpression: 'SET #n596ceb9c = list_append(:v31e6eb45, #n596ceb9c)',
ExpressionAttributeNames: { '#n596ceb9c': 'numbersArray' },
ExpressionAttributeValues: { ':v31e6eb45': [1, 2] },
UpdateExpression: "SET #n596ceb9c = list_append(:v31e6eb45, #n596ceb9c)",
ExpressionAttributeNames: { "#n596ceb9c": "numbersArray" },
ExpressionAttributeValues: { ":v31e6eb45": [1, 2] },
};
expect(actual).toStrictEqual(expected);
});

it('handles list_append with strings', () => {
it("handles list_append with strings", () => {
const params = {
Update: { numbersArray: 'list_append(["a", "b"], numbersArray)' },
};
const actual = dynoexpr(params);

const expected = {
UpdateExpression: 'SET #n596ceb9c = list_append(:v3578c5eb, #n596ceb9c)',
ExpressionAttributeNames: { '#n596ceb9c': 'numbersArray' },
ExpressionAttributeValues: { ':v3578c5eb': ['a', 'b'] },
UpdateExpression: "SET #n596ceb9c = list_append(:v3578c5eb, #n596ceb9c)",
ExpressionAttributeNames: { "#n596ceb9c": "numbersArray" },
ExpressionAttributeValues: { ":v3578c5eb": ["a", "b"] },
};
expect(actual).toStrictEqual(expected);
});
Expand Down
2 changes: 1 addition & 1 deletion src/cjs/index.cjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import dynoexpr from '../index';
import dynoexpr from "../index";

module.exports = dynoexpr;
6 changes: 3 additions & 3 deletions src/dynoexpr.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable @typescript-eslint/indent */
type LogicalOperatorType = string | 'AND' | 'OR';
type LogicalOperatorType = string | "AND" | "OR";

type DynoexprInputValue =
| string
Expand Down Expand Up @@ -44,7 +44,7 @@ type BatchRequestOutput = {
};

// transact operations
type TransactOperation = 'Get' | 'ConditionCheck' | 'Put' | 'Delete' | 'Update';
type TransactOperation = "Get" | "ConditionCheck" | "Put" | "Delete" | "Update";
type TransactRequestItems = Partial<Record<TransactOperation, DynoexprInput>>;
export type TransactRequestInput = {
TransactItems: TransactRequestItems[];
Expand Down Expand Up @@ -110,7 +110,7 @@ type ProjectionOutput = Partial<{

// Update
type Update = Record<string, DynoexprInputValue>;
type UpdateAction = 'SET' | 'ADD' | 'DELETE' | 'REMOVE';
type UpdateAction = "SET" | "ADD" | "DELETE" | "REMOVE";
type UpdateInput = Partial<{
Update?: Update;
UpdateAction?: UpdateAction;
Expand Down

0 comments on commit 688085a

Please sign in to comment.