@regle/schemas 1.11.0-beta.6 → 1.11.0-beta.8
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,16 +1,20 @@
|
|
|
1
1
|
import * as _regle_core0 from "@regle/core";
|
|
2
|
-
import { ArrayElement, CreateScopedUseRegleOptions, DeepMaybeRef, DeepReactiveState, HasNamedKeys, HaveAnyRequiredProps, JoinDiscriminatedUnions, LocalRegleBehaviourOptions, Maybe, NoInferLegacy, PrimitiveTypes, RegleBehaviourOptions, RegleCollectionErrors, RegleCommonStatus, RegleErrorTree, RegleFieldIssue, RegleIssuesTree, RegleRuleStatus, RegleShortcutDefinition, UseScopedRegleOptions, useCollectScopeFn } from "@regle/core";
|
|
2
|
+
import { ArrayElement, CreateScopedUseRegleOptions, DeepMaybeRef, DeepReactiveState, HasNamedKeys, HaveAnyRequiredProps, JoinDiscriminatedUnions, LocalRegleBehaviourOptions, Maybe, NoInferLegacy, PrimitiveTypes, RegleBehaviourOptions, RegleCollectionErrors, RegleCommonStatus, RegleErrorTree, RegleFieldIssue, RegleIssuesTree, RegleRuleStatus, RegleShortcutDefinition, TupleToPlainObj, UseScopedRegleOptions, useCollectScopeFn } from "@regle/core";
|
|
3
3
|
import * as vue0 from "vue";
|
|
4
4
|
import { MaybeRef, Raw, UnwrapNestedRefs } from "vue";
|
|
5
5
|
import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
6
|
-
import { EmptyObject, PartialDeep } from "type-fest";
|
|
6
|
+
import { EmptyObject, IsUnion, PartialDeep, UnionToTuple } from "type-fest";
|
|
7
|
+
type MaybeSchemaVariantStatus<TState extends Record<string, any> | undefined = Record<string, any>, TShortcuts extends RegleShortcutDefinition = {}, TRoot extends boolean = false> = IsUnion<NonNullable<TState>> extends true ? Omit<RegleSchemaStatus<TState, TShortcuts, TRoot>, '$fields'> & {
|
|
8
|
+
$fields: ProcessChildrenFields<TState, TShortcuts>[keyof ProcessChildrenFields<TState, TShortcuts>];
|
|
9
|
+
} & (HasNamedKeys<TState> extends true ? ProcessChildrenFields<TState, TShortcuts>[keyof ProcessChildrenFields<TState, TShortcuts>] : {}) : RegleSchemaStatus<TState, TShortcuts, TRoot>;
|
|
10
|
+
type ProcessChildrenFields<TState extends Record<string, any> | undefined, TShortcuts extends RegleShortcutDefinition = {}> = { [TIndex in keyof TupleToPlainObj<UnionToTuple<TState>>]: TIndex extends `${infer TIndexInt extends number}` ? { [TKey in keyof UnionToTuple<TState>[TIndexInt] as NonNullable<UnionToTuple<TState>[TIndexInt]>[TKey] extends UnionToTuple<TState>[TIndexInt][TKey] ? TKey : never]-?: InferRegleSchemaStatusType<NonNullable<UnionToTuple<TState>[TIndexInt]>[TKey], TShortcuts> } & { [TKey in keyof UnionToTuple<TState>[TIndexInt] as NonNullable<UnionToTuple<TState>[TIndexInt]>[TKey] extends UnionToTuple<TState>[TIndexInt][TKey] ? never : TKey]?: InferRegleSchemaStatusType<NonNullable<UnionToTuple<TState>[TIndexInt]>[TKey], TShortcuts> } : {} };
|
|
7
11
|
type RegleSchema<TState extends Record<string, any>, TShortcuts extends RegleShortcutDefinition = {}, TAdditionalReturnProperties extends Record<string, any> = {}> = {
|
|
8
12
|
/**
|
|
9
13
|
* r$ is a reactive object containing the values, errors, dirty state and all the necessary validations properties you'll need to display information.
|
|
10
14
|
*
|
|
11
15
|
* To see the list of properties: {@link https://reglejs.dev/core-concepts/validation-properties}
|
|
12
16
|
*/
|
|
13
|
-
r$: Raw<
|
|
17
|
+
r$: Raw<MaybeSchemaVariantStatus<TState, TShortcuts, true>>;
|
|
14
18
|
} & TAdditionalReturnProperties;
|
|
15
19
|
type RegleSingleFieldSchema<TState extends Maybe<PrimitiveTypes>, TShortcuts extends RegleShortcutDefinition = {}, TAdditionalReturnProperties extends Record<string, any> = {}> = {
|
|
16
20
|
/**
|
|
@@ -34,11 +38,11 @@ type RegleSchemaResult<TSchema extends unknown> = {
|
|
|
34
38
|
issues: EmptyObject;
|
|
35
39
|
errors: EmptyObject;
|
|
36
40
|
};
|
|
37
|
-
type ProcessNestedFields<TState extends Record<string, any
|
|
41
|
+
type ProcessNestedFields<TState extends Record<string, any> | undefined, TShortcuts extends RegleShortcutDefinition> = HasNamedKeys<TState> extends true ? { readonly [TKey in keyof JoinDiscriminatedUnions<TState>]: TKey extends keyof JoinDiscriminatedUnions<TState> ? InferRegleSchemaStatusType<NonNullable<JoinDiscriminatedUnions<TState>[TKey]>, TShortcuts> : never } & { readonly [TKey in keyof JoinDiscriminatedUnions<TState> as TKey extends keyof JoinDiscriminatedUnions<TState> ? JoinDiscriminatedUnions<TState>[TKey] extends NonNullable<JoinDiscriminatedUnions<TState>[TKey]> ? TKey : never : never]-?: TKey extends keyof JoinDiscriminatedUnions<TState> ? InferRegleSchemaStatusType<NonNullable<JoinDiscriminatedUnions<TState>[TKey]>, TShortcuts> : never } : {};
|
|
38
42
|
/**
|
|
39
43
|
* @public
|
|
40
44
|
*/
|
|
41
|
-
type RegleSchemaStatus<TState extends Record<string, any> = Record<string, any>, TShortcuts extends RegleShortcutDefinition = {}, IsRoot extends boolean = false> = Omit<RegleCommonStatus<TState>, IsRoot extends false ? '$pending' : ''> & {
|
|
45
|
+
type RegleSchemaStatus<TState extends Record<string, any> | undefined = Record<string, any>, TShortcuts extends RegleShortcutDefinition = {}, IsRoot extends boolean = false> = Omit<RegleCommonStatus<TState>, IsRoot extends false ? '$pending' : ''> & {
|
|
42
46
|
/** Represents all the children of your object. You can access any nested child at any depth to get the relevant data you need for your form. */
|
|
43
47
|
readonly $fields: ProcessNestedFields<TState, TShortcuts>;
|
|
44
48
|
/** Collection of all issues, collected for all children properties and nested forms.
|
|
@@ -60,7 +64,7 @@ type RegleSchemaStatus<TState extends Record<string, any> = Record<string, any>,
|
|
|
60
64
|
/**
|
|
61
65
|
* @public
|
|
62
66
|
*/
|
|
63
|
-
type InferRegleSchemaStatusType<TState extends unknown, TShortcuts extends RegleShortcutDefinition = {}> = NonNullable<TState> extends Array<infer A> ? A extends Record<string, any> ? RegleSchemaCollectionStatus<NonNullable<TState>, TShortcuts> : RegleSchemaFieldStatus<TState, TShortcuts> : NonNullable<TState> extends Date | File ? RegleSchemaFieldStatus<TState, TShortcuts> : unknown extends TState ? RegleSchemaFieldStatus<TState extends EmptyObject ? unknown : TState, TShortcuts> : NonNullable<TState> extends Record<string, any> ?
|
|
67
|
+
type InferRegleSchemaStatusType<TState extends unknown, TShortcuts extends RegleShortcutDefinition = {}> = NonNullable<TState> extends Array<infer A> ? A extends Record<string, any> ? RegleSchemaCollectionStatus<NonNullable<TState>, TShortcuts> : RegleSchemaFieldStatus<TState, TShortcuts> : NonNullable<TState> extends Date | File ? RegleSchemaFieldStatus<TState, TShortcuts> : unknown extends TState ? RegleSchemaFieldStatus<TState extends EmptyObject ? unknown : TState, TShortcuts> : NonNullable<TState> extends Record<string, any> ? MaybeSchemaVariantStatus<NonNullable<TState> extends Record<string, any> ? NonNullable<TState> : {}, TShortcuts> : RegleSchemaFieldStatus<TState, TShortcuts>;
|
|
64
68
|
/**
|
|
65
69
|
* @public
|
|
66
70
|
*/
|
|
@@ -227,4 +231,13 @@ declare const createScopedUseRegleSchema: <TCustomRegle extends useRegleSchemaFn
|
|
|
227
231
|
useScopedRegle: TReturnedRegle;
|
|
228
232
|
useCollectScope: useCollectScopeFn<TAsRecord>;
|
|
229
233
|
};
|
|
234
|
+
declare module '@regle/core' {
|
|
235
|
+
interface NarrowVariantExtracts {
|
|
236
|
+
'regle-schemas-status': RegleSchemaStatus<any, any>;
|
|
237
|
+
'regle-schemas-collection-status': RegleSchemaCollectionStatus<any, any>;
|
|
238
|
+
}
|
|
239
|
+
interface NarrowVariantFieldExtracts<T extends unknown> {
|
|
240
|
+
'regle-schemas-field-status': RegleSchemaFieldStatus<T, any>;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
230
243
|
export { type InferRegleSchemaStatusType, type RegleSchema, type RegleSchemaBehaviourOptions, type RegleSchemaCollectionStatus, type RegleSchemaFieldStatus, type RegleSchemaResult, type RegleSchemaStatus, type RegleSingleFieldSchema, createScopedUseRegleSchema, defineRegleSchemaConfig, inferSchema, useCollectSchemaScope, useRegleSchema, useScopedRegleSchema, withDeps };
|
package/dist/regle-schemas.js
CHANGED
|
@@ -39,16 +39,17 @@ function getRegExpFlags(regExp) {
|
|
|
39
39
|
return flags.join("");
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
|
-
function cloneDeep(obj) {
|
|
42
|
+
function cloneDeep(obj, dep = 0) {
|
|
43
|
+
if (dep > 20) return obj;
|
|
43
44
|
let result = obj;
|
|
44
45
|
let type = {}.toString.call(obj).slice(8, -1);
|
|
45
|
-
if (type == "Set") result = new Set([...obj].map((value) => cloneDeep(value)));
|
|
46
|
+
if (type == "Set") result = new Set([...obj].map((value) => cloneDeep(value, dep++)));
|
|
46
47
|
if (type == "Map") result = new Map([...obj].map((kv) => [cloneDeep(kv[0]), cloneDeep(kv[1])]));
|
|
47
48
|
if (type == "Date") result = new Date(obj.getTime());
|
|
48
49
|
if (type == "RegExp") result = RegExp(obj.source, getRegExpFlags(obj));
|
|
49
50
|
if (type == "Array" || type == "Object") {
|
|
50
51
|
result = Array.isArray(obj) ? [] : {};
|
|
51
|
-
for (let key in obj) result[key] = cloneDeep(obj[key]);
|
|
52
|
+
for (let key in obj) result[key] = cloneDeep(obj[key], dep++);
|
|
52
53
|
}
|
|
53
54
|
return result;
|
|
54
55
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createScopedUseRegle as e,useRootStorage as t}from"@regle/core";import{computed as n,getCurrentScope as r,isRef as i,onScopeDispose as a,ref as o,unref as s,watch as c}from"vue";function l(e){return e?.constructor?.name==`File`||e?.constructor?.name==`FileList`}function u(e,t=!0){return e==null?!0:e instanceof Date?isNaN(e.getTime()):l(e)?e.size<=0:Array.isArray(e)?t?e.length===0:!1:typeof e==`object`&&e?Object.keys(e).length===0:!String(e).length}function d(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 f(e){let
|
|
1
|
+
import{createScopedUseRegle as e,useRootStorage as t}from"@regle/core";import{computed as n,getCurrentScope as r,isRef as i,onScopeDispose as a,ref as o,unref as s,watch as c}from"vue";function l(e){return e?.constructor?.name==`File`||e?.constructor?.name==`FileList`}function u(e,t=!0){return e==null?!0:e instanceof Date?isNaN(e.getTime()):l(e)?e.size<=0:Array.isArray(e)?t?e.length===0:!1:typeof e==`object`&&e?Object.keys(e).length===0:!String(e).length}function d(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 f(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=>f(e,t++)))),r==`Map`&&(n=new Map([...e].map(e=>[f(e[0]),f(e[1])]))),r==`Date`&&(n=new Date(e.getTime())),r==`RegExp`&&(n=RegExp(e.source,d(e))),r==`Array`||r==`Object`)for(let r in n=Array.isArray(e)?[]:{},e)n[r]=f(e[r],t++);return n}function p(e){return e&&(e instanceof Date||e.constructor.name==`File`||e.constructor.name==`FileList`)?!1:typeof e==`object`&&!!e&&!Array.isArray(e)}function m(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;g(a);for(var o;o=i.shift();)if(g(o),isNaN(parseInt(o))?(e[o]===void 0&&(e[o]={}),e=e[o]):(e.$each??=[],u(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}:Array.isArray(e[a])?e[a]=e[a].concat(n):e[a]=n,!0}function h(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 g(e){if(e==`__proto__`||e==`constructor`||e==`prototype`)throw Error(`setting of prototype values not supported`)}function _(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 v(e,l){let u={autoDirty:e?.autoDirty,lazy:e?.lazy,rewardEarly:e?.rewardEarly,clearExternalErrorsOnChange:e?.clearExternalErrorsOnChange};function d(e,d,g){let v=n(()=>s(d)),{syncState:y={onUpdate:!1,onValidate:!1},...b}=g??{},{onUpdate:x=!1,onValidate:S=!1}=y,C={...u,...b},w=n(()=>!p(T.value)),T=i(e)?e:o(e),E=o(p(T.value)?{...f(T.value)}:f(T.value)),D=p(T.value)?{...f(T.value)}:f(T.value),O=o({}),k;if(!v.value?.[`~standard`])throw Error(`Only "standard-schema" compatible libraries are supported`);function A(e){let t={};return e.issues&&e.issues.map(e=>{let t=e.path?.map(e=>typeof e==`object`?e.key:e.toString()).join(`.`)??``,n=e.path?.[e.path.length-1],r=typeof n==`object`?n.key:n,i=(typeof n==`object`&&`value`in n?Array.isArray(n.value):!1)||(`type`in e?e.type===`array`:!1)||Array.isArray(h(T.value,t));return!i&&typeof r==`number`&&(t=e.path?.slice(0,e.path.length-1)?.map(e=>typeof e==`object`?e.key:e.toString()).join(`.`)??``),{...e,$path:t,isArray:i,$property:r,$rule:`schema`,$message:e.message}}).forEach(({isArray:e,$path:n,...r})=>{m(t,n,[r],e)}),t}async function j(e=!1){let t=v.value[`~standard`].validate(T.value);return t instanceof Promise&&(t=await t),w.value?O.value=t.issues?.map(e=>({$message:e.message,$property:e.path?.[e.path.length-1]?.toString()??`-`,$rule:`schema`,...e}))??[]:O.value=A(t),t.issues||(e&&S||!e&&x)&&(M?.(),p(T.value)?T.value=_(T.value,t.value):T.value=t.value,N()),t}let M;function N(){M=c([T,v],()=>j(),{deep:!0})}return N(),j(),k=async()=>{try{return{valid:!(await j(!0)).issues?.length,data:T.value,errors:{},issues:{}}}catch(e){return Promise.reject(e)}},r()&&a(()=>{M()}),{r$:t({scopeRules:n(()=>({})),state:T,options:C,schemaErrors:O,initialState:E,originalState:D,shortcuts:l,schemaMode:!0,onValidate:k}).regle}}return d}const y=v();function b(e,t){return e}function x(){function e(e,t){return t}return e}const S=x();function C({modifiers:e,shortcuts:t}){return{useRegleSchema:v(e,t),inferSchema:x()}}const{useCollectScope:w,useScopedRegle:T}=e({customUseRegle:y}),E=t=>{let{customStore:n,customUseRegle:r=y,asRecord:i=!1}=t??{};return e({customStore:n,customUseRegle:r,asRecord:i})};export{E as createScopedUseRegleSchema,C as defineRegleSchemaConfig,S as inferSchema,w as useCollectSchemaScope,y as useRegleSchema,T as useScopedRegleSchema,b as withDeps};
|
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@regle/schemas",
|
|
3
|
-
"version": "1.11.0-beta.
|
|
3
|
+
"version": "1.11.0-beta.8",
|
|
4
4
|
"description": "Schemas adapter for Regle",
|
|
5
5
|
"dependencies": {
|
|
6
6
|
"@standard-schema/spec": "1.0.0",
|
|
7
|
-
"
|
|
8
|
-
"@regle/
|
|
7
|
+
"type-fest": "5.2.0",
|
|
8
|
+
"@regle/core": "1.11.0-beta.8",
|
|
9
|
+
"@regle/rules": "1.11.0-beta.8"
|
|
9
10
|
},
|
|
10
11
|
"peerDependencies": {
|
|
11
12
|
"valibot": "^1.0.0",
|