Skip to content

Commit e69226d

Browse files
committed
fix: no any rule
Signed-off-by: ferhat elmas <elmas.ferhat@gmail.com>
1 parent 7cb07b5 commit e69226d

File tree

80 files changed

+1444
-473
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+1444
-473
lines changed

biome.jsonc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
"noAssignInExpressions": "error",
4343
"noAsyncPromiseExecutor": "error",
4444
"noDoubleEquals": "error",
45-
"noExplicitAny": "warn",
45+
"noExplicitAny": "error",
4646
"noFocusedTests": "error",
4747
"noImplicitAnyLet": "error",
4848
"noShadowRestrictedNames": "error",

build.js

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,39 @@
11
// biome-ignore lint/style/noCommonJs: build script runs as CommonJS
22
const { build } = require('esbuild')
3+
// biome-ignore lint/style/noCommonJs: build script runs as CommonJS
4+
const { readdirSync, rmSync } = require('node:fs')
5+
// biome-ignore lint/style/noCommonJs: build script runs as CommonJS
6+
const { join, sep } = require('node:path')
7+
8+
function collectEntryPoints(dir) {
9+
const entryPoints = []
10+
11+
for (const entry of readdirSync(dir, { withFileTypes: true })) {
12+
const fullPath = join(dir, entry.name)
13+
14+
if (entry.isDirectory()) {
15+
if (fullPath === join('src', 'typecheck')) {
16+
continue
17+
}
18+
19+
entryPoints.push(...collectEntryPoints(fullPath))
20+
continue
21+
}
22+
23+
if (entry.isFile() && entry.name.endsWith('.ts')) {
24+
entryPoints.push(`./${fullPath.split(sep).join('/')}`)
25+
}
26+
}
27+
28+
return entryPoints
29+
}
30+
31+
// Typecheck sentinels are enforced by `tsc -noEmit`
32+
// keep them out of emitted build output.
33+
rmSync('dist/typecheck', { recursive: true, force: true })
334

