|
| 1 | +import { JsonSchema } from '../models/jsonSchema'; |
| 2 | +/** |
| 3 | + * A Property wraps a JsonSchema and provides additional information |
| 4 | + * like a label and the property key. |
| 5 | + */ |
| 6 | +export interface Property { |
| 7 | + /** |
| 8 | + * The label is a text donating a human readable name of the schema the property describes. |
| 9 | + */ |
| 10 | + readonly label: string; |
| 11 | + /** |
| 12 | + * The property is a text donating the schema key from which this property was created. |
| 13 | + */ |
| 14 | + readonly property: string; |
| 15 | + /** |
| 16 | + * The schema is the JsonSchema this property describes. |
| 17 | + */ |
| 18 | + readonly schema: JsonSchema; |
| 19 | +} |
| 20 | +/** |
| 21 | + * A ContainmentProperty extends the Property and provides methods |
| 22 | + * which allow to modify containment data. |
| 23 | + * @see Property |
| 24 | + */ |
| 25 | +export interface ContainmentProperty extends Property { |
| 26 | + /** |
| 27 | + * This allows to add data to the containment. |
| 28 | + * @param data The object to add to |
| 29 | + * @return a function that expects the element to be added and optionally the value next to which |
| 30 | + * the new value is added. insertAfter defines whether the new value should be added |
| 31 | + * after or before the neighbourValue. If no neighbour value is provided or it does not |
| 32 | + * exist in the containment, the valueToAdd is inserted at the end. |
| 33 | + */ |
| 34 | + addToData(data: Object): (valueToAdd: object, neighbourValue?: object, insertAfter?: boolean) => void; |
| 35 | + /** |
| 36 | + * This allows to delete data from the containment. |
| 37 | + * The result is a function accepting the value to delete. |
| 38 | + * @param data The object to delete from |
| 39 | + * @return function accepting the value to delete |
| 40 | + */ |
| 41 | + deleteFromData(data: Object): (valueToDelete: object) => void; |
| 42 | + /** |
| 43 | + * This allows to retrieve the data of the containment. |
| 44 | + * @param data The object the containment is in |
| 45 | + * @return The containment value (e.g. an array) |
| 46 | + */ |
| 47 | + getData(data: Object): Object; |
| 48 | +} |
| 49 | +/** |
| 50 | + * A ReferenceProperty extends the Property and provides methods |
| 51 | + * which allow to modify reference data. |
| 52 | + */ |
| 53 | +export interface ReferenceProperty extends Property { |
| 54 | + /** |
| 55 | + * The schema of the referenced elements. |
| 56 | + */ |
| 57 | + readonly targetSchema: JsonSchema; |
| 58 | + /** |
| 59 | + * This allows to set the reference. |
| 60 | + * @param root The root object, needed for matching the valueToAdd |
| 61 | + * @param data The object to add to |
| 62 | + * @param valueToAdd The object to add |
| 63 | + */ |
| 64 | + addToData(root: Object, data: Object, valueToAdd: object): void; |
| 65 | + /** |
| 66 | + * This allows to retrieve the data of the reference. |
| 67 | + * @param root The root object, needed for finding the value to retrieve |
| 68 | + * @param data The object the reference is in |
| 69 | + * @return The referenced value |
| 70 | + */ |
| 71 | + getData(root: Object, data: Object): Object; |
| 72 | + /** |
| 73 | + * Returns all possible objects which can be referenced by this property. |
| 74 | + * |
| 75 | + * @param root The root data object needed for finding the values |
| 76 | + * @return The array of data objects which are possible reference targets |
| 77 | + * for this reference property. |
| 78 | + */ |
| 79 | + findReferenceTargets(rootData: Object): Object[]; |
| 80 | + /** |
| 81 | + * Resolves a reference value for this Reference by using the given porpertyValue to |
| 82 | + * identify the referenced Object. |
| 83 | + * |
| 84 | + * @param rootData The root data object needed for finding the referenced value. |
| 85 | + * @param propertyValue The property value identifying the referenced data object. |
| 86 | + * @return The resolved data object or null if it coiuld not be resolved. |
| 87 | + */ |
| 88 | + resolveReference(rootData: Object, propertyValue: string): Object; |
| 89 | +} |
| 90 | +export declare class ContainmentPropertyImpl implements ContainmentProperty { |
| 91 | + private innerSchema; |
| 92 | + private key; |
| 93 | + private name; |
| 94 | + private addFunction; |
| 95 | + private deleteFunction; |
| 96 | + private getFunction; |
| 97 | + constructor(innerSchema: JsonSchema, key: string, name: string, addFunction: (data: object) => (valueToAdd: object, neighbourValue?: object, insertAfter?: boolean) => void, deleteFunction: (data: object) => (valueToDelete: object) => void, getFunction: (data: object) => Object); |
| 98 | + readonly label: string; |
| 99 | + readonly schema: JsonSchema; |
| 100 | + readonly property: string; |
| 101 | + addToData(data: object): (valueToAdd: object, neighbourValue?: object, insertAfter?: boolean) => void; |
| 102 | + deleteFromData(data: object): (valueToDelete: object) => void; |
| 103 | + getData(data: object): Object; |
| 104 | +} |
| 105 | +export declare class ReferencePropertyImpl implements ReferenceProperty { |
| 106 | + private innerSchema; |
| 107 | + private innerTargetSchema; |
| 108 | + private key; |
| 109 | + private name; |
| 110 | + private pathToContainment; |
| 111 | + private identifyingProperty; |
| 112 | + private addFunction; |
| 113 | + private getFunction; |
| 114 | + constructor(innerSchema: JsonSchema, innerTargetSchema: JsonSchema, key: string, name: string, pathToContainment: string, identifyingProperty: string, addFunction: (root: object, data: object, valueToAdd: object) => void, getFunction: (root: object, data: object) => Object); |
| 115 | + readonly label: string; |
| 116 | + readonly schema: JsonSchema; |
| 117 | + readonly property: string; |
| 118 | + readonly targetSchema: JsonSchema; |
| 119 | + addToData(root: object, data: object, valueToAdd: object): void; |
| 120 | + getData(root: object, data: object): Object; |
| 121 | + findReferenceTargets(rootData: Object): Object[]; |
| 122 | + resolveReference(rootData: Object, propertyValue: string): Object; |
| 123 | +} |
| 124 | +export declare const isContainmentProperty: (property: Property) => property is ContainmentProperty; |
| 125 | +export declare const isReferenceProperty: (property: Property) => property is ReferenceProperty; |
| 126 | +/** |
| 127 | + * The Schema Service allows to retrieve containments and references. |
| 128 | + */ |
| 129 | +export interface SchemaService { |
| 130 | + /** |
| 131 | + * Retrieves an array of containment properties based on the provided schema. |
| 132 | + * @param schema The schema to check for containments |
| 133 | + * @return The array of {@link ContainmentProperty} or empty if no containments are available |
| 134 | + * @see ContainmentProperty |
| 135 | + */ |
| 136 | + getContainmentProperties(schema: JsonSchema): ContainmentProperty[]; |
| 137 | + /** |
| 138 | + * Checks whether a containment properties are available in the provided schema. |
| 139 | + * @param schema The schema to check for containments |
| 140 | + * @return true if containment properties are available, false otherwise |
| 141 | + * @see {@link getContainmentProperties} |
| 142 | + */ |
| 143 | + hasContainmentProperties(schema: JsonSchema): boolean; |
| 144 | + /** |
| 145 | + * Retieves a self contained schema. |
| 146 | + * @param parentSchema The schema to use for resolvement |
| 147 | + * @param refPath The path to resolve |
| 148 | + * @return a JsonSchema that is self-contained |
| 149 | + */ |
| 150 | + getSelfContainedSchema(parentSchema: JsonSchema, refPath: string): JsonSchema; |
| 151 | + /** |
| 152 | + * Retrieves an array of reference properties based on the provided schema. |
| 153 | + * @param schema The schema to check for references |
| 154 | + * @return The array of {@link ReferenceProperty} or empty if no references are available |
| 155 | + * @see ReferenceProperty |
| 156 | + */ |
| 157 | + getReferenceProperties(schema: JsonSchema): ReferenceProperty[]; |
| 158 | +} |
0 commit comments