@duplojs/type-input
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

duplojs-type-input

NPM version

Instalation

npm i @duplojs/type-input

Utilisation

import Duplo, {zod} from "@duplojs/duplojs";
import {createTypeInput, GetTypeInput} from "@duplojs/type-input";

const typeInput = createTypeInput()
.add<"id", number>()
.add<"firstname", string>()
.add<"ageAndWeight", {age: number, weight: number}>()
.build();

typeInput.id(1); // {name: "id", value: 1}
typeInput.firstname("mathcovax"); // {name: "firstname", value: "mathcovax"}
typeInput.ageAndWeight({age: 21, weight: 74}); // {name: "ageAndWeight", value: {age: 21, weight: 74}}

const duplo = Duplo({port: 1506, host: "localhost", environment: "DEV"});

const testChecker = duplo
.createChecker("testChecker")
.handler(({name, value}: GetTypeInput<typeof typeInput>, output) => {
	if(name === "id") return output("info1", value);
	else return output("info2", value);
})
.build();

duplo.declareRoute("GET", "/")
.check(
    testChecker,
    {
        input: () => typeInput.id(1),
        result: "info1",
        catch: (res) => res.code(400).send(),
        indexing: "value",
    }
)
.handler(({pickup}, res) => res.code(200).info("s").send(pickup("value")));

duplo.launch();

Readme

Keywords

none

Package Sidebar

Install

npm i @duplojs/type-input

Weekly Downloads

193

Version

1.0.1

License

ISC

Unpacked Size

3.94 kB

Total Files

5

Last publish

Collaborators

  • mathcovax