Repository: jeremydaly/dynamodb-toolbox (ts)

Issue:
Error Instantiating Table with V3 SDK (v0.8.0)
https://github.com/jeremydaly/dynamodb-toolbox/blob/646127d42ea5ad8d65e3afb32d0aec6ce954bcc3/src/classes/Table/Table.ts#L113

I'm getting errors on the latest release (v0.8.0) when instantiating a Table. On the new DocClient, `config.translateConfig` is undefined and the evaluation (linked above) short-circuits to `undefined !== false`, which is true, and then attempts to reference `translateConfg` to set a property. This yields "TypeError: Cannot read properties of undefined (reading 'marshallOptions')"

Here is a sample of what I'm creating: 
```javascript
import { DynamoDBClient } from '@aws-sdk/client-dynamodb';
import { DynamoDBDocumentClient } from '@aws-sdk/lib-dynamodb';
import { Table } from 'dynamodb-toolbox';

const ddbClient = new DynamoDBClient({ region: process.env.AWS_REGION });
const docClient = DynamoDBDocumentClient.from(ddbClient);

new Table({
    name: tableName,
    partitionKey: 'pk',
    sortKey: 'sk',
    DocumentClient: docClient,
  });
```

Unfortunately, I am unfamiliar with the configuration settings of the aws-sdk, and so I don't have any positive suggestions to make here.  Is anyone else encountering this problem?


Pull request description:
fix: resolve error when translate config is empty
fixes #498

Patch:
diff --git a/src/classes/Table/Table.ts b/src/classes/Table/Table.ts
index d2325d85..e8d06563 100644
--- a/src/classes/Table/Table.ts
+++ b/src/classes/Table/Table.ts
@@ -109,6 +109,10 @@ class Table<Name extends string, PartitionKey extends A.Key, SortKey extends A.K
   ) {
     // @ts-ignore
     if (docClient && docClient.send) {
+      docClient.config.translateConfig ??= {
+        marshallOptions: {}
+      }
+
       // Automatically set convertEmptyValues to true, unless false
       if (docClient.config.translateConfig?.marshallOptions?.convertEmptyValues !== false) {
         docClient.config.translateConfig!.marshallOptions!.convertEmptyValues = true


Test patch:
diff --git a/src/__tests__/bootstrap.test.ts b/src/__tests__/bootstrap.test.ts
index 6b88ae2c..cfdab54e 100644
--- a/src/__tests__/bootstrap.test.ts
+++ b/src/__tests__/bootstrap.test.ts
@@ -26,6 +26,10 @@ export const DocumentClient = DynamoDBDocumentClient.from(new DynamoDBClient({
   },
 }), translateConfig)
 
+export const DocumentClientWithoutConfig = DynamoDBDocumentClient.from(new DynamoDBClient({
+  endpoint: 'http://localhost:4567',
+  region: 'us-east-1',
+}))
 
 export const DocumentClientWithWrappedNumbers = DynamoDBDocumentClient.from(new DynamoDBClient({
   endpoint: 'http://localhost:4567',
diff --git a/src/__tests__/table-creation.unit.test.ts b/src/__tests__/table-creation.unit.test.ts
index b5ab06ed..f999b805 100644
--- a/src/__tests__/table-creation.unit.test.ts
+++ b/src/__tests__/table-creation.unit.test.ts
@@ -1,5 +1,5 @@
 import Table from '../classes/Table'
-import { DocumentClient } from './bootstrap.test'
+import { DocumentClient, DocumentClientWithoutConfig } from './bootstrap.test'
 
 describe('Table creation', () => {
   it('creates table w/ minimum options', async () => {
@@ -168,4 +168,18 @@ describe('Table creation', () => {
       autoParse: true,
     }))
   })
+
+  it('sets translateConfig with marshalOptions for DocumentClient if empty', async () => {
+    const TestTable = new Table({
+      name: 'test-table',
+      partitionKey: 'pk',
+      DocumentClient: DocumentClientWithoutConfig
+    })
+
+    expect(TestTable.DocumentClient.config.translateConfig).toEqual({
+      marshallOptions: {
+        convertEmptyValues: true,
+      }
+    })
+  })
 })