Skip to content
Open
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
61 changes: 0 additions & 61 deletions packages/aws-durable-execution-sdk-js/eslint.config.js

This file was deleted.

115 changes: 115 additions & 0 deletions packages/aws-durable-execution-sdk-js/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
// @ts-check

import filenameConvention from "eslint-plugin-filename-convention";
import eslintConfigPrettier from "eslint-config-prettier/flat";
import tsdoc from "eslint-plugin-tsdoc";
import { defineConfig } from "eslint/config";
import globals from "globals";
import tseslint from "typescript-eslint";
import js from "@eslint/js";
import { fileURLToPath } from "node:url";
import { includeIgnoreFile } from "@eslint/compat";

const gitIgnorePath = fileURLToPath(new URL(".gitignore", import.meta.url));

export default defineConfig([
includeIgnoreFile(gitIgnorePath, "Imported .gitignore patterns"),
{
files: ["**/*.{js,mjs,cjs,ts,mts,cts}"],
plugins: { js },
extends: ["js/recommended"],
},
{
files: ["**/*.{js,mjs,cjs,ts,mts,cts}"],
languageOptions: { globals: globals.node },
},
tseslint.configs.strictTypeChecked,
tseslint.configs.stylisticTypeChecked,
{
languageOptions: {
ecmaVersion: "latest",
sourceType: "module",
parserOptions: {
projectService: {
allowDefaultProject: ["*.mjs"],
},
tsconfigRootDir: import.meta.dirname,
},
},
plugins: {
"filename-convention": filenameConvention,
tsdoc: tsdoc,
},
rules: {
// Rules that are temporarily set to warning, but should be switched to errors
"@typescript-eslint/restrict-template-expressions": [
"warn",
{
allowNumber: true,
allowBoolean: true,
},
],
"@typescript-eslint/no-unsafe-assignment": "warn",
"@typescript-eslint/no-unsafe-argument": "warn",
"@typescript-eslint/no-non-null-assertion": "warn",
"@typescript-eslint/no-floating-promises": "warn",
"no-empty": "warn",
"@typescript-eslint/no-unsafe-return": "warn",
"@typescript-eslint/prefer-nullish-coalescing": "warn",
"no-async-promise-executor": "warn",
"@typescript-eslint/no-empty-function": "warn",
"@typescript-eslint/no-misused-promises": "warn",
"@typescript-eslint/only-throw-error": "warn",
"@typescript-eslint/use-unknown-in-catch-callback-variable": "warn",
"@typescript-eslint/no-unsafe-member-access": "warn",

// Modified rules
"@typescript-eslint/no-confusing-void-expression": [
"error",
{
ignoreArrowShorthand: true,
},
],
"@typescript-eslint/no-unused-vars": [
"warn",
{
argsIgnorePattern: "^_",
varsIgnorePattern: "^_",
caughtErrorsIgnorePattern: "^_",
},
],

// Additional custom rules
"no-console": "error",
"no-debugger": "error",
"no-duplicate-imports": "error",
"filename-convention/kebab-case": "error",
"tsdoc/syntax": "warn",

// Disabled rules

// Async functions without await allow throwing async promises still
"@typescript-eslint/require-await": "off",
// Validation of parameters will create "unnecessary" conditions
"@typescript-eslint/no-unnecessary-condition": "off",
},
},
{
files: ["src/**/*.test.ts"],
rules: {
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-empty-function": "off",
"@typescript-eslint/no-unsafe-return": "off",
"@typescript-eslint/no-unsafe-member-access": "off",
"@typescript-eslint/unbound-method": "off",
"@typescript-eslint/no-unsafe-call": "off",
"@typescript-eslint/no-unsafe-assignment": "off",
"@typescript-eslint/no-unsafe-argument": "off",
"@typescript-eslint/restrict-plus-operands": "off",
"@typescript-eslint/no-non-null-assertion": "off",
"@typescript-eslint/no-floating-promises": "off",
"@typescript-eslint/only-throw-error": "off",
},
},
eslintConfigPrettier,
]);
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// @ts-check

/**
* @fileoverview ESLint plugin to enforce kebab-case for file names
*/
Expand Down Expand Up @@ -77,7 +79,8 @@ function findProjectRoot(startDir) {
return null;
}

