@regle/schemas 1.2.0-beta.4 → 1.2.0-beta.6
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 +24 -17
- package/dist/regle-schemas.min.mjs +1 -1
- package/dist/regle-schemas.mjs +2 -2
- package/package.json +3 -3
package/dist/regle-schemas.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as _regle_core from '@regle/core';
|
|
2
|
-
import { Maybe, PrimitiveTypes, RegleShortcutDefinition, RegleCommonStatus, RegleRuleStatus, JoinDiscriminatedUnions, RegleCollectionErrors, RegleErrorTree, DeepReactiveState, DeepMaybeRef, RegleBehaviourOptions, LocalRegleBehaviourOptions, NoInferLegacy,
|
|
2
|
+
import { Maybe, PrimitiveTypes, RegleShortcutDefinition, RegleCommonStatus, RegleRuleStatus, JoinDiscriminatedUnions, RegleCollectionErrors, RegleErrorTree, DeepReactiveState, HaveAnyRequiredProps, DeepMaybeRef, RegleBehaviourOptions, LocalRegleBehaviourOptions, NoInferLegacy, UseScopedRegleOptions, CreateScopedUseRegleOptions, useCollectScopeFn, MergedScopedRegles } from '@regle/core';
|
|
3
3
|
import { StandardSchemaV1 } from '@standard-schema/spec';
|
|
4
|
-
import { Raw, MaybeRef, UnwrapNestedRefs, MaybeRefOrGetter
|
|
4
|
+
import { Raw, MaybeRef, UnwrapNestedRefs, MaybeRefOrGetter } from 'vue';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
Matches any [primitive value](https://developer.mozilla.org/en-US/docs/Glossary/Primitive).
|
|
@@ -843,12 +843,17 @@ type RegleSchemaBehaviourOptions = {
|
|
|
843
843
|
};
|
|
844
844
|
};
|
|
845
845
|
|
|
846
|
+
type useRegleSchemaFnOptions<TAdditionalOptions extends Record<string, any>> = Omit<Partial<DeepMaybeRef<RegleBehaviourOptions>> & LocalRegleBehaviourOptions<Record<string, any>, {}, never>, 'validationGroups' | 'lazy' | 'rewardEarly' | 'silent'> & RegleSchemaBehaviourOptions & TAdditionalOptions;
|
|
846
847
|
interface useRegleSchemaFn<TShortcuts extends RegleShortcutDefinition<any> = never, TAdditionalReturnProperties extends Record<string, any> = {}, TAdditionalOptions extends Record<string, any> = {}> {
|
|
847
|
-
<TSchema extends StandardSchemaV1, TState extends StandardSchemaV1.InferInput<TSchema> | undefined>(
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
848
|
+
<TSchema extends StandardSchemaV1, TState extends StandardSchemaV1.InferInput<TSchema> | undefined>(...params: [
|
|
849
|
+
state: MaybeRef<PartialDeep<TState, {
|
|
850
|
+
recurseIntoArrays: true;
|
|
851
|
+
}>> | DeepReactiveState<PartialDeep<TState, {
|
|
852
|
+
recurseIntoArrays: true;
|
|
853
|
+
}>>,
|
|
854
|
+
rulesFactory: MaybeRef<TSchema>,
|
|
855
|
+
...(HaveAnyRequiredProps<useRegleSchemaFnOptions<TAdditionalOptions>> extends true ? [options: useRegleSchemaFnOptions<TAdditionalOptions>] : [options?: useRegleSchemaFnOptions<TAdditionalOptions>])
|
|
856
|
+
]): NonNullable<TState> extends PrimitiveTypes ? RegleSingleFieldSchema<NonNullable<TState>, StandardSchemaV1.InferInput<TSchema>, TShortcuts, TAdditionalReturnProperties> : RegleSchema<UnwrapNestedRefs<NonNullable<TState>>, UnwrapNestedRefs<NonNullable<StandardSchemaV1.InferInput<TSchema>>>, TShortcuts, TAdditionalReturnProperties>;
|
|
852
857
|
}
|
|
853
858
|
/**
|
|
854
859
|
* useRegle serves as the foundation for validation logic.
|
|
@@ -923,23 +928,25 @@ declare function defineRegleSchemaConfig<TShortcuts extends RegleShortcutDefinit
|
|
|
923
928
|
inferSchema: inferSchemaFn;
|
|
924
929
|
};
|
|
925
930
|
|
|
931
|
+
type CreateScopedUseRegleSchemaOptions<TCustomRegle extends useRegleSchemaFn<any, any>, TAsRecord extends boolean> = Omit<CreateScopedUseRegleOptions<any, TAsRecord>, 'customUseRegle'> & {
|
|
932
|
+
/**
|
|
933
|
+
* Inject a global configuration to the exported composables to keep your translations and typings
|
|
934
|
+
*/
|
|
935
|
+
customUseRegle?: TCustomRegle;
|
|
936
|
+
};
|
|
926
937
|
declare const useCollectSchemaScope: <TValue extends Record<string, unknown>[] = Record<string, unknown>[]>(namespace?: MaybeRefOrGetter<string>) => {
|
|
927
938
|
r$: MergedScopedRegles<TValue>;
|
|
928
939
|
};
|
|
929
940
|
declare const useScopedRegleSchema: useRegleSchemaFn<_regle_core.RegleShortcutDefinition<any>, {}, {}>;
|
|
930
|
-
declare const createScopedUseRegleSchema: <TCustomRegle extends useRegleSchemaFn = useRegleSchemaFn, TReturnedRegle extends useRegleSchemaFn = TCustomRegle extends useRegleSchemaFn<infer S> ? useRegleSchemaFn<S, {
|
|
941
|
+
declare const createScopedUseRegleSchema: <TCustomRegle extends useRegleSchemaFn = useRegleSchemaFn, TAsRecord extends boolean = false, TReturnedRegle extends useRegleSchemaFn<any, any, any> = TCustomRegle extends useRegleSchemaFn<infer S> ? useRegleSchemaFn<S, {
|
|
931
942
|
dispose: () => void;
|
|
932
943
|
register: () => void;
|
|
933
|
-
}, {
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
customStore?: Ref<ScopedInstancesRecordLike>;
|
|
938
|
-
}) => {
|
|
944
|
+
}, UseScopedRegleOptions<TAsRecord>> : useRegleSchemaFn<any, {
|
|
945
|
+
dispose: () => void;
|
|
946
|
+
register: () => void;
|
|
947
|
+
}, UseScopedRegleOptions<TAsRecord>>>(options?: CreateScopedUseRegleSchemaOptions<TCustomRegle, TAsRecord>) => {
|
|
939
948
|
useScopedRegle: TReturnedRegle;
|
|
940
|
-
useCollectScope
|
|
941
|
-
r$: MergedScopedRegles<TValue>;
|
|
942
|
-
};
|
|
949
|
+
useCollectScope: useCollectScopeFn<TAsRecord>;
|
|
943
950
|
};
|
|
944
951
|
|
|
945
952
|
export { type InferRegleSchemaStatusType, type RegleSchema, type RegleSchemaBehaviourOptions, type RegleSchemaCollectionStatus, type RegleSchemaFieldStatus, type RegleSchemaResult, type RegleSchemaStatus, type RegleSingleFieldSchema, createScopedUseRegleSchema, defineRegleSchemaConfig, inferSchema, useCollectSchemaScope, useRegleSchema, useScopedRegleSchema, withDeps };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import {createScopedUseRegle,useRootStorage}from'@regle/core';import {computed,unref,ref,isRef,watch}from'vue';function
|
|
1
|
+
import {createScopedUseRegle,useRootStorage}from'@regle/core';import {computed,unref,ref,isRef,watch}from'vue';function J(e){if(typeof e.source.flags=="string")return e.source.flags;{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 u(e){let t=e,r={}.toString.call(e).slice(8,-1);if(r=="Set"&&(t=new Set([...e].map(n=>u(n)))),r=="Map"&&(t=new Map([...e].map(n=>[u(n[0]),u(n[1])]))),r=="Date"&&(t=new Date(e.getTime())),r=="RegExp"&&(t=RegExp(e.source,J(e))),r=="Array"||r=="Object"){t=Array.isArray(e)?[]:{};for(let n in e)t[n]=u(e[n]);}return t}function g(e){return e&&(e instanceof Date||e.constructor.name=="File"||e.constructor.name=="FileList")?false:typeof e=="object"&&e!==null&&!Array.isArray(e)}function P(e,t,r,n){var a,o;if(Array.isArray(t)&&(a=t.slice(0)),typeof t=="string"&&(a=t.split(".")),typeof t=="symbol"&&(a=[t]),!Array.isArray(a))throw new Error("props arg must be an array, a string or a symbol");if(o=a.pop(),!o)return false;A(o);for(var i;i=a.shift();)if(A(i),isNaN(parseInt(i))?(typeof e[i]>"u"&&(e[i]={}),e=e[i]):((e.$each??=[])[i]={},e=e.$each[i]),!e||typeof e!="object")return false;return n?e[o]?e[o].$self=(e[o].$self??=[]).concat(r):e[o]={...e[o],$self:r}:Array.isArray(e[o])?e[o]=e[o].concat(r):e[o]=r,true}function C(e,t,r){if(!e)return r;var n,a;if(Array.isArray(t)&&(n=t.slice(0)),typeof t=="string"&&(n=t.split(".")),typeof t=="symbol"&&(n=[t]),!Array.isArray(n))throw new Error("props arg must be an array, a string or a symbol");for(;n.length;)if(a=n.shift(),!e||!a||(e=e[a],e===void 0))return r;return e}function A(e){if(e=="__proto__"||e=="constructor"||e=="prototype")throw new Error("setting of prototype values not supported")}function x(e,t){let r={autoDirty:e?.autoDirty,lazy:e?.lazy,rewardEarly:e?.rewardEarly,clearExternalErrorsOnChange:e?.clearExternalErrorsOnChange};function n(a,o,i){let m=computed(()=>unref(o)),{syncState:k={onUpdate:false,onValidate:false},...$}=i??{},{onUpdate:L=false,onValidate:H=false}=k,z={...r,...$},W=computed(()=>!g(c.value)),c=isRef(a)?a:ref(a),_=ref(g(c.value)?{...u(c.value)}:u(c.value)),d=ref({}),v;if(!m.value?.["~standard"])throw new Error('Only "standard-schema" compatible libraries are supported');function q(p){let s={};return p.issues&&p.issues.map(l=>{let F=l.path?.map(h=>typeof h=="object"?h.key:h.toString()).join(".")??"",S=l.path?.[l.path.length-1],G=(typeof S=="object"&&"value"in S?Array.isArray(S.value):false)||("type"in l?l.type==="array":false)||Array.isArray(C(c.value,F));return {path:F,message:l.message,isArray:G}}).forEach(l=>{P(s,l.path,[l.message],l.isArray);}),s}async function y(p=false){let s=m.value["~standard"].validate(c.value);return s instanceof Promise&&(s=await s),W.value?d.value=s.issues?.map(b=>b.message)??[]:d.value=q(s),s.issues||(p&&H||!p&&L)&&(D?.(),c.value=s.value,w()),s}let D;function w(){D=watch([c,m],()=>y(),{deep:true});}return w(),y(),v=async()=>{try{return {valid:!(await y(!0)).issues?.length,data:c.value}}catch(p){return Promise.reject(p)}},{r$:useRootStorage({scopeRules:computed(()=>({})),state:c,options:z,schemaErrors:d,initialState:_,shortcuts:t,schemaMode:true,onValidate:v}).regle}}return n}var f=x();function U(e,t){return e}function O(){function e(t,r){return r}return e}var E=O();function N({modifiers:e,shortcuts:t}){let r=x(e,t),n=O();return {useRegleSchema:r,inferSchema:n}}var {useCollectScope:M,useScopedRegle:B}=createScopedUseRegle({customUseRegle:f}),V=e=>{let{customStore:t,customUseRegle:r=f,asRecord:n=false}=e??{};return createScopedUseRegle({customStore:t,customUseRegle:r,asRecord:n})};export{V as createScopedUseRegleSchema,N as defineRegleSchemaConfig,E as inferSchema,M as useCollectSchemaScope,f as useRegleSchema,B as useScopedRegleSchema,U as withDeps};
|
package/dist/regle-schemas.mjs
CHANGED
|
@@ -258,8 +258,8 @@ var { useCollectScope: useCollectSchemaScope, useScopedRegle: useScopedRegleSche
|
|
|
258
258
|
customUseRegle: useRegleSchema
|
|
259
259
|
});
|
|
260
260
|
var createScopedUseRegleSchema = (options) => {
|
|
261
|
-
const { customStore, customUseRegle = useRegleSchema } = options ?? {};
|
|
262
|
-
return createScopedUseRegle({ customStore, customUseRegle });
|
|
261
|
+
const { customStore, customUseRegle = useRegleSchema, asRecord = false } = options ?? {};
|
|
262
|
+
return createScopedUseRegle({ customStore, customUseRegle, asRecord });
|
|
263
263
|
};
|
|
264
264
|
|
|
265
265
|
export { createScopedUseRegleSchema, defineRegleSchemaConfig, inferSchema, useCollectSchemaScope, useRegleSchema, useScopedRegleSchema, withDeps };
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@regle/schemas",
|
|
3
|
-
"version": "1.2.0-beta.
|
|
3
|
+
"version": "1.2.0-beta.6",
|
|
4
4
|
"description": "Schemas adapter for Regle",
|
|
5
5
|
"dependencies": {
|
|
6
6
|
"@standard-schema/spec": "1.0.0",
|
|
7
|
-
"@regle/
|
|
8
|
-
"@regle/
|
|
7
|
+
"@regle/rules": "1.2.0-beta.6",
|
|
8
|
+
"@regle/core": "1.2.0-beta.6"
|
|
9
9
|
},
|
|
10
10
|
"peerDependencies": {
|
|
11
11
|
"valibot": "^1.0.0",
|