Skip to content

Commit

Permalink
Pre-commit fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
kddejong committed Apr 20, 2024
1 parent d7ca8c1 commit 74b0760
Show file tree
Hide file tree
Showing 13 changed files with 88 additions and 82 deletions.
3 changes: 2 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ repos:
- --fix=lf
- id: trailing-whitespace
- id: pretty-format-json
exclude: ^tsconfig.*.json
args:
- --autofix
- --indent=4
Expand Down Expand Up @@ -56,7 +57,7 @@ repos:
types: []
files: (.*.js$|.*.ts$)
additional_dependencies:
- eslint@6.8.0
- eslint@8.21.0
- repo: local
hooks:
- id: pylint-local
Expand Down
2 changes: 2 additions & 0 deletions jest.config.cjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const { ignorePatterns } = require("./.eslintrc");

module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
"eslint-import-resolver-typescript": "^3.6.0",
"eslint-plugin-import": "^2.29.0",
"eslint-plugin-prefer-arrow": "^1.2.2",
"eslint-plugin-prettier": "^5.0.0",
"eslint-plugin-prettier": "^5.1.0",
"jest": "^29.7.0",
"jest-circus": "^29.7.0",
"prettier": "^3.1.0",
Expand Down
39 changes: 21 additions & 18 deletions src/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ export type integer = bigint;

export type InstanceProperties<
T extends object = Service,
C extends Constructor<T> = Constructor<T>
C extends Constructor<T> = Constructor<T>,
> = keyof InstanceType<C>;

export type ServiceProperties<
S extends Service = Service,
C extends Constructor<S> = Constructor<S>
C extends Constructor<S> = Constructor<S>,
> = Exclude<
InstanceProperties<S, C>,
InstanceProperties<Service, Constructor<Service>>
Expand All @@ -40,13 +40,13 @@ export type OverloadedArguments<T> = T extends {
}
? P
: T extends {
(params: infer P, callback: any): any;
(callback: any): any;
}
? P
: T extends (params: infer P, callback: any) => any
? P
: any;
(params: infer P, callback: any): any;
(callback: any): any;
}
? P
: T extends (params: infer P, callback: any) => any
? P
: any;

export type OverloadedReturnType<T> = T extends {
(...args: any[]): any;
Expand All @@ -55,20 +55,20 @@ export type OverloadedReturnType<T> = T extends {
}
? R
: T extends {
(params: any, callback: any): infer R;
(callback: any): any;
}
? R
: T extends (callback: any) => infer R
? R
: any;
(params: any, callback: any): infer R;
(callback: any): any;
}
? R
: T extends (callback: any) => infer R
? R
: any;

export interface Callable<R extends Array<any>, T> {
(...args: R): T;
}


