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
33 changes: 23 additions & 10 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,32 @@ module.exports = {
/** Errors */
"simple-import-sort/imports": "error",
"sort-export-all/sort-export-all": "error",
"no-restricted-imports": [
"error",
{
patterns: [
{
group: ["*src*", "!*CsrC*", "*dist-*"],
},
],
},
],
},
ignorePatterns: [
"packages/nested-clients/src/submodules/**/protocols/*.ts",
"packages/nested-clients/src/submodules/**/models/*.ts",
],
overrides: [
{
files: ["lib/*/src/**/*.ts", "clients/*/src/**/*.ts", "packages/*/src/**/*.ts", "private/*/src/**/*.ts"],
excludedFiles: [
"lib/*/src/**/*.spec.ts",
"clients/*/src/**/*.spec.ts",
"packages/*/src/**/*.spec.ts",
"private/*/src/**/*.spec.ts",
],
rules: {
"no-restricted-imports": [
"error",
{
patterns: [
{
group: ["*src*", "*dist-*"],
},
],
},
],
},
},
],
};
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe(getCrc32ChecksumAlgorithmFunction.name, () => {
const mockData = new Uint8Array([1, 2, 3]);
const mockChecksum = 42;

// @ts-expect-error crc32 is defined only for Node.js >=v20.15.0 and >=v22.2.0.
// @ts-ignore
zlib.crc32 = vi
.fn()
.mockReturnValueOnce(mockChecksum)
Expand All @@ -24,20 +24,20 @@ describe(getCrc32ChecksumAlgorithmFunction.name, () => {
const crc32Fn = getCrc32ChecksumAlgorithmFunction();
expect(crc32Fn).not.toBe(AwsCrc32);

// @ts-expect-error crc32 is defined only for Node.js >=v20.15.0 and >=v22.2.0.
// @ts-ignore
expect(zlib.crc32).not.toHaveBeenCalled();
const crc32 = new crc32Fn();
// @ts-expect-error crc32 is defined only for Node.js >=v20.15.0 and >=v22.2.0.
// @ts-ignore
expect(zlib.crc32).not.toHaveBeenCalled();
expect(await crc32.digest()).toEqual(numToUint8(0));

crc32.update(mockData);
// @ts-expect-error crc32 is defined only for Node.js >=v20.15.0 and >=v22.2.0.
// @ts-ignore
expect(zlib.crc32).toHaveBeenCalledWith(mockData, 0);
expect(await crc32.digest()).toEqual(numToUint8(mockChecksum));

crc32.update(mockData);
// @ts-expect-error crc32 is defined only for Node.js >=v20.15.0 and >=v22.2.0.
// @ts-ignore
expect(zlib.crc32).toHaveBeenCalledWith(mockData, mockChecksum);
expect(await crc32.digest()).toEqual(numToUint8(2 * mockChecksum));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class NodeCrc32 implements Checksum {
private checksum = 0;

update(data: Uint8Array) {
// @ts-expect-error crc32 is defined only for Node.js >=v20.15.0 and >=v22.2.0.
// @ts-ignore
this.checksum = zlib.crc32(data, this.checksum);
}

Expand All @@ -21,7 +21,7 @@ class NodeCrc32 implements Checksum {
}

export const getCrc32ChecksumAlgorithmFunction = () => {
// @ts-expect-error crc32 is defined only for Node.js >=v20.15.0 and >=v22.2.0.
// @ts-ignore
if (typeof zlib.crc32 === "undefined") {
return AwsCrc32;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/middleware-recursion-detection/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"license": "Apache-2.0",
"dependencies": {
"@aws-sdk/types": "*",
"@aws/lambda-invoke-store": "^0.0.1",
"@aws/lambda-invoke-store": "^0.1.1",
"@smithy/protocol-http": "^5.3.3",
"@smithy/types": "^4.8.0",
"tslib": "^2.6.2"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import { InvokeStore } from "@aws/lambda-invoke-store";
// @ts-ignore
import { InvokeStore as InvokeStoreImpl } from "@aws/lambda-invoke-store";
// eslint-disable-next-line no-restricted-imports
import type { InvokeStore as InvokeStoreType } from "@aws/lambda-invoke-store/dist-types/invoke-store.d";
import { HttpRequest } from "@smithy/protocol-http";
import { afterAll, beforeEach, describe, expect, test as it, vi } from "vitest";

import { recursionDetectionMiddleware } from "./recursionDetectionMiddleware";

const InvokeStore = InvokeStoreImpl as typeof InvokeStoreType;

describe(recursionDetectionMiddleware.name, () => {
const mockNextHandler = vi.fn();
const originEnv = process.env;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
// @ts-ignore
import { InvokeStore } from "@aws/lambda-invoke-store";
// eslint-disable-next-line no-restricted-imports
import type { InvokeStore as InvokeStoreType } from "@aws/lambda-invoke-store/dist-types/invoke-store.d";
import { HttpRequest } from "@smithy/protocol-http";
import {
BuildHandler,
Expand Down Expand Up @@ -34,7 +37,7 @@ export const recursionDetectionMiddleware =
const functionName = process.env[ENV_LAMBDA_FUNCTION_NAME];

const traceIdFromEnv = process.env[ENV_TRACE_ID];
const traceIdFromInvokeStore = InvokeStore.getXRayTraceId();
const traceIdFromInvokeStore = (InvokeStore as typeof InvokeStoreType).getXRayTraceId();
const traceId = traceIdFromInvokeStore ?? traceIdFromEnv;

const nonEmptyString = (str: unknown): str is string => typeof str === "string" && str.length > 0;
Expand Down
10 changes: 5 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -23610,7 +23610,7 @@ __metadata:
resolution: "@aws-sdk/middleware-recursion-detection@workspace:packages/middleware-recursion-detection"
dependencies:
"@aws-sdk/types": "npm:*"
"@aws/lambda-invoke-store": "npm:^0.0.1"
"@aws/lambda-invoke-store": "npm:^0.1.1"
"@smithy/protocol-http": "npm:^5.3.3"
"@smithy/types": "npm:^4.8.0"
"@tsconfig/recommended": "npm:1.0.1"
Expand Down Expand Up @@ -24532,10 +24532,10 @@ __metadata:
languageName: node
linkType: hard

"@aws/lambda-invoke-store@npm:^0.0.1":
version: 0.0.1
resolution: "@aws/lambda-invoke-store@npm:0.0.1"
checksum: 10c0/0bbf3060014a462177fb743e132e9b106a6743ad9cd905df4bd26e9ca8bfe2cc90473b03a79938fa908934e45e43f366f57af56a697991abda71d9ac92f5018f
"@aws/lambda-invoke-store@npm:^0.1.1":
version: 0.1.1
resolution: "@aws/lambda-invoke-store@npm:0.1.1"
checksum: 10c0/27c90d9af7cca7ff4870e87dc303516e6d09ebe18f5fa13813397cd6a37fd26cf3ff1715469e3c5323fea0404a55c110f35e21bcc3ea595a4f6ba6406ea1f103
languageName: node
linkType: hard

Expand Down
Loading