[twenty-server] no-misused-promise lint (#20529)
# Introduction
Adding `no-miused-promise` lint rule to the twenty-server
In order to flag such pattern
```ts
// ❌ Flagged — forEach doesn't await the callback
items.forEach(async (item) => {
await process(item);
});
```
## What happened
- Refactored the code-interpreter driver to have a async onResult (
which is also expected by e2b )
- Workspace manager still dirty solution including force cast
- Basic fixes
This commit is contained in:
@@ -57,6 +57,7 @@
|
||||
"typescript/no-empty-function": "off",
|
||||
"typescript/no-explicit-any": "warn",
|
||||
"typescript/no-floating-promises": "error",
|
||||
"typescript/no-misused-promises": "error",
|
||||
"typescript/no-unused-vars": ["warn", {
|
||||
"vars": "all",
|
||||
"varsIgnorePattern": "^_",
|
||||
|
||||
+1
-1
@@ -47,7 +47,7 @@ export class OIDCAuthStrategy extends PassportStrategy(
|
||||
}
|
||||
|
||||
// oxlint-disable-next-line @typescripttypescript/no-explicit-any
|
||||
async authenticate(req: Request, options: any) {
|
||||
authenticate(req: Request, options: any) {
|
||||
return super.authenticate(req, {
|
||||
...options,
|
||||
state: JSON.stringify({
|
||||
|
||||
+1
-1
@@ -134,7 +134,7 @@ export class CacheStorageService {
|
||||
|
||||
async countAllSetMembers(cacheKeys: string[]) {
|
||||
return (
|
||||
await Promise.all(cacheKeys.map((key) => this.getSetLength(key) || 0))
|
||||
await Promise.all(cacheKeys.map((key) => this.getSetLength(key)))
|
||||
).reduce((acc, setLength) => acc + setLength, 0);
|
||||
}
|
||||
|
||||
|
||||
+3
-3
@@ -96,7 +96,7 @@ export class E2BDriver implements CodeInterpreterDriver {
|
||||
const execution = await sbx.runCode(envSetup + code, {
|
||||
onStdout: (data) => callbacks?.onStdout?.(data.line),
|
||||
onStderr: (data) => callbacks?.onStderr?.(data.line),
|
||||
onResult: (result) => {
|
||||
onResult: async (result) => {
|
||||
if (result.png) {
|
||||
const outputFile: OutputFile = {
|
||||
filename: `chart-${chartCounter++}.png`,
|
||||
@@ -105,7 +105,7 @@ export class E2BDriver implements CodeInterpreterDriver {
|
||||
};
|
||||
|
||||
outputFiles.push(outputFile);
|
||||
callbacks?.onResult?.(outputFile);
|
||||
await callbacks?.onResult?.(outputFile);
|
||||
}
|
||||
},
|
||||
});
|
||||
@@ -126,7 +126,7 @@ export class E2BDriver implements CodeInterpreterDriver {
|
||||
};
|
||||
|
||||
outputFiles.push(outputFile);
|
||||
callbacks?.onResult?.(outputFile);
|
||||
await callbacks?.onResult?.(outputFile);
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
|
||||
+1
-1
@@ -25,7 +25,7 @@ export type ExecutionContext = {
|
||||
export type StreamCallbacks = {
|
||||
onStdout?: (line: string) => void;
|
||||
onStderr?: (line: string) => void;
|
||||
onResult?: (result: OutputFile) => void;
|
||||
onResult?: (result: OutputFile) => Promise<void>;
|
||||
};
|
||||
|
||||
export interface CodeInterpreterDriver {
|
||||
|
||||
+1
-1
@@ -111,7 +111,7 @@ export class LocalDriver implements CodeInterpreterDriver {
|
||||
};
|
||||
|
||||
outputFiles.push(outputFile);
|
||||
callbacks?.onResult?.(outputFile);
|
||||
await callbacks?.onResult?.(outputFile);
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
|
||||
+1
-1
@@ -32,9 +32,9 @@ import {
|
||||
type CodeInterpreterFileInput,
|
||||
type CodeInterpreterInput,
|
||||
} from 'src/engine/core-modules/tool/tools/code-interpreter-tool/types/code-interpreter-input.type';
|
||||
import { type ToolExecutionContext } from 'src/engine/core-modules/tool/types/tool-execution-context.type';
|
||||
import { type ToolInput } from 'src/engine/core-modules/tool/types/tool-input.type';
|
||||
import { type ToolOutput } from 'src/engine/core-modules/tool/types/tool-output.type';
|
||||
import { type ToolExecutionContext } from 'src/engine/core-modules/tool/types/tool-execution-context.type';
|
||||
import { type Tool } from 'src/engine/core-modules/tool/types/tool.type';
|
||||
import { TwentyConfigService } from 'src/engine/core-modules/twenty-config/twenty-config.service';
|
||||
import { AuthProviderEnum } from 'src/engine/core-modules/workspace/types/workspace.type';
|
||||
|
||||
+2
-2
@@ -17,9 +17,9 @@ export function wrapAsyncIteratorWithLifecycle<T>(
|
||||
|
||||
const startHeartbeat = () => {
|
||||
if (onHeartbeat && heartbeatIntervalMs) {
|
||||
heartbeatInterval = setInterval(async () => {
|
||||
heartbeatInterval = setInterval(() => {
|
||||
try {
|
||||
await onHeartbeat();
|
||||
void onHeartbeat().catch(() => {});
|
||||
} catch {
|
||||
// Heartbeat failure shouldn't crash the stream
|
||||
}
|
||||
|
||||
+4
@@ -1280,6 +1280,7 @@ export class WorkspaceEntityManager extends EntityManager {
|
||||
)
|
||||
.execute()
|
||||
.then(() => formattedEntityOrEntities as Entity[])
|
||||
// oxlint-disable-next-line @typescripttypescript/no-misused-promises
|
||||
.finally(() => queryRunnerForEntityPersistExecutor.release());
|
||||
|
||||
if (isDefined(filesFieldFileIds)) {
|
||||
@@ -1500,6 +1501,7 @@ export class WorkspaceEntityManager extends EntityManager {
|
||||
)
|
||||
.execute()
|
||||
.then(() => formattedEntity as Entity | Entity[])
|
||||
// oxlint-disable-next-line @typescripttypescript/no-misused-promises
|
||||
.finally(() => queryRunnerForEntityPersistExecutor.release());
|
||||
|
||||
const formattedResult = formatResult<Entity[]>(
|
||||
@@ -1648,6 +1650,7 @@ export class WorkspaceEntityManager extends EntityManager {
|
||||
)
|
||||
.execute()
|
||||
.then(() => formattedEntity as Entity)
|
||||
// oxlint-disable-next-line @typescripttypescript/no-misused-promises
|
||||
.finally(() => queryRunnerForEntityPersistExecutor.release());
|
||||
|
||||
const formattedResult = formatResult<Entity[]>(
|
||||
@@ -1797,6 +1800,7 @@ export class WorkspaceEntityManager extends EntityManager {
|
||||
)
|
||||
.execute()
|
||||
.then(() => formattedEntity as Entity)
|
||||
// oxlint-disable-next-line @typescripttypescript/no-misused-promises
|
||||
.finally(() => queryRunnerForEntityPersistExecutor.release());
|
||||
|
||||
const formattedResult = formatResult<Entity[]>(
|
||||
|
||||
Reference in New Issue
Block a user