import { EntityRawSchemaArray, EntitySchema, Schema, RelationDefinitionSchema, EntityRole } from "@cubicweb/client"; import { Identifier, RaRecord } from "./types.js"; /** * Type describing the input value of a relation */ export type CubicWebReferenceArrayInputValueType = { created?: Identifier[]; selected?: Identifier[]; removed?: Identifier[]; id: "temp_input"; }; /** * Gets a unique key representing the tuple: mode - subject - relation type - object * * Reverse operation from `getRelationFromKey`. * * @param relation The relation definition to get a key for * @param role Subject or object mroe * @returns A unique key representing the relation definition * * @category Relations Utilities */ export declare const getRelationKey: (relation: Readonly, role: "subject" | "object") => string; /** * Retrieves the relation definition schema from the given key. * * Reverse operation from `getRelationKey`. * * @param relationKey The relation key generated with `getRelationKey` * @param schema The CubicWeb schema * @returns The relation definitio schema represented by the given key in the schema * @throws Error if no relation could be found from the given key * * @category Relations Utilities */ export declare const getRelationFromKey: (relationKey: string, schema: EntitySchema | Schema) => RelationDefinitionSchema, Readonly<{ type: string; description: string; cardinality: "**" | "*1" | "*?" | "*+" | "1*" | "11" | "1?" | "1+" | "?*" | "?1" | "??" | "?+" | "+*" | "+1" | "+?" | "++"; subject: string; } & ((import("@cubicweb/client").BuildObj & { final: true; constraints: import("@cubicweb/client").AttributeConstraint[]; options: import("@cubicweb/client").AttributeOptions; }) | { object: string; final: false; constraints: import("@cubicweb/client").RelationConstraint[]; options: import("@cubicweb/client").RelationOptions; })>>; /** * Checks the cardinality of the relation to detect if users can pick new elements to * add to the given relation. * * @param relation The relation to show a list for * @param mode Subject or object mode for the relation * @returns True if users can pick elements from the list, false otherwise * * @category Relations Utilities */ export declare const canPickFromList: (relation: RelationDefinitionSchema, mode: "object" | "subject") => boolean; /** * Checks the content of the input value to detect if the user is creating a * new entity for the relation. When creating a new entity, the input's content will be an object * instead of a string/number. * * @param value THe input value * @returns True if the user is creating a new relation * * @category Relations Utilities */ export declare const isCreatingNewRelation: (value: Identifier | Partial | undefined) => value is Partial; /** * Checks if the given value is a React Admin Identifier. * * @param value The value to check * @returns True if the given value is a string or number * * @category Relations Utilities */ export declare const isIdentifier: (value: unknown) => value is Identifier; /** * Checks if the given keys represent the same relation, with one reversed. * * @param parentRelationKey The parent's relation key * @param relationKey The relation key * @returns True if reversing one of the keys returns the other * * @category Relations Utilities */ export declare const isEditingParentReverseRelation: (parentRelationKey: string | null, relationKey: string) => boolean; /** * Checks if we are trying to edit the parent relation but cardinality forbids us. * * @param parentRelationKey The parent's relation key * @param relation The relation to edit * @param role Subject or object mode * @returns True if the parent is blocking edition * * @category Relations Utilities */ export declare const isParentPreventingEditing: (parentRelationKey: string | null, relation: RelationDefinitionSchema, role: EntityRole) => boolean; /** * If the given value is an empty string, array or object, returns undefined. * Returns the given value otherwise. * * @param v The value to convert * @returns The given value if not empty or undefined * * @category Relations Utilities */ export declare const emptyToUndefined: (v: T) => T | undefined; /** * Recursively parses the given object and removes empty values as defined in `emptyToUndefined`. * * @param data The data to strip * @returns The initial data without empty values * * @category Relations Utilities */ export declare const recursivelyStripEmptyValues: (data: T) => T | undefined; /** * Removes data associated to relations of cardinality + and *. * * This can be useful to prevent react-admin's cache from being modified * after validating an Edit or Create form. * * @param entitySchema The entity schema * @param data The data to strip * @returns The original record without entries associated to relation of cardinality + and * * * @category Relations Utilities */ export declare const removeRelationData: (entitySchema: EntitySchema, data: Partial) => Partial; /** * Generates a humanized label for the given relation. * * @param relation The relation to get a label for * @param mode Subject or object relation mode * @returns A humanized label * * @category Relations Utilities */ export declare const getRelationLabel: (relation: RelationDefinitionSchema, mode: "subject" | "object") => string; //# sourceMappingURL=relations.d.ts.map