Skip to content

Commit

Permalink
Merge branch 'develop' into fix-lolo32-pr
Browse files Browse the repository at this point in the history
  • Loading branch information
nakrovati committed Feb 22, 2024
2 parents ffb2a4e + f94d274 commit 63c49e2
Show file tree
Hide file tree
Showing 39 changed files with 4,383 additions and 418 deletions.
14 changes: 14 additions & 0 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: checks
on:
- push
- pull_request

jobs:
test:
uses: vinejs/.github/.github/workflows/test.yml@main

lint:
uses: vinejs/.github/.github/workflows/lint.yml@main

typecheck:
uses: vinejs/.github/.github/workflows/typecheck.yml@main
39 changes: 0 additions & 39 deletions .github/workflows/test.yml

This file was deleted.

14 changes: 4 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

<div align="center">

[![gh-workflow-image]][gh-workflow-url] [![npm-image]][npm-url] ![][typescript-image] [![license-image]][license-url] [![snyk-image]][snyk-url]
[![gh-workflow-image]][gh-workflow-url] [![npm-image]][npm-url] ![][typescript-image] [![license-image]][license-url]

</div>

Expand Down Expand Up @@ -42,16 +42,10 @@

![](https://github.com/thetutlage/static/blob/main/sponsorkit/sponsors.png?raw=true)

[gh-workflow-image]: https://img.shields.io/github/actions/workflow/status/vinejs/vine/test.yml?style=for-the-badge
[gh-workflow-url]: https://github.com/vinejs/vine/actions/workflows/test.yml "Github action"

[gh-workflow-image]: https://img.shields.io/github/actions/workflow/status/vinejs/vine/checks.yml?style=for-the-badge
[gh-workflow-url]: https://github.com/vinejs/vine/actions/workflows/checks.yml 'Github action'
[npm-image]: https://img.shields.io/npm/v/@vinejs/vine/latest.svg?style=for-the-badge&logo=npm
[npm-url]: https://www.npmjs.com/package/@vinejs/vine/v/latest "npm"

[npm-url]: https://www.npmjs.com/package/@vinejs/vine/v/latest 'npm'
[typescript-image]: https://img.shields.io/badge/Typescript-294E80.svg?style=for-the-badge&logo=typescript

[license-url]: LICENSE.md
[license-image]: https://img.shields.io/github/license/vinejs/vine?style=for-the-badge

[snyk-image]: https://img.shields.io/snyk/vulnerabilities/github/vinejs/vine?label=Snyk%20Vulnerabilities&style=for-the-badge
[snyk-url]: https://snyk.io/test/github/vinejs/vine?targetFile=package.json "snyk"
30 changes: 19 additions & 11 deletions benchmarks.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Following are the results from the benchmarks executed on the `Apple M1 Mac - 16
- VineJS performance is the outcome of our pre-compiling API. Both Yup and Zod have no option for pre-compiling schemas.

## Benchmarking against a flat object

The source for this benchmark is saved inside the [./benchmarks/flat_object.ts](./benchmarks/flat_object.ts) file. You may run the benchmark as follows.

```sh
Expand All @@ -15,17 +16,19 @@ node build/benchmarks/flat_object.js
```

### Results

```
===============================
Benchmarking with flat object
===============================
Vine x 9,348,814 ops/sec ±1.16% (87 runs sampled)
Zod x 1,163,370 ops/sec ±0.64% (87 runs sampled)
Yup x 407,485 ops/sec ±0.65% (89 runs sampled)
Vine x 9,744,651 ops/sec ±0.65% (86 runs sampled)
Zod x 1,277,525 ops/sec ±0.70% (89 runs sampled)
Yup x 521,218 ops/sec ±0.27% (89 runs sampled)
Fastest is Vine
```

## Benchmarking against a nested object

The source for this benchmark is saved inside the [./benchmarks/nested_object.ts](./benchmarks/nested_object.ts) file. You may run the benchmark as follows.

```sh
Expand All @@ -34,17 +37,19 @@ node build/benchmarks/nested_object.js
```

### Results

```
=================================
Benchmarking with nested object
=================================
Vine x 8,404,075 ops/sec ±0.39% (88 runs sampled)
Zod x 542,439 ops/sec ±1.00% (88 runs sampled)
Yup x 189,718 ops/sec ±0.74% (88 runs sampled)
Vine x 8,501,749 ops/sec ±0.47% (86 runs sampled)
Zod x 589,418 ops/sec ±0.17% (89 runs sampled)
Yup x 233,343 ops/sec ±0.25% (89 runs sampled)
Fastest is Vine
```

## Benchmarking arrays

The source for this benchmark is saved inside the [./benchmarks/array.ts](./benchmarks/array.ts) file. You may run the benchmark as follows.

```sh
Expand All @@ -53,17 +58,19 @@ node build/benchmarks/array.js
```

### Results

```
======================
Benchmarking arrays
======================
Vine x 6,733,943 ops/sec ±0.84% (87 runs sampled)
Zod x 400,623 ops/sec ±0.75% (88 runs sampled)
Yup x 115,169 ops/sec ±0.43% (88 runs sampled)
Vine x 6,622,071 ops/sec ±0.55% (89 runs sampled)
Zod x 424,309 ops/sec ±0.15% (90 runs sampled)
Yup x 136,655 ops/sec ±0.22% (88 runs sampled)
Fastest is Vine
```

## Benchmarking unions

The source for this benchmark is saved inside the [./benchmarks/union.ts](./benchmarks/union.ts) file. You may run the benchmark as follows.

> **Note**: Yup does not support unions, so there are no benchmarks for it.
Expand All @@ -74,11 +81,12 @@ node build/benchmarks/union.js
```

### Results

```
=======================
Benchmarking unions
=======================
Vine x 7,809,771 ops/sec ±0.37% (87 runs sampled)
Zod x 180,376 ops/sec ±0.35% (89 runs sampled)
Vine x 8,495,306 ops/sec ±0.37% (86 runs sampled)
Zod x 317,658 ops/sec ±0.23% (88 runs sampled)
Fastest is Vine
```
35 changes: 21 additions & 14 deletions benchmarks/array.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// @ts-ignore
import Benchmark from 'benchmark'
import { z } from 'zod'
import yup from 'yup'
import * as yup from 'yup'
import vine from '../index.js'
import * as valibot from 'valibot'
import Joi from 'joi'
import Ajv, { AsyncSchema } from 'ajv'

Expand Down Expand Up @@ -56,6 +57,15 @@ const vineSchema = vine.compile(
})
)

