Skip to content
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
787 changes: 503 additions & 284 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"@biomejs/biome": "^2.3.5",
"@types/aws-lambda": "^8.10.158",
"@types/node": "^24.10.1",
"@vitest/coverage-v8": "^3.2.4",
"@vitest/coverage-v8": "^4.0.9",
"husky": "^9.1.7",
"lint-staged": "^16.2.5",
"markdownlint-cli2": "^0.19.0",
Expand All @@ -62,7 +62,7 @@
"typedoc": "^0.28.14",
"typedoc-plugin-missing-exports": "^4.1.2",
"typescript": "^5.9.3",
"vitest": "^3.0.9"
"vitest": "^4.0.9"
},
"lint-staged": {
"*.{js,ts,json}": "biome check --write --no-errors-on-unmatched",
Expand Down
1 change: 1 addition & 0 deletions packages/batch/src/BasePartialBatchProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ abstract class BasePartialBatchProcessor extends BasePartialProcessor {

for (const msg of this.failureMessages) {
const msgId = (msg as DynamoDBRecord).dynamodb?.SequenceNumber;
/* v8 ignore else -- @preserve */
if (msgId) {
failures.push({ itemIdentifier: msgId });
}
Expand Down
6 changes: 3 additions & 3 deletions packages/batch/src/BatchProcessorSync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,13 @@ import type { BaseRecord, FailureResponse, SuccessResponse } from './types.js';
* @param eventType The type of event to process (SQS, Kinesis, DynamoDB)
* @deprecated Use {@link BasePartialBatchProcessor} instead, this class is deprecated and will be removed in the next major version.
*/
/* v8 ignore start */ class BatchProcessorSync extends BasePartialBatchProcessor {
/* v8 ignore next -- @preserve */ class BatchProcessorSync extends BasePartialBatchProcessor {
/**
* @throws {BatchProcessingError} This method is not implemented for asynchronous processing.
*
* @param _record The record to be processed
*/
public processRecord(
/* v8 ignore next -- @preserve */ public processRecord(
_record: BaseRecord
): Promise<SuccessResponse | FailureResponse> {
throw new BatchProcessingError('Not implemented. Use process() instead.');
Expand Down Expand Up @@ -120,6 +120,6 @@ import type { BaseRecord, FailureResponse, SuccessResponse } from './types.js';
return this.failureHandler(record, error as Error);
}
}
} /* v8 ignore stop */
}

export { BatchProcessorSync };
4 changes: 2 additions & 2 deletions packages/batch/src/processPartialResponseSync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ import type {
* @param processor Batch processor instance to handle the batch processing
* @param options Batch processing options, which can vary with chosen batch processor implementation
*/
/* v8 ignore start */ const processPartialResponseSync = <
/* v8 ignore next -- @preserve */ const processPartialResponseSync = <
T extends BasePartialBatchProcessor,
>(
event: { Records: BaseRecord[] },
Expand All @@ -116,6 +116,6 @@ import type {
processor.processSync();

return processor.response();
}; /* v8 ignore stop */
};

export { processPartialResponseSync };
2 changes: 2 additions & 0 deletions packages/commons/src/LRUCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ class LRUCache<K, V> {
if (this.mostRecentlyUsed === item) return;

// If the item is not the newest, we need to mark it as the newest
/* v8 ignore else -- @preserve */
if (item[NEWER]) {
if (item === this.leastRecentlyUsed) {
this.leastRecentlyUsed = item[NEWER];
Expand All @@ -226,6 +227,7 @@ class LRUCache<K, V> {
}
item[NEWER] = undefined;
item[OLDER] = this.mostRecentlyUsed;
/* v8 ignore else -- @preserve */
if (this.mostRecentlyUsed) {
this.mostRecentlyUsed[NEWER] = item;
}
Expand Down
1 change: 1 addition & 0 deletions packages/commons/src/awsSdkUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ const customUserAgentMiddleware = (feature: string) => {
const hasPowertools = (middlewareStack: string[]): boolean => {
let found = false;
for (const middleware of middlewareStack) {
/* v8 ignore else -- @preserve */
if (middleware.includes('addPowertoolsToUserAgent')) {
found = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ class RouteHandlerRegistry {
}
}
if (mostSpecificHandler === undefined) {
/* v8 ignore else -- @preserve */
if (!this.#warningSet.has(path)) {
this.#logger.warn(
`No route handler found for path '${path}' registered for ${this.#eventType}.`
Expand Down
4 changes: 2 additions & 2 deletions packages/event-handler/src/appsync-events/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ const isAppSyncEventsEvent = (event: unknown): event is AppSyncEventsEvent => {
'name' in event.info.channelNamespace &&
isString(event.info.channelNamespace.name) &&
'operation' in event.info &&
/* v8 ignore next */
(event.info.operation === 'PUBLISH' || event.info.operation === 'SUBSCRIBE')
isString(event.info.operation) &&
['PUBLISH', 'SUBSCRIBE'].includes(event.info.operation)
);
};

Expand Down
1 change: 1 addition & 0 deletions packages/event-handler/src/rest/converters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ function addProxyEventHeaders(
response: ExtendedAPIGatewayProxyResult
) {
for (const [key, value] of Object.entries(response.headers ?? {})) {
/* v8 ignore else -- @preserve */
if (value != null) {
headers.set(key, String(value));
}
Expand Down
1 change: 1 addition & 0 deletions packages/event-handler/src/rest/middleware/cors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ export const cors = (options?: CorsOptions): Middleware => {
return;
}
setCORSBaseHeaders(requestOrigin, reqCtx.res.headers);
/* v8 ignore else -- @preserve */
if (config.maxAge !== undefined) {
reqCtx.res.headers.set(
'access-control-max-age',
Expand Down
2 changes: 2 additions & 0 deletions packages/event-handler/src/rest/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,7 @@ export const getBase64EncodingFromHeaders = (headers: Headers): boolean => {
}

const contentType = headers.get('content-type');
/* v8 ignore else -- @preserve */
if (contentType != null) {
const type = contentType.split(';')[0].trim();
if (
Expand Down Expand Up @@ -400,6 +401,7 @@ const streamifyResponse =
return (async (event, responseStream, context) => {
await handler(event, responseStream, context);

/* v8 ignore else -- @preserve */
if ('chunks' in responseStream && Array.isArray(responseStream.chunks)) {
const output = Buffer.concat(responseStream.chunks as Buffer[]);
const nullBytes = Buffer.from([0, 0, 0, 0, 0, 0, 0, 0]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,13 @@ describe.each([
expect(actual.hasContext).toBe(true);
});

it('throws an invalid event error for non-API Gateway events', () => {
it('throws an invalid event error for non-API Gateway events', async () => {
// Prepare
const app = new Router();
const nonApiGatewayEvent = { Records: [] }; // SQS-like event

// Act & Assess
expect(app.resolve(nonApiGatewayEvent, context)).rejects.toThrowError(
await expect(app.resolve(nonApiGatewayEvent, context)).rejects.toThrowError(
InvalidEventError
);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ const makeHandlerIdempotent = (
});

const idempotencyHandler = new IdempotencyHandler({
functionToMakeIdempotent: /* v8 ignore next */ () => ({}),
functionToMakeIdempotent: /* v8 ignore next -- @preserve */ () => ({}),
functionArguments: [],
idempotencyConfig,
persistenceStore,
Expand Down
2 changes: 2 additions & 0 deletions packages/idempotency/src/persistence/BasePersistenceLayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ abstract class BasePersistenceLayer implements BasePersistenceLayerInterface {
private deleteFromCache(idempotencyKey: string): void {
if (!this.useLocalCache) return;
// Delete from local cache if it exists
/* v8 ignore else -- @preserve */
if (this.cache?.has(idempotencyKey)) {
this.cache?.remove(idempotencyKey);
}
Expand Down Expand Up @@ -324,6 +325,7 @@ abstract class BasePersistenceLayer implements BasePersistenceLayerInterface {
if (Array.isArray(data) || typeof data === 'object') {
if (data === null) return true;
for (const value of Object.values(data)) {
/* v8 ignore else -- @preserve */
if (value) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,17 @@ vi.mock('node:crypto', () => ({
}));

describe('Class: BasePersistenceLayer', () => {
const ENVIRONMENT_VARIABLES = process.env;

beforeAll(() => {
vi.useFakeTimers().setSystemTime(new Date());
});

beforeEach(() => {
vi.clearAllMocks();
vi.resetModules();
process.env = { ...ENVIRONMENT_VARIABLES };
vi.stubEnv('AWS_LAMBDA_FUNCTION_NAME', 'my-lambda-function');
});

afterAll(() => {
process.env = ENVIRONMENT_VARIABLES;
vi.useRealTimers();
});

Expand Down
1 change: 1 addition & 0 deletions packages/jmespath/src/Parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,7 @@ class Parser {
const value = this.#expression(0);
const node = keyValPair(keyName, value);
pairs.push(node);
/* v8 ignore else -- @preserve */
if (this.#currentToken() === 'comma') {
this.#match('comma');
} else if (this.#currentToken() === 'rbrace') {
Expand Down
3 changes: 3 additions & 0 deletions packages/jmespath/src/TreeInterpreter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ class TreeInterpreter {
if (comparator === 'ne') {
return !isStrictEqual(left, right);
}
/* v8 ignore else -- @preserve */
if (typeof left === 'number' && typeof right === 'number') {
// Ordering operators only work on numbers. Evaluating them on other
// types will return null.
Expand Down Expand Up @@ -221,6 +222,7 @@ class TreeInterpreter {
// @ts-expect-error
return this.#functions[funcName](args);
} catch (error) {
/* v8 ignore else -- @preserve */
if (
error instanceof JMESPathTypeError ||
error instanceof VariadicArityError ||
Expand Down Expand Up @@ -372,6 +374,7 @@ class TreeInterpreter {
}
const collected: Record<string, JSONObject> = {};
for (const child of node.children) {
/* v8 ignore else -- @preserve */
if (typeof child.value === 'string') {
collected[child.value] = this.visit(child, value);
}
Expand Down
1 change: 1 addition & 0 deletions packages/jmespath/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ const checkIfArgumentTypeIsValid = (

return true;
}
/* v8 ignore else -- @preserve */
if (['string', 'number', 'boolean'].includes(type)) {
typeCheckType(arg, type, argumentSpec, hasMoreTypesToCheck);
if (typeof arg === type) return true;
Expand Down
4 changes: 2 additions & 2 deletions packages/kafka/src/consumer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ const deserialize = ({
}
return deserializer(value, config.schema);
}
/* v8 ignore else -- @preserve */
if (config.type === 'protobuf') {
if (!config.schema) {
throw new KafkaConsumerMissingSchemaError(
Expand Down Expand Up @@ -139,12 +140,11 @@ const getDeserializer = async (type?: string) => {
*/
const parseSchema = (value: unknown, schema: StandardSchemaV1) => {
const result = schema['~standard'].validate(value);
/* v8 ignore start */
/* v8 ignore next -- @preserve */
if (result instanceof Promise)
throw new KafkaConsumerParserError(
'Schema parsing supports only synchronous validation'
);
/* v8 ignore stop */
if (result.issues) {
throw new KafkaConsumerParserError('Schema validation failed', {
cause: result.issues,
Expand Down
10 changes: 5 additions & 5 deletions packages/logger/src/Logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,6 @@ class Logger extends Utility implements LoggerInterface {
});
}
throw error;
/* v8 ignore next */
} finally {
if (options?.clearState || options?.resetKeys) loggerRef.resetKeys();
loggerRef.clearBuffer();
Expand All @@ -531,28 +530,29 @@ class Logger extends Utility implements LoggerInterface {
/**
* @deprecated This method is deprecated and will be removed in the future major versions. Use {@link resetKeys()} instead.
*/
/* v8 ignore start */ public static injectLambdaContextAfterOrOnError(
/* v8 ignore next -- @preserve */
public static injectLambdaContextAfterOrOnError(
logger: Logger,
_persistentAttributes: LogAttributes,
options?: InjectLambdaContextOptions
): void {
if (options && (options.clearState || options?.resetKeys)) {
logger.resetKeys();
}
} /* v8 ignore stop */
}

/**
* @deprecated - This method is deprecated and will be removed in the next major version.
*/
/* v8 ignore start */ public static injectLambdaContextBefore(
/* v8 ignore next -- @preserve */ public static injectLambdaContextBefore(
logger: Logger,
event: unknown,
context: Context,
options?: InjectLambdaContextOptions
): void {
logger.addContext(context);
logger.logEventIfEnabled(event, options?.logEvent);
} /* v8 ignore stop */
}

/**
* Log the AWS Lambda event payload for the current invocation if the environment variable `POWERTOOLS_LOGGER_LOG_EVENT` is set to `true`.
Expand Down
2 changes: 2 additions & 0 deletions packages/logger/src/logBuffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export class SizedSet<V> extends Set<SizedItem<V>> {
*/
delete(item: SizedItem<V>): boolean {
const wasDeleted = super.delete(item);
/* v8 ignore next -- @preserve */
if (wasDeleted) {
this.currentBytesSize -= item.byteSize;
}
Expand All @@ -66,6 +67,7 @@ export class SizedSet<V> extends Set<SizedItem<V>> {
*/
shift(): SizedItem<V> | undefined {
const firstElement = this.values().next().value;
/* v8 ignore next -- @preserve */
if (firstElement) {
this.delete(firstElement);
}
Expand Down
9 changes: 5 additions & 4 deletions packages/metrics/src/Metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,7 @@ class Metrics extends Utility implements MetricsInterface {
);
}

/* v8 ignore else -- @preserve */
if (!this.disabled) {
const emfOutput = this.serializeMetrics();
hasMetrics && this.console.log(JSON.stringify(emfOutput));
Expand Down Expand Up @@ -809,9 +810,9 @@ class Metrics extends Utility implements MetricsInterface {
* - `POWERTOOLS_FUNCTION_NAME` environment variable
* - {@link Metrics.captureColdStartMetric | `captureColdStartMetric('myFunctionName')`} method
*/
/* v8 ignore start */ public setFunctionName(name: string): void {
/* v8 ignore next -- @preserve */ public setFunctionName(name: string): void {
this.functionName = name;
} /* v8 ignore end */
}

/**
* Set the flag to throw an error if no metrics are emitted.
Expand Down Expand Up @@ -866,9 +867,9 @@ class Metrics extends Utility implements MetricsInterface {
/**
* @deprecated Use {@link Metrics.setThrowOnEmptyMetrics | `setThrowOnEmptyMetrics()`} instead.
*/
/* v8 ignore start */ public throwOnEmptyMetrics(): void {
/* v8 ignore next -- @preserve */ public throwOnEmptyMetrics(): void {
this.shouldThrowOnEmptyMetrics = true;
} /* v8 ignore stop */
}

/**
* Get the custom config service if it exists.
Expand Down
7 changes: 2 additions & 5 deletions packages/parameters/src/appconfig/AppConfigProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,12 +259,9 @@ class AppConfigProvider extends BaseProvider {
/**
* Retrieving multiple configurations is not supported by AWS AppConfig.
*/
/* v8 ignore start */ public async getMultiple(
path: string,
_options?: unknown
): Promise<void> {
public async getMultiple(path: string, _options?: unknown): Promise<void> {
await super.getMultiple(path);
} /* v8 ignore stop */
}

/**
* Retrieve a configuration from AWS AppConfig.
Expand Down
2 changes: 2 additions & 0 deletions packages/parameters/src/base/BaseProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ abstract class BaseProvider implements BaseProviderInterface {
awsSdkV3ClientPrototype,
}: BaseProviderConstructorOptions) {
this.store = new Map();
/* v8 ignore else -- @preserve */
if (awsSdkV3Client) {
if (!isSdkClient(awsSdkV3Client) && awsSdkV3ClientPrototype) {
console.warn(
Expand Down Expand Up @@ -164,6 +165,7 @@ abstract class BaseProvider implements BaseProviderInterface {
entryKey
);
} catch (error) {
/* v8 ignore else -- @preserve */
if (configs.throwOnTransformError) {
if (error instanceof TransformParameterError) {
throw error;
Expand Down
1 change: 1 addition & 0 deletions packages/parameters/src/base/DefaultProviders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const DEFAULT_PROVIDERS: Record<string, BaseProviderInterface> = {};
*/
const clearCaches = (): void => {
for (const provider of Object.values(DEFAULT_PROVIDERS)) {
/* v8 ignore else -- @preserve */
if (provider.clearCache) {
provider.clearCache();
}
Expand Down
Loading
Loading