import { DataSource, Expr, FieldExpr, OpExpr, Schema } from "@mwater/expressions"; import { ResponseDataValidatorError } from "./ResponseDataValidator"; import { CascadingRefQuestion, FormDesign, Item, Question } from "./formDesign"; import { Answer, ResponseData } from "./response"; import { ResponseRow } from "."; /** Updates data in a response given an expression (mWater expression, see FormSchemaBuilder and also mwater-expressions package) and a value * When updates are complete for data, cleanData must be called to clean data (removing values that are invisble because of conditions). * and then call validateData to ensure that is valid */ export default class ResponseDataExprValueUpdater { formDesign: FormDesign; schema: Schema; dataSource: DataSource; formItems: { [id: string]: Item; }; constructor(formDesign: FormDesign, schema: Schema, dataSource: DataSource); /** True if an expression can be updated */ canUpdate(expr: Expr): boolean; /** Cleans data. Must be called after last update is done. * createResponseRow takes one parameter (data) and returns a response row */ cleanData(data: ResponseData, createResponseRow: (data: ResponseData) => ResponseRow): Promise; cleanData(data: ResponseData, createResponseRow: (data: ResponseData) => ResponseRow, callback: (error: any, cleanedData?: ResponseData) => void): void; /** Validates the data. Clean first. */ validateData(data: ResponseData, responseRow: ResponseRow): Promise; validateData(data: ResponseData, responseRow: ResponseRow, callback: (error: any, result?: ResponseDataValidatorError | null) => void): void; /** Updates the data of a response, given multiple expressions and their values. * This is the preferred way to do multiple updates instead of calling updateData repeatedly, * as some expressions may depend on another. For example, if there are two scalar expressions * for the same join, then the search for the underlying id value must take into account * both constraints (e.g. updating based on water point name and type) */ updateDataMultiple(data: ResponseData, exprValues: { expr: Expr; value: any; }[]): Promise; /** Updates the data of a response, given an expression and its value. For example, * if there is a text field in question q1234, the expression { type: "field", table: "responses:form123", column: "data:q1234:value" } * refers to the text field value. Setting it will set data.q1234.value in the data. */ updateData(data: ResponseData, expr: Expr, value: any): Promise; updateData(data: ResponseData, expr: Expr, value: any, callback: (error: any, responseData?: ResponseData) => void): void; updateCascadingList(data: ResponseData, expr: FieldExpr, value: any, callback: (error: any, responseData?: ResponseData) => void): void; updateValue(data: ResponseData, expr: FieldExpr, value: any, callback: (error: any, responseData?: ResponseData) => void): void | Promise; updateLocationLatLng(data: ResponseData, expr: OpExpr, value: any, callback: (error: any, responseData?: ResponseData) => void): void; updateLocationMethod(data: ResponseData, expr: FieldExpr, value: any, callback: (error: any, responseData?: ResponseData) => void): void; updateLocationAccuracy(data: ResponseData, expr: FieldExpr, value: any, callback: (error: any, responseData?: ResponseData) => void): void; updateLocationAltitude(data: ResponseData, expr: FieldExpr, value: any, callback: (error: any, responseData?: ResponseData) => void): void; updateQuantity(data: ResponseData, expr: FieldExpr, value: any, callback: (error: any, responseData?: ResponseData) => void): void; updateUnits(data: ResponseData, expr: FieldExpr, value: any, callback: (error: any, responseData?: ResponseData) => void): void; updateCBTField(data: ResponseData, expr: FieldExpr, value: any, cbtField: string, callback: (error: any, responseData?: ResponseData) => void): void; updateCBTImage(data: ResponseData, expr: FieldExpr, value: any, callback: (error: any, responseData?: ResponseData) => void): void; updateEnumsetContains(data: ResponseData, expr: OpExpr, value: any, callback: (error: any, responseData?: ResponseData) => void): void; updateSpecify(data: ResponseData, expr: FieldExpr, value: any, callback: (error: any, responseData?: ResponseData) => void): void; updateItemsChoices(data: ResponseData, expr: FieldExpr, value: any, callback: (error: any, responseData?: ResponseData) => void): void; updateRanked(data: ResponseData, expr: FieldExpr, value: any, callback: (error: any, responseData?: ResponseData) => void): void; updateMatrix(data: ResponseData, expr: FieldExpr, value: any, callback: (error: any, responseData?: ResponseData) => void): void; updateComments(data: ResponseData, expr: FieldExpr, value: any, callback: (error: any, responseData?: ResponseData) => void): void; updateAlternate(data: ResponseData, expr: FieldExpr, value: any, callback: (error: any, responseData?: ResponseData) => void): void; setAnswer(data: ResponseData, question: Question, answer: Answer): ResponseData; setValue(data: ResponseData, question: Question, value: any): ResponseData; /** Update a scalar, which may have multiple expressions to determine the row referenced */ updateScalar(data: ResponseData, join: string, exprValues: { expr: Expr; value: any; }[]): Promise; /** Finds the single row of the table of the expressions that matches all expression values, * returning the value of selectColumn. Throws if there is no match or more than one match. * extraFilter is an optional expression on the same table that the row must also satisfy */ findSingleRowValue(selectColumn: string, exprValues: { expr: Expr; value: any; }[], extraFilter: Expr | null): Promise; /** Sets the answer of a multi-select cascading reference question from the dropdown values of each selected member. * members is one array per member, holding the value of each dropdown in question order (null to leave a dropdown * unconstrained). Each member must match exactly one row of the referenced table that also satisfies the question's * filter. Throws naming the member that could not be resolved. */ updateMultiRef(data: ResponseData, questionId: string, members: any[][]): Promise; /** Resolves one member of a multi-select cascading reference question to its row _id from its dropdown values */ resolveMultiRefMember(question: CascadingRefQuestion, values: any[]): Promise; } /** True if an expression refers to response data that can be updated by ResponseDataExprValueUpdater. * Column-pattern based and form-independent. */ export declare function canUpdateExpr(expr: Expr): boolean;