/** * forked from json-typedef-js * 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 type Schema = SchemaFormEmpty | SchemaFormRef | SchemaFormType | SchemaFormEnum | SchemaFormElements | SchemaFormProperties | SchemaFormValues | SchemaFormDiscriminator; /** * SchemaFormEmpty represents schemas of the empty form. */ export type SchemaFormEmpty = SharedFormProperties; /** * SchemaFormRef represents schemas of the ref form. */ export type SchemaFormRef = SharedFormProperties & { ref: string; }; /** * SchemaFormType represents schemas of the type form. */ export type SchemaFormType = SharedFormProperties & { type: Type; }; /** * Type represents the legal values of the "type" keyword in JSON Typedef. */ export type Type = 'boolean' | 'float32' | 'float64' | 'int8' | 'uint8' | 'int16' | 'uint16' | 'int32' | 'uint32' | 'string' | 'timestamp'; /** * SchemaFormEnum represents schemas of the enum form. */ export type SchemaFormEnum = SharedFormProperties & { enum: string[]; }; /** * SchemaFormElements represents schemas of the elements form. */ export type SchemaFormElements = SharedFormProperties & { elements: Schema; }; /** * SchemaFormProperties represents schemas of the properties form. */ export 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 type SchemaFormValues = SharedFormProperties & { values: Schema; }; /** * SchemaFormDiscriminator represents schemas of the discriminator form. */ export 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?: { formats?: Record; /** what schema features must be supported to use this schema */ features?: string[]; /** on any schema. Value must be a valid format key from root schema */ format?: string; /** example keys to be used next to reference of this schema in doc*/ examples?: string[]; /** prosemirror like node patter. Only applicable to 'elements' form */ pattern?: { value: string; description: string; }; validation?: { /** for arrays */ minSize?: number; maxSize?: number; /** for strings */ minLength?: number; maxLength?: number; /** only items with unique tags might be in array */ uniqueTags?: boolean; }; /** Valid only for 'properties' form, works like in protobufs. Should contain names from optionalProperties of which only one should exist */ oneOf?: { strict?: boolean; properties: string[]; }; /** documentation section */ section?: string; /** Description is markdown */ description?: string; /** Record of types used in schema vs their tag values (tag being the key, and type being value) */ refUnion?: { [tagValue: string]: string; }; /** marks as deprecated in wix-docs and ts-doc */ deprecated?: boolean; /** hides from wix-docs and ts-doc */ internal?: boolean; /** emit enum option for typescript gen */ emitEnum?: string; }; 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, path?: string[], skipRefCheck?: boolean, root?: Schema): { type: 'ok'; } | { type: 'error'; message: string; path: string[]; }; /** * 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, path?: string[]): { type: 'ok'; } | { type: 'error'; message: string; path: string[]; }; export {}; //# sourceMappingURL=schema.d.ts.map