diff --git a/packages/pg-migrate/src/migration.ts b/packages/pg-migrate/src/migration.ts index 38eb821e..9334d2b2 100644 --- a/packages/pg-migrate/src/migration.ts +++ b/packages/pg-migrate/src/migration.ts @@ -69,7 +69,7 @@ const getLastSuffix = async (dir: string, ignorePattern?: string) => { try { const files = await loadMigrationFiles(dir, ignorePattern); return files.length > 0 - ? getSuffixFromFileName(files[files.length - 1]) + ? getSuffixFromFileName(files[files.length - 1] as string) : undefined; } catch (err) { return undefined; diff --git a/packages/pg-migrate/src/runner.ts b/packages/pg-migrate/src/runner.ts index 0b3182b1..eedd9e3b 100644 --- a/packages/pg-migrate/src/runner.ts +++ b/packages/pg-migrate/src/runner.ts @@ -172,7 +172,7 @@ const checkOrder = (runNames: string[], migrations: Migration[]) => { const len = Math.min(runNames.length, migrations.length); for (let i = 0; i < len; i += 1) { const runName = runNames[i]; - const migrationName = migrations[i].name; + const migrationName = migrations[i]?.name; if (runName !== migrationName) { throw new Error( `Not run migration ${migrationName} is preceding already run migration ${runName}`, diff --git a/packages/pg-migrate/src/utils.ts b/packages/pg-migrate/src/utils.ts index c88e3e86..eb3858c8 100644 --- a/packages/pg-migrate/src/utils.ts +++ b/packages/pg-migrate/src/utils.ts @@ -25,8 +25,8 @@ export class StringIdGenerator { private increment() { for (let i = this.ids.length - 1; i >= 0; i -= 1) { - this.ids[i] += 1; - if (this.ids[i] < this.chars.length) { + this.ids[i] = (this.ids[i] ?? 0) + 1; + if ((this.ids[i] as number) < this.chars.length) { return; } this.ids[i] = 0; @@ -88,4 +88,4 @@ export const getSchemas = (schema?: string[] | string): string[] => { export const getMigrationTableSchema = (options: RunnerOption): string => options.migrationsSchema !== undefined ? options.migrationsSchema - : getSchemas(options.schema)[0]; + : (getSchemas(options.schema)[0] as string); diff --git a/packages/sidetrack/src/effect.ts b/packages/sidetrack/src/effect.ts index dcf02586..a18ab18e 100644 --- a/packages/sidetrack/src/effect.ts +++ b/packages/sidetrack/src/effect.ts @@ -335,7 +335,7 @@ export function layer( message: (e as any).message, }), try: () => - queues[job.queue].run( + queues[job.queue]!.run( payloadDeserializer(job.queue, job.payload as Queues[string]), { job: job as SidetrackJob, @@ -432,7 +432,7 @@ export function layer( options?.uniqueKey, ], ), - ).pipe(Effect.map((result) => result.rows[0])); + ).pipe(Effect.map((result) => result.rows[0]!)); const getJob = (jobId: string, options?: SidetrackGetJobOptions) => Effect.promise(() => @@ -440,7 +440,7 @@ export function layer( `SELECT * FROM sidetrack_jobs WHERE id = $1`, [jobId], ), - ).pipe(Effect.map((result) => result.rows[0])); + ).pipe(Effect.map((result) => result.rows[0]!)); const scheduleCron = ( queueName: K, @@ -465,7 +465,7 @@ export function layer( ), ), ), - Effect.map((result) => result.rows[0]), + Effect.map((result) => result.rows[0]!), Effect.tap((cronJob) => startCronJob(cronJob, options)), ); @@ -579,7 +579,7 @@ export function layer( ) .pipe( - Effect.map((result) => result.rows[0]), + Effect.map((result) => result.rows[0]!), Effect.flatMap((job) => executeJobRunner(job, options)), ); diff --git a/packages/sidetrack/test/cron.test.ts b/packages/sidetrack/test/cron.test.ts index 09407222..90e9437e 100644 --- a/packages/sidetrack/test/cron.test.ts +++ b/packages/sidetrack/test/cron.test.ts @@ -72,7 +72,7 @@ describe("cron jobs", () => { "SELECT status FROM sidetrack_cron_jobs WHERE queue = $1 AND cron_expression = $2", ["test", "*/5 * * * *"], ); - expect(result.rows[0].status).toBe("inactive"); + expect(result.rows[0]?.status).toBe("inactive"); }); }); @@ -187,11 +187,11 @@ describe("cron jobs", () => { expect(queue2Jobs.some((job) => job.status === "completed")).toBe(true); // Verify payloads - expect(queue1Jobs[0].payload).toEqual({ + expect(queue1Jobs[0]?.payload).toEqual({ description: "First cron job", sequence: 1, }); - expect(queue2Jobs[0].payload).toEqual({ + expect(queue2Jobs[0]?.payload).toEqual({ description: "Second cron job", sequence: 2, }); diff --git a/packages/sidetrack/test/index.test.ts b/packages/sidetrack/test/index.test.ts index f4ee36ce..438ff6b1 100644 --- a/packages/sidetrack/test/index.test.ts +++ b/packages/sidetrack/test/index.test.ts @@ -280,8 +280,8 @@ describe.concurrent("jobs", () => { queue: ["scheduled"], }); expect(jobsBeforeSchedule.length).toBe(1); - expect(jobsBeforeSchedule[0].status).toBe("scheduled"); - expect(jobsBeforeSchedule[0].scheduled_at).toEqual(futureDate); + expect(jobsBeforeSchedule[0]?.status).toBe("scheduled"); + expect(jobsBeforeSchedule[0]?.scheduled_at).toEqual(futureDate); await sidetrack.runJobs({ queue: ["scheduled"] }); @@ -289,8 +289,8 @@ describe.concurrent("jobs", () => { queue: ["scheduled"], }); expect(jobsAfterSchedule.length).toBe(1); - expect(jobsAfterSchedule[0].status).toBe("scheduled"); - expect(jobsAfterSchedule[0].payload).toEqual({ message: "Future job" }); + expect(jobsAfterSchedule[0]?.status).toBe("scheduled"); + expect(jobsAfterSchedule[0]?.payload).toEqual({ message: "Future job" }); await sidetrack.runJobs({ includeFutureJobs: true, @@ -301,8 +301,8 @@ describe.concurrent("jobs", () => { queue: ["scheduled"], }); expect(jobsAfterRun.length).toBe(1); - expect(jobsAfterRun[0].status).toBe("completed"); - expect(jobsAfterRun[0].payload).toEqual({ message: "Future job" }); + expect(jobsAfterRun[0]?.status).toBe("completed"); + expect(jobsAfterRun[0]?.payload).toEqual({ message: "Future job" }); }); }); @@ -371,7 +371,7 @@ describe.concurrent("jobs", () => { const jobs = await sidetrack.listJobs({ queue: ["test"] }); expect(jobs.length).toBe(1); - expect(jobs[0].payload).toEqual({ id: "suppress unique 1" }); + expect(jobs[0]?.payload).toEqual({ id: "suppress unique 1" }); }); }); diff --git a/packages/sidetrack/test/poll.test.ts b/packages/sidetrack/test/poll.test.ts index 03e163a1..cd4b0d95 100644 --- a/packages/sidetrack/test/poll.test.ts +++ b/packages/sidetrack/test/poll.test.ts @@ -75,8 +75,8 @@ describe("polling", () => { const timestamps = [processedJob1, processedJob2, processedJob3].map( (job) => job.attempted_at!.getTime(), ); - expect(timestamps[1] - timestamps[0]).toBeGreaterThanOrEqual(100); // At least one polling interval - expect(timestamps[2] - timestamps[1]).toBeGreaterThanOrEqual(100); + expect(timestamps[1]! - timestamps[0]!).toBeGreaterThanOrEqual(100); // At least one polling interval + expect(timestamps[2]! - timestamps[1]!).toBeGreaterThanOrEqual(100); } finally { // Clean up await sidetrack.stop(); diff --git a/tsconfig.json b/tsconfig.json index 5443839d..4f58d9ea 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -41,23 +41,10 @@ "moduleResolution": "nodenext", "noEmit": true, // TSUP takes care of emitting js for us, in a MUCH faster way "noFallthroughCasesInSwitch": true, - // "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */ - // "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */ - // "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */ - // "strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */ - // "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */ - // "noImplicitThis": true, /* Enable error reporting when 'this' is given the type 'any'. */ - // "useUnknownInCatchVariables": true, /* Default catch clause variables as 'unknown' instead of 'any'. */ - // "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */ - // "noUnusedLocals": true, /* Enable error reporting when local variables aren't read. */ - // "noUnusedParameters": true, /* Raise an error when a function parameter isn't read. */ - // "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */ - // "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */ - // "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */ - // "noUncheckedIndexedAccess": true, /* Add 'undefined' to a type when accessed using an index. */ "noImplicitOverride": true /* Ensure overriding members in derived classes are marked with an override modifier. */, "noImplicitReturns": true, "noPropertyAccessFromIndexSignature": true, + "noUncheckedIndexedAccess": true /* Add 'undefined' to a type when accessed using an index. */, "noUnusedLocals": true, "noUnusedParameters": true, /* Modules */