2026-10-26 17:15:17 +08:00
|
|
|
import { clientSchemaPositions } from "./client-schema-positions.mjs";
|
2026-10-26 17:05:05 +08:00
|
|
|
|
|
|
|
|
/** Check forwarded regex constraints in native plain/Unicode/Unicode-sets modes. */
|
|
|
|
|
export const assertClientSchemaPatterns = (
|
|
|
|
|
schema: unknown,
|
|
|
|
|
): readonly string[] => {
|
|
|
|
|
const patterns: string[] = [];
|
2026-10-26 17:15:17 +08:00
|
|
|
for (const position of clientSchemaPositions(schema)) {
|
|
|
|
|
const pattern =
|
|
|
|
|
position.kind === "pattern-property"
|
|
|
|
|
? position.pattern
|
|
|
|
|
: position.kind === "keyword" &&
|
|
|
|
|
position.keyword === "pattern" &&
|
|
|
|
|
typeof position.value === "string"
|
|
|
|
|
? position.value
|
|
|
|
|
: undefined;
|
|
|
|
|
if (pattern === undefined) continue;
|
2026-10-26 17:05:05 +08:00
|
|
|
for (const flags of ["", "u", "v"]) new RegExp(pattern, flags);
|
|
|
|
|
patterns.push(pattern);
|
2026-10-26 17:15:17 +08:00
|
|
|
}
|
2026-10-26 17:05:05 +08:00
|
|
|
return patterns;
|
|
|
|
|
};
|