Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,34 @@ import {
it,
} from '@jest/globals';

import { isKeyShapeValid } from '../utils';
import { isKeyShapeValid, normalizeKey } from '../utils';

describe('normalizeKey', () => {
it('returns a string key as-is', () => {
expect(normalizeKey('abc')).toBe('abc');
});

it('returns a number key as-is', () => {
expect(normalizeKey(42)).toBe(42);
});

it('converts a single-element CompositeKeyPair array to an object', () => {
expect(normalizeKey([{ field: 'id', value: 1 }])).toEqual({ id: 1 });
});

it('converts a multi-element CompositeKeyPair array to an object', () => {
const pairs = [
{ field: 'region', value: 'us' },
{ field: 'code', value: 100 },
];

expect(normalizeKey(pairs)).toEqual({ region: 'us', code: 100 });
});

it('returns an empty object for an empty array', () => {
expect(normalizeKey([])).toEqual({});
});
});

describe('isKeyShapeValid', () => {
describe('single-field keyExpr (string)', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const compositeKeyPairSchema = z.object({
value: z.union([z.string(), z.number()]),
}).strict();

export const compositeKeyToObject = (
const compositeKeyToObject = (
pairs: CompositeKeyPair[],
): Record<string, string | number> => {
const result: Record<string, string | number> = {};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,6 @@ export const getMessageStatus = (commands: CommandResult[]): ResponseStatus => {
};

/**
Comment thread
dmirgaev marked this conversation as resolved.
* Recursively converts JSON Schema array-style `type`
* (e.g. `{"type": ["string", "number"]}`) to the equivalent `anyOf` form
* (e.g. `{"anyOf": [{"type": "string"}, {"type": "number"}]}`).
*
* Some structured-output APIs do not support array-style `type` fields
* and require explicit `anyOf` instead.
*/
Expand Down
Loading