Skip to content

Commit 4a58b7c

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

63 files changed

Lines changed: 736 additions & 399 deletions

Some content is hidden

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

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",

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: 54 additions & 36 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

@@ -57,39 +63,13 @@ export const logRequest = (options: RequestLoggerOptions) =>
5763
* Adds req.resources and req.operation to the request object
5864
*/
5965
fastify.addHook('preHandler', async (req) => {
60-
let resources = req.resources
61-
62-
if (resources === undefined) {
63-
resources = req.routeOptions.config.resources?.(req)
64-
}
65-
66-
if (resources === undefined) {
67-
resources = (req.raw as any).resources
68-
}
69-
70-
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-
91-
resources = resourceFromParams ? [resourceFromParams] : []
92-
}
66+
const resourceFromParams = getResourceFromParams(req.params)
67+
const resources = getFirstDefined<string[]>(
68+
req.resources,
69+
req.routeOptions.config.resources?.(req),
70+
getRawRequest(req).resources,
71+
resourceFromParams ? [resourceFromParams] : []
72+
)
9373

9474
if (resources && resources.length > 0) {
9575
for (let index = 0; index < resources.length; index++) {
@@ -150,7 +130,7 @@ function doRequestLog(req: FastifyRequest, options: LogRequestOptions) {
150130
const rId = req.id
151131
const cIP = req.ip
152132
const statusCode = options.statusCode
153-
const error = (req.raw as any).executionError || req.executionError
133+
const error = getRawRequest(req).executionError || req.executionError
154134
const tenantId = req.tenantId
155135

156136
let reqMetadata: Record<string, unknown> = {}
@@ -197,3 +177,41 @@ function doRequestLog(req: FastifyRequest, options: LogRequestOptions) {
197177
serverTimes: req.serverTimings,
198178
})
199179
}
180+
181+
function getRawRequest(req: FastifyRequest): RawRequestMetadata {
182+
return req.raw as RawRequestMetadata
183+
}
184+
185+
function getResourceFromParams(params: unknown): string {
186+
if (!params || typeof params !== 'object') {
187+
return ''
188+
}
189+
190+
let resource = ''
191+
let first = true
192+
193+
for (const key in params) {
194+
if (!Object.prototype.hasOwnProperty.call(params, key)) {
195+
continue
196+
}
197+
198+
if (!first) {
199+
resource += '/'
200+
}
201+
202+
const value = (params as Record<string, unknown>)[key]
203+
resource += value == null ? '' : String(value)
204+
first = false
205+
}
206+
207+
return resource
208+
}
209+
210+
function getFirstDefined<T>(...values: (T | undefined)[]): T | undefined {
211+
for (const value of values) {
212+
if (value !== undefined) {
213+
return value
214+
}
215+
}
216+
return undefined
217+
}

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/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

src/http/routes/s3/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,12 @@ export default async function routes(fastify: FastifyInstance) {
6666
req.opentelemetry()?.span?.setAttribute('http.operation', req.operation.type)
6767
}
6868

69-
const data: RequestInput<any> = {
69+
const data = {
7070
Params: req.params,
7171
Body: req.body,
7272
Headers: req.headers,
7373
Querystring: req.query,
74-
}
74+
} as unknown as RequestInput<typeof route.schema>
7575
const compiler = route.compiledSchema()
7676
const isValid = compiler(data)
7777

0 commit comments

Comments
 (0)