Skip to content

Commit

Permalink
feat: allow passing dynamoDB client instance to the config
Browse files Browse the repository at this point in the history
  • Loading branch information
thetutlage committed Sep 26, 2024
1 parent ed838d5 commit 8e8bc0e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
9 changes: 7 additions & 2 deletions src/define_config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,15 @@ export const stores: {
return configProvider.create(async () => {
const { DynamoDBStore } = await import('./stores/dynamodb.js')
const { DynamoDBClient } = await import('@aws-sdk/client-dynamodb')
const client = new DynamoDBClient(config?.clientConfig ?? {})

const client =
'clientConfig' in config ? new DynamoDBClient(config.clientConfig) : config.client

return (_, sessionConfig: SessionConfig) => {
return new DynamoDBStore(client, config.tableName, sessionConfig.age, config.keyAttribute)
return new DynamoDBStore(client, sessionConfig.age, {
tableName: config.tableName,
keyAttribute: config.keyAttribute,
})
}
})
},
Expand Down
12 changes: 9 additions & 3 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import { HttpContext } from '@adonisjs/core/http'
import { RedisConnections } from '@adonisjs/redis/types'
import type { CookieOptions } from '@adonisjs/core/types/http'
import type { DynamoDBClientConfig } from '@aws-sdk/client-dynamodb'
import type { DynamoDBClient, DynamoDBClientConfig } from '@aws-sdk/client-dynamodb'

/**
* The values allowed by the `session.put` method
Expand Down Expand Up @@ -106,8 +106,14 @@ export type RedisStoreConfig = {
/**
* Configuration used by the dynamodb store.
*/
export type DynamoDBStoreConfig = {
clientConfig?: DynamoDBClientConfig
export type DynamoDBStoreConfig = (
| {
client: DynamoDBClient
}
| {
clientConfig: DynamoDBClientConfig
}
) & {
tableName?: string
keyAttribute?: string
}
Expand Down
4 changes: 2 additions & 2 deletions tests_helpers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ import type { Test } from '@japa/runner/core'
import { browserClient } from '@japa/browser-client'
import { pluginAdonisJS } from '@japa/plugin-adonisjs'
import { ApiClient, apiClient } from '@japa/api-client'
import { DeleteItemCommand, DynamoDBClient, GetItemCommand } from '@aws-sdk/client-dynamodb'
import { NamedReporterContract } from '@japa/runner/types'
import { runner, syncReporter } from '@japa/runner/factories'
import type { ApplicationService } from '@adonisjs/core/types'
import { DynamoDBClient, GetItemCommand } from '@aws-sdk/client-dynamodb'
import { IncomingMessage, ServerResponse, createServer } from 'node:http'

import { sessionApiClient } from '../src/plugins/japa/api_client.js'
Expand Down Expand Up @@ -67,7 +67,7 @@ export const dynamodbClient = {
create() {
const client = new DynamoDBClient({
region: 'us-east-1',
endpoint: 'http://localhost:8002',
endpoint: 'http://localhost:8000',
credentials: {
accessKeyId: 'accessKeyId',
secretAccessKey: 'secretAccessKey',
Expand Down

0 comments on commit 8e8bc0e

Please sign in to comment.