Files
klz-cables.com/.pnpm-store/v10/files/d7/60981a1d4dcf565ddce0f8a0041339a13537f21c1d5a50b9d818797aed7025c5bf0fb758bbaebe60e1bf578ad5fec8208118a995d2f5f895326bcbce48125a
Marc Mintel 5397309103
Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 20s
Build & Deploy / 🧪 QA (push) Failing after 34s
Build & Deploy / 🏗️ Build (push) Has started running
Build & Deploy / 🚀 Deploy (push) Has been cancelled
Build & Deploy / 🧪 Smoke Test (push) Has been cancelled
Build & Deploy / ⚡ Lighthouse (push) Has been cancelled
Build & Deploy / 🔔 Notify (push) Has been cancelled
fix(products): fix breadcrumbs and product filtering (backport from main)
2026-02-24 16:04:21 +01:00

44 lines
1.6 KiB
Plaintext

import { GraphQLScalarType, Kind } from 'graphql';
import { createGraphQLError } from '../error.js';
// 24-hour time with optional seconds and milliseconds - `HH:mm[:ss[.SSS]]`
export const LOCAL_TIME_FORMAT = /^([0-1][0-9]|2[0-3]):([0-5][0-9])(:[0-5][0-9](\.\d{3})?)?$/;
export function validateLocalTime(value, ast) {
if (typeof value !== 'string') {
throw createGraphQLError(`Value is not string: ${value}`, ast ? { nodes: ast } : undefined);
}
const isValidFormat = LOCAL_TIME_FORMAT.test(value);
if (!isValidFormat) {
throw createGraphQLError(`Value is not a valid LocalTime: ${value}`, ast ? { nodes: ast } : undefined);
}
return value;
}
export const GraphQLLocalTime = /*#__PURE__*/ new GraphQLScalarType({
name: 'LocalTime',
description: 'A local time string (i.e., with no associated timezone) in 24-hr `HH:mm[:ss[.SSS]]` format, e.g. `14:25` or `14:25:06` or `14:25:06.123`.',
serialize(value) {
// value sent to client as string
return validateLocalTime(value);
},
parseValue(value) {
// value from client as json
return validateLocalTime(value);
},
parseLiteral(ast) {
// value from client in ast
if (ast.kind !== Kind.STRING) {
throw createGraphQLError(`Can only validate strings as local times but got a: ${ast.kind}`, {
nodes: ast,
});
}
return validateLocalTime(ast.value, ast);
},
extensions: {
codegenScalarType: 'string',
jsonSchema: {
title: 'LocalTime',
type: 'string',
pattern: LOCAL_TIME_FORMAT.source,
},
},
});