@regle/schemas 1.28.4 → 1.28.5
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-schemas.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @regle/schemas v1.28.
|
|
2
|
+
* @regle/schemas v1.28.5
|
|
3
3
|
* (c) 2026 Victor Garcia
|
|
4
4
|
* @license MIT
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import { ArrayElement, CreateScopedUseRegleOptions, DeepMaybeRef, DeepPartial, DeepReactiveState, GlobalConfigOverrides, HasNamedKeys, HaveAnyRequiredProps, JoinDiscriminatedUnions, LocalRegleBehaviourOptions, Maybe, MaybeOutput, MergedScopedRegles, NoInferLegacy, PrimitiveTypes, RegleBehaviourOptions, RegleCollectionErrors, RegleCommonStatus, RegleErrorTree, RegleExternalCollectionErrors, RegleExternalSchemaErrorTree, RegleExternalSchemaIssueTree, RegleFieldIssue, RegleIssuesTree, RegleRuleStatus, RegleShortcutDefinition, RegleStaticImpl, TupleToPlainObj, UseScopedRegleOptions, useCollectScopeFn } from "@regle/core";
|
|
7
|
+
import { ArrayElement, CreateScopedUseRegleOptions, CustomCollectionProperties, CustomFieldProperties, CustomNestedProperties, DeepMaybeRef, DeepPartial, DeepReactiveState, GlobalConfigOverrides, HasNamedKeys, HaveAnyRequiredProps, JoinDiscriminatedUnions, LocalRegleBehaviourOptions, Maybe, MaybeOutput, MergedScopedRegles, NoInferLegacy, PrimitiveTypes, RegleBehaviourOptions, RegleCollectionErrors, RegleCommonStatus, RegleErrorTree, RegleExternalCollectionErrors, RegleExternalSchemaErrorTree, RegleExternalSchemaIssueTree, RegleFieldIssue, RegleIssuesTree, RegleRuleStatus, RegleShortcutDefinition, RegleStaticImpl, TupleToPlainObj, UseScopedRegleOptions, useCollectScopeFn } from "@regle/core";
|
|
8
8
|
import { MaybeRef, MaybeRefOrGetter, Raw, UnwrapNestedRefs } from "vue";
|
|
9
9
|
import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
10
10
|
import { EmptyObject, IsAny, IsUnion, IsUnknown, UnionToTuple } from "type-fest";
|
|
@@ -64,7 +64,7 @@ type RegleSchemaStatus<TInput extends Record<string, any> | undefined = Record<s
|
|
|
64
64
|
$extractDirtyFields: (filterNullishValues?: boolean) => DeepPartial<TInput>;
|
|
65
65
|
} & (HasNamedKeys<TInput> extends true ? ProcessNestedFields<JoinDiscriminatedUnions<TInput>, JoinDiscriminatedUnions<TOutput>, TShortcuts> : {}) & (IsRoot extends true ? {
|
|
66
66
|
/** Sets all properties as dirty, triggering all rules. It returns a promise that will either resolve to 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). */$validate: (forceValues?: TInput extends EmptyObject ? (HasNamedKeys<TInput> extends true ? TInput : any) : TInput) => Promise<RegleSchemaResult<StandardSchemaV1.InferOutput<TSchema>>>;
|
|
67
|
-
} : {}) & ([TShortcuts['nested']] extends [never] ? {} : { [K in keyof TShortcuts['nested']]: ReturnType<NonNullable<TShortcuts['nested']>[K]> });
|
|
67
|
+
} : {}) & CustomNestedProperties & ([TShortcuts['nested']] extends [never] ? {} : { [K in keyof TShortcuts['nested']]: ReturnType<NonNullable<TShortcuts['nested']>[K]> });
|
|
68
68
|
/**
|
|
69
69
|
* @public
|
|
70
70
|
*/
|
|
@@ -107,7 +107,7 @@ type RegleSchemaFieldStatus<TInput = any, TOutput = TInput, TShortcuts extends R
|
|
|
107
107
|
$setExternalErrors(errors: string[]): void; /** Sets the external issues for the field. */
|
|
108
108
|
$setExternalIssues(issues: (RegleFieldIssue & StandardSchemaV1.Issue)[]): void; /** Will return a copy of your state with only the fields that are dirty. By default it will filter out nullish values or objects, but you can override it with the first parameter $extractDirtyFields(false). */
|
|
109
109
|
$extractDirtyFields: (filterNullishValues?: boolean) => DeepPartial<TInput>;
|
|
110
|
-
} & ([TShortcuts['fields']] extends [never] ? {} : { [K in keyof TShortcuts['fields']]: ReturnType<NonNullable<TShortcuts['fields']>[K]> });
|
|
110
|
+
} & CustomFieldProperties & ([TShortcuts['fields']] extends [never] ? {} : { [K in keyof TShortcuts['fields']]: ReturnType<NonNullable<TShortcuts['fields']>[K]> });
|
|
111
111
|
type RegleSchemaCommonStatus<TInput extends unknown = unknown, TOutput = TInput> = Omit<RegleCommonStatus<TInput, TOutput>, '$pending'>;
|
|
112
112
|
/**
|
|
113
113
|
* @public
|
|
@@ -132,7 +132,7 @@ type RegleSchemaCollectionStatus<TInput extends any[], TOutput = TInput, TShortc
|
|
|
132
132
|
$setExternalErrors(errors: RegleExternalCollectionErrors<TInput>): void; /** Sets the external issues for the field. */
|
|
133
133
|
$setExternalIssues(errors: RegleExternalCollectionErrors<TInput, true>): void; /** Will return a copy of your state with only the fields that are dirty. By default, it will filter out nullish values or objects, but you can override it with the first parameter $extractDirtyFields(false). */
|
|
134
134
|
$extractDirtyFields: (filterNullishValues?: boolean) => DeepPartial<TInput>;
|
|
135
|
-
} & ([TShortcuts['collections']] extends [never] ? {} : { [K in keyof TShortcuts['collections']]: ReturnType<NonNullable<TShortcuts['collections']>[K]> });
|
|
135
|
+
} & CustomCollectionProperties & ([TShortcuts['collections']] extends [never] ? {} : { [K in keyof TShortcuts['collections']]: ReturnType<NonNullable<TShortcuts['collections']>[K]> });
|
|
136
136
|
type RegleSchemaBehaviourOptions = {
|
|
137
137
|
/**
|
|
138
138
|
* Settings for applying transforms and default to the current state
|
package/dist/regle-schemas.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @regle/schemas v1.28.
|
|
2
|
+
* @regle/schemas v1.28.5
|
|
3
3
|
* (c) 2026 Victor Garcia
|
|
4
4
|
* @license MIT
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import { createScopedUseRegle, useRootStorage } from "@regle/core";
|
|
8
|
-
import { computed, effectScope, getCurrentInstance, getCurrentScope, isRef, nextTick, onMounted, onScopeDispose, reactive, ref, toValue, unref, watch } from "vue";
|
|
7
|
+
import { createScopedUseRegle, regleConfigSymbol, useRootStorage } from "@regle/core";
|
|
8
|
+
import { computed, effectScope, getCurrentInstance, getCurrentScope, inject, isRef, nextTick, onMounted, onScopeDispose, reactive, ref, toValue, unref, watch } from "vue";
|
|
9
9
|
/**
|
|
10
10
|
* Server side friendly way of checking for a File
|
|
11
11
|
*/
|
|
@@ -354,10 +354,23 @@ function createUseRegleSchemaComposable(params) {
|
|
|
354
354
|
onValidate: false
|
|
355
355
|
}, ...defaultOptions } = options ?? {};
|
|
356
356
|
const { onUpdate: syncOnUpdate = false, onValidate: syncOnValidate = false } = syncState;
|
|
357
|
+
/**
|
|
358
|
+
* Options injected by the plugin (`RegleVuePlugin` / `defineRegleConfig`)
|
|
359
|
+
*/
|
|
360
|
+
const pluginOptions = inject(regleConfigSymbol, void 0) ?? {};
|
|
357
361
|
const resolvedOptions = {
|
|
362
|
+
...pluginOptions.modifiers,
|
|
358
363
|
...modifiers,
|
|
359
364
|
...defaultOptions
|
|
360
365
|
};
|
|
366
|
+
const mergedShortcuts = {
|
|
367
|
+
...pluginOptions.shortcuts,
|
|
368
|
+
...shortcuts
|
|
369
|
+
};
|
|
370
|
+
const mergedOverrides = {
|
|
371
|
+
...pluginOptions.overrides,
|
|
372
|
+
...overrides
|
|
373
|
+
};
|
|
361
374
|
const { processedState, isSingleField, initialState, originalState } = createSchemaState(state);
|
|
362
375
|
const customErrors = ref({});
|
|
363
376
|
const previousIssues = ref([]);
|
|
@@ -446,10 +459,10 @@ function createUseRegleSchemaComposable(params) {
|
|
|
446
459
|
schemaErrors: customErrors,
|
|
447
460
|
initialState,
|
|
448
461
|
originalState,
|
|
449
|
-
shortcuts,
|
|
462
|
+
shortcuts: mergedShortcuts,
|
|
450
463
|
schemaMode: true,
|
|
451
464
|
onValidate,
|
|
452
|
-
overrides
|
|
465
|
+
overrides: mergedOverrides
|
|
453
466
|
});
|
|
454
467
|
bindSchemaToCurrentScope();
|
|
455
468
|
return { r$: toReactive(regle.regle, isDisabled, () => {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @regle/schemas v1.28.
|
|
2
|
+
* @regle/schemas v1.28.5
|
|
3
3
|
* (c) 2026 Victor Garcia
|
|
4
4
|
* @license MIT
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import{createScopedUseRegle as e,useRootStorage as
|
|
7
|
+
import{createScopedUseRegle as e,regleConfigSymbol as t,useRootStorage as n}from"@regle/core";import{computed as r,effectScope as i,getCurrentInstance as a,getCurrentScope as o,inject as s,isRef as c,nextTick as l,onMounted as u,onScopeDispose as d,reactive as f,ref as p,toValue as m,unref as h,watch as g}from"vue";function _(e){return e?.constructor?.name==`File`}function v(e){return e&&(e instanceof Date||e.constructor.name==`File`||e.constructor.name==`FileList`)?!1:typeof e==`object`&&!!e&&!Array.isArray(e)}function y(e,t,n,r){var i,a;if(Array.isArray(t)&&(i=t.slice(0)),typeof t==`string`&&(i=t.split(`.`)),typeof t==`symbol`&&(i=[t]),!Array.isArray(i))throw Error(`props arg must be an array, a string or a symbol`);if(a=i.pop(),!a)return!1;if(x(a))throw Error(`setting of prototype values not supported`);for(var o;o=i.shift();){if(x(o))throw Error(`setting of prototype values not supported`);if(isNaN(parseInt(o))?(e[o]===void 0&&(e[o]={}),e=e[o]):(e.$each??=[],C(e.$each[o])&&(e.$each[o]={}),e=e.$each[o]),!e||typeof e!=`object`)return!1}return r?e[a]?e[a].$self=(e[a].$self??=[]).concat(n):e[a]={$self:n}:isNaN(parseInt(a))?Array.isArray(e[a])?e[a]=e[a].concat(n):e[a]=n:(e.$each??=[],e.$each[a]=(e.$each[a]??=[]).concat(n)),!0}function b(e,t,n){if(!e)return n;var r,i;if(Array.isArray(t)&&(r=t.slice(0)),typeof t==`string`&&(r=t.split(`.`)),typeof t==`symbol`&&(r=[t]),!Array.isArray(r))throw Error(`props arg must be an array, a string or a symbol`);for(;r.length;)if(i=r.shift(),!e||!i||(e=e[i],e===void 0))return n;return e}function x(e){let t=String(e);return t===`__proto__`||t===`constructor`||t===`prototype`}function S(e,...t){for(var n=[].slice.call(arguments),r,i=n.length;r=n[i-1],i--;)if(!r||typeof r!=`object`&&typeof r!=`function`)throw Error(`expected object, got `+r);for(var a=n[0],o=n.slice(1),s=o.length,i=0;i<s;i++){var c=o[i];for(var l in c)a[l]=c[l]}return a}function C(e,t=!0,n=!0){return e==null?!0:e instanceof Date?isNaN(e.getTime()):_(e)?e.size<=0:Array.isArray(e)?t?e.length===0:!1:v(e)?e==null?!0:n?Object.keys(e).length===0:!1:!String(e).length}function w(e){let t=[];return e.global&&t.push(`g`),e.ignoreCase&&t.push(`i`),e.multiline&&t.push(`m`),e.sticky&&t.push(`y`),e.unicode&&t.push(`u`),t.join(``)}function T(e,t=0){if(t>20)return e;let n=e,r={}.toString.call(e).slice(8,-1);if(r==`Set`&&(n=new Set([...e].map(e=>T(e,t+1)))),r==`Map`&&(n=new Map([...e].map(e=>[T(e[0],t+1),T(e[1],t+1)]))),r==`Date`&&(n=new Date(e.getTime())),r==`RegExp`&&(n=RegExp(e.source,w(e))),r==`Array`||r==`Object`){n=Array.isArray(e)?[]:{};for(let r in e)n[r]=T(e[r],t+1)}return n}function E(e,t,n){if(!c(e))return n?.(),f(e);let r=p(!1);return a()&&u(async()=>{await l(),typeof window<`u`&&window.requestAnimationFrame(()=>{r.value=!0})}),f(new Proxy({},{get(i,a,o){if(n?.(),t.value&&a!==`$value`&&r.value)return Reflect.get(i,a,o);if(e.value!==void 0)return h(Reflect.get(e.value,a,o))},set(t,r,i){return n?.(),c(e.value[r])&&!c(i)?e.value[r].value=i:e.value[r]=i,!0},deleteProperty(t,r){return n?.(),Reflect.deleteProperty(e.value,r)},has(t,r){return n?.(),e.value===void 0?!1:Reflect.has(e.value,r)},ownKeys(){return n?.(),e.value===void 0?[]:Object.keys(e.value)},getOwnPropertyDescriptor(){return n?.(),{enumerable:!0,configurable:!0}}}))}function D(e){return e.path?.map(e=>typeof e==`object`?e.key:e.toString()).join(`.`)??``}function O(e){let t=e.path?.at(-1);return typeof t==`object`?t.key:t}function k(e){let t=e.path?.at(-1),n=typeof t==`object`?typeof t.key==`string`:typeof t==`string`,r=e.path?.findLastIndex(e=>typeof e==`object`?typeof e.key==`number`:typeof e==`number`);if(!(!n&&r===-1)&&r!=null){let t=e.path?.slice(0,r+1);return{...e,path:t}}}function A(e,t){let n=D(e),r=e.path?.[e.path.length-1],i=typeof r==`object`?r.key:r;return{isArray:(typeof r==`object`&&`value`in r?Array.isArray(r.value):!1)||(`type`in e?e.type===`array`:!1)||Array.isArray(b(t.value,n)),$path:n,lastItemKey:i,lastItem:r}}function j(e,t,n,r=!1){return!r&&n?t.value.length?t.value.reduce((t,n)=>{if(`$currentArrayValue`in n&&v(n.$currentArrayValue)&&`$id`in n.$currentArrayValue){let r=n.$currentArrayValue.$id,i=O(n),a=e.find(e=>e?.$currentArrayValue?.$id===r&&O(e)===i);a&&t.push({...n,path:a?.path??[]})}else e.some(e=>D(e)===D(n))&&t.push(n);return t},[]):[]:e}function M(e,t,n,r=!1){return j(e,t,n,r)?.map(e=>({$message:e.message,$property:e.path?.[e.path.length-1]?.toString()??`-`,$rule:`schema`,...e}))??[]}function N({result:e,previousIssues:t,processedState:n,rewardEarly:r,isValidate:i=!1}){let a={},o=e.issues?.map(e=>{let t=k(e);if(t){let r=b(n.value,D(t));Object.defineProperty(e,"$currentArrayValue",{value:r,enumerable:!0,configurable:!0,writable:!0})}return e}),s=j(o??[],t,r,i);if(o?.length){let e=s.map(e=>{let{isArray:t,$path:r,lastItemKey:i}=A(e,n);return{...e,$path:r,isArray:t,$property:i,$rule:`schema`,$message:e.message}});e.forEach(({isArray:e,$path:t,...n})=>{y(a,t,[n],e)}),t.value=e}else t.value=[];return a}function P(e){let t=c(e)?e:p(e);return{processedState:t,isSingleField:r(()=>!v(t.value)),initialState:p(v(t.value)?{...T(t.value)}:T(t.value)),originalState:v(t.value)?{...T(t.value)}:T(t.value)}}function F({processedState:e,getSchema:t,isSingleField:n,customErrors:r,previousIssues:i,resolvedOptions:a,syncOnUpdate:o,syncOnValidate:s}){let c;function l(){u(),c=g([e,t],()=>{a.silent||t()[`~standard`].vendor!==`regle`&&d()},{deep:!0})}function u(){c?.(),c=void 0}async function d(c=!1){let d=t()[`~standard`].validate(e.value);return d instanceof Promise&&(d=await d),n.value?r.value=M(d.issues??[],i,m(a.rewardEarly),c):r.value=N({result:d,previousIssues:i,processedState:e,rewardEarly:m(a.rewardEarly),isValidate:c}),d.issues||(c&&s||!c&&o)&&(u(),v(e.value)?e.value=S(e.value,d.value):e.value=d.value,l()),d}return{computeErrors:d,defineWatchState:l,stopWatching:u}}function I(e){let{options:a,shortcuts:c,overrides:u}=e??{};function f(e,f,_){if(!h(f)?.[`~standard`])throw Error(`Only "standard-schema" compatible libraries are supported`);let{syncState:v={onUpdate:!1,onValidate:!1},...y}=_??{},{onUpdate:b=!1,onValidate:x=!1}=v,S=s(t,void 0)??{},C={...S.modifiers,...a,...y},w={...S.shortcuts,...c},T={...S.overrides,...u},{processedState:D,isSingleField:O,initialState:k,originalState:A}=P(e),j=p({}),M=p([]),N=new Set,I=!1,L,R,z;function B(){return F({processedState:D,getSchema:()=>h(f),isSingleField:O,customErrors:j,previousIssues:M,resolvedOptions:C,syncOnUpdate:b,syncOnValidate:x})}function V(){L?.stop(),L=i(),L.run(()=>{R=B(),R.defineWatchState(),R.computeErrors()})}function H(){R?.stopWatching(),R=void 0,L?.stop(),L=void 0}function U(){I||(I=!0,V(),z=g(()=>m(C.disabled),e=>{e?H():V()}),m(C.disabled)&&l().then(()=>{H()}))}function W(){I&&(I=!1,z?.(),z=void 0,H())}let G,K=async()=>{try{let e=await(R??B()).computeErrors(!0);return G?.regle.value?.$touch(),{valid:!e.issues?.length,data:e.issues?D.value:e.value,errors:G?.regle.value?.$errors,issues:j.value}}catch(e){return Promise.reject(e)}};function q(){let e=o();!e||N.has(e)||(I||U(),N.add(e),d(()=>{N.delete(e),N.size||W()}))}let J=r(()=>m(C.disabled)??!1);return U(),G=n({scopeRules:r(()=>({})),state:D,options:C,schemaErrors:j,initialState:k,originalState:A,shortcuts:w,schemaMode:!0,onValidate:K,overrides:T}),q(),{r$:E(G.regle,J,()=>{G.regle.value||(q(),G.bindToCurrentScope())})}}return f}const L=I();function R(e,t){return e}function z(){function e(e,t){return t}return e}const B=z();function V({modifiers:e,shortcuts:t,overrides:n}){return{useRegleSchema:I({options:e,shortcuts:t,overrides:n}),inferSchema:z()}}const H=t=>{let{customStore:n,customUseRegle:r=L,asRecord:i=!1}=t??{};return e({customStore:n,customUseRegle:r,asRecord:i})},{useCollectScope:U,useScopedRegle:W}=e({customUseRegle:L}),G=U,K=W;export{H as createScopedUseRegleSchema,V as defineRegleSchemaConfig,B as inferSchema,G as useCollectSchemaScope,L as useRegleSchema,K as useScopedRegleSchema,R as withDeps};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@regle/schemas",
|
|
3
|
-
"version": "1.28.
|
|
3
|
+
"version": "1.28.5",
|
|
4
4
|
"description": "Schemas adapter for Regle",
|
|
5
5
|
"homepage": "https://reglejs.dev/",
|
|
6
6
|
"license": "MIT",
|
|
@@ -37,8 +37,8 @@
|
|
|
37
37
|
"dependencies": {
|
|
38
38
|
"@standard-schema/spec": "1.1.0",
|
|
39
39
|
"type-fest": "5.7.0",
|
|
40
|
-
"@regle/core": "1.28.
|
|
41
|
-
"@regle/rules": "1.28.
|
|
40
|
+
"@regle/core": "1.28.5",
|
|
41
|
+
"@regle/rules": "1.28.5"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"@arethetypeswrong/core": "0.18.3",
|