Skip to content

chore(maintenance): migrate snippets to biome #2814

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/core/tracer.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ You can quickly start by importing the `Tracer` class, initialize it outside the

=== "Manual"

```typescript hl_lines="9-15 18-19 23 26 29-34"
```typescript hl_lines="10-16 19-20 24 27 30-35"
--8<-- "examples/snippets/tracer/manual.ts"
```

Expand Down Expand Up @@ -239,7 +239,7 @@ You can trace other class methods using the `captureMethod` decorator or any arb

=== "Manual"

```typescript hl_lines="6-12 18 21 25-30"
```typescript hl_lines="7-13 19 22 26-31"
--8<-- "examples/snippets/tracer/captureMethodManual.ts"
```

Expand Down
2 changes: 1 addition & 1 deletion docs/utilities/batch.md
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ classDiagram

You can then use this class as a context manager, or pass it to `processPartialResponseSync` to process the records in your Lambda handler function.

```typescript hl_lines="21 35 56 61 73 86" title="Creating a custom batch processor"
```typescript hl_lines="21 35 55 60 72 85" title="Creating a custom batch processor"
--8<-- "examples/snippets/batch/customPartialProcessor.ts"
```

Expand Down
2 changes: 1 addition & 1 deletion docs/utilities/idempotency.md
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,7 @@ Below an example implementation of a custom persistence layer backed by a generi

=== "CustomPersistenceLayer"

```typescript hl_lines="9 19 28 34 50 90"
```typescript hl_lines="9 19 28 35 52 95"
--8<-- "examples/snippets/idempotency/advancedBringYourOwnPersistenceLayer.ts"
```

Expand Down
2 changes: 1 addition & 1 deletion examples/snippets/batch/accessLambdaContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
processPartialResponse,
} from '@aws-lambda-powertools/batch';
import { Logger } from '@aws-lambda-powertools/logger';
import type { SQSRecord, Context, SQSHandler } from 'aws-lambda';
import type { Context, SQSHandler, SQSRecord } from 'aws-lambda';

const processor = new BatchProcessor(EventType.SQS);
const logger = new Logger();
Expand Down
2 changes: 1 addition & 1 deletion examples/snippets/batch/accessProcessedMessages.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { BatchProcessor, EventType } from '@aws-lambda-powertools/batch';
import { Logger } from '@aws-lambda-powertools/logger';
import type { SQSRecord, SQSHandler } from 'aws-lambda';
import type { SQSHandler, SQSRecord } from 'aws-lambda';

const processor = new BatchProcessor(EventType.SQS);
const logger = new Logger();
Expand Down
2 changes: 1 addition & 1 deletion examples/snippets/batch/advancedTracingRecordHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
import { Tracer } from '@aws-lambda-powertools/tracer';
import { captureLambdaHandler } from '@aws-lambda-powertools/tracer/middleware';
import middy from '@middy/core';
import type { SQSRecord, SQSHandler, SQSEvent } from 'aws-lambda';
import type { SQSEvent, SQSHandler, SQSRecord } from 'aws-lambda';

const processor = new BatchProcessor(EventType.SQS);
const tracer = new Tracer({ serviceName: 'serverlessAirline' });
Expand Down
19 changes: 9 additions & 10 deletions examples/snippets/batch/customPartialProcessor.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import { randomInt } from 'node:crypto';
import {
DynamoDBClient,
BatchWriteItemCommand,
} from '@aws-sdk/client-dynamodb';
import { marshall } from '@aws-sdk/util-dynamodb';
import {
EventType,
BasePartialBatchProcessor,
EventType,
processPartialResponse,
} from '@aws-lambda-powertools/batch';
import type {
SuccessResponse,
FailureResponse,
BaseRecord,
FailureResponse,
SuccessResponse,
} from '@aws-lambda-powertools/batch/types';
import {
BatchWriteItemCommand,
DynamoDBClient,
} from '@aws-sdk/client-dynamodb';
import { marshall } from '@aws-sdk/util-dynamodb';
import type { SQSHandler } from 'aws-lambda';

