@42.nl/jarb-final-form
Version:
Validating forms through JaRB.
86 lines (85 loc) • 2.65 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.loadConstraints = loadConstraints;
exports.setConstraints = setConstraints;
exports.getConstraints = getConstraints;
const config_1 = require("./config");
const spring_connect_1 = require("@42.nl/spring-connect");
let constraints = undefined;
/**
* Loads the constraints from the back-end.
*
* The URL it will send the request to is defined by the 'constraintsUrl'
* from the Config object. The HTTP method it uses is 'get'.
*
* The entire response will be written to the `constraints` variable.
* Whatever the JSON response is will be the constraints.
*
* An example response:
*
* ```JSON
* {
* "SuperHero": {
* "name": {
* "javaType": "java.lang.String",
* "types": ["text"],
* "required": true,
* "minimumLength": null,
* "maximumLength": 50,
* "fractionLength": null,
* "radix": null,
* "pattern": null,
* "min": null,
* "max": null,
* "name": "name"
* },
* "email": {
* "javaType": "java.lang.String",
* "types": ["email", "text"],
* "required": true,
* "minimumLength": null,
* "maximumLength": 255,
* "fractionLength": null,
* "radix": null,
* "pattern": null,
* "min": null,
* "max": null,
* "name": "email"
* }
* }
* }
* ```
*
* @returns {Promise}
*/
function loadConstraints() {
return __awaiter(this, void 0, void 0, function* () {
const { constraintsUrl } = (0, config_1.getConfig)();
constraints = yield (0, spring_connect_1.get)(constraintsUrl);
});
}
/**
* Sets the constraints.
*
* @param newConstraints The new constraints
*/
function setConstraints(newConstraints) {
constraints = newConstraints;
}
/**
* Get the current constraints.
*
* @returns The current constraints
*/
function getConstraints() {
return constraints;
}