UNPKG

@atproto/lexicon

Version:

atproto Lexicon schema language library

48 lines 1.4 kB
import { z } from 'zod'; export function toLexUri(str, baseUri) { if (str.split('#').length > 2) { throw new Error('Uri can only have one hash segment'); } if (str.startsWith('lex:')) { return str; } if (str.startsWith('#')) { if (!baseUri) { throw new Error(`Unable to resolve uri without anchor: ${str}`); } return `${baseUri}${str}`; } return `lex:${str}`; } export function requiredPropertiesRefinement(object, ctx) { // Required fields check if (object.required === undefined) { return; } if (!Array.isArray(object.required)) { ctx.addIssue({ code: z.ZodIssueCode.invalid_type, received: typeof object.required, expected: 'array', }); return; } if (object.properties === undefined) { if (object.required.length > 0) { ctx.addIssue({ code: z.ZodIssueCode.custom, message: `Required fields defined but no properties defined`, }); } return; } for (const field of object.required) { if (object.properties[field] === undefined) { ctx.addIssue({ code: z.ZodIssueCode.custom, message: `Required field "${field}" not defined`, }); } } } //# sourceMappingURL=util.js.map