Skip to content

Commit

Permalink
chore: reverts unnecessary changes and adds some cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
lmammino committed Aug 25, 2023
1 parent 475444a commit 385d007
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
3 changes: 1 addition & 2 deletions packages/core/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,14 @@ declare type MiddlewareFn<
TEvent = any,
TResult = any,
TErr = Error,
TContext extends LambdaContext = LambdaContext
TContext extends LambdaContext = LambdaContext,
> = (request: Request<TEvent, TResult, TErr, TContext>) => any

export interface MiddlewareObj<
TEvent = unknown,
TResult = any,
TErr = Error,
TContext extends LambdaContext = LambdaContext,
TInternal = {}
> {
before?: MiddlewareFn<TEvent, TResult, TErr, TContext>
after?: MiddlewareFn<TEvent, TResult, TErr, TContext>
Expand Down
4 changes: 2 additions & 2 deletions packages/ssm/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ type ExtractSingles<T> = T extends `/${infer _}` ? never : T

export type Internal<TOptions extends Options> = Record<ExtractSingles<keyof TOptions['fetchData']>, JsonValue>

export type Context<TOptions extends Options | undefined> = TOptions extends {
export type Context<TOptions extends Options | undefined = undefined> = TOptions extends {
setToContext: true
}
? LambdaContext &
Expand All @@ -25,6 +25,6 @@ export type Context<TOptions extends Options | undefined> = TOptions extends {

declare function ssm<TOptions extends Options> (
options?: TOptions
): middy.MiddlewareObj<unknown, any, Error, Context<TOptions>, Internal<TOptions>>
): middy.MiddlewareObj<unknown, any, Error, Context<TOptions>>

export default ssm
8 changes: 4 additions & 4 deletions packages/ssm/index.test-d.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import middy from '@middy/core'
import { SSMClient } from '@aws-sdk/client-ssm'
import { captureAWSv3Client } from 'aws-xray-sdk'
import { expectType } from 'tsd'
import { expectType, expectAssignable } from 'tsd'
import ssm, { Context } from '.'
import { JsonValue } from 'type-fest'

// use with default options
expectType<middy.MiddlewareObj<unknown, any, Error, Context<undefined>>>(ssm())
expectType<middy.MiddlewareObj<unknown, any, Error, Context>>(ssm())

// use with all options
const options = {
Expand Down Expand Up @@ -40,9 +40,9 @@ middy()
)
.before((request) => {
// checks that the context is correctly enriched in before
expectType<Record<'accessToken' | 'dbParams' | 'defaults', JsonValue>>(request.context)
expectAssignable<Context & Record<'accessToken' | 'dbParams' | 'defaults', JsonValue>>(request.context)
})
.handler(async (req, context) => {
// checks that the context is correctly enriched in handler
expectType<Record<'accessToken' | 'dbParams' | 'defaults', JsonValue>>(context)
expectAssignable<Record<'accessToken' | 'dbParams' | 'defaults', JsonValue>>(context)
})

0 comments on commit 385d007

Please sign in to comment.