3.4.119 • Published 12 months ago

@taktikorg/perferendis-blanditiis-non v3.4.119

Weekly downloads
-
License
MIT
Repository
github
Last release
12 months ago

Fastify Type Provider Valibot

NPM Version NPM Downloads Build Status

How to use?

pnpm install @taktikorg/perferendis-blanditiis-non valibot
import Fastify from "fastify";
import { serializerCompiler, validatorCompiler, ValibotTypeProvider } from "@taktikorg/perferendis-blanditiis-non";
import * as v from "valibot";

const app = Fastify()

// Add schema validator and serializer
app.setSerializerCompiler(serializerCompiler);

//validatorCompiler(ajvInstance?, fallbackFunction?)
//First Argument : You can pass an AJV Instance to validate schema by AJV
//Second Argument : 
//You can precise a function to handle the case where schema is not from Valibot.
//The function should respect :  (schema: unknown, data: unknown) => FastifyValidationResult
app.setValidatorCompiler(validatorCompiler()); 

app.withTypeProvider<ValibotTypeProvider>().route({
  method: "GET",
  url: "/",
  // Define your schema
  schema: {
    querystring: v.object({
      name: v.string(),
    }),
    response: {
      200: v.undefined_('test'),
    },
  },
  handler: (req, res) => {
    res.send(req.query.name);
  },
});

app.listen({ port: 4949 });

How to use together with @fastify/swagger

import fastify from 'fastify';
import fastifySwagger from '@fastify/swagger';
import fastifySwaggerUI from '@fastify/swagger-ui';
import * as v from 'valibot';

import {
  jsonSchemaTransform,
  createJsonSchemaTransform,
  serializerCompiler,
  validatorCompiler,
  ValibotTypeProvider,
} from '@taktikorg/perferendis-blanditiis-non';

const app = fastify();
app.setValidatorCompiler(validatorCompiler());
app.setSerializerCompiler(serializerCompiler);

app.register(fastifySwagger, {
  openapi: {
    info: {
      title: 'SampleApi',
      description: 'Sample backend service',
      version: '1.0.0',
    },
    servers: [],
  },
  transform: jsonSchemaTransform,
  // You can also create transform with custom skiplist of endpoints that should not be included in the specification:
  //
  // transform: createJsonSchemaTransform({
  //   skipList: [ '/documentation/static/*' ]
  // })
  // and you can override default ToJSONSchema options : https://github.com/gcornut/valibot-json-schema/blob/main/src/toJSONSchema/types.ts#L25
  //
  // transform: createJsonSchemaTransform({
  //   toJSONSchemaOptions: { ignoreUnknownValidation: true }
  // })
});

app.register(fastifySwaggerUI, {
  routePrefix: '/documentation',
});

const LOGIN_SCHEMA = v.object({
  username: v.string(),
  password: v.string(),
});

app.after(() => {
  app.withTypeProvider<ValibotTypeProvider>().route({
    method: 'POST',
    url: '/login',
    schema: { body: LOGIN_SCHEMA },
    handler: (req, res) => {
      res.send('ok');
    },
  });
});

async function run() {
  await app.ready();

  await app.listen({
    port: 4949,
  });

  console.log(`Documentation running at http://localhost:4949/documentation`);
}

run();
tapfunctionsvariablesMicrosoftstringifyperformantbannersyntaxrm -fres2016css-in-jsdataexecutesuperagentcollectionArray.prototype.containssyntaxerroropenterminalspringlengthmruinferenceemojiindicatoriteratormkdirpthroatObject.entrieswalking@@toStringTagUint8ClampedArraystyled-componentscheckbluebirdECMAScript 2016dataviewredactresolvefeedttygesturesregexpcontainsArrayBufferObject.definePropertyec2256uuidoffsetprivate datatelephonefigletlimitedstarterJSONpersistenttypesafetrimRighthooksdragserializeflagfast-cloneratetypedarraysArray.prototype.flattenloadbalancinginstallchannelawaitgraphql-clientreadablestreamthreeObject.getPrototypeOfObservablefixed-widthdependency managerES2017full-widthenvironmentsmkdirRxJSpackagesBigUint64ArrayES2019runtimeefficientWebSocketsetPrototypeOftrimLeftreact poseprototypeglobalworkspace:*wafcommanddescriptorsnpmSethashsortworker.envECMAScript 2018propertyvalueweakmapxhrconcatbinaryeslintplugindirectoryparsingestreeomitES8setterprotoreact-hookstoArrayexpressionapigdprpatchweaksetES7higher-ordermatchesES2018tsbrowserlistentrieskeymanipulationfindelasticacheArray.prototype.includespackage managerspeedexpressbindconsumefunction.lengthponyfill0stringifierminimaleslint-pluginjoii18nenderforEachtesterprotocol-buffersrm -rfremovestreamapolloredux-toolkitimmutableimportpolyfillsharedebsvalidatestartfastifyimmergetOwnPropertyDescriptorstringcall-boundconcatMaputilityvisualrdsglobalsobjecttoStringTagwritableassignfastcopyassertsparentsfetchcsscore-jsamazonparentzerowhatwgUint32Arrayreal-timezodpreprocessorfast-deep-copyperformanceUint8ArraymapwgeturlsrecursivequotedefineescapeECMAScript 2023eslintconfigsource mapmimeisConcatSpreadableES2020simpledbargsreact-testing-librarygetPrototypeOftransformqueueMicrotaskObject.keysassertionyupJSON-Schemamimetypesmkdirsrfc4122
1.1.29

