/** * Module schema provides code to safely handle JSON Typedef schemas. * * JSON Typedef schemas are represented in this module with {@link Schema}, and * you can check if a JSON object is a correct schema by using {@link isSchema} * and {@link isValidSchema}. * * @packageDocumentation */ /** * Schema is a TypeScript representation of a correct JSON Typedef schema. * * The JSON Typedef specification allows schemas to take on one of eight forms. * Each of those forms has its own type in this module; Schema is simply a union * of each of those eight types. */ export declare type Schema = SchemaFormEmpty | SchemaFormRef | SchemaFormType | SchemaFormEnum | SchemaFormElements | SchemaFormProperties | SchemaFormValues | SchemaFormDiscriminator; /** * SchemaFormEmpty represents schemas of the empty form. */ export declare type SchemaFormEmpty = SharedFormProperties; /** * SchemaFormRef represents schemas of the ref form. */ export declare type SchemaFormRef = SharedFormProperties & { ref: string; }; /** * SchemaFormType represents schemas of the type form. */ export declare type SchemaFormType = SharedFormProperties & { type: Type; }; /** * Type represents the legal values of the "type" keyword in JSON Typedef. */ export declare type Type = "boolean" | "float32" | "float64" | "int8" | "uint8" | "int16" | "uint16" | "int32" | "uint32" | "string" | "timestamp"; /** * SchemaFormEnum represents schemas of the enum form. */ export declare type SchemaFormEnum = SharedFormProperties & { enum: string[]; }; /** * SchemaFormElements represents schemas of the elements form. */ export declare type SchemaFormElements = SharedFormProperties & { elements: Schema; }; /** * SchemaFormProperties represents schemas of the properties form. */ export declare type SchemaFormProperties = SharedFormProperties & ({ properties?: { [name: string]: Schema; }; optionalProperties: { [name: string]: Schema; }; additionalProperties?: boolean; } | { properties: { [name: string]: Schema; }; optionalProperties?: { [name: string]: Schema; }; additionalProperties?: boolean; }); /** * SchemaFormValues represents schemas of the values form. */ export declare type SchemaFormValues = SharedFormProperties & { values: Schema; }; /** * SchemaFormDiscriminator represents schemas of the discriminator form. */ export declare type SchemaFormDiscriminator = SharedFormProperties & { discriminator: string; mapping: { [name: string]: Schema; }; }; /** * SharedFormProperties contains the properties shared among all schema forms. */ interface SharedFormProperties { definitions?: { [definition: string]: Schema; }; metadata?: { [name: string]: unknown; }; nullable?: boolean; } /** * isEmptyForm checks whether some Schema is of the empty form. * * @param schema The schema to validate */ export declare function isEmptyForm(schema: Schema): schema is SchemaFormEmpty; /** * isRefForm checks whether some Schema is of the ref form. * * @param schema The schema to validate */ export declare function isRefForm(schema: Schema): schema is SchemaFormRef; /** * isTypeForm checks whether some Schema is of the type form. * * @param schema The schema to validate */ export declare function isTypeForm(schema: Schema): schema is SchemaFormType; /** * isEnumForm checks whether some Schema is of the enum form. * * @param schema The schema to validate */ export declare function isEnumForm(schema: Schema): schema is SchemaFormEnum; /** * isElementsForm checks whether some Schema is of the elements form. * * @param schema The schema to validate */ export declare function isElementsForm(schema: Schema): schema is SchemaFormElements; /** * isPropertiesForm checks whether some Schema is of the properties form. * * @param schema The schema to validate */ export declare function isPropertiesForm(schema: Schema): schema is SchemaFormProperties; /** * isPropertiesForm checks whether some Schema is of the values form. * * @param schema The schema to validate */ export declare function isValuesForm(schema: Schema): schema is SchemaFormValues; /** * isDiscriminatorForm checks whether some Schema is of the values form. * * @param schema The schema to validate */ export declare function isDiscriminatorForm(schema: Schema): schema is SchemaFormDiscriminator; /** * isValidSchema checks whether some Schema is correct, according to the syntax * rules of JSON Typedef. * * In particular, isValidSchema verifies that: * * 1. The schema does not have any non-root definitions, * 2. All references point to actually-existing definitions, * 3. All enums are non-empty, and do not contain duplicates, * 4. The `properties` and `optionalProperties` of a schema never share * properties, * 5. All schemas in `mapping` are of the properties form, * 6. Schemas in `mapping` never re-specify the `discriminator` property * * If an object returned from `JSON.parse` passes both {@link isSchema} and * {@link isValidSchema}, then it is a correct JSON Typedef schema. * * @param schema The schema to validate * @param root The schema to consider as the "root" schema. If undefined, * `schema` will be used as the root. This is usually what you want to do. */ export declare function isValidSchema(schema: Schema, root?: Schema): boolean; /** * isSchema checks whether some piece of JSON data has the shape of a JSON * Typedef Schema. * * This function only looks at the "shape" of data: it just makes sure all * property names and types are valid, and that the data takes on one of the * eight JSON Typedef forms. * * If an object returned from `JSON.parse` passes both {@link isSchema} and * {@link isValidSchema}, then it is a correct JSON Typedef schema. * * @param data The data to check */ export declare function isSchema(data: unknown): data is Schema; export {};