@regle/mcp-server 1.19.0-beta.4 β 1.19.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 +6 -6
- package/package.json +4 -4
package/dist/regle-mcp-server.js
CHANGED
|
@@ -146,14 +146,14 @@ var docs_data_default = {
|
|
|
146
146
|
"title": "Rules",
|
|
147
147
|
"category": "rules",
|
|
148
148
|
"path": "core-concepts/rules/index.md",
|
|
149
|
-
"content": "# Rules\n\nRules are the core
|
|
149
|
+
"content": "# Rules\n\nRules are the core building block of Regle (and also its name).\n\nA rule takes a value (and optional parameters) as input and returns a validation result as output.\n\nThe **result** can be either:\n\n- A `boolean`\n- An object containing at least `{ $valid: boolean }` (allowing you to attach [metadata](/advanced-usage/rule-metadata))\n\n## Reusable rules with `createRule`\n\nThe recommended way to write rules in Regle is with `createRule`. It provides a structured definition that includes the validator logic, an error message, and optional configuration β all in one place.\n\n```ts\nimport { createRule, type Maybe } from '@regle/core';\nimport { isFilled } from '@regle/rules';\n\nexport const mustBe = createRule({\n validator(value: Maybe<string>, expected: string) {\n if (isFilled(value)) {\n return value === expected;\n }\n return true;\n },\n message: ({ $params: [expected] }) => `The value must be '${expected}'`,\n});\n\n// Rule can now accept reactive parameters\nconst expected = ref('foo');\n\nconst { r$ } = useRegle({ name: '' }, {\n name: {\n mustBe: mustBe(expected),\n // or\n mustBe: mustBe(() => expected.value),\n },\n});\n```\n\nRules created with `createRule` can accept reactive parameters, return custom metadata, run async logic, and more.\n\n:::tip\nHead to the [Reusable rules](/core-concepts/rules/reusable-rules) page for the full guide on `createRule`, including parameters, reactivity, async rules, and metadata.\n:::\n\n## Inline rules\n\nFor quick, one-off validations, you can write rules directly as inline functions. The function receives the current field value as its first argument.\n\nSimple rule:\n\n```ts\nconst { r$ } = useRegle({ name: '' }, {\n name: {\n simpleRule: (value) => value === 'regle',\n },\n})\n```\n\nAsync rule:\n\n```ts\nconst { r$ } = useRegle({ name: '' }, {\n name: {\n asyncRule: async (value) => await someAsyncCall(),\n },\n})\n```\n\nRule with metadata:\n\n```ts\nconst { r$ } = useRegle({ name: '' }, {\n name: {\n metadataRule: (value) => ({\n $valid: value === 'regle',\n foo: 'bar',\n }),\n },\n})\n```\n\n## Adding error messages\n\nAny rule β inline or reusable β can be wrapped with the `withMessage` helper to associate an error message with it.\n\n```ts\nimport { withMessage } from '@regle/rules';\n\nconst { r$ } = useRegle({ name: '' }, {\n name: {\n foo: withMessage((value: Maybe<string>) => value === 'foo', \"Value must be 'foo'\"),\n },\n})\n```\n\n:::tip\nLearn more about `withMessage` and other wrappers in the [Rule wrappers](/core-concepts/rules/rule-wrappers) section.\n:::\n\n## Handling `optional` and `required` rules\n\nIn Regle (borrowed from Vuelidate), all rules are **optional by default**. This means a rule will only run when the field has a value.\n\nThe only exceptions are:\n\n- `required`\n- `checked`\n- `literal`\n\nThis separation keeps the validation logic clean: you define *how* a field should be validated independently from *whether* it's mandatory.\n\nWhen writing custom rules, follow the same convention by checking if the value is filled before validating:\n\n```ts\nimport { isFilled } from '@regle/rules';\n\nconst { r$ } = useRegle({ name: '' }, {\n name: {\n mustBeFoo: (value) => {\n return isFilled(value) && value === 'foo';\n },\n },\n})\n```"
|
|
150
150
|
},
|
|
151
151
|
{
|
|
152
152
|
"id": "core-concepts-rules-reusable-rules",
|
|
153
153
|
"title": "Reusable rules",
|
|
154
154
|
"category": "rules",
|
|
155
155
|
"path": "core-concepts/rules/reusable-rules.md",
|
|
156
|
-
"content": "# Reusable rules\n\n## `createRule`\n\nTo create reusable rules, itβs recommended to use `createRule`. This utility simplifies defining the ruleβs type, parameters, active state as well as track reactive dependencies automatically.\n\nExample: Recreating a simple `required` rule\n\n```ts\nimport { createRule } from '@regle/core';\nimport { isFilled } from '@regle/rules';\n\nexport const required = createRule({\n validator: (value: unknown) => {\n return isFilled(value);\n },\n message: 'This field is required',\n});\n```\n\n## Available options:\n\n### `validator`\n_**Type**_: `(value, ...params?) => boolean | {$valid: boolean, [x: string]: any}`\n\n*required*\n\nThe `validator` function determines whether the field is valid. You can write it in the same way as an inline rule.\n\n### `message`\n_**Type**_: `string | string[] | (metadata) => (string | string[])`\n\n*required*\n\nThis will define what error message you assign to your rule. It can be a string or a function receiving the value, params and metadata as parameters.\n\n### `type` \n_**Type**_: `string`\n\n*optional*\n\nSpecifies the type of validator. This is useful when multiple rules share the same target, such as `required` and `requiredIf`.\n\n### `active`\n_**Type**_: `boolean | (metadata) => boolean`\n\n*optional*\n\nDefines the `$active` state of the rule, indicating whether the rule is currently being validated. This can be computed dynamically.\nFor more details, see [Parameters and active mode](#parameters-and-active-mode).\n\n### `async`\n_**Type**_: `boolean`\n\n*optional*\n\nIf your validator function is not written with `async await` syntax, you can enforce the rule to be async with this parameter.\n\n### `tooltip`\n_**Type**_: `string | string[] | (metadata) => (string | string[])`\n\n*optional*\n\nUse `tooltip` to display non-error-related messages for your field. These tooltips are aggregated and made accessible via `xxx.$tooltips`. This is useful for providing additional information or guidance.\n\n## Reactive parameters\n\nWith `createRule` you can easily define a rule that will depend on external reactive parameters.\n\n### Declaration\n\nWhen declaring your validator, **Regle** will detect that your rule requires parameters and transform it into a function declaration:\n\n```ts\nimport { createRule, type Maybe } from '@regle/core';\n\nexport const myValidator = createRule({\n validator: (value: Maybe<string>, arg: number) => {\n return true;\n },\n message: ({ $params: [arg] }) => {\n return 'This field is invalid';\n }\n});\n```\n\nThe parameters detection also works with optional and spread parameters\n\n```ts\nimport { createRule, type Maybe } from '@regle/core';\n\nexport const myValidator = createRule({\n validator: (value: Maybe<string>, optionalArg?: number, otherOptional?: string) => {\n return true;\n },\n message: ({ $params: [optionalArg, otherOptional] }) => {\n return 'This field is invalid';\n }\n});\n\nconst {r$} = useRegle({foo: ''}, {\n foo: {\n // Can be used inline if first parameter is optional\n myValidator,\n // or\n myValidator: myValidator(5),\n // or\n myValidator: myValidator(5, 'foo');\n }\n})\n```\n\n:::warning\n\nWhile adding spread parameters `...anyOtherArg` is supported, keep in mind that it will receive every parameters, even the ones injected by a parent modifier like `applyIf`, `and`, `or` etc..\n\nSo it's not advised to use it\n:::\n\n### Reactivity\n\nThe real advantage of using `createRule` is that it automatically registers parameters as reactive dependencies. This means your rule works seamlessly with plain values, refs, or getter functions.\n\n```ts\nconst max = ref(5);\n\nuseRegle({name: ''},{\n name: {\n // Plain value\n rule1: myValidator(5),\n // Ref\n rule2: myValidator(max),\n // Getter value\n rule3: myValidator(() => max.value)\n }\n})\n```\n\n:::warning\nIf you pass a raw value as a parameter, it will only be reactive if all your rules are declared as a computed or a getter function\n\n```ts\nconst state = ref({name: ''})\nconst max = ref(5);\n\n// β Not reactive\nuseRegle(state, {\n name: {\n maxLength: maxLength(max.value),\n ...(max.value === 3 && {\n required,\n })\n }\n})\n\n// β
Reactive\nuseRegle(state, () => ({\n name: {\n maxLength: maxLength(max.value),\n ...(max.value === 3 && {\n required,\n })\n }\n}))\n\n// β
Reactive\nconst rules = computed(() => ({\n name: {\n maxLength: maxLength(max.value),\n ...(max.value === 3 && {\n required,\n })\n }\n}))\nuseRegle(state, rules);\n\n```\n:::\n\n### Active property\n\nThe `active` property option is a field that will provide the rule an `on/off` behaviour.\n\nSome rules have conditional validation properties, such as `requiredIf` or any rule using `applyIf`.\nThis property allows you to declare the active state of the rule.\n\nIt will then be exposed in the `$active` rule property and be used to reflect the validation to your user.\n\n```ts\nimport { createRule, useRegle } from '@regle/core';\n\nconst myConditionalRule = createRule({\n validator(value: unknown, param: string) {\n // Params like `condition` will always be unwrapped here\n // no need to check if it's a value, a ref or a getter function\n if (param === \"Yes\") {\n return isFilled(value);\n }\n return true;\n },\n active({ $params: [condition] }) {\n return condition === 'Yes';\n },\n});\n```\n\nUsage in a component:\n\n```vue\n\n<template>\n <label>\n Name <span v-if=\"r$.name.$rules.myConditionalRule.$active\">(required)</span>\n </label>\n</template>\n\n```\n\n### Recreating `requiredIf` rule\n\n::: code-group\n\n```vue [Form.vue]\n\n<template>\n <div>\n <input v-model=\"condition\" type='checkbox'/>\n <label>The field is required</label>\n </div>\n\n <div>\n <!-- Here we can use $active to know if the rule is enabled -->\n <input \n v-model='form.name'\n :placeholder='`Type your name${r$.name.$rules.required.$active ? \"*\": \"\"}`'\n />\n\n <button type=\"button\" @click=\"r$.$reset({toInitialState: true})\">Reset</button>\n </div>\n\n <ul v-if=\"r$.$errors.name.length\">\n <li v-for=\"error of r$.$errors.name\" :key='error'>\n {{ error }}\n </li>\n </ul>\n</template>\n```\n:::\n\nResult: \n\n## Async rules\n\nAsync rules are useful for server-side validations or computationally expensive local checks. They update the `$pending` state whenever invoked.\n\n```vue [App.vue]\n<template>\n <div class=\"demo-container\">\n <div>\n <input\n v-model=\"form.email\"\n :class=\"{ pending: r$.email.$pending }\"\n placeholder=\"Type your email\"\n />\n\n <button type=\"button\" @click=\"r$.$reset({toInitialState: true})\">Reset</button>\n <button type=\"button\" @click=\"r$.$validate()\">Submit</button>\n </div>\n\n <span v-if=\"r$.email.$pending\"> Checking... </span>\n \n <ul v-if=\"r$.$errors.email.length\">\n <li v-for=\"error of r$.$errors.email\" :key=\"error\">\n {{ error }}\n </li>\n </ul>\n </div>\n</template>\n\n```\n\n## Metadata\n\nLike in inline rules, you can return any data from your validator function as long as it returns an object containing at least `$valid: boolean`.\n\nIt can be useful for returning computed data from the validator, or in async function to process api result, or api errors.\n\n```ts twoslash {8}\nimport { createRule } from '@regle/core';\n\nexport const example = createRule({\n validator: (value) => {\n if (value === 'regle') {\n return {\n $valid: false,\n foo: 'bar'\n }\n }\n return true;\n },\n message({foo}) {\n\n return 'Error example';\n },\n});\n```"
|
|
156
|
+
"content": "# Reusable rules\n\n## `createRule`\n\nTo create reusable rules, itβs recommended to use `createRule`. This utility simplifies defining the ruleβs type, parameters, active state as well as track reactive dependencies automatically.\n\nExample: Recreating a simple `required` rule\n\n```ts\nimport { createRule } from '@regle/core';\nimport { isFilled } from '@regle/rules';\n\nexport const required = createRule({\n validator: (value: unknown) => {\n return isFilled(value);\n },\n message: 'This field is required',\n});\n```\n\n## Available options:\n\n### `validator`\n_**Type**_: `(value, ...params?) => boolean | {$valid: boolean, [x: string]: any}`\n\n*required*\n\nThe `validator` function determines whether the field is valid. You can write it in the same way as an inline rule.\n\n### `message`\n_**Type**_: `string | string[] | (metadata) => (string | string[])`\n\n*required*\n\nThis will define what error message you assign to your rule. It can be a string or a function receiving the value, params and metadata as parameters.\n\n### `type` \n_**Type**_: `string`\n\n*optional*\n\nSpecifies the type of validator. This is useful when multiple rules share the same target, such as `required` and `requiredIf`.\n\n### `active`\n_**Type**_: `boolean | (metadata) => boolean`\n\n*optional*\n\nDefines the `$active` state of the rule, indicating whether the rule is currently being validated. This can be computed dynamically.\nFor more details, see [Parameters and active mode](#parameters-and-active-mode).\n\n### `async`\n_**Type**_: `boolean`\n\n*optional*\n\nIf your validator function is not written with `async await` syntax, you can enforce the rule to be async with this parameter.\n\n### `tooltip`\n_**Type**_: `string | string[] | (metadata) => (string | string[])`\n\n*optional*\n\nUse `tooltip` to display non-error-related messages for your field. These tooltips are aggregated and made accessible via `xxx.$tooltips`. This is useful for providing additional information or guidance.\n\n## Reactive parameters\n\nWith `createRule` you can easily define a rule that will depend on external reactive parameters.\n\n### Declaration\n\nWhen declaring your validator, **Regle** will detect that your rule requires parameters and transform it into a function declaration:\n\n```ts\nimport { createRule, type Maybe } from '@regle/core';\n\nexport const myValidator = createRule({\n validator: (value: Maybe<string>, arg: number) => {\n return true;\n },\n message: ({ $params: [arg] }) => {\n return 'This field is invalid';\n }\n});\n```\n\nThe parameters detection also works with optional and spread parameters\n\n```ts\nimport { createRule, type Maybe } from '@regle/core';\n\nexport const myValidator = createRule({\n validator: (value: Maybe<string>, optionalArg?: number, otherOptional?: string) => {\n return true;\n },\n message: ({ $params: [optionalArg, otherOptional] }) => {\n return 'This field is invalid';\n }\n});\n\nconst {r$} = useRegle({foo: ''}, {\n foo: {\n // Can be used inline if first parameter is optional\n myValidator,\n // or\n myValidator: myValidator(5),\n // or\n myValidator: myValidator(5, 'foo');\n }\n})\n```\n\n:::warning\n\nWhile adding spread parameters `...anyOtherArg` is supported, keep in mind that it will receive every parameters, even the ones injected by a parent modifier like `applyIf`, `and`, `or` etc..\n\nSo it's not advised to use it\n:::\n\n### Reactivity\n\nThe real advantage of using `createRule` is that it automatically registers parameters as reactive dependencies. This means your rule works seamlessly with plain values, refs, or getter functions.\n\n```ts\nconst max = ref(5);\n\nuseRegle({name: ''},{\n name: {\n // Plain value\n rule1: myValidator(5),\n // Ref\n rule2: myValidator(max),\n // Getter value\n rule3: myValidator(() => max.value)\n }\n})\n```\n\n:::warning\nIf you pass a raw value as a parameter, it will only be reactive if all your rules are declared as a computed or a getter function\n\n```ts\nconst state = ref({name: ''})\nconst max = ref(5);\n\n// β Not reactive\nuseRegle(state, {\n name: {\n maxLength: maxLength(max.value),\n ...(max.value === 3 && {\n required,\n })\n }\n})\n\n// β
Reactive\nuseRegle(state, () => ({\n name: {\n maxLength: maxLength(max.value),\n ...(max.value === 3 && {\n required,\n })\n }\n}))\n\n// β
Reactive\nconst rules = computed(() => ({\n name: {\n maxLength: maxLength(max.value),\n ...(max.value === 3 && {\n required,\n })\n }\n}))\nuseRegle(state, rules);\n\n```\n:::\n\n### Default values\n\nYou can set default value directly in the rule declaration. Be sure to type it correctly.\n\nThere will be difference in implementation if you want to access the parameter value in the message factory function as a function scope is undereadble from outside its scope.\n\nYou'll have to return explicitly the default value in the validator function, and declare the parameter as metadata.\n\n```ts\nexport const myValidator = createRule({\n validator: (value: Maybe<number>, arg: number = 0) => {\n return {\n $valid: value === arg,\n arg,\n };\n },\n message: ({ arg }) => `The value must be ${arg}`,\n});\n```\n\n### Active property\n\nThe `active` property option is a field that will provide the rule an `on/off` behaviour.\n\nSome rules have conditional validation properties, such as `requiredIf` or any rule using `applyIf`.\nThis property allows you to declare the active state of the rule.\n\nIt will then be exposed in the `$active` rule property and be used to reflect the validation to your user.\n\n```ts\nimport { createRule, useRegle } from '@regle/core';\n\nconst myConditionalRule = createRule({\n validator(value: unknown, param: string) {\n // Params like `condition` will always be unwrapped here\n // no need to check if it's a value, a ref or a getter function\n if (param === \"Yes\") {\n return isFilled(value);\n }\n return true;\n },\n active({ $params: [condition] }) {\n return condition === 'Yes';\n },\n});\n```\n\nUsage in a component:\n\n```vue\n\n<template>\n <label>\n Name <span v-if=\"r$.name.$rules.myConditionalRule.$active\">(required)</span>\n </label>\n</template>\n\n```\n\n### Recreating `requiredIf` rule\n\n::: code-group\n\n```vue [Form.vue]\n\n<template>\n <div>\n <input v-model=\"condition\" type='checkbox'/>\n <label>The field is required</label>\n </div>\n\n <div>\n <!-- Here we can use $active to know if the rule is enabled -->\n <input \n v-model='form.name'\n :placeholder='`Type your name${r$.name.$rules.required.$active ? \"*\": \"\"}`'\n />\n\n <button type=\"button\" @click=\"r$.$reset({toInitialState: true})\">Reset</button>\n </div>\n\n <ul v-if=\"r$.$errors.name.length\">\n <li v-for=\"error of r$.$errors.name\" :key='error'>\n {{ error }}\n </li>\n </ul>\n</template>\n```\n:::\n\nResult: \n\n## Async rules\n\nAsync rules are useful for server-side validations or computationally expensive local checks. They update the `$pending` state whenever invoked.\n\n```vue [App.vue]\n<template>\n <div class=\"demo-container\">\n <div>\n <input\n v-model=\"form.email\"\n :class=\"{ pending: r$.email.$pending }\"\n placeholder=\"Type your email\"\n />\n\n <button type=\"button\" @click=\"r$.$reset({toInitialState: true})\">Reset</button>\n <button type=\"button\" @click=\"r$.$validate()\">Submit</button>\n </div>\n\n <span v-if=\"r$.email.$pending\"> Checking... </span>\n \n <ul v-if=\"r$.$errors.email.length\">\n <li v-for=\"error of r$.$errors.email\" :key=\"error\">\n {{ error }}\n </li>\n </ul>\n </div>\n</template>\n\n```\n\n## Metadata\n\nLike in inline rules, you can return any data from your validator function as long as it returns an object containing at least `$valid: boolean`.\n\nIt can be useful for returning computed data from the validator, or in async function to process api result, or api errors.\n\n```ts twoslash {8}\nimport { createRule } from '@regle/core';\n\nexport const example = createRule({\n validator: (value) => {\n if (value === 'regle') {\n return {\n $valid: false,\n foo: 'bar'\n }\n }\n return true;\n },\n message({foo}) {\n\n return 'Error example';\n },\n});\n```"
|
|
157
157
|
},
|
|
158
158
|
{
|
|
159
159
|
"id": "core-concepts-rules-rule-wrappers",
|
|
@@ -841,7 +841,7 @@ var docs_data_default = {
|
|
|
841
841
|
"optional": true
|
|
842
842
|
}
|
|
843
843
|
],
|
|
844
|
-
"returnType": "TRulesDelc",
|
|
844
|
+
"returnType": "MapRulesToUnsafeRules<TRulesDelc>",
|
|
845
845
|
"example": "import { required, email, minLength, assignIf } from '@regle/rules';\n\nconst condition = ref(false);\n\nconst { r$ } = useRegle(ref({ name: '', email: '' }), {\n name: assignIf(condition, { required, minLength: minLength(4) }),\n email: { email },\n});",
|
|
846
846
|
"tags": { "see": "://reglejs.dev/core-concepts/rules/rules-operators#assignif Documentation" }
|
|
847
847
|
},
|
|
@@ -851,11 +851,11 @@ var docs_data_default = {
|
|
|
851
851
|
"description": "Checks if at least one key is filled in the object.",
|
|
852
852
|
"parameters": [{
|
|
853
853
|
"name": "keys",
|
|
854
|
-
"type": "MaybeRefOrGetter<(NoInfer<keyof T> & string)[]>",
|
|
854
|
+
"type": "MaybeRefOrGetter<readonly (NoInfer<keyof T> & string)[]>",
|
|
855
855
|
"description": "",
|
|
856
856
|
"optional": true
|
|
857
857
|
}],
|
|
858
|
-
"returnType": "RegleRuleDefinition<\"atLeastOne\", T, [keys?: (NoInfer<keyof T> & string)[]], false, boolean, false, T, boolean>",
|
|
858
|
+
"returnType": "RegleRuleDefinition<\"atLeastOne\", T, [keys?: readonly (NoInfer<keyof T> & string)[]], false, boolean, false, T, boolean>",
|
|
859
859
|
"example": "import { atLeastOne } from '@regle/rules';\n\nconst { r$ } = useRegle({ user: { firstName: '', lastName: '' } }, {\n user: {\n atLeastOne,\n // or\n atLeastOne: atLeastOne(['firstName', 'lastName'])\n // or\n atLeastOne: atLeastOne<{ firstName: string; lastName: string }>(['firstName', 'lastName'])\n },\n});",
|
|
860
860
|
"tags": { "see": "://reglejs.dev/core-concepts/rules/built-in-rules#atleastone Documentation" }
|
|
861
861
|
},
|
|
@@ -1955,7 +1955,7 @@ function searchApi(query) {
|
|
|
1955
1955
|
return results;
|
|
1956
1956
|
}
|
|
1957
1957
|
|
|
1958
|
-
var version = "1.19.
|
|
1958
|
+
var version = "1.19.1";
|
|
1959
1959
|
|
|
1960
1960
|
let posthogClient = null;
|
|
1961
1961
|
posthogClient = new PostHog("phc_kqgJoylCpKkGkkRGxb4MyN2mViehoQcUFEGwVkk4l8E", {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@regle/mcp-server",
|
|
3
|
-
"version": "1.19.
|
|
3
|
+
"version": "1.19.1",
|
|
4
4
|
"description": "MCP Server for Regle",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ai",
|
|
@@ -50,9 +50,9 @@
|
|
|
50
50
|
"zod": "4.3.6"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
|
-
"@types/node": "24.10.
|
|
54
|
-
"dotenv": "17.2.
|
|
55
|
-
"tsdown": "0.20.
|
|
53
|
+
"@types/node": "24.10.13",
|
|
54
|
+
"dotenv": "17.2.4",
|
|
55
|
+
"tsdown": "0.20.3",
|
|
56
56
|
"tsx": "4.21.0",
|
|
57
57
|
"typescript": "5.9.3"
|
|
58
58
|
},
|