From 755b76cbce991cb7c0bd679b501a3dd451c2e9d4 Mon Sep 17 00:00:00 2001 From: Nawaz Dhandala Date: Sun, 28 Dec 2025 12:40:00 +0000 Subject: [PATCH] style: Improve code formatting and readability in various files --- .../Models/DatabaseModels/AIAgentTaskLog.ts | 3 +- Common/Server/API/AIAgentTaskLogAPI.ts | 3 +- .../1766923324521-MigrationName.ts | 47 ++++++++---- .../Postgres/SchemaMigrations/Index.ts | 2 +- Telemetry/Tests/Utils/Exception.test.ts | 24 +++--- Telemetry/Utils/Exception.ts | 74 +++++++++---------- 6 files changed, 83 insertions(+), 70 deletions(-) diff --git a/Common/Models/DatabaseModels/AIAgentTaskLog.ts b/Common/Models/DatabaseModels/AIAgentTaskLog.ts index a9bec77927..e44b9b1197 100644 --- a/Common/Models/DatabaseModels/AIAgentTaskLog.ts +++ b/Common/Models/DatabaseModels/AIAgentTaskLog.ts @@ -296,7 +296,8 @@ export default class AIAgentTaskLog extends BaseModel { required: true, type: TableColumnType.ShortText, title: "Severity", - description: "Severity level of this log entry (e.g., Information, Warning, Error).", + description: + "Severity level of this log entry (e.g., Information, Warning, Error).", }) @Column({ nullable: false, diff --git a/Common/Server/API/AIAgentTaskLogAPI.ts b/Common/Server/API/AIAgentTaskLogAPI.ts index f97983f7d1..6dd1a02c0b 100644 --- a/Common/Server/API/AIAgentTaskLogAPI.ts +++ b/Common/Server/API/AIAgentTaskLogAPI.ts @@ -76,7 +76,8 @@ export default class AIAgentTaskLogAPI extends BaseAPI< const message: string = data["message"] as string; /* Validate severity value */ - const validSeverities: Array = Object.values(LogSeverity); + const validSeverities: Array = + Object.values(LogSeverity); if (!validSeverities.includes(severity)) { return Response.sendErrorResponse( req, diff --git a/Common/Server/Infrastructure/Postgres/SchemaMigrations/1766923324521-MigrationName.ts b/Common/Server/Infrastructure/Postgres/SchemaMigrations/1766923324521-MigrationName.ts index cec10bc14e..486746f741 100644 --- a/Common/Server/Infrastructure/Postgres/SchemaMigrations/1766923324521-MigrationName.ts +++ b/Common/Server/Infrastructure/Postgres/SchemaMigrations/1766923324521-MigrationName.ts @@ -1,22 +1,37 @@ import { MigrationInterface, QueryRunner } from "typeorm"; export class MigrationName1766923324521 implements MigrationInterface { - public name = 'MigrationName1766923324521' + public name = "MigrationName1766923324521"; - public async up(queryRunner: QueryRunner): Promise { - await queryRunner.query(`ALTER TABLE "AIAgentTaskLog" DROP COLUMN "logs"`); - await queryRunner.query(`ALTER TABLE "AIAgentTaskLog" ADD "severity" character varying(50) NOT NULL`); - await queryRunner.query(`ALTER TABLE "AIAgentTaskLog" ADD "message" text NOT NULL`); - await queryRunner.query(`ALTER TABLE "OnCallDutyPolicyScheduleLayer" ALTER COLUMN "rotation" SET DEFAULT '{"_type":"Recurring","value":{"intervalType":"Day","intervalCount":{"_type":"PositiveNumber","value":1}}}'`); - await queryRunner.query(`ALTER TABLE "OnCallDutyPolicyScheduleLayer" ALTER COLUMN "restrictionTimes" SET DEFAULT '{"_type":"RestrictionTimes","value":{"restictionType":"None","dayRestrictionTimes":null,"weeklyRestrictionTimes":[]}}'`); - } - - public async down(queryRunner: QueryRunner): Promise { - await queryRunner.query(`ALTER TABLE "OnCallDutyPolicyScheduleLayer" ALTER COLUMN "restrictionTimes" SET DEFAULT '{"_type": "RestrictionTimes", "value": {"restictionType": "None", "dayRestrictionTimes": null, "weeklyRestrictionTimes": []}}'`); - await queryRunner.query(`ALTER TABLE "OnCallDutyPolicyScheduleLayer" ALTER COLUMN "rotation" SET DEFAULT '{"_type": "Recurring", "value": {"intervalType": "Day", "intervalCount": {"_type": "PositiveNumber", "value": 1}}}'`); - await queryRunner.query(`ALTER TABLE "AIAgentTaskLog" DROP COLUMN "message"`); - await queryRunner.query(`ALTER TABLE "AIAgentTaskLog" DROP COLUMN "severity"`); - await queryRunner.query(`ALTER TABLE "AIAgentTaskLog" ADD "logs" jsonb`); - } + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE "AIAgentTaskLog" DROP COLUMN "logs"`); + await queryRunner.query( + `ALTER TABLE "AIAgentTaskLog" ADD "severity" character varying(50) NOT NULL`, + ); + await queryRunner.query( + `ALTER TABLE "AIAgentTaskLog" ADD "message" text NOT NULL`, + ); + await queryRunner.query( + `ALTER TABLE "OnCallDutyPolicyScheduleLayer" ALTER COLUMN "rotation" SET DEFAULT '{"_type":"Recurring","value":{"intervalType":"Day","intervalCount":{"_type":"PositiveNumber","value":1}}}'`, + ); + await queryRunner.query( + `ALTER TABLE "OnCallDutyPolicyScheduleLayer" ALTER COLUMN "restrictionTimes" SET DEFAULT '{"_type":"RestrictionTimes","value":{"restictionType":"None","dayRestrictionTimes":null,"weeklyRestrictionTimes":[]}}'`, + ); + } + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query( + `ALTER TABLE "OnCallDutyPolicyScheduleLayer" ALTER COLUMN "restrictionTimes" SET DEFAULT '{"_type": "RestrictionTimes", "value": {"restictionType": "None", "dayRestrictionTimes": null, "weeklyRestrictionTimes": []}}'`, + ); + await queryRunner.query( + `ALTER TABLE "OnCallDutyPolicyScheduleLayer" ALTER COLUMN "rotation" SET DEFAULT '{"_type": "Recurring", "value": {"intervalType": "Day", "intervalCount": {"_type": "PositiveNumber", "value": 1}}}'`, + ); + await queryRunner.query( + `ALTER TABLE "AIAgentTaskLog" DROP COLUMN "message"`, + ); + await queryRunner.query( + `ALTER TABLE "AIAgentTaskLog" DROP COLUMN "severity"`, + ); + await queryRunner.query(`ALTER TABLE "AIAgentTaskLog" ADD "logs" jsonb`); + } } diff --git a/Common/Server/Infrastructure/Postgres/SchemaMigrations/Index.ts b/Common/Server/Infrastructure/Postgres/SchemaMigrations/Index.ts index c53d67189c..53706aac2d 100644 --- a/Common/Server/Infrastructure/Postgres/SchemaMigrations/Index.ts +++ b/Common/Server/Infrastructure/Postgres/SchemaMigrations/Index.ts @@ -425,5 +425,5 @@ export default [ MigrationName1766774689743, MigrationName1766777986427, AddAIAgentIsDefault1766918848434, - MigrationName1766923324521 + MigrationName1766923324521, ]; diff --git a/Telemetry/Tests/Utils/Exception.test.ts b/Telemetry/Tests/Utils/Exception.test.ts index e3f9e972d5..8412227035 100644 --- a/Telemetry/Tests/Utils/Exception.test.ts +++ b/Telemetry/Tests/Utils/Exception.test.ts @@ -47,10 +47,8 @@ describe("ExceptionUtil", () => { }); test("normalizes MongoDB ObjectIDs", () => { - const message1: string = - "Document not found: 507f1f77bcf86cd799439011"; - const message2: string = - "Document not found: 60a1b2c3d4e5f6a7b8c9d0e1"; + const message1: string = "Document not found: 507f1f77bcf86cd799439011"; + const message2: string = "Document not found: 60a1b2c3d4e5f6a7b8c9d0e1"; const normalized1: string = ExceptionUtil.normalizeForFingerprint(message1); @@ -88,10 +86,8 @@ describe("ExceptionUtil", () => { }); test("normalizes timestamps", () => { - const message1: string = - "Request failed at 2024-03-15T14:30:00.000Z"; - const message2: string = - "Request failed at 2024-12-01T09:15:30.500Z"; + const message1: string = "Request failed at 2024-03-15T14:30:00.000Z"; + const message2: string = "Request failed at 2024-12-01T09:15:30.500Z"; const normalized1: string = ExceptionUtil.normalizeForFingerprint(message1); @@ -155,8 +151,10 @@ describe("ExceptionUtil", () => { }); test("normalizes large numbers", () => { - // Large numbers (8+ digits) may match hex pattern since 0-9 are valid hex - // The important thing is both normalize to the same value + /* + * Large numbers (8+ digits) may match hex pattern since 0-9 are valid hex + * The important thing is both normalize to the same value + */ const message1: string = "User 8234567890 not found"; const message2: string = "User 9876543210 not found"; @@ -190,9 +188,11 @@ describe("ExceptionUtil", () => { test("handles null/undefined gracefully", () => { // @ts-expect-error - testing edge case - const normalizedNull: string = ExceptionUtil.normalizeForFingerprint(null); + const normalizedNull: string = + ExceptionUtil.normalizeForFingerprint(null); // @ts-expect-error - testing edge case - const normalizedUndefined: string = ExceptionUtil.normalizeForFingerprint(undefined); + const normalizedUndefined: string = + ExceptionUtil.normalizeForFingerprint(undefined); expect(normalizedNull).toBe(""); expect(normalizedUndefined).toBe(""); diff --git a/Telemetry/Utils/Exception.ts b/Telemetry/Utils/Exception.ts index 2fee078eb6..7340f62ea6 100644 --- a/Telemetry/Utils/Exception.ts +++ b/Telemetry/Utils/Exception.ts @@ -49,16 +49,20 @@ export default class ExceptionUtil { // 2. MongoDB ObjectIDs (24 hex characters) normalized = normalized.replace(/\b[0-9a-f]{24}\b/gi, ""); - // 3. Stripe-style IDs (e.g., sub_xxx, cus_xxx, pi_xxx, ch_xxx, etc.) - // These have a prefix followed by underscore and alphanumeric characters + /* + * 3. Stripe-style IDs (e.g., sub_xxx, cus_xxx, pi_xxx, ch_xxx, etc.) + * These have a prefix followed by underscore and alphanumeric characters + */ normalized = normalized.replace( /\b(sub|cus|pi|ch|pm|card|price|prod|inv|txn|evt|req|acct|payout|ba|btok|src|tok|seti|si|cs|link|file|dp|icr|ii|il|is|isci|mbur|or|po|qt|rcpt|re|refund|sku|tax|txi|tr|us|wh)_[A-Za-z0-9]{10,32}\b/g, "", ); - // 4. Generic API/Service IDs - alphanumeric strings that look like IDs - // Matches patterns like: prefix_alphanumeric or just long alphanumeric strings - // Common in many services (AWS, GCP, etc.) + /* + * 4. Generic API/Service IDs - alphanumeric strings that look like IDs + * Matches patterns like: prefix_alphanumeric or just long alphanumeric strings + * Common in many services (AWS, GCP, etc.) + */ normalized = normalized.replace( /\b[a-z]{2,10}_[A-Za-z0-9]{8,}\b/g, "", @@ -95,15 +99,19 @@ export default class ExceptionUtil { "", ); - // 10. URLs with dynamic paths/query params (normalize the dynamic parts) - // Keep the domain but normalize path segments that look like IDs + /* + * 10. URLs with dynamic paths/query params (normalize the dynamic parts) + * Keep the domain but normalize path segments that look like IDs + */ normalized = normalized.replace( /\/[0-9a-f]{8,}(?=\/|$|\?|#|\s|'|")/gi, "/", ); - // 11. Timestamps in various formats - // ISO 8601 timestamps + /* + * 11. Timestamps in various formats + * ISO 8601 timestamps + */ normalized = normalized.replace( /\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}:?\d{2})?/g, "", @@ -112,20 +120,11 @@ export default class ExceptionUtil { normalized = normalized.replace(/\b1[0-9]{9,12}\b/g, ""); // 12. Date formats (YYYY-MM-DD, MM/DD/YYYY, etc.) - normalized = normalized.replace( - /\b\d{4}[-/]\d{2}[-/]\d{2}\b/g, - "", - ); - normalized = normalized.replace( - /\b\d{2}[-/]\d{2}[-/]\d{4}\b/g, - "", - ); + normalized = normalized.replace(/\b\d{4}[-/]\d{2}[-/]\d{2}\b/g, ""); + normalized = normalized.replace(/\b\d{2}[-/]\d{2}[-/]\d{4}\b/g, ""); // 13. Time formats (HH:MM:SS, HH:MM) - normalized = normalized.replace( - /\b\d{2}:\d{2}(?::\d{2})?\b/g, - "