const tableName = process.env.TABLE_NAME || 'table-not-found';
Expand All @@ -33,8 +33,7 @@ class MyPartialProcessor extends BasePartialBatchProcessor {
* Here we are writing all the processed messages to DynamoDB.
*/
public clean(): void {
// We know that the client is defined because clean() is called after prepare()
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
// biome-ignore lint/style/noNonNullAssertion: We know that the client is defined because clean() is called after prepare()
this.#client!.send(
new BatchWriteItemCommand({
RequestItems: {
Expand Down
6 changes: 3 additions & 3 deletions examples/snippets/batch/extendingFailure.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { Metrics, MetricUnit } from '@aws-lambda-powertools/metrics';
import {
BatchProcessor,
EventType,
processPartialResponse,
} from '@aws-lambda-powertools/batch';
import type {
FailureResponse,
EventSourceDataClassTypes,
FailureResponse,
} from '@aws-lambda-powertools/batch/types';
import { Logger } from '@aws-lambda-powertools/logger';
import type { SQSRecord, SQSHandler } from 'aws-lambda';
import { MetricUnit, Metrics } from '@aws-lambda-powertools/metrics';
import type { SQSHandler, SQSRecord } from 'aws-lambda';

class MyProcessor extends BatchProcessor {
#metrics: Metrics;
Expand Down
2 changes: 1 addition & 1 deletion examples/snippets/batch/gettingStartedDynamoDBStreams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const processor = new BatchProcessor(EventType.DynamoDBStreams); // (1)!
const logger = new Logger();

const recordHandler = async (record: DynamoDBRecord): Promise<void> => {
if (record.dynamodb && record.dynamodb.NewImage) {
if (record.dynamodb?.NewImage) {
logger.info('Processing record', { record: record.dynamodb.NewImage });
const message = record.dynamodb.NewImage.Message.S;
if (message) {
Expand Down
6 changes: 3 additions & 3 deletions examples/snippets/batch/gettingStartedErrorHandling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
processPartialResponse,
} from '@aws-lambda-powertools/batch';
import { Logger } from '@aws-lambda-powertools/logger';
import type { SQSRecord, SQSHandler } from 'aws-lambda';
import type { SQSHandler, SQSRecord } from 'aws-lambda';

const processor = new BatchProcessor(EventType.SQS);
const logger = new Logger();
Expand All @@ -22,13 +22,13 @@ const recordHandler = async (record: SQSRecord): Promise<void> => {
const item = JSON.parse(payload);
logger.info('Processed item', { item });
} else {
// prettier-ignore
// biome-ignore format: we need the comment in the next line to stay there to annotate the code snippet in the docs
throw new InvalidPayload('Payload does not contain minimum required fields'); // (1)!
}
};

export const handler: SQSHandler = async (event, context) =>
// prettier-ignore
// biome-ignore format: we need the comment in the next line to stay there to annotate the code snippet in the docs
processPartialResponse(event, recordHandler, processor, { // (2)!
context,
});
6 changes: 3 additions & 3 deletions examples/snippets/batch/gettingStartedSQS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import {
processPartialResponse,
} from '@aws-lambda-powertools/batch';
import { Logger } from '@aws-lambda-powertools/logger';
import type { SQSRecord, SQSHandler } from 'aws-lambda';
import type { SQSHandler, SQSRecord } from 'aws-lambda';

const processor = new BatchProcessor(EventType.SQS); // (1)!
const logger = new Logger();

// prettier-ignore
// biome-ignore format: we need the comment in the next line to stay there to annotate the code snippet in the docs
const recordHandler = async (record: SQSRecord): Promise<void> => { // (2)!
const payload = record.body;
if (payload) {
Expand All @@ -19,7 +19,7 @@ const recordHandler = async (record: SQSRecord): Promise<void> => { // (2)!
};

export const handler: SQSHandler = async (event, context) =>
// prettier-ignore
// biome-ignore format: we need the comment in the next line to stay there to annotate the code snippet in the docs
processPartialResponse(event, recordHandler, processor, { // (3)!
context,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import {
} from '@aws-lambda-powertools/batch';
import { Logger } from '@aws-lambda-powertools/logger';
import type {
SQSEvent,
SQSRecord,
Context,
SQSBatchResponse,
SQSEvent,
SQSRecord,
} from 'aws-lambda';

const processor = new SqsFifoPartialProcessor();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import {
IdempotencyItemNotFoundError,
IdempotencyRecordStatus,
} from '@aws-lambda-powertools/idempotency';
import { IdempotencyRecordOptions } from '@aws-lambda-powertools/idempotency/types';
import {
IdempotencyRecord,
BasePersistenceLayer,
IdempotencyRecord,
} from '@aws-lambda-powertools/idempotency/persistence';
import { getSecret } from '@aws-lambda-powertools/parameters/secrets';
import type { IdempotencyRecordOptions } from '@aws-lambda-powertools/idempotency/types';
import { Transform } from '@aws-lambda-powertools/parameters';
import { getSecret } from '@aws-lambda-powertools/parameters/secrets';
import {
ProviderClient,
ProviderItemAlreadyExists,
Expand All @@ -26,18 +26,20 @@ class CustomPersistenceLayer extends BasePersistenceLayer {
}

protected async _deleteRecord(record: IdempotencyRecord): Promise<void> {
await (
await this.#getClient()
).delete(this.#collectionName, record.idempotencyKey);
await (await this.#getClient()).delete(
this.#collectionName,
record.idempotencyKey
);
}

protected async _getRecord(
idempotencyKey: string
): Promise<IdempotencyRecord> {
try {
const item = await (
await this.#getClient()
).get(this.#collectionName, idempotencyKey);
const item = await (await this.#getClient()).get(
this.#collectionName,
idempotencyKey
);

return new IdempotencyRecord({
...(item as unknown as IdempotencyRecordOptions),
Expand Down Expand Up @@ -67,11 +69,14 @@ class CustomPersistenceLayer extends BasePersistenceLayer {

let existingItem: ProviderItem | undefined;
try {
existingItem = await (
await this.#getClient()
).put(this.#collectionName, record.idempotencyKey, item, {
ttl,
});
existingItem = await (await this.#getClient()).put(
this.#collectionName,
record.idempotencyKey,
item,
{
ttl,
}
);
} catch (error) {
if (error instanceof ProviderItemAlreadyExists) {
if (
Expand All @@ -97,9 +102,11 @@ class CustomPersistenceLayer extends BasePersistenceLayer {
value.validation = record.payloadHash;
}

await (
await this.#getClient()
).update(this.#collectionName, record.idempotencyKey, value);
await (await this.#getClient()).update(
this.#collectionName,
record.idempotencyKey,
value
);
}

async #getClient(): Promise<ProviderClient> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type { ProviderItem } from './types.js';
* This is a mock implementation of an SDK client for a generic key-value store.
*/
class ProviderClient {
// biome-ignore lint/complexity/noUselessConstructor: Keep mock constructor for clarity
public constructor(_config: { apiKey: string; defaultTtlSeconds: number }) {
// ...
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import type { Context } from 'aws-lambda';
import { randomUUID } from 'node:crypto';
import { CustomPersistenceLayer } from './advancedBringYourOwnPersistenceLayer';
import {
IdempotencyConfig,
makeIdempotent,
} from '@aws-lambda-powertools/idempotency';
import type { Context } from 'aws-lambda';
import { CustomPersistenceLayer } from './advancedBringYourOwnPersistenceLayer';
import type { Request, Response, SubscriptionResult } from './types.js';

const persistenceStore = new CustomPersistenceLayer({
Expand Down
2 changes: 1 addition & 1 deletion examples/snippets/idempotency/customizePersistenceLayer.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { makeHandlerIdempotent } from '@aws-lambda-powertools/idempotency/middleware';
import { DynamoDBPersistenceLayer } from '@aws-lambda-powertools/idempotency/dynamodb';
import { makeHandlerIdempotent } from '@aws-lambda-powertools/idempotency/middleware';
import middy from '@middy/core';
import type { Context } from 'aws-lambda';
import type { Request, Response } from './types.js';
Expand Down
2 changes: 1 addition & 1 deletion examples/snippets/idempotency/idempotentDecoratorBase.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import type { Context } from 'aws-lambda';
import type { LambdaInterface } from '@aws-lambda-powertools/commons/types';
import {
IdempotencyConfig,
idempotent,
} from '@aws-lambda-powertools/idempotency';
import { DynamoDBPersistenceLayer } from '@aws-lambda-powertools/idempotency/dynamodb';
import type { Context } from 'aws-lambda';
import type { Request, Response } from './types.js';

const dynamoDBPersistenceLayer = new DynamoDBPersistenceLayer({
Expand Down
2 changes: 1 addition & 1 deletion examples/snippets/idempotency/makeHandlerIdempotent.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { randomUUID } from 'node:crypto';
import { makeHandlerIdempotent } from '@aws-lambda-powertools/idempotency/middleware';
import { DynamoDBPersistenceLayer } from '@aws-lambda-powertools/idempotency/dynamodb';
import { makeHandlerIdempotent } from '@aws-lambda-powertools/idempotency/middleware';
import middy from '@middy/core';
import type { Context } from 'aws-lambda';
import type { Request, Response, SubscriptionResult } from './types.js';
Expand Down
2 changes: 1 addition & 1 deletion examples/snippets/idempotency/makeIdempotentAnyFunction.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { randomUUID } from 'node:crypto';
import {
makeIdempotent,
IdempotencyConfig,
makeIdempotent,
} from '@aws-lambda-powertools/idempotency';
import { DynamoDBPersistenceLayer } from '@aws-lambda-powertools/idempotency/dynamodb';
import type { Context } from 'aws-lambda';
Expand Down
2 changes: 1 addition & 1 deletion examples/snippets/idempotency/makeIdempotentJmes.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { randomUUID } from 'node:crypto';
import {
makeIdempotent,
IdempotencyConfig,
makeIdempotent,
} from '@aws-lambda-powertools/idempotency';
import { DynamoDBPersistenceLayer } from '@aws-lambda-powertools/idempotency/dynamodb';
import type { Context } from 'aws-lambda';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { randomUUID } from 'node:crypto';
import {
makeIdempotent,
IdempotencyConfig,
makeIdempotent,
} from '@aws-lambda-powertools/idempotency';
import { DynamoDBPersistenceLayer } from '@aws-lambda-powertools/idempotency/dynamodb';
import type { Context } from 'aws-lambda';
Expand Down
6 changes: 3 additions & 3 deletions examples/snippets/idempotency/templates/tableCdk.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Stack, type StackProps } from 'aws-cdk-lib';
import { Construct } from 'constructs';
import { NodejsFunction } from 'aws-cdk-lib/aws-lambda-nodejs';
import { Runtime } from 'aws-cdk-lib/aws-lambda';
import { AttributeType, BillingMode, Table } from 'aws-cdk-lib/aws-dynamodb';
import { Runtime } from 'aws-cdk-lib/aws-lambda';
import { NodejsFunction } from 'aws-cdk-lib/aws-lambda-nodejs';
import type { Construct } from 'constructs';

export class IdempotencyStack extends Stack {
public constructor(scope: Construct, id: string, props?: StackProps) {
Expand Down
2 changes: 1 addition & 1 deletion examples/snippets/idempotency/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IdempotencyRecordStatusValue } from '@aws-lambda-powertools/idempotency/types';
import type { IdempotencyRecordStatusValue } from '@aws-lambda-powertools/idempotency/types';

export type Request = {
user: string;
Expand Down
10 changes: 5 additions & 5 deletions examples/snippets/idempotency/workingWithBatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ import {
EventType,
processPartialResponse,
} from '@aws-lambda-powertools/batch';
import {
IdempotencyConfig,
makeIdempotent,
} from '@aws-lambda-powertools/idempotency';
import { DynamoDBPersistenceLayer } from '@aws-lambda-powertools/idempotency/dynamodb';
import type {
Context,
SQSBatchResponse,
SQSEvent,
SQSRecord,
} from 'aws-lambda';
import { DynamoDBPersistenceLayer } from '@aws-lambda-powertools/idempotency/dynamodb';
import {
IdempotencyConfig,
makeIdempotent,
} from '@aws-lambda-powertools/idempotency';

const processor = new BatchProcessor(EventType.SQS);

Expand Down
2 changes: 1 addition & 1 deletion examples/snippets/idempotency/workingWithCompositeKey.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { makeHandlerIdempotent } from '@aws-lambda-powertools/idempotency/middleware';
import { DynamoDBPersistenceLayer } from '@aws-lambda-powertools/idempotency/dynamodb';
import { makeHandlerIdempotent } from '@aws-lambda-powertools/idempotency/middleware';
import middy from '@middy/core';
import type { Context } from 'aws-lambda';
import type { Request, Response } from './types.js';
Expand Down
Loading