435
build({
5-
entryPoints: ['./src/**/*.ts'],
36+
entryPoints: collectEntryPoints('src').sort(),
637
bundle: false,
738
outdir: 'dist',
839
platform: 'node',

src/http/error-handler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export const setErrorHandler = (
1414
app: FastifyInstance,
1515
options?: {
1616
respectStatusCode?: boolean
17-
formatter?: (error: StorageError) => Record<string, any>
17+
formatter?: (error: StorageError) => unknown
1818
}
1919
) => {
2020
app.setErrorHandler<Error>(function (error, request, reply) {

src/http/plugins/log-request.ts

Lines changed: 40 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { logger, logSchema, redactQueryParamFromRequest } from '@internal/monitoring'
2+
import { RouteGenericInterface } from 'fastify'
23
import { FastifyReply } from 'fastify/types/reply'
34
import { FastifyRequest } from 'fastify/types/request'
45
import fastifyPlugin from 'fastify-plugin'
@@ -7,6 +8,11 @@ interface RequestLoggerOptions {
78
excludeUrls?: string[]
89
}
910

11+
type RawRequestMetadata = FastifyRequest['raw'] & {
12+
executionError?: Error
13+
resources?: string[]
14+
}
15+
1016
declare module 'fastify' {
1117
interface FastifyRequest {
1218
executionError?: Error
@@ -18,8 +24,8 @@ declare module 'fastify' {
1824

1925
interface FastifyContextConfig {
2026
operation?: { type: string }
21-
resources?: (req: FastifyRequest<any>) => string[]
22-
logMetadata?: (req: FastifyRequest<any>) => Record<string, unknown>
27+
resources?(req: FastifyRequest<RouteGenericInterface>): string[]
28+
logMetadata?(req: FastifyRequest<RouteGenericInterface>): Record<string, unknown>
2329
}
2430
}
2531

@@ -64,30 +70,11 @@ export const logRequest = (options: RequestLoggerOptions) =>
6470
}
6571

6672
if (resources === undefined) {
67-
resources = (req.raw as any).resources
73+
resources = getRawRequest(req).resources
6874
}
6975

7076
if (resources === undefined) {
71-
const params = req.params as Record<string, unknown> | undefined
72-
let resourceFromParams = ''
73-
74-
if (params) {
75-
let first = true
76-
for (const key in params) {
77-
if (!Object.prototype.hasOwnProperty.call(params, key)) {
78-
continue
79-
}
80-
81-
if (!first) {
82-
resourceFromParams += '/'
83-
}
84-
85-
const value = params[key]
86-
resourceFromParams += value == null ? '' : String(value)
87-
first = false
88-
}
89-
}
90-
77+
const resourceFromParams = getResourceFromParams(req.params)
9178
resources = resourceFromParams ? [resourceFromParams] : []
9279
}
9380

@@ -150,7 +137,7 @@ function doRequestLog(req: FastifyRequest, options: LogRequestOptions) {
150137
const rId = req.id
151138
const cIP = req.ip
152139
const statusCode = options.statusCode
153-
const error = (req.raw as any).executionError || req.executionError
140+
const error = getRawRequest(req).executionError || req.executionError
154141
const tenantId = req.tenantId
155142

156143
let reqMetadata: Record<string, unknown> = {}
@@ -197,3 +184,32 @@ function doRequestLog(req: FastifyRequest, options: LogRequestOptions) {
197184
serverTimes: req.serverTimings,
198185
})
199186
}
187+
188+
function getRawRequest(req: FastifyRequest): RawRequestMetadata {
189+
return req.raw as RawRequestMetadata
190+
}
191+
192+
function getResourceFromParams(params: unknown): string {
193+
if (!params || typeof params !== 'object') {
194+
return ''
195+
}
196+
197+
let resource = ''
198+
let first = true
199+
200+
for (const key in params) {
201+
if (!Object.prototype.hasOwnProperty.call(params, key)) {
202+
continue
203+
}
204+
205+
if (!first) {
206+
resource += '/'
207+
}
208+
209+
const value = (params as Record<string, unknown>)[key]
210+
resource += value == null ? '' : String(value)
211+
first = false
212+
}
213+
214+
return resource
215+
}

src/http/routes-helper.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
type BucketResponseType = { message: string; statusCode?: string; error?: string }
2+
type SchemaObject = Record<string, unknown>
23

34
/**
45
* Create generic response for all buckets
@@ -23,7 +24,10 @@ function createResponse(message: string, status?: string, error?: string): Bucke
2324
return response
2425
}
2526

26-
function createDefaultSchema(successResponseSchema: any, properties: any): any {
27+
function createDefaultSchema(
28+
successResponseSchema: SchemaObject,
29+
properties: SchemaObject
30+
): SchemaObject {
2731
return {
2832
headers: { $ref: 'authSchema#' },
2933
response: {

src/http/routes/admin/migrations.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,15 @@ import apiKey from '../../plugins/apikey'
1313
const { pgQueueEnable } = getConfig()
1414
const migrationQueueName = RunMigrationsOnTenants.getQueueName()
1515

16+
type ResetFleetBody = {
17+
untilMigration?: unknown
18+
markCompletedTillMigration?: unknown
19+
}
20+
21+
type FailedQuery = {
22+
cursor?: string
23+
}
24+
1625
export default async function routes(fastify: FastifyInstance) {
1726
fastify.register(apiKey)
1827

@@ -31,7 +40,7 @@ export default async function routes(fastify: FastifyInstance) {
3140
return reply.status(400).send({ message: 'Queue is not enabled' })
3241
}
3342

34-
const { untilMigration, markCompletedTillMigration } = req.body as Record<string, unknown>
43+
const { untilMigration, markCompletedTillMigration } = req.body as ResetFleetBody
3544

3645
if (!isDBMigrationName(untilMigration)) {
3746
return reply.status(400).send({ message: 'Invalid migration' })
@@ -96,7 +105,8 @@ export default async function routes(fastify: FastifyInstance) {
96105
if (!pgQueueEnable) {
97106
return reply.code(400).send({ message: 'Queue is not enabled' })
98107
}
99-
const offset = (req.query as any).cursor ? Number((req.query as any).cursor) : 0
108+
const { cursor } = req.query as FailedQuery
109+
const offset = cursor ? Number(cursor) : 0
100110

101111
const failed = await multitenantKnex
102112
.table('tenants')

src/http/routes/admin/queue.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ import { getConfig } from '../../../config'
55
import apiKey from '../../plugins/apikey'
66

77
const { pgQueueEnable } = getConfig()
8+
// Empty ref/host mark system-scoped events and intentionally skip per-tenant shouldSend lookups.
9+
const systemTenant = {
10+
ref: '',
11+
host: '',
12+
} as const
813

914
const moveJobsSchema = {
1015
body: {
@@ -37,7 +42,9 @@ export default async function routes(fastify: FastifyInstance) {
3742
return reply.status(400).send({ message: 'Queue is not enabled' })
3843
}
3944

40-
await UpgradePgBossV10.send({})
45+
await UpgradePgBossV10.send({
46+
tenant: systemTenant,
47+
})
4148

4249
return reply.send({ message: 'Migration scheduled' })
4350
})
@@ -58,6 +65,7 @@ export default async function routes(fastify: FastifyInstance) {
5865
fromQueue,
5966
toQueue,
6067
deleteJobsFromOriginalQueue,
68+
tenant: systemTenant,
6169
})
6270

6371
return reply.send({ message: 'Move jobs scheduled' })

src/http/routes/iceberg/table.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -518,12 +518,10 @@ export default async function routes(fastify: FastifyInstance) {
518518
try {
519519
if (typeof payload === 'string') return done(null, JSONBigint.parse(payload))
520520
if (Buffer.isBuffer(payload)) return done(null, JSONBigint.parse(payload.toString('utf8')))
521-
if (payload && typeof (payload as any).on === 'function') {
521+
if (isReadablePayload(payload)) {
522522
const chunks: Buffer[] = []
523-
;(payload as NodeJS.ReadableStream).on('data', (c) =>
524-
chunks.push(Buffer.isBuffer(c) ? c : Buffer.from(String(c)))
525-
)
526-
;(payload as NodeJS.ReadableStream).on('end', () => {
523+
payload.on('data', (c) => chunks.push(Buffer.isBuffer(c) ? c : Buffer.from(String(c))))
524+
payload.on('end', () => {
527525
try {
528526
done(null, JSONBigint.parse(Buffer.concat(chunks).toString('utf8')))
529527
} catch (err) {
@@ -574,3 +572,9 @@ export default async function routes(fastify: FastifyInstance) {
574572
)
575573
})
576574
}
575+
576+
function isReadablePayload(payload: unknown): payload is NodeJS.ReadableStream {
577+
return (
578+
!!payload && typeof payload === 'object' && 'on' in payload && typeof payload.on === 'function'
579+
)
580+
}

src/http/routes/render/rate-limiter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const {
1313
rateLimiterRenderPathMaxReqSec,
1414
} = getConfig()
1515

16-
export const rateLimiter = fp((fastify: FastifyInstance, ops: any, done: () => void) => {
16+
export const rateLimiter = fp((fastify: FastifyInstance, _ops: unknown, done: () => void) => {
1717
fastify.register(fastifyRateLimit, {
1818
global: true,
1919
max: rateLimiterRenderPathMaxReqSec * 4,

src/http/routes/s3/error-handler.ts

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,18 @@ import { FastifyReply } from 'fastify/types/reply'
55
import { FastifyRequest } from 'fastify/types/request'
66
import { DatabaseError } from 'pg'
77

8+
type ValidationIssue = {
9+
instancePath?: string
10+
message?: string
11+
}
12+
813
export const s3ErrorHandler = (
914
error: FastifyError | Error,
1015
request: FastifyRequest,
1116
reply: FastifyReply
1217
) => {
1318
request.executionError = error
19+
const validation = getValidationIssues(error)
1420

1521
const resource = request.url
1622
.split('?')[0]
@@ -19,12 +25,12 @@ export const s3ErrorHandler = (
1925
.filter((e) => e)
2026
.join('/')
2127

22-
if ('validation' in error) {
28+
if (validation) {
2329
return reply.status(400).send({
2430
Error: {
2531
Resource: resource,
2632
Code: ErrorCode.InvalidRequest,
27-
Message: formatValidationError(error.validation).message,
33+
Message: formatValidationError(validation).message,
2834
},
2935
})
3036
}
@@ -91,7 +97,20 @@ export const s3ErrorHandler = (
9197
})
9298
}
9399

94-
function formatValidationError(errors: any) {
100+
function isValidationIssueArray(value: unknown): value is ValidationIssue[] {
101+
return Array.isArray(value)
102+
}
103+
104+
function getValidationIssues(error: FastifyError | Error): ValidationIssue[] | undefined {
105+
if (!('validation' in error)) {
106+
return undefined
107+
}
108+
109+
const value = error.validation
110+
return isValidationIssueArray(value) ? value : undefined
111+
}
112+
113+
function formatValidationError(errors: readonly ValidationIssue[]) {
95114
let text = ''
96115
const separator = ', '
97116

0 commit comments

Comments
 (0)