interface Integer extends BigInt {
// @ts-expect-error extending bigint
interface Integer extends bigint {

Check failure on line 71 in src/interface.ts

View workflow job for this annotation

GitHub Actions / os_build (ubuntu-latest, 3.8, 20)

'extends' clause of exported interface 'Integer' has or is using private name 'bigint'.

Check failure on line 71 in src/interface.ts

View workflow job for this annotation

GitHub Actions / os_build (ubuntu-latest, 3.11, 20)

'extends' clause of exported interface 'Integer' has or is using private name 'bigint'.
/**
* Defines the default JSON representation of
* Integer (BigInt) to be a number.
Expand All @@ -79,6 +79,7 @@ interface Integer extends BigInt {
valueOf(): integer;
}

// @ts-expect-error extending bigint
interface IntegerConstructor extends BigIntConstructor {
(value?: bigint | boolean | number | string): integer;
readonly prototype: Integer;
Expand All @@ -93,7 +94,9 @@ interface IntegerConstructor extends BigIntConstructor {
/**
* Wrapper with additional JSON serialization for bigint type
*/
// @ts-expect-error extending bigint
export const Integer: IntegerConstructor = new Proxy(BigInt, {
// @ts-expect-error extending bigint
apply(
target: IntegerConstructor,
_thisArg: unknown,
Expand Down
5 changes: 4 additions & 1 deletion src/log-delivery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,10 @@ export class LoggerProxy implements Logger {
// @ts-expect-error fix in aws sdk v3
if (err.retryable === true) {
try {
await logPublisher.publishLogEvent(formatted, eventTime);
await logPublisher.publishLogEvent(
formatted,
eventTime
);
this.tracker.addCompleted();
} catch (err) {
console.error(err);
Expand Down
16 changes: 8 additions & 8 deletions src/proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export type ServiceOperation<
S extends Service = Service,
C extends Constructor<S> = Constructor<S>,
O extends ServiceProperties<S, C> = ServiceProperties<S, C>,
E extends Error = AWSError
E extends Error = AWSError,
> = InstanceType<C>[O] & {
promise(): Promise<PromiseResult<any, E>>;
};
Expand All @@ -42,15 +42,15 @@ export type InferredResult<
C extends Constructor<S> = Constructor<S>,
O extends ServiceProperties<S, C> = ServiceProperties<S, C>,
E extends Error = AWSError,
N extends ServiceOperation<S, C, O, E> = ServiceOperation<S, C, O, E>
N extends ServiceOperation<S, C, O, E> = ServiceOperation<S, C, O, E>,
> = Input<Input<Result<Result<N>['promise']>['then']>[0]>[0];

type AwsTaskSignature = <
S extends Service = Service,
C extends Constructor<S> = Constructor<S>,
O extends ServiceProperties<S, C> = ServiceProperties<S, C>,
E extends Error = AWSError,
N extends ServiceOperation<S, C, O, E> = ServiceOperation<S, C, O, E>
N extends ServiceOperation<S, C, O, E> = ServiceOperation<S, C, O, E>,
>(
params: any
) => Promise<InferredResult<S, C, O, E, N>>;
Expand All @@ -70,7 +70,7 @@ export type ExtendedClient<S extends Service = Service> = S & {
C extends Constructor<S> = Constructor<S>,
O extends ServiceProperties<S, C> = ServiceProperties<S, C>,
E extends Error = AWSError,
N extends ServiceOperation<S, C, O, E> = ServiceOperation<S, C, O, E>
N extends ServiceOperation<S, C, O, E> = ServiceOperation<S, C, O, E>,
>(
operation: O,
input?: OverloadedArguments<N>,
Expand Down Expand Up @@ -98,7 +98,7 @@ export class SessionProxy implements Session {
C extends Constructor<S> = Constructor<S>,
O extends ServiceProperties<S, C> = ServiceProperties<S, C>,
E extends Error = AWSError,
N extends ServiceOperation<S, C, O, E> = ServiceOperation<S, C, O, E>
N extends ServiceOperation<S, C, O, E> = ServiceOperation<S, C, O, E>,
>(
service: S,
options?: ServiceConfigurationOptions,
Expand Down Expand Up @@ -166,7 +166,7 @@ export class SessionProxy implements Session {
if (typeof service === 'string') {
// Kept for backward compatibility
const clients: { [K in ClientName]: ClientMap[K] } = Aws;
ctor = (clients[service] as unknown) as Constructor<S>;
ctor = clients[service] as unknown as Constructor<S>;
} else if (typeof service === 'function') {
ctor = service as Constructor<S>;
} else {
Expand Down Expand Up @@ -203,7 +203,7 @@ export class SessionProxy implements Session {
@builder
export class ProgressEvent<
ResourceT extends BaseModel = BaseModel,
CallbackT = Dict
CallbackT = Dict,
> extends BaseDto {
/**
* The status indicates whether the handler has reached a terminal state or is
Expand Down Expand Up @@ -318,5 +318,5 @@ export class ProgressEvent<
* @param <T> Type of resource model being provisioned
*/
export class ResourceHandlerRequest<
T extends BaseModel
T extends BaseModel,
> extends BaseResourceHandlerRequest<T> {}
16 changes: 7 additions & 9 deletions src/resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ const MUTATING_ACTIONS: [Action, Action, Action] = [

export type HandlerSignature<
T extends BaseModel,
TypeConfiguration extends BaseModel
TypeConfiguration extends BaseModel,
> = Callable<
[Optional<SessionProxy>, any, Dict, LoggerProxy, TypeConfiguration],
Promise<ProgressEvent<T>>
>;
export class HandlerSignatures<
T extends BaseModel,
TypeConfiguration extends BaseModel
TypeConfiguration extends BaseModel,
> extends Map<Action, HandlerSignature<T, TypeConfiguration>> {}
class HandlerEvents extends Map<Action, string | symbol> {}

Expand Down Expand Up @@ -98,7 +98,7 @@ function ensureSerialize<T extends BaseModel>(toResponse = false): MethodDecorat

export abstract class BaseResource<
T extends BaseModel = BaseModel,
TypeConfiguration extends BaseModel = BaseModel
TypeConfiguration extends BaseModel = BaseModel,
> {
protected loggerProxy: LoggerProxy;
protected metricsPublisherProxy: MetricsPublisherProxy;
Expand Down Expand Up @@ -327,9 +327,8 @@ export abstract class BaseResource<
if (!this.handlers.has(action)) {
throw new Error(`Unknown action ${actionName}`);
}
const handleRequest: HandlerSignature<T, TypeConfiguration> = this.handlers.get(
action
);
const handleRequest: HandlerSignature<T, TypeConfiguration> =
this.handlers.get(action);
// We will make the callback context and resource states readonly
// to avoid modification at a later time
deepFreeze(callbackContext);
Expand Down Expand Up @@ -541,9 +540,8 @@ export abstract class BaseResource<
'Missing Model class to be used to deserialize JSON data.'
);
}
const [credentials, action, callback, event] = BaseResource.parseRequest(
eventData
);
const [credentials, action, callback, event] =
BaseResource.parseRequest(eventData);
bearerToken = event.bearerToken;
const [callerCredentials, providerCredentials] = credentials;
const request = this.castResourceRequest(event);
Expand Down
18 changes: 12 additions & 6 deletions tests/data/sample-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,20 @@ export class ResourceModel extends BaseModel {

export class NestedList extends BaseModel {
@Expose({ name: 'NestedListBool' })
@Transform(({ value, obj }) => transformValue(Boolean, 'nestedListBool', value, obj), {
toClassOnly: true,
})
@Transform(
({ value, obj }) => transformValue(Boolean, 'nestedListBool', value, obj),
{
toClassOnly: true,
}
)
nestedListBool?: Optional<boolean>;
@Expose({ name: 'NestedListList' })
@Transform(({ value, obj }) => transformValue(Number, 'nestedListList', value, obj), {
toClassOnly: true,
})
@Transform(
({ value, obj }) => transformValue(Number, 'nestedListList', value, obj),
{
toClassOnly: true,
}
)
nestedListList?: Optional<number>;
}

Expand Down
18 changes: 11 additions & 7 deletions tests/lib/log-delivery.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ describe('when delivering logs', () => {
ResponseMetadata: { RequestId: 'mock-request' },
});
putLogEvents = mockResult({ ResponseMetadata: { RequestId: 'mock-request' } });
cwLogs = (CloudWatchLogs as unknown) as jest.Mock;
cwLogs = CloudWatchLogs as unknown as jest.Mock;
cwLogs.mockImplementation((config = {}) => {
const returnValue: jest.Mocked<Partial<CloudWatchLogs>> = {
createLogGroup,
Expand All @@ -133,7 +133,7 @@ describe('when delivering logs', () => {
createBucket = mockResult({ ResponseMetadata: { RequestId: 'mock-request' } });
putObject = mockResult({ ResponseMetadata: { RequestId: 'mock-request' } });
listObjectsV2 = mockResult({ ResponseMetadata: { RequestId: 'mock-request' } });
s3 = (S3 as unknown) as jest.Mock;
s3 = S3 as unknown as jest.Mock;
s3.mockImplementation((config = {}) => {
const returnValue: jest.Mocked<Partial<S3>> = {
createBucket,
Expand All @@ -159,7 +159,8 @@ describe('when delivering logs', () => {
publishExceptionMetric = mockResult({
ResponseMetadata: { RequestId: 'mock-request' },
});
metricsPublisherProxy.publishLogDeliveryExceptionMetric = publishExceptionMetric;
metricsPublisherProxy.publishLogDeliveryExceptionMetric =
publishExceptionMetric;
spyPublishLogEvent = jest.spyOn<any, any>(
LogPublisher.prototype,
'publishLogEvent'
Expand Down Expand Up @@ -284,8 +285,7 @@ describe('when delivering logs', () => {
logGroups: [
{
logGroupName: LOG_GROUP_NAME,
arn:
'arn:aws:loggers:us-east-1:123456789012:log-group:/aws/lambda/testLogGroup-X:*',
arn: 'arn:aws:loggers:us-east-1:123456789012:log-group:/aws/lambda/testLogGroup-X:*',
creationTime: 4567898765,
storedBytes: 456789,
},
Expand Down Expand Up @@ -321,7 +321,9 @@ describe('when delivering logs', () => {
await cloudWatchLogHelper.prepareLogStream();
} catch (e) {
if (e instanceof Error) {
expect(e.message).toMatch(/CloudWatchLogs client was not initialized/);
expect(e.message).toMatch(
/CloudWatchLogs client was not initialized/
);
}
}
});
Expand Down Expand Up @@ -632,7 +634,9 @@ describe('when delivering logs', () => {
await cloudWatchLogger.publishLogEvent('How is it going?');
} catch (e) {
if (e instanceof Error) {
expect(e.message).toMatch(/CloudWatchLogs client was not initialized/);
expect(e.message).toMatch(
/CloudWatchLogs client was not initialized/
);
}
}
});
Expand Down
2 changes: 1 addition & 1 deletion tests/lib/metrics.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ describe('when getting metrics', () => {

beforeEach(() => {
putMetricData = mockResult({ ResponseMetadata: { RequestId: 'mock-request' } });
cloudwatch = (CloudWatch as unknown) as jest.Mock;
cloudwatch = CloudWatch as unknown as jest.Mock;
cloudwatch.mockImplementation((config = {}) => {
const returnValue: jest.Mocked<Partial<CloudWatch>> = {
putMetricData,
Expand Down
2 changes: 1 addition & 1 deletion tests/lib/proxy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ describe('when getting session proxy', () => {
const proxy = new SessionProxy(AWS_CONFIG);
const modifiedConfig = { ...AWS_CONFIG, region: 'us-east-2' };
const mockMakeRequest = mockResult(true);
((STS as unknown) as jest.Mock).mockImplementation(() => {
(STS as unknown as jest.Mock).mockImplementation(() => {
const ctor = STS;
ctor['serviceIdentifier'] = 'sts';
return {
Expand Down
Loading

0 comments on commit 74b0760

Please sign in to comment.