actionhero
Version:
The reusable, scalable, and quick node.js API server for stateless and stateful applications
42 lines (41 loc) • 1.37 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ValidationTest = void 0;
const index_1 = require("./../index");
class ValidationTest extends index_1.Action {
constructor() {
super(...arguments);
this.name = "validationTest";
this.description = "I will test action input validators.";
this.inputs = {
string: {
required: true,
validator: (param) => {
return typeof param === "string";
},
},
number: {
required: false,
formatter: (param, name) => {
if (parseInt(param) == 123) {
throw new Error(`Failed formatting ${name} correctly!`);
}
return parseInt(param);
},
validator: (param, name) => {
if (typeof param === "number") {
throw new Error(`Param ${name} is not a valid number!`);
}
},
},
};
this.outputExample = {
string: "imAString!",
number: 2,
};
}
async run({ params }) {
return { string: params.string, number: params.number };
}
}
exports.ValidationTest = ValidationTest;