const valibotSchema = valibot.object({
contacts: valibot.array(
valibot.object({
type: valibot.string(),
value: valibot.string(),
})
),
})

const joiSchema = Joi.object({
contacts: Joi.array()
.items(
Expand Down Expand Up @@ -101,28 +111,25 @@ suite
.add('Vine', {
defer: true,
fn: function (deferred: any) {
vineSchema
.validate(getData())
.then(() => deferred.resolve())
.catch(console.log)
vineSchema.validate(getData()).then(() => deferred.resolve())
},
})
.add('Zod', {
defer: true,
fn: function (deferred: any) {
zodSchema
.parseAsync(getData())
.then(() => deferred.resolve())
.catch(console.log)
zodSchema.parseAsync(getData()).then(() => deferred.resolve())
},
})
.add('Yup', {
defer: true,
fn: function (deferred: any) {
yupSchema
.validate(getData())
.then(() => deferred.resolve())
.catch(console.log)
yupSchema.validate(getData()).then(() => deferred.resolve())
},
})
.add('Valibot', {
defer: true,
fn: function (deferred: any) {
valibot.parseAsync(valibotSchema, getData()).then(() => deferred.resolve())
},
})
.add('Joi', {
Expand All @@ -148,4 +155,4 @@ suite
.on('complete', function (this: any) {
console.log('Fastest is ' + this.filter('fastest').map('name'))
})
.run({ async: false })
.run({ async: true })
31 changes: 17 additions & 14 deletions benchmarks/flat_object.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// @ts-ignore
import Benchmark from 'benchmark'
import { z } from 'zod'
import yup from 'yup'
import * as yup from 'yup'
import vine from '../index.js'
import * as valibot from 'valibot'
import Joi from 'joi'
import Ajv, { AsyncSchema } from 'ajv'

Expand Down Expand Up @@ -32,6 +33,11 @@ const vineSchema = vine.compile(
})
)

const valibotSchema = valibot.object({
username: valibot.string(),
password: valibot.string(),
})

const joiSchema = Joi.object({
username: Joi.string().required(),
password: Joi.string().required(),
Expand Down Expand Up @@ -63,28 +69,25 @@ suite
.add('Vine', {
defer: true,
fn: function (deferred: any) {
vineSchema
.validate(getData())
.then(() => deferred.resolve())
.catch(console.log)
vineSchema.validate(getData()).then(() => deferred.resolve())
},
})
.add('Zod', {
defer: true,
fn: function (deferred: any) {
zodSchema
.parseAsync(getData())
.then(() => deferred.resolve())
.catch(console.log)
zodSchema.parseAsync(getData()).then(() => deferred.resolve())
},
})
.add('Yup', {
defer: true,
fn: function (deferred: any) {
yupSchema
.validate(getData())
.then(() => deferred.resolve())
.catch(console.log)
yupSchema.validate(getData()).then(() => deferred.resolve())
},
})
.add('Valibot', {
defer: true,
fn: function (deferred: any) {
valibot.parseAsync(valibotSchema, getData()).then(() => deferred.resolve())
},
})
.add('Joi', {
Expand All @@ -110,4 +113,4 @@ suite
.on('complete', function (this: any) {
console.log('Fastest is ' + this.filter('fastest').map('name'))
})
.run({ async: false })
.run({ async: true })
35 changes: 21 additions & 14 deletions benchmarks/nested_object.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// @ts-ignore
import Benchmark from 'benchmark'
import { z } from 'zod'
import yup from 'yup'
import * as yup from 'yup'
import vine from '../index.js'
import * as valibot from 'valibot'
import Joi from 'joi'
import Ajv, { AsyncSchema } from 'ajv'

Expand Down Expand Up @@ -50,6 +51,15 @@ const vineSchema = vine.compile(
})
)

const valibotSchame = valibot.object({
username: valibot.string(),
password: valibot.string(),
contact: valibot.object({
name: valibot.string(),
address: valibot.optional(valibot.string()),
}),
})

const joiSchema = Joi.object({
username: Joi.string().required(),
password: Joi.string().required(),
Expand Down Expand Up @@ -97,28 +107,25 @@ suite
.add('Vine', {
defer: true,
fn: function (deferred: any) {
vineSchema
.validate(getData())
.then(() => deferred.resolve())
.catch(console.log)
vineSchema.validate(getData()).then(() => deferred.resolve())
},
})
.add('Zod', {
defer: true,
fn: function (deferred: any) {
zodSchema
.parseAsync(getData())
.then(() => deferred.resolve())
.catch(console.log)
zodSchema.parseAsync(getData()).then(() => deferred.resolve())
},
})
.add('Yup', {
defer: true,
fn: function (deferred: any) {
yupSchema
.validate(getData())
.then(() => deferred.resolve())
.catch(console.log)
yupSchema.validate(getData()).then(() => deferred.resolve())
},
})
.add('Valibot', {
defer: true,
fn: function (deferred: any) {
valibot.parseAsync(valibotSchame, getData()).then(() => deferred.resolve())
},
})
.add('Joi', {
Expand All @@ -144,4 +151,4 @@ suite
.on('complete', function (this: any) {
console.log('Fastest is ' + this.filter('fastest').map('name'))
})
.run({ async: false })
.run({ async: true })
Loading

0 comments on commit 63c49e2

Please sign in to comment.