Skip to content

Commit

Permalink
chore: updated naming and package to better match wordings
Browse files Browse the repository at this point in the history
  • Loading branch information
victorgarciaesgi committed Nov 12, 2024
1 parent 00549e4 commit 11ab3c0
Show file tree
Hide file tree
Showing 112 changed files with 126 additions and 144 deletions.
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ It's heavily inspired by Vuelidate.
- [Zod](https://zod.dev/) support
- Made for Vue 3 and composition API first
- Collection validation (`$each` is back)
- Typed validator metadata
- Typed rule metadata
- Global config
- Async rules with params
- Per field options (debounce, lazy...)
Expand Down Expand Up @@ -63,14 +63,14 @@ TODO
- [x] validateForm typesafe
- [x] Deep nested rules
- [x] Collection validation
- [x] `applyIf` helper (like requiredIf for any validator)
- [x] `applyIf` helper (like requiredIf for any rule)
- [x] Async with params (need deps array) (withAsync)
- [x] Options (lazy, rewardEarly, autoDirty)
- [x] Regex helper
- [x] Additional rules and "and" helper
- [x] "or" and "not" helper
- [x] externalErrors
- [x] Dates built-in validators
- [x] Dates built-in rule
- [x] Usable Metadata
- [x] Zod support
- [x] Per field validation option (lazy, debounce, etc...)
Expand All @@ -91,11 +91,11 @@ TODO
# Quick start

```bash
pnpm install @regle/core @regle/validators
pnpm install @regle/core @regle/rules
# or
yarn add @regle/core @regle/validators
yarn add @regle/core @regle/rules
# or
npm install @regle/core @regle/validators
npm install @regle/core @regle/rules
```


Expand All @@ -122,7 +122,7 @@ npm install @regle/core @regle/validators
<script setup lang='ts'>
import {useRegle} from '@regle/core';
import {email, required, minLength, sameAs} from '@regle/validators';
import {email, required, minLength, sameAs} from '@regle/rules';
type MyForm = {
email?: string,
Expand Down Expand Up @@ -157,15 +157,15 @@ function submit() {
const result = await validateForm();
if (result) {
console.log(result.email); // email: string
// ^ type safe form result based on your validators
// ^ type safe form result based on your rules
}
}
</script>
```


## Create your own validators rules
## Create your own rules

```ts
// validations.ts
Expand Down
2 changes: 1 addition & 1 deletion docs/src/core-concepts/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ In the returned helpers we have:
- `state`: a copy of your form state. You can bind your model on this state if you have a non-reactive one as parameter
- `errors`: a computed tree focusing only on displaying errors to the user when it's needed. You can map on this tree to display the field error. It will contain an error only if the field is dirty
- `invalid`: a computed state returning the current invalid state of your form.
- `validateForm`: a Promise that will turn all the fields dirty, and run all their validation rules. It will return either `false` or a type safe copy of your form state. Values that had the `required` validators will be transformed into a non-nullable value (type only)
- `validateForm`: a Promise that will turn all the fields dirty, and run all their validation rules. It will return either `false` or a type safe copy of your form state. Values that had the `required` rule will be transformed into a non-nullable value (type only)
- `resetForm`: Will reset both your validation state and your form state to their initial values. If you want only the validation to be reset you can call `regle.$reset()`


Expand Down
8 changes: 4 additions & 4 deletions docs/src/core-concepts/rules-properties.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Let's make a simple exemple to explain the different properties
<script setup lang='ts'>
// @noErrors
import {useRegle} from '@regle/core';
import {required} from '@regle/validators';
import {required} from '@regle/rules';
import {ref} from 'vue';
const form = ref({email: '', user: {firstName: '', lastName: ''}});
Expand Down Expand Up @@ -45,7 +45,7 @@ regle.$fields.email.$rules.required.
### `$invalid`
- Type: `readonly boolean`

Indicates the state of validation for given model becomes true when any of its children validators specified in options returns a falsy value.
Indicates the state of validation for given model becomes true when any of its children rules specified in options returns a falsy value.


### `$valid`
Expand Down Expand Up @@ -76,7 +76,7 @@ A reference to the original validated model. It can be used to bind your form wi
### `$pending`
- Type: `readonly boolean`

Indicates if any child async validator is currently pending. Always false if all validators are synchronous.
Indicates if any child async rule is currently pending. Always false if all rules are synchronous.


### `$error`
Expand All @@ -102,7 +102,7 @@ Collection of all the error messages, collected for all child properties.
### `$validate`
- Type: `() => Promise<boolean>`

Sets all properties as dirty, triggering all validators. Returns a Promise with a boolean, which resolves once all validators finish.
Sets all properties as dirty, triggering all rules. Returns a Promise with a boolean, which resolves once all rules finish.

### `$touch`
- Type: `() => void`
Expand Down
6 changes: 3 additions & 3 deletions docs/src/core-concepts/rules.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Rules are the core concept of Regle (and also it's name 🙄).
A rule is a function (inline or created with the `createRule` helper) that receive the matching value and return either a boolean or an object with a $valid property. If the validation passes, return true or an object containing at least `{ $valid: boolean }`, false otherwise.


## Simple inline validators
## Simple inline rule

``` ts twoslash
import type { Maybe, InlineRuleDeclaration } from '@regle/core';
Expand All @@ -27,7 +27,7 @@ const customRuleInlineWithMetaData = ((value: Maybe<string>) => {
}) satisfies InlineRuleDeclaration;
```

Inline rules are then usable with a set of tools from `@regle/validators`
Inline rules are then usable with a set of tools from `@regle/rules`

### `withMessage`

Expand All @@ -36,7 +36,7 @@ This tool take your rule as a first argument and your error message as a second.
``` ts twoslash
// @noErrors
import {useRegle, type InlineRuleDeclaration, type Maybe} from '@regle/core';
import {withMessage} from '@regle/validators';
import {withMessage} from '@regle/rules';

const customRuleInlineWithMetaData = ((value: Maybe<string>) => {
return {
Expand Down
8 changes: 4 additions & 4 deletions docs/src/core-concepts/validation-properties.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Let's make a simple exemple to explain the different properties
<script setup lang='ts'>
// @noErrors
import {useRegle} from '@regle/core';
import {required} from '@regle/validators';
import {required} from '@regle/rules';
import {ref} from 'vue';
const form = ref({email: '', user: {firstName: '', lastName: ''}});
Expand Down Expand Up @@ -45,7 +45,7 @@ regle.$fields.email.
### `$invalid`
- Type: `readonly boolean`

Indicates the state of validation for given model becomes true when any of its children validators specified in options returns a falsy value.
Indicates the state of validation for given model becomes true when any of its children rules specified in options returns a falsy value.


### `$valid`
Expand Down Expand Up @@ -76,7 +76,7 @@ A reference to the original validated model. It can be used to bind your form wi
### `$pending`
- Type: `readonly boolean`

Indicates if any child async validator is currently pending. Always false if all validators are synchronous.
Indicates if any child async rule is currently pending. Always false if all rules are synchronous.


### `$error`
Expand All @@ -102,7 +102,7 @@ Collection of all the error messages, collected for all child properties.
### `$validate`
- Type: `() => Promise<boolean>`

Sets all properties as dirty, triggering all validators. Returns a Promise with a boolean, which resolves once all validators finish.
Sets all properties as dirty, triggering all rules. Returns a Promise with a boolean, which resolves once all rules finish.

### `$touch`
- Type: `() => void`
Expand Down
8 changes: 4 additions & 4 deletions docs/src/introduction/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,19 @@ Declare your form rules inside a component or a Pinia stores and use it wherever
::: code-group

```sh [pnpm]
pnpm add @regle/core @regle/validators
pnpm add @regle/core @regle/rules
```

```sh [npm]
npm install @regle/core @regle/validators
npm install @regle/core @regle/rules
```

```sh [yarn]
yarn add @regle/core @regle/validators
yarn add @regle/core @regle/rules
```

```sh [bun]
bun add @regle/core @regle/validators
bun add @regle/core @regle/rules
```

:::
Expand Down
4 changes: 2 additions & 2 deletions docs/src/parts/QuickUsage.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<script setup lang='ts'>
import {useRegle} from '@regle/core';
import {required, minLength, email} from '@regle/validators';
import {required, minLength, email} from '@regle/rules';
import {ref} from 'vue';
const form = ref({email: ''});
Expand Down Expand Up @@ -38,7 +38,7 @@ Result:

<script setup lang='ts'>
import {useRegle} from '@regle/core';
import {required, minLength, email} from '@regle/validators';
import {required, minLength, email} from '@regle/rules';
import {ref} from 'vue';

const form = ref({email: ''});
Expand Down
3 changes: 3 additions & 0 deletions docs/src/rules/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
title: Rules
---
3 changes: 0 additions & 3 deletions docs/src/validators/index.md

This file was deleted.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
},
"devDependencies": {
"@regle/core": "workspace:*",
"@regle/validators": "workspace:*",
"@regle/rules": "workspace:*",
"@regle/zod": "workspace:*",
"@shikijs/vitepress-twoslash": "1.22.2",
"@typescript-eslint/eslint-plugin": "8.14.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@regle/core",
"version": "0.0.16",
"description": "Vue form validator",
"description": "Typescript first model-based validation library for Vue 3",
"scripts": {
"lint": "eslint --ext .ts --ext .vue .",
"typecheck": "tsc --noEmit && vitest run --typecheck",
Expand Down Expand Up @@ -57,4 +57,4 @@
"url": "https://github.com/victorgarciaesgi"
},
"license": "MIT"
}
}
4 changes: 2 additions & 2 deletions packages/core/src/core/createRule/createRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { getFunctionParametersLength } from './unwrapRuleParameters';

/**
* @description
* Create a typed custom rule that can be used like default validators.
* Create a typed custom rule that can be used like default rules.
* It can also be declared in the global options
*
* It will automatically detect if the rule is async
Expand All @@ -25,7 +25,7 @@ import { getFunctionParametersLength } from './unwrapRuleParameters';
*
* ```ts
* // Create a simple rule with no params
* import {ruleHelpers} from '@regle/validators';
* import {ruleHelpers} from '@regle/rules';
*
* export const isFoo = createRule({
* type: defineType<string>('foo'),
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/core/defineRegleConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { AllRulesDeclarations, RegleBehaviourOptions } from '../types';
import { createUseRegleComposable } from './useRegle';

/**
* Root function that allows you to define project-wise all your custom validators or overwrite default ones
* Root function that allows you to define project-wise all your custom rules or overwrite default ones
*
* It will return utility functions that let you build type-safe forms
*
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@regle/validators",
"name": "@regle/rules",
"version": "0.0.16",
"description": "Vue form validator",
"description": "Collection of rules and helpers for Regle",
"scripts": {
"lint": "eslint --ext .ts --ext .vue .",
"typecheck": "tsc --noEmit && vitest run --typecheck",
Expand Down Expand Up @@ -54,4 +54,4 @@
"url": "https://github.com/victorgarciaesgi"
},
"license": "MIT"
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { RegleRuleDefinition } from '@regle/core';
import { timeout } from '../../../../../tests/utils';
import { email, minLength, required } from '../../validators';
import { email, minLength, required } from '../../rules';
import { and } from '../and';

describe('and validator', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import type { RegleRuleDefinition} from '@regle/core';
import type { RegleRuleDefinition } from '@regle/core';
import { useRegle } from '@regle/core';
import { flushPromises, mount } from '@vue/test-utils';
import { defineComponent, ref } from 'vue';
import { timeout } from '../../../../../tests/utils';
import { applyIf } from '../../helpers/applyIf';
import { required } from '../../validators';
import { applyIf } from '../applyIf';
import { required } from '../../rules';

describe('applyIf helper', () => {
const testComponent = defineComponent({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { RegleRuleDefinition } from '@regle/core';
import { minLength, required } from '../../validators';
import { minLength, required } from '../../rules';
import { not } from '../not';

describe('not validator', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { RegleRuleDefinition } from '@regle/core';
import { timeout } from '../../../../../tests/utils';
import { email, minLength, required } from '../../validators';
import { email, minLength, required } from '../../rules';
import { or } from '../or';

describe('or validator', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useRegle } from '@regle/core';
import { flushPromises, mount } from '@vue/test-utils';
import { defineComponent, nextTick, ref } from 'vue';
import { timeout } from '../../../../../tests/utils';
import { withAsync } from '../../helpers/withAsync';
import { withAsync } from '../withAsync';
import { withMessage } from '../withMessage';

describe('withAsync helper', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import type { RegleRuleDefinition} from '@regle/core';
import type { RegleRuleDefinition } from '@regle/core';
import { useRegle } from '@regle/core';
import { flushPromises, mount } from '@vue/test-utils';
import { Ref, defineComponent, ref } from 'vue';
import { and } from '../../helpers/and';
import { email, minLength, required } from '../../validators';
import { and } from '../and';
import { email, minLength, required } from '../../rules';
import { withMessage } from '../withMessage';
import { withAsync } from '../../helpers/withAsync';
import { ruleHelpers } from '../../helpers/ruleHelpers';
import { withAsync } from '../withAsync';
import { ruleHelpers } from '../ruleHelpers';

describe('withMessage helper', () => {
const testComponent = defineComponent({
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 2 additions & 0 deletions packages/rules/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './helpers';
export * from './rules';
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 0 additions & 2 deletions packages/validators/src/index.ts

This file was deleted.

6 changes: 3 additions & 3 deletions packages/zod/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@regle/zod",
"version": "0.0.16",
"description": "Vue form validator",
"description": "Zod adapter for Regle",
"scripts": {
"lint": "eslint --ext .ts --ext .vue .",
"typecheck": "tsc --noEmit",
Expand All @@ -16,7 +16,7 @@
},
"dependencies": {
"@regle/core": "workspace:*",
"@regle/validators": "workspace:*"
"@regle/rules": "workspace:*"
},
"devDependencies": {
"@total-typescript/ts-reset": "0.6.1",
Expand Down Expand Up @@ -61,4 +61,4 @@
"url": "https://github.com/victorgarciaesgi"
},
"license": "MIT"
}
}
2 changes: 1 addition & 1 deletion packages/zod/src/core/parser/processZodTypeDef.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { RegleFormPropertyType } from '@regle/core';
import { withMessage } from '@regle/validators';
import { withMessage } from '@regle/rules';
import z from 'zod';
import {
extractIssuesMessages,
Expand Down
Loading

0 comments on commit 11ab3c0

Please sign in to comment.