Skip to content

Commit

Permalink
Merge pull request #1173 from dnicolson/fix-typescript-workflows
Browse files Browse the repository at this point in the history
Fix TypeScript workflows
willfarrell authored Feb 8, 2024

Verified

This commit was signed with the committer’s verified signature.
2 parents 8db0b67 + 3789b07 commit 4462596
Showing 4 changed files with 37 additions and 36 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -20,7 +20,7 @@
"test:packages": "npm run test:packages:typings && npm run test:packages:unit --workspaces",
"test:packages:unit": "c8 npm run test:unit --workspaces",
"test:packages:benchmark": "npm run test:benchmark --workspaces",
"test:packages:typings": "tsd --workspaces",
"test:packages:typings": "ls packages | xargs -I {} tsd packages/{}",
"release:tag": "git tag $npm_package_version && git push --tags",
"rm": "npm run lerna:rm:coverage && npm run lerna:rm:node_modules && npm run lerna:rm:lock",
"rm:coverage": "rm -rf coverage --workspaces",
5 changes: 3 additions & 2 deletions packages/core/index.test-d.ts
Original file line number Diff line number Diff line change
@@ -19,7 +19,8 @@ type EnhanceHandlerType<T, NewReturn> = T extends (
type AWSLambdaHandlerWithoutCallback<TEvent = any, TResult = any> = (
event: TEvent,
context: Context,
) => void | Promise<TResult>;
// eslint-disable-next-line
) => void | Promise<TResult>

type LambdaHandler<TEvent = any, TResult = any> = EnhanceHandlerType<AWSLambdaHandlerWithoutCallback<TEvent, TResult>, TResult>

@@ -63,7 +64,7 @@ expectType<Handler>(handler)
expectAssignable<AWSLambdaHandler<APIGatewayProxyEvent, APIGatewayProxyResult>>(handler)

// Middy handlers third argument is an object containing a abort signal
middy((event, context, { signal }) => expectType<AbortSignal>(signal));
middy((event, context, { signal }) => expectType<AbortSignal>(signal))

// invokes the handler to test that it is callable
// eslint-disable-next-line @typescript-eslint/no-invalid-void-type
56 changes: 28 additions & 28 deletions packages/util/index.d.ts
Original file line number Diff line number Diff line change
@@ -29,16 +29,16 @@ declare class HttpError extends Error {
[key: number]: any
}

