Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 40 additions & 40 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
"testcontainers": "12.1.0"
},
"devDependencies": {
"@biomejs/biome": "2.5.8",
"@types/node": "26.2.0",
"@biomejs/biome": "2.5.11",
"@types/node": "26.4.0",
"get-port": "7.2.0",
"tsx": "4.23.12",
"typescript": "7.0.2"
Expand Down
11 changes: 7 additions & 4 deletions src/runEventQlQuery.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { afterEach, beforeEach, suite, test } from 'node:test';
import { Container } from './Container.js';
import type { EventCandidate } from './EventCandidate.js';
import { getImageVersionFromDockerfile } from './getImageVersionFromDockerfile.js';
import { isRecord } from './types/isRecord.js';

suite('runEventQlQuery', { timeout: 30_000 }, () => {
let container: Container;
Expand Down Expand Up @@ -58,14 +59,16 @@ suite('runEventQlQuery', { timeout: 30_000 }, () => {

assert.equal(rowsRead.length, 2);

// biome-ignore lint/suspicious/noExplicitAny: Here, the cast is okay.
const firstRow = rowsRead[0] as any;
const firstRow = rowsRead[0];
assert.ok(isRecord(firstRow));
assert.equal(firstRow.id, '0');
assert.ok(isRecord(firstRow.data));
assert.equal(firstRow.data.value, 23);

// biome-ignore lint/suspicious/noExplicitAny: Here, the cast is okay.
const secondRow = rowsRead[1] as any;
const secondRow = rowsRead[1];
assert.ok(isRecord(secondRow));
assert.equal(secondRow.id, '1');
assert.ok(isRecord(secondRow.data));
assert.equal(secondRow.data.value, 42);
});

Expand Down
23 changes: 9 additions & 14 deletions src/types/hasShapeOf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,30 @@ type Shape<T> = {
[K in keyof T]: T[K] extends object ? Shape<T[K]> | Guard<T[K]> : Guard<T[K]>;
};

const isGuard = (value: unknown): value is Guard<unknown> => typeof value === 'function';
const isShape = (value: unknown): value is Shape<object> => isRecord(value);

const hasShapeOf = <T extends object>(value: unknown, shape: Shape<T>): value is T => {
if (!isRecord(value)) {
return false;
}

for (const key of Object.keys(shape) as Array<keyof T>) {
const spec = shape[key] as unknown;
const val = value[key as string];

if (typeof spec === 'function') {
const guard = spec as Guard<T[typeof key]>;
for (const [key, spec] of Object.entries(shape)) {
const val = value[key];

if (!guard(val)) {
if (isGuard(spec)) {
if (!spec(val)) {
return false;
}

continue;
}

if (!isRecord(val)) {
if (!(isRecord(val) && isShape(spec))) {
return false;
}

if (
!hasShapeOf<Extract<T[typeof key], object>>(
val,
spec as Shape<Extract<T[typeof key], object>>,
)
) {
if (!hasShapeOf(val, spec)) {
return false;
}
}
Expand Down