@shopify/cli-kit
Version:
A set of utilities, interfaces, and models that are common across all the platform features
31 lines (30 loc) • 1.49 kB
TypeScript
import { ParseConfigurationResult } from './schema.js';
import { ErrorObject, SchemaObject } from 'ajv';
export type HandleInvalidAdditionalProperties = 'strip' | 'fail';
type AjvError = ErrorObject<string, {
[key: string]: unknown;
}>;
/**
* Normalises a JSON Schema by standardising it's internal implementation.
*
* We prefer to not use $ref elements in our schemas, so we inline them; it's easier then to process errors.
*
* @param schema - The JSON schema (as a string) to normalise.
* @returns The normalised JSON schema.
*/
export declare function normaliseJsonSchema(schema: string): Promise<SchemaObject>;
/**
* Given a subject object and a JSON schema contract, validate the subject against the contract.
*
* Errors are returned in a zod-like format, and processed to better handle unions.
*
* @param subject - The object to validate.
* @param schema - The JSON schema to validate against.
* @param handleInvalidAdditionalProperties - Whether to strip or fail on invalid additional properties.
* @param identifier - The identifier of the schema being validated, used to cache the validator.
* @returns The result of the validation. If the state is 'error', the errors will be in a zod-like format.
*/
export declare function jsonSchemaValidate(subject: object, schema: SchemaObject, handleInvalidAdditionalProperties: HandleInvalidAdditionalProperties, identifier?: string): ParseConfigurationResult<unknown> & {
rawErrors?: AjvError[];
};
export {};