chore: strengthen backend eslint profile

This commit is contained in:
2026-09-28 16:37:01 +03:00
committed by ksv741
parent 53b2794963
commit a970eaaf7a
179 changed files with 4485 additions and 2716 deletions
@@ -1,25 +1,26 @@
import { createHash } from 'node:crypto';
import { InvestmentResourceMetaDto } from './investment-resource.dto';
export function investmentResourceMeta(input: {
resourceKey: string;
dataRevision: string;
availability: InvestmentResourceMetaDto['availability'];
coverage?: NonNullable<InvestmentResourceMetaDto['coverage']>;
dataRevision: string;
dependencies?: InvestmentResourceMetaDto[];
fetchedAt: Date | null;
freshForMs: number;
work: { id: string; state: string; errorCode: string | null } | null;
dependencies?: InvestmentResourceMetaDto[];
coverage?: InvestmentResourceMetaDto['coverage'];
resourceKey: string;
unavailableReason?: string;
work: null | { errorCode: null | string; id: string; state: string };
}): InvestmentResourceMetaDto {
const ownSync = {
id: input.work?.id ?? null,
state:
input.work?.state === 'running'
? ('running' as const)
: input.work?.state === 'failed'
? ('failed' as const)
: ('idle' as const),
input.work?.state === 'running' ?
('running' as const) :
input.work?.state === 'failed' ?
('failed' as const) :
('idle' as const),
errorCode: input.work?.errorCode ?? null,
};
const states = [
@@ -33,11 +34,11 @@ export function investmentResourceMeta(input: {
states.find((state) => state.state === 'queued') ??
states.find((state) => state.state === 'failed') ??
ownSync;
const sourceFreshness = input.fetchedAt
? Date.now() - input.fetchedAt.valueOf() < input.freshForMs
? ('fresh' as const)
: ('stale' as const)
: ('unknown' as const);
const sourceFreshness = input.fetchedAt ?
Date.now() - input.fetchedAt.valueOf() < input.freshForMs ?
('fresh' as const) :
('stale' as const) :
('unknown' as const);
const freshness = [
sourceFreshness,
...(input.dependencies ?? [])
@@ -51,19 +52,20 @@ export function investmentResourceMeta(input: {
),
]
.filter((timestamp): timestamp is string => Boolean(timestamp))
// eslint-disable-next-line sonarjs/no-alphabetical-sort -- Code-unit ordering is intentional for canonical keys and ISO dates; locale collation would change persisted bindings.
.sort();
const meta = {
resourceKey: input.resourceKey,
...(input.unavailableReason
? { unavailableReason: input.unavailableReason }
: {}),
...(input.unavailableReason ?
{ unavailableReason: input.unavailableReason } :
{}),
dataRevision: input.dataRevision,
availability: input.availability,
freshness: freshness.includes('unknown')
? ('unknown' as const)
: freshness.includes('stale')
? ('stale' as const)
: ('fresh' as const),
freshness: freshness.includes('unknown') ?
('unknown' as const) :
freshness.includes('stale') ?
('stale' as const) :
('fresh' as const),
lastSuccessfulAt: timestamps[0] ?? null,
sync,
...(input.coverage ? { coverage: input.coverage } : {}),
@@ -77,9 +79,9 @@ export function investmentResourceMeta(input: {
...meta,
// The requested window is identified by resourceKey. Its moving "now"
// boundary is not a change to saved coverage between status and GET.
coverage: meta.coverage
? { ...meta.coverage, requested: undefined }
: undefined,
coverage: meta.coverage ?
{ ...meta.coverage, requested: undefined } :
undefined,
}),
)
.digest('base64url'),