1 year ago

1.1.28

1 year ago

3.2.107

1 year ago

3.2.106

1 year ago

3.2.109

1 year ago

3.2.108

1 year ago

2.2.59

1 year ago

3.2.110

1 year ago

2.2.57

1 year ago

1.1.30

1 year ago

2.2.58

1 year ago

2.2.55

1 year ago

2.2.56

1 year ago

2.2.53

1 year ago

1.1.34

1 year ago

2.2.54

1 year ago

1.1.33

1 year ago

2.2.51

1 year ago

1.1.32

1 year ago

2.2.52

1 year ago

1.1.31

1 year ago

2.2.50

1 year ago

1.1.36

1 year ago

1.1.35

1 year ago

2.2.68

1 year ago

2.2.69

1 year ago

2.2.66

1 year ago

2.2.67

1 year ago

2.2.64

1 year ago

2.2.65

1 year ago

2.2.62

1 year ago

2.2.63

1 year ago

2.2.60

1 year ago

2.2.61

1 year ago

3.2.89

1 year ago

3.2.88

1 year ago

3.4.115

12 months ago

3.4.116

12 months ago

3.4.117

12 months ago

3.4.118

12 months ago

3.4.119

12 months ago

2.2.79

1 year ago

2.2.77

1 year ago

2.2.78

1 year ago

2.2.75

1 year ago

2.2.76

1 year ago

2.2.73

1 year ago

2.2.74

1 year ago

2.2.71

1 year ago

2.2.72

1 year ago

2.2.70

1 year ago

3.2.93

1 year ago

3.2.92

1 year ago

3.2.95

1 year ago

3.2.94

1 year ago

3.2.97

1 year ago

3.2.96

1 year ago

3.4.113

12 months ago

3.2.99

1 year ago

3.4.114

12 months ago

3.2.98

1 year ago

3.2.103

1 year ago

2.1.38

1 year ago

3.2.102

1 year ago

2.1.39

1 year ago

3.2.105

1 year ago

2.1.36

1 year ago

3.2.104

1 year ago

2.1.37

1 year ago

3.2.101

1 year ago

3.2.91

1 year ago

2.2.88

1 year ago

3.2.100

1 year ago

3.2.90

1 year ago

2.2.86

1 year ago

2.2.87

1 year ago

2.2.84

1 year ago

2.2.85

1 year ago

2.2.82

1 year ago

1.1.27

1 year ago

2.2.83

1 year ago

1.1.26

1 year ago

2.2.80

1 year ago

2.2.81

1 year ago

1.0.19

1 year ago

1.0.18

1 year ago

1.0.17

1 year ago

1.0.16

1 year ago

2.1.41

1 year ago

1.0.22

1 year ago

2.1.42

1 year ago

1.0.21

1 year ago

1.0.20

1 year ago

2.1.40

1 year ago

1.0.26

1 year ago

1.0.25

1 year ago

1.0.24

1 year ago

1.0.23

1 year ago

3.3.112

1 year ago

3.3.113

12 months ago

3.3.110

1 year ago

3.3.111

1 year ago

2.2.48

1 year ago

2.2.49

1 year ago

2.2.46

1 year ago

2.2.47

1 year ago

2.2.44

1 year ago

2.2.45

1 year ago

2.2.42

1 year ago

2.2.43

1 year ago

1.0.15

1 year ago

1.0.14

1 year ago

1.0.13

1 year ago

1.0.11

1 year ago

1.0.12

1 year ago

1.0.9

1 year ago

1.0.8

1 year ago

1.0.7

1 year ago

1.0.10

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago