@regle/schemas 1.4.0-beta.1 → 1.4.0
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 +59 -18
- package/dist/regle-schemas.js +9 -8
- package/dist/regle-schemas.min.js +1 -1
- package/package.json +3 -3
package/dist/regle-schemas.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ type Prettify<T> = T extends infer R ? { [K in keyof R]: R[K] } & {} : never;
|
|
|
7
7
|
type Maybe<T = any> = T | null | undefined;
|
|
8
8
|
type MaybeInput<T = any> = T | null | undefined;
|
|
9
9
|
type MaybeOutput<T = any> = T | undefined;
|
|
10
|
+
type NonUndefined<T> = Exclude<T, undefined>;
|
|
10
11
|
type PromiseReturn<T> = T extends Promise<infer U> ? U : T;
|
|
11
12
|
type MaybeGetter<T, V = any, TAdd extends Record<string, any> = {}> = T | ((value: Ref<V>, index: number) => T & TAdd);
|
|
12
13
|
type Unwrap<T extends MaybeRef<Record<string, any>>> = T extends Ref ? UnwrapRef<T> : UnwrapNestedRefs<T>;
|
|
@@ -1701,7 +1702,7 @@ type GetMaybeObjectValue<O extends Record<string, any>, K extends string> = K ex
|
|
|
1701
1702
|
/**
|
|
1702
1703
|
* Combine all union values to be able to get even the normally "never" values, act as an intersection type
|
|
1703
1704
|
*/
|
|
1704
|
-
type RetrieveUnionUnknownValues<T extends readonly any[], TKeys extends string> = T extends [infer F extends Record<string, any>, ...infer R] ? [{ [K in TKeys as GetMaybeObjectValue<F, K> extends
|
|
1705
|
+
type RetrieveUnionUnknownValues<T extends readonly any[], TKeys extends string> = T extends [infer F extends Record<string, any>, ...infer R] ? [{ [K in TKeys as GetMaybeObjectValue<F, K> extends NonUndefined<GetMaybeObjectValue<F, K>> ? never : K]?: GetMaybeObjectValue<F, K> } & { [K in TKeys as GetMaybeObjectValue<F, K> extends NonUndefined<GetMaybeObjectValue<F, K>> ? K : never]: GetMaybeObjectValue<F, K> }, ...RetrieveUnionUnknownValues<R, TKeys>] : [];
|
|
1705
1706
|
/**
|
|
1706
1707
|
* Get all possible keys from a union, even the ones present only on one union
|
|
1707
1708
|
*/
|
|
@@ -1855,6 +1856,7 @@ interface RegleRuleCore<TValue extends any, TParams extends any[] = [], TAsync e
|
|
|
1855
1856
|
active?: RegleInitPropertyGetter<TValue, string | string[], TParams, TMetadata>;
|
|
1856
1857
|
tooltip?: RegleInitPropertyGetter<TValue, string | string[], TParams, TMetadata>;
|
|
1857
1858
|
type?: string;
|
|
1859
|
+
async?: boolean;
|
|
1858
1860
|
}
|
|
1859
1861
|
/**
|
|
1860
1862
|
* @internal
|
|
@@ -2017,10 +2019,17 @@ type RegleRoot<TState extends Record<string, any> = {}, TRules extends ReglePart
|
|
|
2017
2019
|
type RegleStatus<TState extends Record<string, any> | undefined = Record<string, any>, TRules extends ReglePartialRuleTree<NonNullable<TState>> = Record<string, any>, TShortcuts extends RegleShortcutDefinition = {}> = RegleCommonStatus<TState> & {
|
|
2018
2020
|
/** 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. */
|
|
2019
2021
|
readonly $fields: { readonly [TKey in keyof TState as TRules[TKey] extends NonNullable<TRules[TKey]> ? NonNullable<TRules[TKey]> extends RegleRuleDecl ? IsEmptyObject$1<TRules[TKey]> extends true ? TKey : never : never : TKey]: IsUnion<NonNullable<TRules[TKey]>> extends true ? ExtendOnlyRealRecord<TState[TKey]> extends true ? MaybeVariantStatus<NonNullable<TState>[TKey], NonNullable<TRules[TKey]>, TShortcuts> : InferRegleStatusType<NonNullable<TRules[TKey]>, NonNullable<TState>, TKey, TShortcuts> : InferRegleStatusType<NonNullable<TRules[TKey]>, NonNullable<TState>, TKey, TShortcuts> } & { readonly [TKey in keyof TState as TRules[TKey] extends NonNullable<TRules[TKey]> ? NonNullable<TRules[TKey]> extends RegleRuleDecl ? IsEmptyObject$1<TRules[TKey]> extends true ? never : TKey : TKey : never]-?: IsUnion<NonNullable<TRules[TKey]>> extends true ? ExtendOnlyRealRecord<TState[TKey]> extends true ? MaybeVariantStatus<NonNullable<TState>[TKey], NonNullable<TRules[TKey]>, TShortcuts> : InferRegleStatusType<NonNullable<TRules[TKey]>, NonNullable<TState>, TKey, TShortcuts> : InferRegleStatusType<NonNullable<TRules[TKey]>, NonNullable<TState>, TKey, TShortcuts> };
|
|
2022
|
+
/**
|
|
2023
|
+
* Collection of all the issues, collected for all children properties and nested forms.
|
|
2024
|
+
*
|
|
2025
|
+
* Only contains issues from properties where $dirty equals true.
|
|
2026
|
+
*/
|
|
2027
|
+
readonly $issues: RegleIssuesTree<TState>;
|
|
2020
2028
|
/**
|
|
2021
2029
|
* Collection of all the error messages, collected for all children properties and nested forms.
|
|
2022
2030
|
*
|
|
2023
|
-
* Only contains errors from properties where $dirty equals true.
|
|
2031
|
+
* Only contains errors from properties where $dirty equals true.
|
|
2032
|
+
* */
|
|
2024
2033
|
readonly $errors: RegleErrorTree<TState>;
|
|
2025
2034
|
/** Collection of all the error messages, collected for all children properties. */
|
|
2026
2035
|
readonly $silentErrors: RegleErrorTree<TState>;
|
|
@@ -2043,13 +2052,26 @@ type InferRegleStatusType<TRule extends RegleCollectionRuleDecl | RegleRuleDecl
|
|
|
2043
2052
|
* @reference {@link InferRegleStatusType}
|
|
2044
2053
|
*/
|
|
2045
2054
|
|
|
2046
|
-
|
|
2047
|
-
$property: string;
|
|
2048
|
-
$
|
|
2049
|
-
$
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
}
|
|
2055
|
+
type RegleFieldIssue<TRules extends RegleFormPropertyType<any, Partial<AllRulesDeclarations>> = EmptyObject$1> = {
|
|
2056
|
+
readonly $property: string;
|
|
2057
|
+
readonly $type?: string;
|
|
2058
|
+
readonly $message: string;
|
|
2059
|
+
} & (IsEmptyObject$1<TRules> extends true ? {
|
|
2060
|
+
readonly $rule: string;
|
|
2061
|
+
} : { [K in keyof ComputeFieldRules<any, TRules>]: ComputeFieldRules<any, TRules>[K] extends {
|
|
2062
|
+
$metadata: infer TMetadata;
|
|
2063
|
+
} ? K extends string ? {
|
|
2064
|
+
readonly $rule: K;
|
|
2065
|
+
} & (TMetadata extends boolean ? {
|
|
2066
|
+
readonly $rule: string;
|
|
2067
|
+
} : TMetadata) : {
|
|
2068
|
+
readonly $rule: string;
|
|
2069
|
+
} : {
|
|
2070
|
+
readonly $rule: string;
|
|
2071
|
+
} }[keyof ComputeFieldRules<any, TRules>]);
|
|
2072
|
+
type ComputeFieldRules<TState extends any, TRules extends RegleFormPropertyType<any, Partial<AllRulesDeclarations>>> = IsEmptyObject$1<TRules> extends true ? {
|
|
2073
|
+
readonly [x: string]: RegleRuleStatus<TState, any[], any>;
|
|
2074
|
+
} : { readonly [TRuleKey in keyof Omit<TRules, '$each' | keyof FieldRegleBehaviourOptions>]: RegleRuleStatus<TState, TRules[TRuleKey] extends RegleRuleDefinition<any, infer TParams, any> ? TParams : [], TRules[TRuleKey] extends RegleRuleDefinition<any, any, any, infer TMetadata> ? TMetadata : TRules[TRuleKey] extends InlineRuleDeclaration<any, any[], infer TMetadata> ? TMetadata extends Promise<infer P> ? P : TMetadata : boolean> };
|
|
2053
2075
|
/**
|
|
2054
2076
|
* @public
|
|
2055
2077
|
*/
|
|
@@ -2065,9 +2087,13 @@ type RegleFieldStatus<TState extends any = any, TRules extends RegleFormProperty
|
|
|
2065
2087
|
/** Collection of all the error messages, collected for all children properties and nested forms. */
|
|
2066
2088
|
readonly $silentErrors: string[];
|
|
2067
2089
|
/**
|
|
2068
|
-
* Collect all metadata of validators,
|
|
2090
|
+
* Collect all metadata of validators, Only contains metadata from properties where $dirty equals true.
|
|
2091
|
+
*/
|
|
2092
|
+
readonly $issues: RegleFieldIssue<TRules>[];
|
|
2093
|
+
/**
|
|
2094
|
+
* Collect all metadata of validators, including the error message.
|
|
2069
2095
|
*/
|
|
2070
|
-
readonly $
|
|
2096
|
+
readonly $silentIssues: RegleFieldIssue<TRules>[];
|
|
2071
2097
|
/** Stores external errors of the current field */
|
|
2072
2098
|
readonly $externalErrors: string[];
|
|
2073
2099
|
/** Stores active tooltips messages of the current field */
|
|
@@ -2079,9 +2105,7 @@ type RegleFieldStatus<TState extends any = any, TRules extends RegleFormProperty
|
|
|
2079
2105
|
/** 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). */
|
|
2080
2106
|
$validate: () => Promise<RegleResult<TState, TRules>>;
|
|
2081
2107
|
/** This is reactive tree containing all the declared rules of your field. To know more about the rule properties check the rules properties section */
|
|
2082
|
-
readonly $rules:
|
|
2083
|
-
readonly [x: string]: RegleRuleStatus<TState, any[], any>;
|
|
2084
|
-
} : { readonly [TRuleKey in keyof Omit<TRules, '$each' | keyof FieldRegleBehaviourOptions>]: RegleRuleStatus<TState, TRules[TRuleKey] extends RegleRuleDefinition<any, infer TParams, any> ? TParams : [], TRules[TRuleKey] extends RegleRuleDefinition<any, any, any, infer TMetadata> ? TMetadata : TRules[TRuleKey] extends InlineRuleDeclaration<any, any[], infer TMetadata> ? TMetadata extends Promise<infer P> ? P : TMetadata : boolean> };
|
|
2108
|
+
readonly $rules: ComputeFieldRules<TState, TRules>;
|
|
2085
2109
|
} & ([TShortcuts['fields']] extends [never] ? {} : { [K in keyof TShortcuts['fields']]: ReturnType<NonNullable<TShortcuts['fields']>[K]> });
|
|
2086
2110
|
/**
|
|
2087
2111
|
* @internal
|
|
@@ -2122,6 +2146,8 @@ interface RegleCommonStatus<TValue = any> {
|
|
|
2122
2146
|
readonly $ready: boolean;
|
|
2123
2147
|
/** Return the current key name of the field. */
|
|
2124
2148
|
readonly $name: string;
|
|
2149
|
+
/** Returns the current path of the rule (used internally for tracking) */
|
|
2150
|
+
readonly $path: string;
|
|
2125
2151
|
/** Id used to track collections items */
|
|
2126
2152
|
$id?: string;
|
|
2127
2153
|
/** A reference to the original validated model. It can be used to bind your form with v-model.*/
|
|
@@ -2212,6 +2238,12 @@ type RegleCollectionStatus<TState extends any[] = any[], TRules extends ReglePar
|
|
|
2212
2238
|
readonly $each: Array<InferRegleStatusType<NonNullable<TRules>, NonNullable<TState>, number, TShortcuts>>;
|
|
2213
2239
|
/** Represents the status of the collection itself. You can have validation rules on the array like minLength, this field represents the isolated status of the collection. */
|
|
2214
2240
|
readonly $self: RegleFieldStatus<TState, TFieldRule, TShortcuts>;
|
|
2241
|
+
/**
|
|
2242
|
+
* Collection of all the issues, collected for all children properties and nested forms.
|
|
2243
|
+
*
|
|
2244
|
+
* Only contains issues from properties where $dirty equals true.
|
|
2245
|
+
*/
|
|
2246
|
+
readonly $issues: RegleCollectionErrors<TState, true>;
|
|
2215
2247
|
/** Collection of all the error messages, collected for all children properties and nested forms.
|
|
2216
2248
|
*
|
|
2217
2249
|
* Only contains errors from properties where $dirty equals true. */
|
|
@@ -2231,14 +2263,15 @@ type RegleCollectionStatus<TState extends any[] = any[], TRules extends ReglePar
|
|
|
2231
2263
|
//#endregion
|
|
2232
2264
|
//#region src/types/rules/rule.errors.types.d.ts
|
|
2233
2265
|
type RegleErrorTree<TState = MaybeRef<Record<string, any> | any[]>> = { readonly [K in keyof JoinDiscriminatedUnions<UnwrapMaybeRef<TState>>]: RegleValidationErrors<JoinDiscriminatedUnions<UnwrapMaybeRef<TState>>[K], false> };
|
|
2266
|
+
type RegleIssuesTree<TState = MaybeRef<Record<string, any> | any[]>> = { readonly [K in keyof JoinDiscriminatedUnions<UnwrapMaybeRef<TState>>]: RegleValidationErrors<JoinDiscriminatedUnions<UnwrapMaybeRef<TState>>[K], false, true> };
|
|
2234
2267
|
type RegleExternalErrorTree<TState = MaybeRef<Record<string, any> | any[]>> = { readonly [K in keyof JoinDiscriminatedUnions<UnwrapMaybeRef<TState>>]?: RegleValidationErrors<JoinDiscriminatedUnions<UnwrapMaybeRef<TState>>[K], true> };
|
|
2235
2268
|
type RegleValidationErrors<TState extends Record<string, any> | any[] | unknown = never, TExternal extends boolean = false, TIssue extends boolean = false> = NonNullable<TState> extends Array<infer U extends Record<string, any>> ? ExtendOnlyRealRecord<U> extends true ? TExternal extends false ? RegleCollectionErrors<U> : RegleExternalCollectionErrors<U> : TIssue extends true ? RegleFieldIssue[] : string[] : NonNullable<TState> extends Date | File ? TIssue extends true ? RegleFieldIssue[] : string[] : NonNullable<TState> extends Record<string, any> ? TExternal extends false ? RegleErrorTree<TState> : RegleExternalErrorTree<TState> : TIssue extends true ? RegleFieldIssue[] : string[];
|
|
2236
2269
|
type RegleCollectionErrors<TState extends Record<string, any>, TIssue extends boolean = false> = {
|
|
2237
|
-
readonly $self: string[];
|
|
2270
|
+
readonly $self: TIssue extends true ? RegleFieldIssue[] : string[];
|
|
2238
2271
|
readonly $each: RegleValidationErrors<TState, false, TIssue>[];
|
|
2239
2272
|
};
|
|
2240
2273
|
type RegleExternalCollectionErrors<TState extends Record<string, any>, TIssue extends boolean = false> = {
|
|
2241
|
-
readonly $self?: string[];
|
|
2274
|
+
readonly $self?: TIssue extends true ? RegleFieldIssue[] : string[];
|
|
2242
2275
|
readonly $each?: RegleValidationErrors<TState, true, TIssue>[];
|
|
2243
2276
|
};
|
|
2244
2277
|
/** @internal */
|
|
@@ -3112,6 +3145,14 @@ type RegleSchemaFieldStatus<TSchema extends unknown, TState = any, TShortcuts ex
|
|
|
3112
3145
|
readonly $errors: string[];
|
|
3113
3146
|
/** Collection of all the error messages, collected for all children properties and nested forms. */
|
|
3114
3147
|
readonly $silentErrors: string[];
|
|
3148
|
+
/**
|
|
3149
|
+
* Collect all metadata of validators, Only contains errors from properties where $dirty equals true.
|
|
3150
|
+
*/
|
|
3151
|
+
readonly $issues: (RegleFieldIssue & StandardSchemaV1.Issue)[];
|
|
3152
|
+
/**
|
|
3153
|
+
* Collect all metadata of validators, including the error message.
|
|
3154
|
+
*/
|
|
3155
|
+
readonly $silentIssues: (RegleFieldIssue & StandardSchemaV1.Issue)[];
|
|
3115
3156
|
/** 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). */
|
|
3116
3157
|
readonly $externalErrors?: string[];
|
|
3117
3158
|
/** Represents the inactive status. Is true when this state have empty rules */
|
|
@@ -3161,9 +3202,9 @@ type RegleSchemaBehaviourOptions = {
|
|
|
3161
3202
|
//#region src/core/useRegleSchema.d.ts
|
|
3162
3203
|
type useRegleSchemaFnOptions<TAdditionalOptions extends Record<string, any>> = Omit<Partial<DeepMaybeRef<RegleBehaviourOptions>> & LocalRegleBehaviourOptions<Record<string, any>, {}, never>, 'validationGroups' | 'lazy' | 'rewardEarly' | 'silent'> & RegleSchemaBehaviourOptions & TAdditionalOptions;
|
|
3163
3204
|
interface useRegleSchemaFn<TShortcuts extends RegleShortcutDefinition<any> = never, TAdditionalReturnProperties extends Record<string, any> = {}, TAdditionalOptions extends Record<string, any> = {}> {
|
|
3164
|
-
<TSchema extends StandardSchemaV1, TState extends StandardSchemaV1.InferInput<TSchema> | undefined>(...params: [state: MaybeRef<PartialDeep<TState
|
|
3205
|
+
<TSchema extends StandardSchemaV1, TState extends StandardSchemaV1.InferInput<TSchema> | undefined>(...params: [state: MaybeRef<PartialDeep<NoInferLegacy<TState>, {
|
|
3165
3206
|
recurseIntoArrays: true;
|
|
3166
|
-
}>> | DeepReactiveState<PartialDeep<TState
|
|
3207
|
+
}>> | DeepReactiveState<PartialDeep<NoInferLegacy<TState>, {
|
|
3167
3208
|
recurseIntoArrays: true;
|
|
3168
3209
|
}>>, rulesFactory: MaybeRef<TSchema>, ...(HaveAnyRequiredProps<useRegleSchemaFnOptions<TAdditionalOptions>> extends true ? [options: useRegleSchemaFnOptions<TAdditionalOptions>] : [options?: useRegleSchemaFnOptions<TAdditionalOptions>])]): NonNullable<TState> extends PrimitiveTypes ? RegleSingleFieldSchema<NonNullable<TState>, StandardSchemaV1.InferInput<TSchema>, TShortcuts, TAdditionalReturnProperties> : RegleSchema<UnwrapNestedRefs<NonNullable<TState>>, UnwrapNestedRefs<NonNullable<StandardSchemaV1.InferInput<TSchema>>>, TShortcuts, TAdditionalReturnProperties>;
|
|
3169
3210
|
}
|
package/dist/regle-schemas.js
CHANGED
|
@@ -132,22 +132,23 @@ function createUseRegleSchemaComposable(options, shortcuts) {
|
|
|
132
132
|
const output = {};
|
|
133
133
|
if (result.issues) {
|
|
134
134
|
const issues = result.issues.map((issue) => {
|
|
135
|
-
let path = issue.path?.map((item) => typeof item === "object" ? item.key : item.toString()).join(".") ?? "";
|
|
135
|
+
let $path = issue.path?.map((item) => typeof item === "object" ? item.key : item.toString()).join(".") ?? "";
|
|
136
136
|
const lastItem = issue.path?.[issue.path.length - 1];
|
|
137
|
-
const
|
|
138
|
-
const
|
|
139
|
-
|
|
137
|
+
const lastItemKey = typeof lastItem === "object" ? lastItem.key : lastItem;
|
|
138
|
+
const isArray = (typeof lastItem === "object" && "value" in lastItem ? Array.isArray(lastItem.value) : false) || ("type" in issue ? issue.type === "array" : false) || Array.isArray(getDotPath(processedState.value, $path));
|
|
139
|
+
const isPrimitivesArray = !isArray && typeof lastItemKey === "number";
|
|
140
|
+
if (isPrimitivesArray) $path = issue.path?.slice(0, issue.path.length - 1)?.map((item) => typeof item === "object" ? item.key : item.toString()).join(".") ?? "";
|
|
140
141
|
return {
|
|
141
142
|
...issue,
|
|
142
|
-
path,
|
|
143
|
+
$path,
|
|
143
144
|
isArray,
|
|
144
|
-
$property:
|
|
145
|
+
$property: lastItemKey,
|
|
145
146
|
$rule: "schema",
|
|
146
147
|
$message: issue.message
|
|
147
148
|
};
|
|
148
149
|
});
|
|
149
|
-
issues.forEach(({ isArray, path,...issue }) => {
|
|
150
|
-
setObjectError(output, path, [issue], isArray);
|
|
150
|
+
issues.forEach(({ isArray, $path,...issue }) => {
|
|
151
|
+
setObjectError(output, $path, [issue], isArray);
|
|
151
152
|
});
|
|
152
153
|
}
|
|
153
154
|
return output;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createScopedUseRegle as e,useRootStorage as t}from"@regle/core";import{computed as n,isRef as r,ref as i,unref as a,watch as o}from"vue";const s=Symbol(`regle-rule`);function c(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 l(e){let t=e,n={}.toString.call(e).slice(8,-1);if(n==`Set`&&(t=new Set([...e].map(e=>l(e)))),n==`Map`&&(t=new Map([...e].map(e=>[l(e[0]),l(e[1])]))),n==`Date`&&(t=new Date(e.getTime())),n==`RegExp`&&(t=RegExp(e.source,c(e))),n==`Array`||n==`Object`)for(let n in t=Array.isArray(e)?[]:{},e)t[n]=l(e[n]);return t}function u(e){return e&&(e instanceof Date||e.constructor.name==`File`||e.constructor.name==`FileList`)?!1:typeof e==`object`&&!!e&&!Array.isArray(e)}function d(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;p(a);for(var o;o=i.shift();)if(p(o),isNaN(parseInt(o))?(e[o]===void 0&&(e[o]={}),e=e[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]={...e[a],$self:n}:Array.isArray(e[a])?e[a]=e[a].concat(n):e[a]=n,!0}function f(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 p(e){if(e==`__proto__`||e==`constructor`||e==`prototype`)throw Error(`setting of prototype values not supported`)}function m(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 h(e,s){let c={autoDirty:e?.autoDirty,lazy:e?.lazy,rewardEarly:e?.rewardEarly,clearExternalErrorsOnChange:e?.clearExternalErrorsOnChange};function p(e,p,h){let g=n(()=>a(p)),{syncState:_={onUpdate:!1,onValidate:!1},...v}=h??{},{onUpdate:y=!1,onValidate:b=!1}=_,x={...c,...v},S=n(()=>!u(C.value)),C=r(e)?e:i(e),w=i(u(C.value)?{...l(C.value)}:l(C.value)),T=i({}),E;if(!g.value?.[`~standard`])throw Error(`Only "standard-schema" compatible libraries are supported`);function D(e){let t={};if(e.issues){let n=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`&&`value`in n?Array.isArray(n.value):!1)||(`type`in e?e.type===`array`:!1)||Array.isArray(f(C.value,t)),i
|
|
1
|
+
import{createScopedUseRegle as e,useRootStorage as t}from"@regle/core";import{computed as n,isRef as r,ref as i,unref as a,watch as o}from"vue";const s=Symbol(`regle-rule`);function c(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 l(e){let t=e,n={}.toString.call(e).slice(8,-1);if(n==`Set`&&(t=new Set([...e].map(e=>l(e)))),n==`Map`&&(t=new Map([...e].map(e=>[l(e[0]),l(e[1])]))),n==`Date`&&(t=new Date(e.getTime())),n==`RegExp`&&(t=RegExp(e.source,c(e))),n==`Array`||n==`Object`)for(let n in t=Array.isArray(e)?[]:{},e)t[n]=l(e[n]);return t}function u(e){return e&&(e instanceof Date||e.constructor.name==`File`||e.constructor.name==`FileList`)?!1:typeof e==`object`&&!!e&&!Array.isArray(e)}function d(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;p(a);for(var o;o=i.shift();)if(p(o),isNaN(parseInt(o))?(e[o]===void 0&&(e[o]={}),e=e[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]={...e[a],$self:n}:Array.isArray(e[a])?e[a]=e[a].concat(n):e[a]=n,!0}function f(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 p(e){if(e==`__proto__`||e==`constructor`||e==`prototype`)throw Error(`setting of prototype values not supported`)}function m(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 h(e,s){let c={autoDirty:e?.autoDirty,lazy:e?.lazy,rewardEarly:e?.rewardEarly,clearExternalErrorsOnChange:e?.clearExternalErrorsOnChange};function p(e,p,h){let g=n(()=>a(p)),{syncState:_={onUpdate:!1,onValidate:!1},...v}=h??{},{onUpdate:y=!1,onValidate:b=!1}=_,x={...c,...v},S=n(()=>!u(C.value)),C=r(e)?e:i(e),w=i(u(C.value)?{...l(C.value)}:l(C.value)),T=i({}),E;if(!g.value?.[`~standard`])throw Error(`Only "standard-schema" compatible libraries are supported`);function D(e){let t={};if(e.issues){let n=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(f(C.value,t)),a=!i&&typeof r==`number`;return a&&(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}});n.forEach(({isArray:e,$path:n,...r})=>{d(t,n,[r],e)})}return t}async function O(e=!1){let t=g.value[`~standard`].validate(C.value);return t instanceof Promise&&(t=await t),S.value?T.value=t.issues?.map(e=>({$message:e.message,$property:e.path?.[e.path.length-1]?.toString()??`-`,$rule:`schema`,...e}))??[]:T.value=D(t),t.issues||(e&&b||!e&&y)&&(k?.(),u(C.value)?C.value=m(C.value,t.value):C.value=t.value,A()),t}let k;function A(){k=o([C,g],()=>O(),{deep:!0})}A(),O(),E=async()=>{try{let e=await O(!0);return{valid:!e.issues?.length,data:C.value}}catch(e){return Promise.reject(e)}};let j=t({scopeRules:n(()=>({})),state:C,options:x,schemaErrors:T,initialState:w,shortcuts:s,schemaMode:!0,onValidate:E});return{r$:j.regle}}return p}const g=h();function _(e,t){return e}function v(){function e(e,t){return t}return e}const y=v();function b({modifiers:e,shortcuts:t}){let n=h(e,t),r=v();return{useRegleSchema:n,inferSchema:r}}const{useCollectScope:x,useScopedRegle:S}=e({customUseRegle:g}),C=t=>{let{customStore:n,customUseRegle:r=g,asRecord:i=!1}=t??{};return e({customStore:n,customUseRegle:r,asRecord:i})};export{C as createScopedUseRegleSchema,b as defineRegleSchemaConfig,y as inferSchema,x as useCollectSchemaScope,g as useRegleSchema,S as useScopedRegleSchema,_ as withDeps};
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@regle/schemas",
|
|
3
|
-
"version": "1.4.0
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"description": "Schemas adapter for Regle",
|
|
5
5
|
"dependencies": {
|
|
6
6
|
"@standard-schema/spec": "1.0.0",
|
|
7
|
-
"@regle/core": "1.4.0
|
|
8
|
-
"@regle/rules": "1.4.0
|
|
7
|
+
"@regle/core": "1.4.0",
|
|
8
|
+
"@regle/rules": "1.4.0"
|
|
9
9
|
},
|
|
10
10
|
"peerDependencies": {
|
|
11
11
|
"valibot": "^1.0.0",
|