UNPKG

@ng-formworks/core

Version:

Angular ng-formworks - JSON Schema Form builder core

216 lines (214 loc) 6.64 kB
/** * JSON Schema function library: * * buildSchemaFromLayout: TODO: Write this function * * buildSchemaFromData: * * getFromSchema: * * removeRecursiveReferences: * * getInputType: * * checkInlineType: * * isInputRequired: * * updateInputOptions: * * getTitleMapFromOneOf: * * getControlValidators: * * resolveSchemaReferences: * * getSubSchema: * * combineAllOf: * * fixRequiredArrayProperties: */ /** * 'buildSchemaFromLayout' function * * TODO: Build a JSON Schema from a JSON Form layout * * // layout - The JSON Form layout * // - The new JSON Schema */ export declare function buildSchemaFromLayout(layout: any): void; /** * 'buildSchemaFromData' function * * Build a JSON Schema from a data object * * // data - The data object * // { boolean = false } requireAllFields - Require all fields? * // { boolean = true } isRoot - is root * // - The new JSON Schema */ export declare function buildSchemaFromData(data: any, requireAllFields?: boolean, isRoot?: boolean): any; /** * 'getFromSchema' function * * Uses a JSON Pointer for a value within a data object to retrieve * the schema for that value within schema for the data object. * * The optional third parameter can also be set to return something else: * 'schema' (default): the schema for the value indicated by the data pointer * 'parentSchema': the schema for the value's parent object or array * 'schemaPointer': a pointer to the value's schema within the object's schema * 'parentSchemaPointer': a pointer to the schema for the value's parent object or array * * // schema - The schema to get the sub-schema from * // { Pointer } dataPointer - JSON Pointer (string or array) * // { string = 'schema' } returnType - what to return? * // - The located sub-schema */ export declare function getFromSchema(schema: any, dataPointer: any, returnType?: string): any; /** * 'removeRecursiveReferences' function * * Checks a JSON Pointer against a map of recursive references and returns * a JSON Pointer to the shallowest equivalent location in the same object. * * Using this functions enables an object to be constructed with unlimited * recursion, while maintaing a fixed set of metadata, such as field data types. * The object can grow as large as it wants, and deeply recursed nodes can * just refer to the metadata for their shallow equivalents, instead of having * to add additional redundant metadata for each recursively added node. * * Example: * * pointer: '/stuff/and/more/and/more/and/more/and/more/stuff' * recursiveRefMap: [['/stuff/and/more/and/more', '/stuff/and/more/']] * returned: '/stuff/and/more/stuff' * * // { Pointer } pointer - * // { Map<string, string> } recursiveRefMap - * // { Map<string, number> = new Map() } arrayMap - optional * // { string } - */ export declare function removeRecursiveReferences(pointer: any, recursiveRefMap: any, arrayMap?: Map<any, any>): any; /** * 'getInputType' function * * // schema * // { any = null } layoutNode * // { string } */ export declare function getInputType(schema: any, layoutNode?: any): any; /** * 'checkInlineType' function * * Checks layout and schema nodes for 'inline: true', and converts * 'radios' or 'checkboxes' to 'radios-inline' or 'checkboxes-inline' * * // { string } controlType - * // schema - * // { any = null } layoutNode - * // { string } */ export declare function checkInlineType(controlType: any, schema: any, layoutNode?: any): any; /** * 'isInputRequired' function * * Checks a JSON Schema to see if an item is required * * // schema - the schema to check * // { string } schemaPointer - the pointer to the item to check * // { boolean } - true if the item is required, false if not */ export declare function isInputRequired(schema: any, schemaPointer: any): any; /** * 'updateInputOptions' function * * // layoutNode * // schema * // jsf * // { void } */ export declare function updateInputOptions(layoutNode: any, schema: any, jsf: any): void; /** * 'getTitleMapFromOneOf' function * * // { schema } schema * // { boolean = null } flatList * // { boolean = false } validateOnly * // { validators } */ export declare function getTitleMapFromOneOf(schema?: any, flatList?: boolean, validateOnly?: boolean): any; /** * 'getControlValidators' function * * // schema * // { validators } */ export declare function getControlValidators(schema: any): any; /** * 'resolveSchemaReferences' function * * Find all $ref links in schema and save links and referenced schemas in * schemaRefLibrary, schemaRecursiveRefMap, and dataRecursiveRefMap * * // schema * // schemaRefLibrary * // { Map<string, string> } schemaRecursiveRefMap * // { Map<string, string> } dataRecursiveRefMap * // { Map<string, number> } arrayMap * // */ export declare function resolveSchemaReferences(schema: any, schemaRefLibrary: any, schemaRecursiveRefMap: any, dataRecursiveRefMap: any, arrayMap: any): any; /** * 'getSubSchema' function * * // schema * // { Pointer } pointer * // { object } schemaRefLibrary * // { Map<string, string> } schemaRecursiveRefMap * // { string[] = [] } usedPointers * // */ export declare function getSubSchema(schema: any, pointer: any, schemaRefLibrary?: any, schemaRecursiveRefMap?: Map<string, string>, usedPointers?: string[]): any; export declare function omitKeys<T extends object>(objects: T[], keysToOmit: (keyof T)[]): Omit<T, keyof T>[]; export declare function combineAllOfITE(schema: any): void; /** * 'combineAllOf' function * * Attempt to convert an allOf schema object into * a non-allOf schema object with equivalent rules. * * // schema - allOf schema object * // - converted schema object */ export declare function combineAllOf(schema: any): any; /** * 'fixRequiredArrayProperties' function * * Fixes an incorrectly placed required list inside an array schema, by moving * it into items.properties or additionalItems.properties, where it belongs. * * // schema - allOf schema object * // - converted schema object */ export declare function fixRequiredArrayProperties(schema: any): any; /** * 'convertJSONSchemaIfToCondition' function * converts something like * "if": { * "properties": { * "animal": { * "const": "Cat" * }, * "habitat":{ * "const": "City" * } * } * } * to "model.animal=='Cat' && habitat=='City" contion * @param schema:any * @param negate:boolean=false * @returns */ export declare function convertJSONSchemaIfToCondition(schema: any, negate?: boolean): {};