module.exports = {
/** @type {import('eslint').ESLint.Plugin} */
const plugin = {
rules: {
"kebab-case": {
meta: {
Expand All @@ -87,15 +90,15 @@ module.exports = {
category: "Stylistic Issues",
recommended: true,
},
fixable: null,
fixable: undefined,
schema: [],
},
create: function (context) {
// Use default ignore patterns (ESLint v9+ doesn't support CLIEngine)
let ignorePatterns = defaultIgnorePatterns;

// Function to check if a path should be ignored
const shouldIgnorePath = (filePath) => {
const shouldIgnorePath = (/** @type {string} */ filePath) => {
// Convert to posix path for consistent pattern matching
const posixPath = filePath.split(path.sep).join("/");

Expand Down Expand Up @@ -178,3 +181,5 @@ module.exports = {
},
},
};

module.exports = plugin;
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@

export class DurableContextImpl implements DurableContext {
private _stepPrefix?: string;
private _stepCounter: number = 0;
private _stepCounter = 0;
private contextLogger: Logger | null;
private modeAwareLoggingEnabled: boolean = true;
private modeAwareLoggingEnabled = true;
private runningOperations = new Set<string>();
private operationsEmitter = new EventEmitter();
private checkpoint: ReturnType<typeof createCheckpoint>;
Expand All @@ -73,17 +73,17 @@
) {
this._stepPrefix = stepPrefix;
this._parentId = parentId;
this.contextLogger = inheritedLogger || null;

Check warning on line 76 in packages/aws-durable-execution-sdk-js/src/context/durable-context/durable-context.ts

View workflow job for this annotation

GitHub Actions / build

Prefer using nullish coalescing operator (`??`) instead of a logical or (`||`), as it is a safer operator
this.checkpoint = createCheckpoint(
executionContext,
checkpointToken || "",

Check warning on line 79 in packages/aws-durable-execution-sdk-js/src/context/durable-context/durable-context.ts

View workflow job for this annotation

GitHub Actions / build

Prefer using nullish coalescing operator (`??`) instead of a logical or (`||`), as it is a safer operator
this.operationsEmitter,
this.contextLogger || undefined,

Check warning on line 81 in packages/aws-durable-execution-sdk-js/src/context/durable-context/durable-context.ts

View workflow job for this annotation

GitHub Actions / build

Prefer using nullish coalescing operator (`??`) instead of a logical or (`||`), as it is a safer operator
);
this.durableExecutionMode = durableExecutionMode;

const getLogger = (): Logger => {
return this.contextLogger || createDefaultLogger();

Check warning on line 86 in packages/aws-durable-execution-sdk-js/src/context/durable-context/durable-context.ts

View workflow job for this annotation

GitHub Actions / build

Prefer using nullish coalescing operator (`??`) instead of a logical or (`||`), as it is a safer operator
};

this.createContextLogger = createContextLoggerFactory(
Expand Down Expand Up @@ -168,7 +168,7 @@
nextStepData.Status !== OperationStatus.SUCCEEDED &&
nextStepData.Status !== OperationStatus.FAILED
) {
return new Promise<never>(() => {}); // Non-resolving promise

Check warning on line 171 in packages/aws-durable-execution-sdk-js/src/context/durable-context/durable-context.ts

View workflow job for this annotation

GitHub Actions / build

Unexpected empty arrow function
}
}
return null;
Expand Down Expand Up @@ -280,7 +280,7 @@
this.checkpoint,
this.lambdaContext,
this.createStepId.bind(this),
() => this.contextLogger || createDefaultLogger(),

Check warning on line 283 in packages/aws-durable-execution-sdk-js/src/context/durable-context/durable-context.ts

View workflow job for this annotation

GitHub Actions / build

Prefer using nullish coalescing operator (`??`) instead of a logical or (`||`), as it is a safer operator
createDurableContext,
this._parentId,
);
Expand Down Expand Up @@ -308,7 +308,7 @@
this.checkAndUpdateReplayMode.bind(this),
);
return typeof nameOrDuration === "string"
? waitHandler(nameOrDuration, maybeDuration!)

Check warning on line 311 in packages/aws-durable-execution-sdk-js/src/context/durable-context/durable-context.ts

View workflow job for this annotation

GitHub Actions / build

Forbidden non-null assertion
: waitHandler(nameOrDuration);
});
}
Expand Down Expand Up @@ -361,7 +361,7 @@
}

waitForCallback<T>(
nameOrSubmitter?: string | undefined | WaitForCallbackSubmitterFunc,
nameOrSubmitter?: string | WaitForCallbackSubmitterFunc,
submitterOrConfig?: WaitForCallbackSubmitterFunc | WaitForCallbackConfig<T>,
maybeConfig?: WaitForCallbackConfig<T>,
): DurablePromise<T> {
Expand All @@ -376,7 +376,7 @@
this.runInChildContext.bind(this),
);
return waitForCallbackHandler(
nameOrSubmitter!,
nameOrSubmitter,
submitterOrConfig,
maybeConfig,
);
Expand Down Expand Up @@ -413,7 +413,7 @@
? waitForConditionHandler(
nameOrCheckFunc,
checkFuncOrConfig as WaitForConditionCheckFunc<T>,
maybeConfig!,
maybeConfig,
)
: waitForConditionHandler(
nameOrCheckFunc,
Expand Down Expand Up @@ -499,7 +499,7 @@
maybeConfig,
);
// Prevent unhandled promise rejections
promise?.catch(() => {});

