chore: strengthen backend eslint profile

This commit is contained in:
2026-09-28 11:04:18 +03:00
parent ca5dbcb382
commit 9b3558f96c
179 changed files with 4485 additions and 2716 deletions
@@ -1,8 +1,8 @@
export type OperationInterval = {
accountId: string;
from: Date;
to: Date;
instrumentUid?: string;
to: Date;
};
// Normalize duplicate/overlapping targets before creating a durable identity.
@@ -12,8 +12,10 @@ export function operationIntervals(
): OperationInterval[] {
const groups = new Map<string, OperationInterval[]>();
for (const interval of requested) {
if (!(interval.from < interval.to))
// eslint-disable-next-line sonarjs/no-inverted-boolean-check -- Negation also rejects Invalid Date; >= would silently accept NaN.
if (!(interval.from < interval.to)) {
throw new Error('Invalid operations interval');
}
const key = JSON.stringify([
interval.accountId,
interval.instrumentUid ?? '',
@@ -23,17 +25,18 @@ export function operationIntervals(
groups.set(key, group);
}
const result: OperationInterval[] = [];
// 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.
for (const key of [...groups.keys()].sort()) {
const merged: OperationInterval[] = [];
for (const interval of (groups.get(key) ?? []).sort(
(left, right) => left.from.valueOf() - right.from.valueOf(),
)) {
const previous = merged.at(-1);
if (previous && interval.from <= previous.to)
if (previous && interval.from <= previous.to) {
previous.to = new Date(
Math.max(previous.to.valueOf(), interval.to.valueOf()),
);
else merged.push({ ...interval });
} else merged.push({ ...interval });
}
for (const interval of merged) {
let from = interval.from;
@@ -61,8 +64,8 @@ export function operationIntervalsOverlap(
(!left.instrumentUid ||
!right.instrumentUid ||
left.instrumentUid === right.instrumentUid) &&
left.from < right.to &&
right.from < left.to
left.from < right.to &&
right.from < left.to
);
}
@@ -78,15 +81,16 @@ export function uncoveredOperationIntervals(
!operationIntervalsOverlap(fragment, covered) ||
(covered.instrumentUid &&
covered.instrumentUid !== fragment.instrumentUid)
)
) {
return [fragment];
}
return [
...(fragment.from < covered.from
? [{ ...fragment, to: covered.from }]
: []),
...(covered.to < fragment.to
? [{ ...fragment, from: covered.to }]
: []),
...(fragment.from < covered.from ?
[{ ...fragment, to: covered.from }] :
[]),
...(covered.to < fragment.to ?
[{ ...fragment, from: covered.to }] :
[]),
];
});
}
@@ -95,8 +99,8 @@ export function uncoveredOperationIntervals(
}
export type OperationCoverage = OperationInterval & {
fetchedAt: Date;
asOf: Date;
fetchedAt: Date;
};
const operationsFreshForMs = 300_000;
@@ -104,7 +108,7 @@ export function planOperationRead(
requested: OperationInterval[],
coverage: OperationCoverage[],
now: Date,
options: { movingEnd?: boolean; force?: boolean } = {},
options: { force?: boolean; movingEnd?: boolean } = {},
) {
const monthStart = new Date(
Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), 1),
@@ -137,8 +141,9 @@ export function planOperationRead(
row.asOf.valueOf() === row.to.valueOf() && row.to > target.from,
)
.sort((left, right) => right.to.valueOf() - left.to.valueOf())[0];
if (latest && latest.to < target.to)
if (latest && latest.to < target.to) {
effective = { ...target, to: latest.to };
}
}
const missing = uncoveredOperationIntervals([effective], ranges);
const complete = missing.length === 0;
@@ -163,20 +168,20 @@ export function planOperationRead(
// Completeness is bounded by the observed end, never by the new wall clock.
return {
...effective,
availability: complete
? ('complete' as const)
: sources.length
? ('partial' as const)
: ('missing' as const),
availability: complete ?
('complete' as const) :
sources.length ?
('partial' as const) :
('missing' as const),
stale,
asOf: sources.length
? new Date(
asOf: sources.length ?
new Date(
Math.min(
effective.to.valueOf(),
Math.max(...sources.map((row) => row.asOf.valueOf())),
),
)
: null,
) :
null,
};
});
return { intervals, load: operationIntervals(load) };