@regle/mcp-server 1.27.2 → 1.28.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/regle-mcp-server.js +3 -3
- package/package.json +5 -5
package/dist/regle-mcp-server.js
CHANGED
|
@@ -19,7 +19,7 @@ const rawData = {
|
|
|
19
19
|
"title": "Global configuration",
|
|
20
20
|
"category": "advanced-usage",
|
|
21
21
|
"path": "advanced-usage/global-config.md",
|
|
22
|
-
"content": "# Global configuration\n\nIf your app includes multiple forms, it can be helpful to define a global configuration that centralizes your custom validators, error messages, and modifiers. This eliminates the need to declare these settings repeatedly for every `useRegle` call, improving both code consistency and developer experience with features like autocompletion and type checking.\n\nRegle offers two ways to define your global configuration:\n\n- **Composable** — use `defineRegleConfig` to create a custom `useRegle` composable that encapsulates your configuration. Best for scoped or modular setups.\n- **Declarative** — use `defineRegleOptions` with the `RegleVuePlugin` to provide configuration at the app level via Vue's plugin system. Best for app-wide defaults that apply everywhere, including the default `useRegle`.\n\n## Composable {#composable}\n\n`defineRegleConfig` creates and returns a custom `useRegle` composable (along with `inferRules` and `useRules`) that has your configuration baked in. This is ideal when you want strong typing and autocompletion for your custom rules.\n\n### Replace built-in rules messages\n\nEach `@regle/rules` rule provides a default error message. You may not want to call `withMessage` every time you need to use one with a custom error message.\n\n`defineRegleConfig` allows you to redefine the default messages of built-in rules.\n\n```ts\nimport { defineRegleConfig } from '@regle/core';\nimport { withMessage, minLength, required } from '@regle/rules';\n\nconst { useRegle: useCustomRegle } = defineRegleConfig({\n rules: () => ({\n required: withMessage(required, 'You need to provide a value'),\n minLength: withMessage(minLength, ({ $value, $params: [min] }) => {\n return `Minimum length is ${min}. Current length: ${$value?.length}`;\n })\n })\n})\n\nconst { r$ } = useCustomRegle({ name: '' }, {\n name: {\n required,\n minLength: minLength(6)\n }\n})\n```\n\nResult: \n\n:::tip\nIf you use Nuxt, check out the [Nuxt module](/integrations/nuxt) for a even better DX. \nIt provides a way to add your custom global config to your auto-imports.\n:::\n\n#### i18n\n\nYou can also use any i18n library directly inside the config.\n\n```ts\nimport { defineRegleConfig } from '@regle/core';\nimport { withMessage, minLength, required } from '@regle/rules';\nimport { useI18n } from 'vue-i18n';\n\nconst { useRegle: useCustomRegle } = defineRegleConfig({\n rules: () => {\n const { t } = useI18n()\n\n return {\n required: withMessage(required, t('general.required')),\n minLength: withMessage(minLength, ({ $value, $params: [max] }) => {\n return t('general.minLength', {max});\n })\n }\n }\n})\n```\n\n### Declare new rules\n\nWhile `useRegle` allows you to use any rule key, adding custom rules to the global configuration provides autocompletion and type checking. This improves maintainability and consistency across your application.\n\n```ts twoslash\nconst someAsyncCall = async () => await Promise.resolve(true);\n// ---cut---\n\nimport { defineRegleConfig, createRule, type Maybe } from '@regle/core';\nimport { withMessage, isFilled } from '@regle/rules';\n\nconst asyncEmail = createRule({\n async validator(value: Maybe<string>) {\n if (!isFilled(value)) {\n return true;\n }\n\n const result = await someAsyncCall();\n return result;\n },\n message: 'Email already exists',\n});\n\nconst { useRegle: useCustomRegle } = defineRegleConfig({\n rules: () => ({\n asyncEmail\n })\n})\n\nconst { r$ } = useCustomRegle({ name: '' }, {\n name: {\n asy\n\n }\n})\n```\n\n### Declare modifiers\n\nYou can include global modifiers in your configuration to automatically apply them wherever you use the `useRegle` composable. This avoids repetitive declarations and keeps your code clean.\n\n```ts\nimport { defineRegleConfig } from '@regle/core';\nimport { withMessage, minLength, required } from '@regle/rules';\n\nexport const { useRegle: useCustomRegle } = defineRegleConfig({\n modifiers: {\n autoDirty: false,\n silent: true,\n lazy: true,\n rewardEarly: true\n }\n})\n```\n\n### Export scoped `inferRules` helper\n\n`defineRegleConfig` also returns a scoped `inferRules` helper, similar to the one exported from `@regle/core`, but that will autocomplete and check your custom rules.\n\nFor information about `inferRules`, check [Typing rules docs](/typescript/typing-rules)\n\n```ts\nimport { defineRegleConfig } from '@regle/core';\nimport { withMessage, minLength, required } from '@regle/rules';\n\nexport const { useRegle, inferRules } = defineRegleConfig({/* */})\n```\n\n### Extend global config\n\nIt's also possible to add additional config to an already created custom `useRegle`.\n\nWith `extendRegleConfig`, you can recreate a custom one with a existing composable as an input.\n\n```ts twoslash\n\nimport { defineRegleConfig, extendRegleConfig, createRule } from '@regle/core';\nimport { withMessage, required } from '@regle/rules';\n\nconst { useRegle: useCustomRegle } = defineRegleConfig({\n rules: () => ({\n customRule: withMessage(required, 'Custom rule'),\n })\n})\n\nconst {useRegle: useExtendedRegle} = extendRegleConfig(useCustomRegle, {\n rules: () => ({\n customRuleExtended: withMessage(required, 'Custom rule 2'),\n })\n})\n\nuseExtendedRegle({name: ''}, {\n name: {\n custom\n \n }\n})\n\n```\n\n## Declarative {#declarative}\n\nThe declarative approach uses `defineRegleOptions` combined with the `RegleVuePlugin` to provide global configuration at the Vue app level. The configuration is injected via Vue's `provide/inject` mechanism, so it applies to every `useRegle` call in your application — including the default one from `@regle/core`.\n\nThis is especially useful when you want app-wide defaults without needing to import a custom composable everywhere.\n\n### Setup\n\nPass your options as the second argument to `app.use`:\n\n```ts [main.ts]\nimport { createApp } from 'vue';\nimport { RegleVuePlugin, defineRegleOptions } from '@regle/core';\nimport { withMessage, required, minLength } from '@regle/rules';\nimport App from './App.vue';\n\nconst options = defineRegleOptions({\n rules: () => ({\n required: withMessage(required, 'You need to provide a value'),\n minLength: withMessage(minLength, ({ $value, $params: [min] }) => {\n return `Minimum length is ${min}. Current length: ${$value?.length}`;\n })\n }),\n modifiers: {\n autoDirty: false,\n },\n shortcuts: {\n fields: {\n $isRequired: (field) => field.$rules.required?.$active ?? false,\n },\n },\n});\n\nconst app = createApp(App);\n\n// Add the options to the RegleVuePlugin\napp.use(RegleVuePlugin, options);\n\napp.mount('#app');\n```\n\nNow, every `useRegle` call in your app will automatically use the configured rules and modifiers — no need to import a custom composable.\n\n```vue\n\n```\n\n### Type augmentation\n\nTo get full type-safety and autocompletion with the declarative approach, you can augment Regle's interfaces using TypeScript module augmentation. This lets the default `useRegle` composable know about your custom rules and shortcut properties.\n\n```ts [regle.config.ts]\nimport { createRule } from '@regle/core';\n\nconst customRule = createRule({\n validator: (value: unknown) => value === 'custom',\n message: 'Custom rule',\n});\n\ndeclare module '@regle/core' {\n interface CustomRules {\n customRule: typeof customRule;\n }\n interface CustomFieldProperties {\n $isRequired: boolean;\n }\n interface CustomNestedProperties {\n $isEmpty: boolean;\n }\n interface CustomCollectionProperties {\n $isEmpty: boolean;\n }\n}\n```\n\n### Combining with composable configuration\n\nIf both the plugin options and a `defineRegleConfig` composable are used, the composable's configuration takes precedence and is merged on top of the plugin's. This lets you set app-wide defaults via the plugin while still allowing scoped overrides where needed.\n\n## Override default behaviors\n\nYou can override the default behaviors of Regle processors by using the `overrides` property. This works with both the composable and declarative approaches.\n\n### `isEdited`\n\nOverride the default `$edited` property handler. Useful to handle custom comparisons for complex object types.\n\n:::warning\nIt's highly recommended to use this override with the [`markStatic`](/advanced-usage/immutable-constructors) helper to handle immutable constructors.\n:::\n\n```ts\nimport { defineRegleConfig } from '@regle/core';\nimport { Decimal } from 'decimal.js';\n\nexport const { useRegle: useCustomRegle } = defineRegleConfig({\n overrides: {\n isEdited(currentValue, initialValue, defaultHandlerFn) {\n if (currentValue instanceof Decimal && initialValue instanceof Decimal) {\n return currentValue.toNearest(0.01).toString() !== initialValue.toNearest(0.01).toString();\n }\n // fallback to the default handler\n return defaultHandlerFn(currentValue, initialValue);\n },\n },\n})\n\n// Or with the declarative approach\nimport { defineRegleOptions } from '@regle/core';\n\nconst options = defineRegleOptions({\n overrides: {\n isEdited: (currentValue, initialValue, defaultHandlerFn) => {\n return currentValue !== initialValue;\n },\n },\n});\n\napp.use(RegleVuePlugin, options);\n```"
|
|
22
|
+
"content": "# Global configuration\n\nIf your app includes multiple forms, it can be helpful to define a global configuration that centralizes your custom validators, error messages, and modifiers. This eliminates the need to declare these settings repeatedly for every `useRegle` call, improving both code consistency and developer experience with features like autocompletion and type checking.\n\nRegle offers two ways to define your global configuration:\n\n- **Composable** — use `defineRegleConfig` to create a custom `useRegle` composable that encapsulates your configuration. Best for scoped or modular setups.\n- **Declarative** — use `defineRegleOptions` with the `RegleVuePlugin` to provide configuration at the app level via Vue's plugin system. Best for app-wide defaults that apply everywhere, including the default `useRegle`.\n\n## Composable {#composable}\n\n`defineRegleConfig` creates and returns a custom `useRegle` composable (along with `inferRules` and `useRules`) that has your configuration baked in. This is ideal when you want strong typing and autocompletion for your custom rules.\n\n### Replace built-in rules messages\n\nEach `@regle/rules` rule provides a default error message. You may not want to call `withMessage` every time you need to use one with a custom error message.\n\n`defineRegleConfig` allows you to redefine the default messages of built-in rules.\n\n```ts\nimport { defineRegleConfig } from '@regle/core';\nimport { withMessage, minLength, required } from '@regle/rules';\n\nconst { useRegle: useCustomRegle } = defineRegleConfig({\n rules: () => ({\n required: withMessage(required, 'You need to provide a value'),\n minLength: withMessage(minLength, ({ $value, $params: [min] }) => {\n return `Minimum length is ${min}. Current length: ${$value?.length}`;\n })\n })\n})\n\nconst { r$ } = useCustomRegle({ name: '' }, {\n name: {\n required,\n minLength: minLength(6)\n }\n})\n```\n\nResult: \n\n:::tip\nIf you use Nuxt, check out the [Nuxt module](/integrations/nuxt) for a even better DX. \nIt provides a way to add your custom global config to your auto-imports.\n:::\n\n#### i18n\n\nYou can also use any i18n library directly inside the config.\n\n```ts\nimport { defineRegleConfig } from '@regle/core';\nimport { withMessage, minLength, required } from '@regle/rules';\nimport { useI18n } from 'vue-i18n';\n\nconst { useRegle: useCustomRegle } = defineRegleConfig({\n rules: () => {\n const { t } = useI18n()\n\n return {\n required: withMessage(required, t('general.required')),\n minLength: withMessage(minLength, ({ $value, $params: [max] }) => {\n return t('general.minLength', {max});\n })\n }\n }\n})\n```\n\n### Declare new rules\n\nWhile `useRegle` allows you to use any rule key, adding custom rules to the global configuration provides autocompletion and type checking. This improves maintainability and consistency across your application.\n\n```ts twoslash\nconst someAsyncCall = async () => await Promise.resolve(true);\n// ---cut---\n\nimport { defineRegleConfig, createRule, type Maybe } from '@regle/core';\nimport { withMessage, isFilled } from '@regle/rules';\n\nconst asyncEmail = createRule({\n async validator(value: Maybe<string>) {\n if (!isFilled(value)) {\n return true;\n }\n\n const result = await someAsyncCall();\n return result;\n },\n message: 'Email already exists',\n});\n\nconst { useRegle: useCustomRegle } = defineRegleConfig({\n rules: () => ({\n asyncEmail\n })\n})\n\nconst { r$ } = useCustomRegle({ name: '' }, {\n name: {\n asy\n\n }\n})\n```\n\n### Declare modifiers\n\nYou can include global modifiers in your configuration to automatically apply them wherever you use the `useRegle` composable. This avoids repetitive declarations and keeps your code clean.\n\n```ts\nimport { defineRegleConfig } from '@regle/core';\nimport { withMessage, minLength, required } from '@regle/rules';\n\nexport const { useRegle: useCustomRegle } = defineRegleConfig({\n modifiers: {\n autoDirty: false,\n silent: true,\n lazy: true,\n rewardEarly: true,\n // Applies to every async field. A per-field `$debounce` still takes priority.\n debounce: 500\n }\n})\n```\n\n### Export scoped `inferRules` helper\n\n`defineRegleConfig` also returns a scoped `inferRules` helper, similar to the one exported from `@regle/core`, but that will autocomplete and check your custom rules.\n\nFor information about `inferRules`, check [Typing rules docs](/typescript/typing-rules)\n\n```ts\nimport { defineRegleConfig } from '@regle/core';\nimport { withMessage, minLength, required } from '@regle/rules';\n\nexport const { useRegle, inferRules } = defineRegleConfig({/* */})\n```\n\n### Extend global config\n\nIt's also possible to add additional config to an already created custom `useRegle`.\n\nWith `extendRegleConfig`, you can recreate a custom one with a existing composable as an input.\n\n```ts twoslash\n\nimport { defineRegleConfig, extendRegleConfig, createRule } from '@regle/core';\nimport { withMessage, required } from '@regle/rules';\n\nconst { useRegle: useCustomRegle } = defineRegleConfig({\n rules: () => ({\n customRule: withMessage(required, 'Custom rule'),\n })\n})\n\nconst {useRegle: useExtendedRegle} = extendRegleConfig(useCustomRegle, {\n rules: () => ({\n customRuleExtended: withMessage(required, 'Custom rule 2'),\n })\n})\n\nuseExtendedRegle({name: ''}, {\n name: {\n custom\n \n }\n})\n\n```\n\n## Declarative {#declarative}\n\nThe declarative approach uses `defineRegleOptions` combined with the `RegleVuePlugin` to provide global configuration at the Vue app level. The configuration is injected via Vue's `provide/inject` mechanism, so it applies to every `useRegle` call in your application — including the default one from `@regle/core`.\n\nThis is especially useful when you want app-wide defaults without needing to import a custom composable everywhere.\n\n### Setup\n\nPass your options as the second argument to `app.use`:\n\n```ts [main.ts]\nimport { createApp } from 'vue';\nimport { RegleVuePlugin, defineRegleOptions } from '@regle/core';\nimport { withMessage, required, minLength } from '@regle/rules';\nimport App from './App.vue';\n\nconst options = defineRegleOptions({\n rules: () => ({\n required: withMessage(required, 'You need to provide a value'),\n minLength: withMessage(minLength, ({ $value, $params: [min] }) => {\n return `Minimum length is ${min}. Current length: ${$value?.length}`;\n })\n }),\n modifiers: {\n autoDirty: false,\n },\n shortcuts: {\n fields: {\n $isRequired: (field) => field.$rules.required?.$active ?? false,\n },\n },\n});\n\nconst app = createApp(App);\n\n// Add the options to the RegleVuePlugin\napp.use(RegleVuePlugin, options);\n\napp.mount('#app');\n```\n\nNow, every `useRegle` call in your app will automatically use the configured rules and modifiers — no need to import a custom composable.\n\n```vue\n\n```\n\n### Type augmentation\n\nTo get full type-safety and autocompletion with the declarative approach, you can augment Regle's interfaces using TypeScript module augmentation. This lets the default `useRegle` composable know about your custom rules and shortcut properties.\n\n```ts [regle.config.ts]\nimport { createRule } from '@regle/core';\n\nconst customRule = createRule({\n validator: (value: unknown) => value === 'custom',\n message: 'Custom rule',\n});\n\ndeclare module '@regle/core' {\n interface CustomRules {\n customRule: typeof customRule;\n }\n interface CustomFieldProperties {\n $isRequired: boolean;\n }\n interface CustomNestedProperties {\n $isEmpty: boolean;\n }\n interface CustomCollectionProperties {\n $isEmpty: boolean;\n }\n}\n```\n\n### Combining with composable configuration\n\nIf both the plugin options and a `defineRegleConfig` composable are used, the composable's configuration takes precedence and is merged on top of the plugin's. This lets you set app-wide defaults via the plugin while still allowing scoped overrides where needed.\n\n## Override default behaviors\n\nYou can override the default behaviors of Regle processors by using the `overrides` property. This works with both the composable and declarative approaches.\n\n### `isEdited`\n\nOverride the default `$edited` property handler. Useful to handle custom comparisons for complex object types.\n\n:::warning\nIt's highly recommended to use this override with the [`markStatic`](/advanced-usage/immutable-constructors) helper to handle immutable constructors.\n:::\n\n```ts\nimport { defineRegleConfig } from '@regle/core';\nimport { Decimal } from 'decimal.js';\n\nexport const { useRegle: useCustomRegle } = defineRegleConfig({\n overrides: {\n isEdited(currentValue, initialValue, defaultHandlerFn) {\n if (currentValue instanceof Decimal && initialValue instanceof Decimal) {\n return currentValue.toNearest(0.01).toString() !== initialValue.toNearest(0.01).toString();\n }\n // fallback to the default handler\n return defaultHandlerFn(currentValue, initialValue);\n },\n },\n})\n\n// Or with the declarative approach\nimport { defineRegleOptions } from '@regle/core';\n\nconst options = defineRegleOptions({\n overrides: {\n isEdited: (currentValue, initialValue, defaultHandlerFn) => {\n return currentValue !== initialValue;\n },\n },\n});\n\napp.use(RegleVuePlugin, options);\n```"
|
|
23
23
|
},
|
|
24
24
|
{
|
|
25
25
|
"id": "advanced-usage-immutable-constructors",
|
|
@@ -131,7 +131,7 @@ const rawData = {
|
|
|
131
131
|
"title": "Modifiers",
|
|
132
132
|
"category": "core-concepts",
|
|
133
133
|
"path": "core-concepts/modifiers.md",
|
|
134
|
-
"content": "# Modifiers\n\nModifiers allow you to control the behavior and settings of validation rules in your application. They can be applied globally to all fields or customized per field.\n\n## Deep modifiers\n\nDeep modifiers are specified as the third argument of the `useRegle` composable. They apply recursively to all fields within your state.\n\n```ts\nconst { r$ } = useRegle({}, {}, {\n /* modifiers */\n})\n```\n\n### `autoDirty`\n\n__Type__: `boolean`\n\n__Default__: `true`\n\nAutomatically set the dirty state to `true` when the value changes.\n\n### `immediateDirty`\n\n__Type__: `boolean | 'eager' | 'non-empty' | 'lazy-non-empty'`\n\n__Default__: `false`\n\nSet the dirty state to `true` when the form is initialized.\n\n- `true` or `'eager'`: touch the whole form on mount.\n- `'non-empty'`: touch the whole form on mount only if one of the initial values is non-empty.\n- `'lazy-non-empty'`: touch only the fields that are non-empty on mount.\n\n### `disabled`\n\n__Type__: `boolean`\n\n__Default__: `false`\n\nTemporarily pauses Regle reactivity and validation computation.\n\nWhen `disabled` is `true`, state changes still happen, but validation status does not update until you enable it again.\n\n```ts\nimport { ref } from 'vue';\nimport { useRegle } from '@regle/core';\nimport { required } from '@regle/rules';\n\nconst disabled = ref(false);\n\nconst { r$ } = useRegle(\n { name: '' },\n { name: { required } },\n { disabled }\n);\n\ndisabled.value = true;\nr$.$value.name = 'John'; // value updates, validation is paused\n\ndisabled.value = false; // validation reactivity resumes\n```\n\n### `silent`\n\n__Type__: `boolean`\n\n__Default__: `false`\n\nRegle Automatically tracks changes in the state for all nested rules. If set to `true`, you must manually call `$touch` or `$validate` to display errors.\n\n### `lazy`\n\n__Type__: `boolean`\n\n__Default__: `false`\n\nUsage:\n\nWhen set to false, tells the rules to be called on init, otherwise they are lazy and only called when the field is dirty.\n\n### `externalErrors`\n\n__Type__: `RegleExternalErrorTree<State>` \n\nPass an object, matching your error state, that holds external validation errors. These can be from a backend validations or something else.\n\nCheck the [External errors](/common-usage/external-errors) section for more details.\n\n### `externalIssues`\n\n__Type__: `RegleExternalIssueTree<State>`\n\nPass an object, matching your state, that holds structured external validation issues. Each issue keeps its metadata in `$issues`, and its `$message` is also exposed through `$errors`.\n\n`externalIssues` and `externalErrors` are mutually exclusive. Setting one clears the other.\n\nCheck the [External errors and issues](/common-usage/external-errors) section for more details.\n\n### `rewardEarly`\n\n__Type__: `boolean`\n\n__Default__: `false`\n\n__Side effect__: disable `$autoDirty` when `true`.\n\nEnables the `reward-early-punish-late` mode of Regle. This mode will not set fields as invalid once they are valid, unless manually triggered by `$validate` method.\n\nThis has no effect when `autoDirty` is set to `true` (the default). Set `autoDirty: false` for `rewardEarly` to take effect.\n\n### `clearExternalErrorsOnChange`\n\n__Type__: `boolean`\n\n__Default__: `true`\n\nThis mode is similar to `rewardEarly`, but only applies to external errors.\nSetting it to `false` will keep the server errors and issues until `$clearExternalErrors` or `$clearExternalIssues` is called.\n\n### `clearExternalErrorsOnValidate`\n\n__Type__: `boolean`\n\n__Default__: `false`\n\nThis mode is similar to `clearExternalErrorsOnChange`, but for the `$validate` and `$validateSync` methods.\nSetting it to `false` will keep the server errors and issues until `$clearExternalErrors` or `$clearExternalIssues` is called manually, or `externalErrors` / `externalIssues` is set again.\n\n### `validationGroups`\n\n__Type__: `(fields) => Record<string, (RegleFieldStatus |RegleCollectionStatus)[]>`\n\nValidation groups let you merge field properties under one, to better handle validation status.\n\nYou will have access to your declared groups in the `r$.$groups` object.\n\n```ts twoslash\n\nimport { ref } from 'vue';\n// ---cut---\nimport { useRegle } from '@regle/core';\nimport { required } from '@regle/rules';\n\nconst { r$ } = useRegle({ email: '', user: { firstName: '' } }, {\n email: { required },\n user: {\n firstName: { required },\n }\n}, {\n validationGroups: (fields) => ({\n group1: [fields.email, fields.user.firstName]\n })\n})\n\nr$.$groups.group1.\n\n```\n<br><br><br><br>\n\n## Per-field modifiers\n\nPer-field modifiers allow to customize more precisely which behavior you want for each field.\n\n```ts twoslash\n\nimport { useRegle } from '@regle/core';\n// ---cut---\nconst { r$ } = useRegle({ name: '' }, {\n name: { $ }\n\n})\n```\n\n<br><br>\n\n`$autoDirty` `$lazy`, `$silent`, `$immediateDirty` and `$rewardEarly` work the same as the deep modifiers.\n\n### `$debounce`\nType: `number` (ms)\n\nThis let you declare the number of milliseconds the rule needs to wait before executing. Useful for async or heavy computations.\n\n:::tip\nAll async rules have a default debounce of `200ms`, you can disable or modify this setting with `$debounce`\n:::\n\n### `$isEdited`\nType: `(currentValue: MaybeInput<TValue>, initialValue: MaybeInput<TValue>, defaultHandlerFn: (currentValue: unknown, initialValue: unknown) => boolean) => boolean`\n\nOverride the default `$edited` property handler. Useful to handle custom comparisons for complex object types.\n\n:::warning\nIt's highly recommended to use this modifier with the [`markStatic`](/advanced-usage/immutable-constructors) helper to handle immutable constructors.\n:::\n\n```ts\nimport { markStatic, useRegle } from '@regle/core';\nimport { Decimal } from 'decimal.js';\nimport { required } from '@regle/rules';\n\nconst { r$ } = useRegle({ decimal: markStatic(new Decimal(1)) }, {\n decimal: {\n required,\n $isEdited(currentValue, initialValue, defaultHandlerFn) {\n if (currentValue != null && initialValue != null) {\n return currentValue.toNearest(0.01).toString() !== initialValue.toNearest(0.01).toString();\n }\n // fallback to the default handler\n return defaultHandlerFn(currentValue, initialValue);\n },\n },\n})\n```\n\n## Array specific modifiers\n\nThis modifiers are only impacting Array collections.\n\n```ts\nconst { r$ } = useRegle({ collection: [] }, {\n collection: { /** Deep modifiers */ }\n})\n```\n\n### `$deepCompare`\nType: `boolean`\n\nDefault: `false`\n\nAllow deep compare of array children to compute the `$edited` property.\n\nIt's disabled by default for performance reasons."
|
|
134
|
+
"content": "# Modifiers\n\nModifiers allow you to control the behavior and settings of validation rules in your application. They can be applied globally to all fields or customized per field.\n\n## Deep modifiers\n\nDeep modifiers are specified as the third argument of the `useRegle` composable. They apply recursively to all fields within your state.\n\n```ts\nconst { r$ } = useRegle({}, {}, {\n /* modifiers */\n})\n```\n\n### `autoDirty`\n\n__Type__: `boolean`\n\n__Default__: `true`\n\nAutomatically set the dirty state to `true` when the value changes.\n\n### `immediateDirty`\n\n__Type__: `boolean | 'eager' | 'non-empty' | 'lazy-non-empty'`\n\n__Default__: `false`\n\nSet the dirty state to `true` when the form is initialized.\n\n- `true` or `'eager'`: touch the whole form on mount.\n- `'non-empty'`: touch the whole form on mount only if one of the initial values is non-empty.\n- `'lazy-non-empty'`: touch only the fields that are non-empty on mount.\n\n### `disabled`\n\n__Type__: `boolean`\n\n__Default__: `false`\n\nTemporarily pauses Regle reactivity and validation computation.\n\nWhen `disabled` is `true`, state changes still happen, but validation status does not update until you enable it again.\n\n```ts\nimport { ref } from 'vue';\nimport { useRegle } from '@regle/core';\nimport { required } from '@regle/rules';\n\nconst disabled = ref(false);\n\nconst { r$ } = useRegle(\n { name: '' },\n { name: { required } },\n { disabled }\n);\n\ndisabled.value = true;\nr$.$value.name = 'John'; // value updates, validation is paused\n\ndisabled.value = false; // validation reactivity resumes\n```\n\n### `silent`\n\n__Type__: `boolean`\n\n__Default__: `false`\n\nRegle Automatically tracks changes in the state for all nested rules. If set to `true`, you must manually call `$touch` or `$validate` to display errors.\n\n### `lazy`\n\n__Type__: `boolean`\n\n__Default__: `false`\n\nUsage:\n\nWhen set to false, tells the rules to be called on init, otherwise they are lazy and only called when the field is dirty.\n\n### `debounce`\n\n__Type__: `number` (ms)\n\n__Default__: `200` (for fields with async rules)\n\nNumber of milliseconds every async field should wait before executing its rules. It applies to every async field in your form.\n\nThe per-field [`$debounce`](#debounce-1) modifier always takes priority over this global value.\n\nSet to `0` to disable the default debounce on async rules.\n\n### `externalErrors`\n\n__Type__: `RegleExternalErrorTree<State>` \n\nPass an object, matching your error state, that holds external validation errors. These can be from a backend validations or something else.\n\nCheck the [External errors](/common-usage/external-errors) section for more details.\n\n### `externalIssues`\n\n__Type__: `RegleExternalIssueTree<State>`\n\nPass an object, matching your state, that holds structured external validation issues. Each issue keeps its metadata in `$issues`, and its `$message` is also exposed through `$errors`.\n\n`externalIssues` and `externalErrors` are mutually exclusive. Setting one clears the other.\n\nCheck the [External errors and issues](/common-usage/external-errors) section for more details.\n\n### `rewardEarly`\n\n__Type__: `boolean`\n\n__Default__: `false`\n\n__Side effect__: disable `$autoDirty` when `true`.\n\nEnables the `reward-early-punish-late` mode of Regle. This mode will not set fields as invalid once they are valid, unless manually triggered by `$validate` method.\n\nThis has no effect when `autoDirty` is set to `true` (the default). Set `autoDirty: false` for `rewardEarly` to take effect.\n\n### `clearExternalErrorsOnChange`\n\n__Type__: `boolean`\n\n__Default__: `true`\n\nThis mode is similar to `rewardEarly`, but only applies to external errors.\nSetting it to `false` will keep the server errors and issues until `$clearExternalErrors` or `$clearExternalIssues` is called.\n\n### `clearExternalErrorsOnValidate`\n\n__Type__: `boolean`\n\n__Default__: `false`\n\nThis mode is similar to `clearExternalErrorsOnChange`, but for the `$validate` and `$validateSync` methods.\nSetting it to `false` will keep the server errors and issues until `$clearExternalErrors` or `$clearExternalIssues` is called manually, or `externalErrors` / `externalIssues` is set again.\n\n### `validationGroups`\n\n__Type__: `(fields) => Record<string, (RegleFieldStatus |RegleCollectionStatus)[]>`\n\nValidation groups let you merge field properties under one, to better handle validation status.\n\nYou will have access to your declared groups in the `r$.$groups` object.\n\n```ts twoslash\n\nimport { ref } from 'vue';\n// ---cut---\nimport { useRegle } from '@regle/core';\nimport { required } from '@regle/rules';\n\nconst { r$ } = useRegle({ email: '', user: { firstName: '' } }, {\n email: { required },\n user: {\n firstName: { required },\n }\n}, {\n validationGroups: (fields) => ({\n group1: [fields.email, fields.user.firstName]\n })\n})\n\nr$.$groups.group1.\n\n```\n<br><br><br><br>\n\n## Per-field modifiers\n\nPer-field modifiers allow to customize more precisely which behavior you want for each field.\n\n```ts twoslash\n\nimport { useRegle } from '@regle/core';\n// ---cut---\nconst { r$ } = useRegle({ name: '' }, {\n name: { $ }\n\n})\n```\n\n<br><br>\n\n`$autoDirty` `$lazy`, `$silent`, `$immediateDirty` and `$rewardEarly` work the same as the deep modifiers.\n\n### `$debounce`\nType: `number` (ms)\n\nThis let you declare the number of milliseconds the rule needs to wait before executing. Useful for async or heavy computations.\n\nIt takes priority over the global [`debounce`](#debounce) deep modifier.\n\n:::tip\nAll async rules have a default debounce of `200ms`, you can disable or modify this setting with `$debounce`\n:::\n\n### `$isEdited`\nType: `(currentValue: MaybeInput<TValue>, initialValue: MaybeInput<TValue>, defaultHandlerFn: (currentValue: unknown, initialValue: unknown) => boolean) => boolean`\n\nOverride the default `$edited` property handler. Useful to handle custom comparisons for complex object types.\n\n:::warning\nIt's highly recommended to use this modifier with the [`markStatic`](/advanced-usage/immutable-constructors) helper to handle immutable constructors.\n:::\n\n```ts\nimport { markStatic, useRegle } from '@regle/core';\nimport { Decimal } from 'decimal.js';\nimport { required } from '@regle/rules';\n\nconst { r$ } = useRegle({ decimal: markStatic(new Decimal(1)) }, {\n decimal: {\n required,\n $isEdited(currentValue, initialValue, defaultHandlerFn) {\n if (currentValue != null && initialValue != null) {\n return currentValue.toNearest(0.01).toString() !== initialValue.toNearest(0.01).toString();\n }\n // fallback to the default handler\n return defaultHandlerFn(currentValue, initialValue);\n },\n },\n})\n```\n\n## Array specific modifiers\n\nThis modifiers are only impacting Array collections.\n\n```ts\nconst { r$ } = useRegle({ collection: [] }, {\n collection: { /** Deep modifiers */ }\n})\n```\n\n### `$deepCompare`\nType: `boolean`\n\nDefault: `false`\n\nAllow deep compare of array children to compute the `$edited` property.\n\nIt's disabled by default for performance reasons."
|
|
135
135
|
},
|
|
136
136
|
{
|
|
137
137
|
"id": "core-concepts-rules-built-in-rules",
|
|
@@ -2002,7 +2002,7 @@ function searchApi(query) {
|
|
|
2002
2002
|
});
|
|
2003
2003
|
return results;
|
|
2004
2004
|
}
|
|
2005
|
-
var version = "1.
|
|
2005
|
+
var version = "1.28.0-beta.1";
|
|
2006
2006
|
let posthogClient = null;
|
|
2007
2007
|
posthogClient = new PostHog("phc_kqgJoylCpKkGkkRGxb4MyN2mViehoQcUFEGwVkk4l8E", {
|
|
2008
2008
|
host: "https://eu.i.posthog.com",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@regle/mcp-server",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.28.0-beta.1",
|
|
4
4
|
"description": "MCP Server for Regle",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ai",
|
|
@@ -49,14 +49,14 @@
|
|
|
49
49
|
},
|
|
50
50
|
"dependencies": {
|
|
51
51
|
"@modelcontextprotocol/sdk": "1.29.0",
|
|
52
|
-
"posthog-node": "5.
|
|
52
|
+
"posthog-node": "5.37.0",
|
|
53
53
|
"zod": "4.4.3"
|
|
54
54
|
},
|
|
55
55
|
"devDependencies": {
|
|
56
|
-
"@types/node": "24.
|
|
57
|
-
"@typescript/native-preview": "7.0.0-dev.
|
|
56
|
+
"@types/node": "24.13.2",
|
|
57
|
+
"@typescript/native-preview": "7.0.0-dev.20260616.1",
|
|
58
58
|
"dotenv": "17.4.2",
|
|
59
|
-
"tsdown": "0.22.
|
|
59
|
+
"tsdown": "0.22.2",
|
|
60
60
|
"tsx": "4.22.4",
|
|
61
61
|
"typescript": "6.0.3"
|
|
62
62
|
},
|