Check warning on line 502 in packages/aws-durable-execution-sdk-js/src/context/durable-context/durable-context.ts

View workflow job for this annotation

GitHub Actions / build

Unexpected empty arrow function
return promise;
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@
nextMarker,
initLogger,
);
operationsArray.push(...(response.Operations || []));

Check warning on line 47 in packages/aws-durable-execution-sdk-js/src/context/execution-context/execution-context.ts

View workflow job for this annotation

GitHub Actions / build

Prefer using nullish coalescing operator (`??`) instead of a logical or (`||`), as it is a safer operator
nextMarker = response.NextMarker || "";

Check warning on line 48 in packages/aws-durable-execution-sdk-js/src/context/execution-context/execution-context.ts

View workflow job for this annotation

GitHub Actions / build

Prefer using nullish coalescing operator (`??`) instead of a logical or (`||`), as it is a safer operator
}

// Determine replay mode based on operations array length
Expand All @@ -56,16 +56,15 @@

log("📝", "Operations:", operationsArray);

const stepData: Record<string, Operation> = operationsArray.reduce(
(acc, operation: Operation) => {
if (operation.Id) {
// The stepData received from backend has Id and ParentId as hash, so no need to hash it again
acc[operation.Id] = operation;
}
return acc;
},
{} as Record<string, Operation>,
);
const stepData: Record<string, Operation> = operationsArray.reduce<
Record<string, Operation>
>((acc, operation: Operation) => {
if (operation.Id) {
// The stepData received from backend has Id and ParentId as hash, so no need to hash it again
acc[operation.Id] = operation;
}
return acc;
}, {});

log("📝", "Loaded step data:", stepData);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,14 @@ import { TerminationReason } from "../../termination-manager/types";
// Create concrete implementations for testing
class TestUnrecoverableError extends UnrecoverableError {
readonly terminationReason = TerminationReason.CUSTOM;

constructor(message: string, originalError?: Error) {
super(message, originalError);
}
}

class TestExecutionError extends UnrecoverableExecutionError {
readonly terminationReason = TerminationReason.CUSTOM;

constructor(message: string, originalError?: Error) {
super(message, originalError);
}
}

class TestInvocationError extends UnrecoverableInvocationError {
readonly terminationReason = TerminationReason.CUSTOM;

constructor(message: string, originalError?: Error) {
super(message, originalError);
}
}

describe("UnrecoverableError", () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const createCallback = (
parentId?: string,
) => {
return <T>(
nameOrConfig?: string | undefined | CreateCallbackConfig<T>,
nameOrConfig?: string | CreateCallbackConfig<T>,
maybeConfig?: CreateCallbackConfig<T>,
): DurablePromise<CreateCallbackResult<T>> => {
let name: string | undefined;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,28 @@ import { Serdes, SerdesContext } from "../../utils/serdes/serdes";

export class BatchResultImpl<R> implements BatchResult<R> {
constructor(
public readonly all: Array<BatchItem<R>>,
public readonly all: BatchItem<R>[],
public readonly completionReason:
| "ALL_COMPLETED"
| "MIN_SUCCESSFUL_REACHED"
| "FAILURE_TOLERANCE_EXCEEDED",
) {}

succeeded(): Array<BatchItem<R> & { result: R }> {
succeeded(): (BatchItem<R> & { result: R })[] {
return this.all.filter(
(item): item is BatchItem<R> & { result: R } =>
item.status === BatchItemStatus.SUCCEEDED && item.result !== undefined,
);
}

failed(): Array<BatchItem<R> & { error: ChildContextError }> {
failed(): (BatchItem<R> & { error: ChildContextError })[] {
return this.all.filter(
(item): item is BatchItem<R> & { error: ChildContextError } =>
item.status === BatchItemStatus.FAILED && item.error !== undefined,
);
}

started(): Array<BatchItem<R> & { status: BatchItemStatus.STARTED }> {
started(): (BatchItem<R> & { status: BatchItemStatus.STARTED })[] {
return this.all.filter(
(item): item is BatchItem<R> & { status: BatchItemStatus.STARTED } =>
item.status === BatchItemStatus.STARTED,
Expand All @@ -53,11 +53,11 @@ export class BatchResultImpl<R> implements BatchResult<R> {
}
}

getResults(): Array<R> {
getResults(): R[] {
return this.succeeded().map((item) => item.result);
}

getErrors(): Array<ChildContextError> {
getErrors(): ChildContextError[] {
return this.failed().map((item) => item.error);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -742,7 +742,7 @@ describe("ConcurrencyController", () => {
const executor = jest.fn();

// Resolve in reverse order
let resolvers: Array<(value: any) => void> = [];
const resolvers: ((value: any) => void)[] = [];
mockParentContext.runInChildContext.mockImplementation(() => {
return new Promise((resolve) => {
resolvers.push(resolve);
Expand Down
Loading
Loading