Skip to content

Commit

Permalink
feat!: move to AWS-SDK v3 (#471)
Browse files Browse the repository at this point in the history
  • Loading branch information
naorpeled committed Apr 8, 2023
1 parent 6127274 commit 6873d7e
Show file tree
Hide file tree
Showing 34 changed files with 7,908 additions and 5,322 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@
"@typescript-eslint/ban-ts-comment": "off",
// TODO: remove this rule when all the code is fully migrated to TS, atm it just produces a lot of noise
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/ban-types": "warn"
"@typescript-eslint/ban-types": "warn",
"@typescript-eslint/no-non-null-assertion": "warn"
},
"globals": {
"expect": true,
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ jobs:
node-version: '16'
- name: Install dependencies
run: npm ci --legacy-peer-deps
- name: Build
run: npm run build
- name: Check types
run: npm run check-types
- name: Test types
Expand Down
11,475 changes: 7,097 additions & 4,378 deletions package-lock.json

Large diffs are not rendered by default.

5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
"check-types": "tsc --noEmit",
"lint": "eslint .",
"build": "rm -rf dist && tsc -p tsconfig.build.json",
"prepare": "npm run build",
"prepublishOnly": "npm test && npm run lint && npm run test-types",
"changelog": "git log $(git describe --tags --abbrev=0)..HEAD --oneline"
},
Expand Down Expand Up @@ -43,12 +42,12 @@
"@types/node": "^14.14.16",
"@typescript-eslint/eslint-plugin": "^5.43.0",
"@typescript-eslint/parser": "^5.43.0",
"aws-sdk": "^2.818.0",
"@aws-sdk/lib-dynamodb": "^3.287.0",
"@aws-sdk/client-dynamodb": "^3.287.0",
"coveralls": "^3.1.0",
"dynalite": "^3.2.1",
"eslint": "^8.2.0",
"jest": "^29.2.2",
"mockdate": "^3.0.2",
"prettier": "^2.2.1",
"ts-jest": "^29.0.3",
"tsd": "^0.23.0",
Expand Down
71 changes: 31 additions & 40 deletions src/__tests__/bootstrap.test.ts
Original file line number Diff line number Diff line change
@@ -1,52 +1,43 @@
// Include dynalite and config server (use in memory)
// @ts-ignore: No type file available
import dynalite from 'dynalite'
import { DynamoDBClient } from '@aws-sdk/client-dynamodb'
import { DynamoDBDocumentClient } from '@aws-sdk/lib-dynamodb'

export const dynaliteServer = dynalite({
createTableMs: 0,
updateTableMs: 0,
deleteTableMs: 0
})
const marshallOptions = {
// Whether to automatically convert empty strings, blobs, and sets to `null`.
convertEmptyValues: false, // false, by default.
// Whether to remove undefined values while marshalling.
removeUndefinedValues: false, // false, by default.
// Whether to convert typeof object to map attribute.
convertClassInstanceToMap: false, // false, by default.
}

// Load AWS SDK
import AWS from 'aws-sdk'
const unmarshallOptions = {
// Whether to return numbers as a string instead of converting them to native JavaScript numbers.
wrapNumbers: false, // false, by default.
}

// Create DynamoDB connection to dynalite
export const DynamoDB = new AWS.DynamoDB({
endpoint: 'http://localhost:4567',
region: 'us-east-1',
credentials: new AWS.Credentials({
accessKeyId: 'test',
secretAccessKey: 'test'
})
})
const translateConfig = { marshallOptions, unmarshallOptions }

// Create our document client
export const DocumentClient = new AWS.DynamoDB.DocumentClient({
export const DocumentClient = DynamoDBDocumentClient.from(new DynamoDBClient({
endpoint: 'http://localhost:4567',
region: 'us-east-1',
credentials: new AWS.Credentials({
credentials: {
accessKeyId: 'test',
secretAccessKey: 'test'
})
// convertEmptyValues: true
})
secretAccessKey: 'test',
},
}), translateConfig)

export const DocumentClientWrappedNumbers = new AWS.DynamoDB.DocumentClient({

export const DocumentClientWithWrappedNumbers = DynamoDBDocumentClient.from(new DynamoDBClient({
endpoint: 'http://localhost:4567',
region: 'us-east-1',
credentials: new AWS.Credentials({
credentials: {
accessKeyId: 'test',
secretAccessKey: 'test'
}),
wrapNumbers: true
})

// Delay helper
export const delay = (ms: number) => new Promise(res => setTimeout(res, ms))

export const DocumentClient2 = new AWS.DynamoDB.DocumentClient({
region: 'us-east-1',
credentials: new AWS.SharedIniFileCredentials({ profile: '' })
// convertEmptyValues: false
secretAccessKey: 'test',
},
}), {
...translateConfig,
unmarshallOptions: {
...translateConfig.unmarshallOptions,
wrapNumbers: true,
}
})

0 comments on commit 6873d7e

Please sign in to comment.