# Dynamo-Easy Config

{% embed url="<https://shiftcode.github.io/dynamo-easy/modules/dynamo_easy.html>" %}
technical api doc
{% endembed %}

## Authorization

The AWS SDK creates a Snapshot of the credentials when creating the underlying DynamoDB client, if you use short-lived credentials (for instance with Cognito Identity) you have to ensure the credentials are valid before making requests.

{% code title="session-validity-ensurer.snippet.ts" %}

```typescript
import { updateDynamoEasyConfig } from '@shiftcoders/dynamo-easy'

updateDynamoEasyConfig({
  sessionValidityEnsurer: (): Promise<void> => {
    // do whatever you need to do to make sure the session is valid
    // and return an Promise<void> when done
    return Promise.resolve()
  },
})

```

{% endcode %}

## Logging

To receive log statements from dynamo-easy you can provide a function

{% code title="log-receiver.snippet.ts" %}

```typescript
import { LogInfo, updateDynamoEasyConfig } from '@shiftcoders/dynamo-easy'

updateDynamoEasyConfig({
  logReceiver: (logInfo: LogInfo) => {
    const msg = `[${logInfo.level}] ${logInfo.timestamp} ${logInfo.className} (${
      logInfo.modelConstructor
      }): ${logInfo.message}`
    console.debug(msg, logInfo.data)
  }
})

```

{% endcode %}

## TableNameResolver

To use different table names per stage you can provide the tableNameResolver function.

This function will receive the default table name (either resolved using the model name or custom value when a tableName was provided in the @Model decorator) and needs to return the extended table name as string.

{% code title="table-name-resolver.snippet.ts" %}

```typescript
import { TableNameResolver, updateDynamoEasyConfig } from '@shiftcoders/dynamo-easy'

const myTableNameResolver: TableNameResolver = (tableName: string) => {
  return `myPrefix-${tableName}`
}

updateDynamoEasyConfig({
  tableNameResolver: myTableNameResolver
})
```

{% endcode %}

## DateMapper

If you want to use a different type for the @DateProperty decorator (eg. Moment or DayJS) you need to define a custom mapper and register it in dynamo-easy easy config.

{% code title="date-mapper.snippet.ts" %}

```typescript
import { updateDynamoEasyConfig } from '@shiftcoders/dynamo-easy'
import { dateToNumberMapper } from '../models'

updateDynamoEasyConfig({
  dateMapper: dateToNumberMapper
})
```

{% endcode %}

{% content-ref url="/pages/-LWAWOtE2gNKYePVgB1r" %}
[CustomMapper](/dynamo-easy/api/model/custommapper.md)
{% endcontent-ref %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://shiftcode.gitbook.io/dynamo-easy/api/dynamo-easy-config/configuration.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