declare function createPrefetchClient<Client, ClientOptions>(
declare function createPrefetchClient<Client, ClientOptions> (
options: Options<Client, ClientOptions>
): Client

declare function createClient<Client, ClientOptions>(
declare function createClient<Client, ClientOptions> (
options: Options<Client, ClientOptions>,
request: middy.Request
): Promise<Client>

declare function canPrefetch<Client, ClientOptions>(
declare function canPrefetch<Client, ClientOptions> (
options: Options<Client, ClientOptions>
): boolean

@@ -50,7 +50,7 @@ type InternalOutput<TVariables> = TVariables extends string[]
declare function getInternal<
TContext extends LambdaContext,
TInternal extends Record<string, unknown>
>(
> (
variables: false,
request: middy.Request<unknown, unknown, unknown, TContext, TInternal>
): Promise<{}>
@@ -59,7 +59,7 @@ declare function getInternal<
declare function getInternal<
TContext extends LambdaContext,
TInternal extends Record<string, unknown>
>(
> (
variables: true,
request: middy.Request<unknown, unknown, unknown, TContext, TInternal>
): Promise<DeepAwaited<TInternal>>
@@ -69,79 +69,79 @@ declare function getInternal<
TContext extends LambdaContext,
TInternal extends Record<string, unknown>,
TVars extends keyof TInternal | string
>(
> (
variables: TVars,
request: middy.Request<unknown, unknown, unknown, TContext, TInternal>
): TVars extends keyof TInternal
? Promise<DeepAwaited<{ [_ in SanitizeKey<TVars>]: TInternal[TVars] }>>
: TVars extends string
? IsUnknown<Choose<DeepAwaited<TInternal>, TVars>> extends true
? unknown // could not find the path
: Promise<{
? IsUnknown<Choose<DeepAwaited<TInternal>, TVars>> extends true
? unknown // could not find the path
: Promise<{
[_ in SanitizeKey<TVars>]: Choose<DeepAwaited<TInternal>, TVars>
}>
: unknown // path is not a string or a keyof TInternal
: unknown // path is not a string or a keyof TInternal

// get multiple values
declare function getInternal<
TContext extends LambdaContext,
TInternal extends Record<string, unknown>,
TVars extends Array<keyof TInternal | string>
>(
> (
variables: TVars,
request: middy.Request<unknown, unknown, unknown, TContext, TInternal>
): Promise<
SanitizeKeys<{
[TVar in ArrayValues<TVars>]: TVar extends keyof TInternal
? DeepAwaited<TInternal[TVar]>
: TVar extends string
SanitizeKeys<{
[TVar in ArrayValues<TVars>]: TVar extends keyof TInternal
? DeepAwaited<TInternal[TVar]>
: TVar extends string
? Choose<DeepAwaited<TInternal>, TVar>
: unknown // path is not a string or a keyof TInternal
}>
}>
>

// remap object
declare function getInternal<
TContext extends LambdaContext,
TInternal extends Record<string, unknown>,
TMap extends Record<string, keyof TInternal | string>
>(
> (
variables: TMap,
request: middy.Request<unknown, unknown, unknown, TContext, TInternal>
): Promise<{
[P in keyof TMap]: TMap[P] extends keyof TInternal
? DeepAwaited<TInternal[TMap[P]]>
: TMap[P] extends string
? Choose<DeepAwaited<TInternal>, TMap[P]>
: unknown // path is not a string or a keyof TInternal
? Choose<DeepAwaited<TInternal>, TMap[P]>
: unknown // path is not a string or a keyof TInternal
}>

declare function sanitizeKey<T extends string>(key: T): SanitizeKey<T>
declare function sanitizeKey<T extends string> (key: T): SanitizeKey<T>

declare function processCache<Client, ClientOptions>(
declare function processCache<Client, ClientOptions> (
options: Options<Client, ClientOptions>,
fetch: (request: middy.Request, cachedValues: any) => any,
request?: middy.Request
): { value: any; expiry: number }
): { value: any, expiry: number }

declare function getCache(keys: string): any
declare function getCache (keys: string): any

declare function clearCache(keys?: string | string[] | null): void
declare function clearCache (keys?: string | string[] | null): void

declare function jsonSafeParse(
declare function jsonSafeParse (
string: string,
reviver?: (key: string, value: any) => any
): any

declare function normalizeHttpResponse(
declare function normalizeHttpResponse (
request: any,
fallbackResponse?: any
): any

declare function createError(
declare function createError (
code: number,
message: string,
properties?: Record<string, any>
): HttpError

declare function modifyCache(cacheKey: string, value: any): void
declare function modifyCache (cacheKey: string, value: any): void
10 changes: 5 additions & 5 deletions packages/util/type-utils.test-d.ts
Original file line number Diff line number Diff line change
@@ -28,7 +28,7 @@ expectType<SanitizeKeyPrefixLeadingNumber<'-abcd'>>('-abcd')
// SanitizeKeyRemoveDisallowedChar
// removes all disallowed chars and replaces them with _
expectType<
SanitizeKeyRemoveDisallowedChar<'1234!@#AA$%^&*()BBB_+{}|:"<>?~CC`-=[D]E\\;,./F'>
SanitizeKeyRemoveDisallowedChar<'1234!@#AA$%^&*()BBB_+{}|:"<>?~CC`-=[D]E\\;,./F'>
>('1234___AA_______BBB___________CC____D_E_____F')

// RemoveAllLeadingUnderscore
@@ -62,16 +62,16 @@ expectType<SanitizeKeys<{ '0key': 0 }>>({ _0key: 0 })
expectType<SanitizeKeys<{ 'api//secret-key0.pem': 0 }>>({
api_secret_key0_pem: 0
})
expectType<SanitizeKeys<{ '0key': 0; 'api//secret-key0.pem': 0 }>>({
expectType<SanitizeKeys<{ '0key': 0, 'api//secret-key0.pem': 0 }>>({
_0key: 0,
api_secret_key0_pem: 0
})

// DeepAwaited
expectType<
DeepAwaited<{
level1: { level2: Promise<Promise<{ innerPromise: Promise<22> }>> }
}>
DeepAwaited<{
level1: { level2: Promise<Promise<{ innerPromise: Promise<22> }>> }
}>
>({
level1: {
level2: {

0 comments on commit 4462596

Please sign in to comment.