synapse-react-client
Version:
[](https://badge.fury.io/js/synapse-react-client) [](https://github.com/prettier/prettie
79 lines • 3.92 kB
TypeScript
import { AdditionalPropertiesSchemaField } from '@/components/SchemaDrivenAnnotationEditor/field/AdditionalPropertiesSchemaField';
import { RJSFValidationError, TranslatableString } from '@rjsf/utils';
import { JSONSchema7 } from 'json-schema';
/**
* Generates a JSON schema for the form UI based on the provided validation schema and entity schema base properties.
*
* To meet the requirements of the desired form to display, we cannot simply show the validation schema. This is because
* validation schemas may use conditional logic based on default entity properties (e.g. concreteType) to show/hide fields.
* This method combines the validation schema with the entity schema base properties to create a new schema that will yield
* the expected form with desired logic.
* @param validationSchema
* @param entitySchema
*/
export declare function getJsonSchemaForForm(validationSchema?: JSONSchema7, entitySchema?: JSONSchema7): JSONSchema7;
/**
* Generates the UiSchema for the annotations editor.
* @param entitySchemaBaseProperties
*/
export declare function getUiSchemaForForm(entitySchemaBaseProperties?: JSONSchema7['properties']): {
'ui:globalOptions': {
copyable: boolean;
duplicateKeySuffixSeparator: string;
};
additionalProperties: {
'ui:field': typeof AdditionalPropertiesSchemaField;
};
};
/**
* Strips null values from arrays in the provided form data. If the array is empty after
* removing null values, the key is removed from the form data.
*
* This allows users to submit forms with empty array fields (SWC-5762)
*/
export declare function dropNullishArrayValues(formData: Record<string, unknown>): Record<string, unknown>;
export declare function dropNullValues(formData?: Record<string, unknown>): Record<string, unknown>;
/**
* Inspects the property of the AjvError and modifies it to be comparable to simple key strings, like entity property keys.
* @param error
* @returns
*/
export declare function getFriendlyPropertyName(error: RJSFValidationError): string;
export declare function transformErrors(errors: RJSFValidationError[]): RJSFValidationError[];
/**
* Custom annotations in Synapse are always arrays. This function converts initial data to be an array type.
* If the initial data is an array, return the data itself.
* Otherwise, wrap the data in an array.
*/
export declare function convertToArray<T>(value: T): Array<unknown>;
/**
* Returns true if the default behavior of the form should be to live validate
* @param existingAnnotations
* @param validationSchema
*/
export declare function shouldLiveValidate(existingAnnotations: Record<string, unknown> | undefined, validationSchema: JSONSchema7 | undefined): boolean;
/**
* Returns all possible properties in the schema, including those in nested schemas/definitions. Note that this function
* only works for 'flat objects', i.e. the schema must
* - define an object AND
* - the properties of the object cannot be objects
* which is compatible with how Synapse Annotations are defined.
* @param resolvedSchema
*/
export declare function getPossibleTopLevelPropertiesInObjectSchema(resolvedSchema: JSONSchema7): JSONSchema7['properties'];
/**
* Get the Synapse entity schema ID for a particular concrete type.
* @param concreteType
*/
export declare function getSchemaIdForConcreteType(concreteType: string): string | null;
/**
* Custom string translator for react-jsonschema-form.
* Overrides the translation for "NewStringDefault" by returning an empty string.
* For all other keys, falls back to the default English string translator.
*
* @param stringToTranslate
* @param params - Optional parameters used to format the translated string.
* @returns - The translated string.
*/
export declare function customTranslateString(stringToTranslate: TranslatableString, params?: string[]): string;
//# sourceMappingURL=AnnotationEditorUtils.d.ts.map