Skip to content

Commit 81ff3c4

Browse files
authored
style(parser): apply stricter linting (#4567)
1 parent 8436fa9 commit 81ff3c4

File tree

11 files changed

+35
-26
lines changed

11 files changed

+35
-26
lines changed

packages/parser/src/envelopes/sns-sqs.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,11 @@ export const SnsSqsEnvelope = {
150150
}>(
151151
(acc, record, index) => {
152152
const parsed = parseRecord(record, index);
153-
if (!parsed.success) {
153+
if (parsed.success) {
154+
acc.records.push(parsed.data);
155+
} else {
154156
acc.success = false;
155157
acc.errors[index] = parsed.error;
156-
} else {
157-
acc.records.push(parsed.data);
158158
}
159159
return acc;
160160
},

packages/parser/src/parserDecorator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ export const parser = <
8484

8585
const { schema, envelope, safeParse } = options;
8686

87-
descriptor.value = async function (
87+
descriptor.value = function (
8888
this: Handler,
8989
...args: [ParserOutput<TSchema, TEnvelope, TSafeParse>, Context, Callback]
9090
) {

packages/parser/src/schemas/appsync-events.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,12 +169,14 @@ const AppSyncEventsSubscribeSchema = AppSyncEventsBaseSchema.extend({
169169

170170
export {
171171
AppSyncEventsBaseSchema,
172-
AppSyncCognitoIdentity,
173-
AppSyncIamIdentity,
174172
AppSyncLambdaAuthIdentity,
175-
AppSyncOidcIdentity,
176173
AppSyncEventsRequestSchema,
177174
AppSyncEventsInfoSchema,
178175
AppSyncEventsPublishSchema,
179176
AppSyncEventsSubscribeSchema,
180177
};
178+
export {
179+
AppSyncCognitoIdentity,
180+
AppSyncIamIdentity,
181+
AppSyncOidcIdentity,
182+
} from './appsync-shared.js';

packages/parser/src/schemas/appsync.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,8 +236,10 @@ const AppSyncBatchResolverSchema = z.array(AppSyncResolverSchema);
236236
export {
237237
AppSyncResolverSchema,
238238
AppSyncBatchResolverSchema,
239+
AppSyncLambdaIdentity,
240+
};
241+
export {
239242
AppSyncCognitoIdentity,
240243
AppSyncIamIdentity,
241244
AppSyncOidcIdentity,
242-
AppSyncLambdaIdentity,
243-
};
245+
} from './appsync-shared.js';

packages/parser/src/schemas/cognito.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ const PostConfirmationTriggerSchema = CognitoTriggerBaseSchema.extend({
132132
* }
133133
* ```
134134
*
135-
* * @see {@link https://docs.aws.amazon.com/cognito/latest/developerguide/user-pool-lambda-pre-authentication.html | Amazon Cognito Developer Guide}
135+
* @see {@link https://docs.aws.amazon.com/cognito/latest/developerguide/user-pool-lambda-pre-authentication.html | Amazon Cognito Developer Guide}
136136
*/
137137
const PreAuthenticationTriggerSchema = CognitoTriggerBaseSchema.extend({
138138
triggerSource: z.literal('PreAuthentication_Authentication'),

packages/parser/src/schemas/kafka.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const KafkaRecordSchema = z.object({
2323
z.record(
2424
z.string(),
2525
z.array(z.number()).transform((value) => {
26-
return String.fromCharCode(...value);
26+
return String.fromCodePoint(...value);
2727
})
2828
)
2929
),

packages/parser/src/types/parser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ type ParserOutput<
8585
/**
8686
* The parser function that can parse the data using the provided schema and envelope
8787
* we use function overloads to provide the correct return type based on the provided envelope
88-
**/
88+
*/
8989
type ParseFunction = {
9090
// No envelope, no safeParse
9191
<T extends StandardSchemaV1>(

packages/parser/tests/types/parser.test-d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ describe('Parser types', () => {
7373
envelope: SqsEnvelope,
7474
})
7575
)
76-
.handler(async (event) => {
76+
.handler((event) => {
7777
expectTypeOf(event).toEqualTypeOf<User[]>();
7878
});
7979
});

packages/parser/tests/unit/parser.decorator.test.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { setTimeout } from 'node:timers/promises';
12
import type { LambdaInterface } from '@aws-lambda-powertools/commons/types';
23
import type { Context } from 'aws-lambda';
34
import { describe, expect, it } from 'vitest';
@@ -30,6 +31,7 @@ describe('Decorator: parser', () => {
3031
class TestClass implements LambdaInterface {
3132
@parser({ schema: extendedSchema })
3233
public async handler(event: event, _context: Context): Promise<event> {
34+
await setTimeout(1); // simulate some processing time
3335
return event;
3436
}
3537

@@ -38,6 +40,7 @@ describe('Decorator: parser', () => {
3840
event: z.infer<typeof schema>,
3941
_context: Context
4042
): Promise<unknown> {
43+
await setTimeout(1); // simulate some processing time
4144
return this.anotherMethod(event);
4245
}
4346

@@ -49,6 +52,7 @@ describe('Decorator: parser', () => {
4952
event: ParsedResult<unknown, event>,
5053
_context: Context
5154
): Promise<ParsedResult<unknown, event>> {
55+
await setTimeout(1); // simulate some processing time
5256
return event;
5357
}
5458

@@ -61,10 +65,11 @@ describe('Decorator: parser', () => {
6165
event: ParsedResult<event, event>,
6266
_context: Context
6367
): Promise<ParsedResult> {
68+
await setTimeout(1); // simulate some processing time
6469
return event;
6570
}
6671

67-
private async anotherMethod(event: unknown): Promise<unknown> {
72+
private anotherMethod(event: unknown): unknown {
6873
return event;
6974
}
7075
}

packages/parser/tests/unit/parser.middy.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ describe('Middleware: parser', () => {
5454
const event = structuredClone(baseEventBridgeEvent);
5555

5656
// Act & Assess
57-
expect(
57+
await expect(
5858
middy()
5959
.use(parser({ schema: z.string(), envelope: SqsEnvelope }))
6060
.handler((event) => event)(event as unknown as string[], {} as Context)
@@ -68,7 +68,7 @@ describe('Middleware: parser', () => {
6868
event.Records[1].body = undefined;
6969

7070
// Act & Assess
71-
expect(
71+
await expect(
7272
handlerWithSchemaAndEnvelope(event as unknown as string[], {} as Context)
7373
).rejects.toThrow();
7474
});
@@ -91,7 +91,7 @@ describe('Middleware: parser', () => {
9191
const event = structuredClone(JSONPayload);
9292

9393
// Act & Assess
94-
expect(
94+
await expect(
9595
middy((event) => event).use(parser({ schema: z.number() }))(
9696
event as unknown as number,
9797
{} as Context

0 commit comments

Comments
 (0)