@regle/schemas 1.28.4 → 1.29.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 +52 -34
- package/dist/regle-schemas.js +47 -15
- package/dist/regle-schemas.min.js +2 -2
- package/package.json +13 -13
package/dist/regle-schemas.d.ts
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @regle/schemas v1.
|
|
2
|
+
* @regle/schemas v1.29.0
|
|
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";
|
|
11
11
|
type MaybeSchemaVariantStatus<TInput extends Record<string, any> | undefined = Record<string, any>, TOutput extends Record<string, any> | undefined = TInput, TSchema extends StandardSchemaV1 = StandardSchemaV1, TShortcuts extends RegleShortcutDefinition = {}, TRoot extends boolean = false> = IsUnion<NonNullable<TInput>> extends true ? Omit<RegleSchemaStatus<TInput, TOutput, TSchema, TShortcuts, TRoot>, '$fields'> & {
|
|
12
12
|
$fields: ProcessChildrenFields<TInput, TOutput, TShortcuts>[keyof ProcessChildrenFields<TInput, TOutput, TShortcuts>];
|
|
13
13
|
} & (HasNamedKeys<TInput> extends true ? ProcessChildrenFields<TInput, TOutput, TShortcuts>[keyof ProcessChildrenFields<TInput, TOutput, TShortcuts>] : {}) : RegleSchemaStatus<TInput, TOutput, TSchema, TShortcuts, TRoot>;
|
|
14
|
-
type ProcessChildrenFields<TInput extends Record<string, any> | undefined, TOutput = TInput, TShortcuts extends RegleShortcutDefinition = {}> = { [TIndex in keyof TupleToPlainObj<UnionToTuple<TInput>>]: TIndex extends `${infer TIndexInt extends number}` ? { [TKey in keyof UnionToTuple<TInput>[TIndexInt] as NonNullable<UnionToTuple<TInput>[TIndexInt]>[TKey] extends UnionToTuple<TInput>[TIndexInt][TKey] ? TKey : never]-?: InferRegleSchemaStatusType<NonNullable<UnionToTuple<TInput>[TIndexInt]>[TKey], NonNullable<UnionToTuple<TOutput>[TIndexInt]>[TKey], TShortcuts
|
|
14
|
+
type ProcessChildrenFields<TInput extends Record<string, any> | undefined, TOutput = TInput, TShortcuts extends RegleShortcutDefinition = {}> = { [TIndex in keyof TupleToPlainObj<UnionToTuple<TInput>>]: TIndex extends `${infer TIndexInt extends number}` ? { [TKey in keyof UnionToTuple<TInput>[TIndexInt] as NonNullable<UnionToTuple<TInput>[TIndexInt]>[TKey] extends UnionToTuple<TInput>[TIndexInt][TKey] ? TKey : never]-?: InferRegleSchemaStatusType<NonNullable<UnionToTuple<TInput>[TIndexInt]>[TKey], NonNullable<UnionToTuple<TOutput>[TIndexInt]>[TKey], TShortcuts>; } & { [TKey in keyof UnionToTuple<TInput>[TIndexInt] as NonNullable<UnionToTuple<TInput>[TIndexInt]>[TKey] extends UnionToTuple<TInput>[TIndexInt][TKey] ? never : TKey]?: InferRegleSchemaStatusType<NonNullable<UnionToTuple<TInput>[TIndexInt]>[TKey], NonNullable<UnionToTuple<TOutput>[TIndexInt]>[TKey], TShortcuts>; } : {}; };
|
|
15
15
|
type RegleSchema<TInput extends Record<string, any>, TOutput extends Record<string, any> = TInput, TSchema extends StandardSchemaV1 = StandardSchemaV1, TShortcuts extends RegleShortcutDefinition = {}, TAdditionalReturnProperties extends Record<string, any> = {}> = {
|
|
16
16
|
/**
|
|
17
17
|
* r$ is a reactive object containing the values, errors, dirty state and all the necessary validations properties you'll need to display information.
|
|
@@ -27,7 +27,8 @@ type RegleSingleFieldSchema<TInput extends Maybe<PrimitiveTypes>, TOutput = TInp
|
|
|
27
27
|
* To see the list of properties: {@link https://reglejs.dev/core-concepts/validation-properties}
|
|
28
28
|
*/
|
|
29
29
|
r$: Raw<RegleSchemaFieldStatus<TInput, TOutput, TShortcuts> & {
|
|
30
|
-
/** 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).
|
|
30
|
+
/** 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). */
|
|
31
|
+
$validate: (forceValues?: TInput extends EmptyObject ? any : HasNamedKeys<TInput> extends true ? TInput : any) => Promise<RegleSchemaResult<StandardSchemaV1.InferOutput<TSchema>>>;
|
|
31
32
|
}>;
|
|
32
33
|
} & TAdditionalReturnProperties;
|
|
33
34
|
type RegleSchemaResult<TSchema extends unknown> = {
|
|
@@ -41,14 +42,15 @@ type RegleSchemaResult<TSchema extends unknown> = {
|
|
|
41
42
|
issues: EmptyObject;
|
|
42
43
|
errors: EmptyObject;
|
|
43
44
|
};
|
|
44
|
-
type ProcessNestedFields<TInput extends Record<string, any> | undefined, TOutput extends Record<string, any> | undefined = TInput, TShortcuts extends RegleShortcutDefinition = {}> = HasNamedKeys<TInput> extends true ? { readonly [TKey in keyof JoinDiscriminatedUnions<TInput>]: TKey extends keyof JoinDiscriminatedUnions<TInput> ? InferRegleSchemaStatusType<NonNullable<JoinDiscriminatedUnions<TInput>[TKey]>, TKey extends keyof JoinDiscriminatedUnions<TOutput> ? NonNullable<JoinDiscriminatedUnions<TOutput>[TKey]> : undefined, TShortcuts> : never } & { readonly [TKey in keyof JoinDiscriminatedUnions<TInput> as TKey extends keyof JoinDiscriminatedUnions<TInput> ? JoinDiscriminatedUnions<TInput>[TKey] extends NonNullable<JoinDiscriminatedUnions<TInput>[TKey]> ? TKey : never : never]-?: TKey extends keyof JoinDiscriminatedUnions<TInput> ? InferRegleSchemaStatusType<NonNullable<JoinDiscriminatedUnions<TInput>[TKey]>, TKey extends keyof JoinDiscriminatedUnions<TOutput> ? NonNullable<JoinDiscriminatedUnions<TOutput>[TKey]> : undefined, TShortcuts> : never } : {
|
|
45
|
+
type ProcessNestedFields<TInput extends Record<string, any> | undefined, TOutput extends Record<string, any> | undefined = TInput, TShortcuts extends RegleShortcutDefinition = {}> = HasNamedKeys<TInput> extends true ? { readonly [TKey in keyof JoinDiscriminatedUnions<TInput>]: TKey extends keyof JoinDiscriminatedUnions<TInput> ? InferRegleSchemaStatusType<NonNullable<JoinDiscriminatedUnions<TInput>[TKey]>, TKey extends keyof JoinDiscriminatedUnions<TOutput> ? NonNullable<JoinDiscriminatedUnions<TOutput>[TKey]> : undefined, TShortcuts> : never; } & { readonly [TKey in keyof JoinDiscriminatedUnions<TInput> as TKey extends keyof JoinDiscriminatedUnions<TInput> ? JoinDiscriminatedUnions<TInput>[TKey] extends NonNullable<JoinDiscriminatedUnions<TInput>[TKey]> ? TKey : never : never]-?: TKey extends keyof JoinDiscriminatedUnions<TInput> ? InferRegleSchemaStatusType<NonNullable<JoinDiscriminatedUnions<TInput>[TKey]>, TKey extends keyof JoinDiscriminatedUnions<TOutput> ? NonNullable<JoinDiscriminatedUnions<TOutput>[TKey]> : undefined, TShortcuts> : never; } : {
|
|
45
46
|
[x: string]: RegleSchemaCommonStatus<unknown, unknown>;
|
|
46
47
|
};
|
|
47
48
|
/**
|
|
48
49
|
* @public
|
|
49
50
|
*/
|
|
50
51
|
type RegleSchemaStatus<TInput extends Record<string, any> | undefined = Record<string, any>, TOutput extends Record<string, any> | undefined = TInput, TSchema extends StandardSchemaV1 = StandardSchemaV1, TShortcuts extends RegleShortcutDefinition = {}, IsRoot extends boolean = false> = Omit<RegleCommonStatus<TInput, TOutput>, (IsRoot extends false ? '$pending' : '') | '$issues' | '$errors'> & {
|
|
51
|
-
/** 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. */
|
|
52
|
+
/** 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. */
|
|
53
|
+
readonly $fields: ProcessNestedFields<JoinDiscriminatedUnions<TInput>, JoinDiscriminatedUnions<TOutput>, TShortcuts>;
|
|
52
54
|
/** Collection of all issues, collected for all children properties and nested forms.
|
|
53
55
|
*
|
|
54
56
|
* Only contains errors from properties where $dirty equals true. */
|
|
@@ -57,14 +59,19 @@ type RegleSchemaStatus<TInput extends Record<string, any> | undefined = Record<s
|
|
|
57
59
|
*
|
|
58
60
|
* Only contains errors from properties where $dirty equals true. */
|
|
59
61
|
readonly $errors: RegleErrorTree<TInput, false, true>;
|
|
60
|
-
readonly $output: TOutput;
|
|
61
|
-
|
|
62
|
-
$
|
|
63
|
-
|
|
62
|
+
readonly $output: TOutput;
|
|
63
|
+
/** Collection of all the error messages, collected for all children properties. */
|
|
64
|
+
readonly $silentErrors: RegleErrorTree<TInput, false, true>;
|
|
65
|
+
/** Sets the external errors for the field. */
|
|
66
|
+
$setExternalErrors(errors: RegleExternalSchemaErrorTree<TInput>): void;
|
|
67
|
+
/** Sets the external issues for the field. */
|
|
68
|
+
$setExternalIssues(issues: RegleExternalSchemaIssueTree<TInput>): void;
|
|
69
|
+
/** 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). */
|
|
64
70
|
$extractDirtyFields: (filterNullishValues?: boolean) => DeepPartial<TInput>;
|
|
65
71
|
} & (HasNamedKeys<TInput> extends true ? ProcessNestedFields<JoinDiscriminatedUnions<TInput>, JoinDiscriminatedUnions<TOutput>, TShortcuts> : {}) & (IsRoot extends true ? {
|
|
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).
|
|
67
|
-
|
|
72
|
+
/** 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). */
|
|
73
|
+
$validate: (forceValues?: TInput extends EmptyObject ? (HasNamedKeys<TInput> extends true ? TInput : any) : TInput) => Promise<RegleSchemaResult<StandardSchemaV1.InferOutput<TSchema>>>;
|
|
74
|
+
} : {}) & CustomNestedProperties & ([TShortcuts['nested']] extends [never] ? {} : { [K in keyof TShortcuts['nested']]: ReturnType<NonNullable<TShortcuts['nested']>[K]>; });
|
|
68
75
|
/**
|
|
69
76
|
* @public
|
|
70
77
|
*/
|
|
@@ -73,7 +80,9 @@ type InferRegleSchemaStatusType<TInput extends unknown, TOutput = TInput, TShort
|
|
|
73
80
|
* @public
|
|
74
81
|
*/
|
|
75
82
|
type RegleSchemaFieldStatus<TInput = any, TOutput = TInput, TShortcuts extends RegleShortcutDefinition = {}> = Omit<RegleCommonStatus<TInput, TOutput>, '$pending' | '$value' | '$silentValue' | '$initialValue' | '$originalValue' | '$issues' | '$errors'> & {
|
|
76
|
-
/** A reference to the original validated model. It can be used to bind your form with v-model
|
|
83
|
+
/** A reference to the original validated model. It can be used to bind your form with v-model.*/
|
|
84
|
+
$value: MaybeOutput<UnwrapNestedRefs<TInput>>;
|
|
85
|
+
/** $value variant that will not "touch" the field and update the value silently, running only the rules, so you can easily swap values without impacting user interaction. */
|
|
77
86
|
$silentValue: MaybeOutput<UnwrapNestedRefs<TInput>>;
|
|
78
87
|
/**
|
|
79
88
|
* This value reflect the current initial value of the field.
|
|
@@ -87,7 +96,8 @@ type RegleSchemaFieldStatus<TInput = any, TOutput = TInput, TShortcuts extends R
|
|
|
87
96
|
/** Collection of all the error messages, collected for all children properties and nested forms.
|
|
88
97
|
*
|
|
89
98
|
* Only contains errors from properties where $dirty equals true. */
|
|
90
|
-
readonly $errors: string[];
|
|
99
|
+
readonly $errors: string[];
|
|
100
|
+
/** Collection of all the error messages, collected for all children properties and nested forms. */
|
|
91
101
|
readonly $silentErrors: string[];
|
|
92
102
|
/**
|
|
93
103
|
* Collect all metadata of validators, Only contains errors from properties where $dirty equals true.
|
|
@@ -96,24 +106,33 @@ type RegleSchemaFieldStatus<TInput = any, TOutput = TInput, TShortcuts extends R
|
|
|
96
106
|
/**
|
|
97
107
|
* Collect all metadata of validators, including the error message.
|
|
98
108
|
*/
|
|
99
|
-
readonly $silentIssues: (RegleFieldIssue & StandardSchemaV1.Issue)[];
|
|
100
|
-
|
|
101
|
-
readonly $
|
|
102
|
-
|
|
109
|
+
readonly $silentIssues: (RegleFieldIssue & StandardSchemaV1.Issue)[];
|
|
110
|
+
/** 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). */
|
|
111
|
+
readonly $externalErrors: string[];
|
|
112
|
+
/** Stores external issues of the current field */
|
|
113
|
+
readonly $externalIssues: (RegleFieldIssue & StandardSchemaV1.Issue)[];
|
|
114
|
+
/** Represents the inactive status. Is true when this state have empty rules */
|
|
115
|
+
readonly $inactive: boolean;
|
|
116
|
+
/** This is reactive tree containing all the declared rules of your field. To know more about the rule properties check the rules properties section */
|
|
103
117
|
readonly $rules: {
|
|
104
118
|
[`~validator`]: RegleRuleStatus<IsUnion<TInput> extends true ? any : TInput, []>;
|
|
105
119
|
};
|
|
106
|
-
readonly $output: TOutput;
|
|
107
|
-
|
|
108
|
-
$
|
|
120
|
+
readonly $output: TOutput;
|
|
121
|
+
/** Sets the external errors for the field. */
|
|
122
|
+
$setExternalErrors(errors: string[]): void;
|
|
123
|
+
/** Sets the external issues for the field. */
|
|
124
|
+
$setExternalIssues(issues: (RegleFieldIssue & StandardSchemaV1.Issue)[]): void;
|
|
125
|
+
/** 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
126
|
$extractDirtyFields: (filterNullishValues?: boolean) => DeepPartial<TInput>;
|
|
110
|
-
} & ([TShortcuts['fields']] extends [never] ? {} : { [K in keyof TShortcuts['fields']]: ReturnType<NonNullable<TShortcuts['fields']>[K]
|
|
127
|
+
} & CustomFieldProperties & ([TShortcuts['fields']] extends [never] ? {} : { [K in keyof TShortcuts['fields']]: ReturnType<NonNullable<TShortcuts['fields']>[K]>; });
|
|
111
128
|
type RegleSchemaCommonStatus<TInput extends unknown = unknown, TOutput = TInput> = Omit<RegleCommonStatus<TInput, TOutput>, '$pending'>;
|
|
112
129
|
/**
|
|
113
130
|
* @public
|
|
114
131
|
*/
|
|
115
132
|
type RegleSchemaCollectionStatus<TInput extends any[], TOutput = TInput, TShortcuts extends RegleShortcutDefinition = {}> = Omit<RegleSchemaFieldStatus<TInput, TOutput, TShortcuts>, '$issues' | '$errors' | '$silentErrors'> & {
|
|
116
|
-
/** Collection of status for every item in your collection. Each item will be a field you can access or iterate to display your elements. */
|
|
133
|
+
/** Collection of status for every item in your collection. Each item will be a field you can access or iterate to display your elements. */
|
|
134
|
+
readonly $each: Array<InferRegleSchemaStatusType<ArrayElement<TInput>, ArrayElement<TOutput>, TShortcuts>>;
|
|
135
|
+
/** 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. */
|
|
117
136
|
readonly $self: RegleSchemaFieldStatus<TInput, TOutput, TShortcuts>;
|
|
118
137
|
/**
|
|
119
138
|
* Collection of all the issues, collected for all children properties and nested forms.
|
|
@@ -124,15 +143,18 @@ type RegleSchemaCollectionStatus<TInput extends any[], TOutput = TInput, TShortc
|
|
|
124
143
|
/** Collection of all the error messages, collected for all children properties and nested forms.
|
|
125
144
|
*
|
|
126
145
|
* Only contains errors from properties where $dirty equals true. */
|
|
127
|
-
readonly $errors: RegleCollectionErrors<TInput>;
|
|
146
|
+
readonly $errors: RegleCollectionErrors<TInput>;
|
|
147
|
+
/** Collection of all the error messages, collected for all children properties and nested forms. */
|
|
128
148
|
readonly $silentErrors: RegleCollectionErrors<TInput>;
|
|
129
149
|
readonly $output: TOutput;
|
|
130
150
|
/** 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). */
|
|
131
151
|
/** Sets the external errors for the field. */
|
|
132
|
-
$setExternalErrors(errors: RegleExternalCollectionErrors<TInput>): void;
|
|
133
|
-
|
|
152
|
+
$setExternalErrors(errors: RegleExternalCollectionErrors<TInput>): void;
|
|
153
|
+
/** Sets the external issues for the field. */
|
|
154
|
+
$setExternalIssues(errors: RegleExternalCollectionErrors<TInput, true>): void;
|
|
155
|
+
/** 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
156
|
$extractDirtyFields: (filterNullishValues?: boolean) => DeepPartial<TInput>;
|
|
135
|
-
} & ([TShortcuts['collections']] extends [never] ? {} : { [K in keyof TShortcuts['collections']]: ReturnType<NonNullable<TShortcuts['collections']>[K]
|
|
157
|
+
} & CustomCollectionProperties & ([TShortcuts['collections']] extends [never] ? {} : { [K in keyof TShortcuts['collections']]: ReturnType<NonNullable<TShortcuts['collections']>[K]>; });
|
|
136
158
|
type RegleSchemaBehaviourOptions = {
|
|
137
159
|
/**
|
|
138
160
|
* Settings for applying transforms and default to the current state
|
|
@@ -282,11 +304,7 @@ declare const inferSchema: inferSchemaFn;
|
|
|
282
304
|
*
|
|
283
305
|
* @see {@link https://reglejs.dev/integrations/schemas-libraries Documentation}
|
|
284
306
|
*/
|
|
285
|
-
declare function defineRegleSchemaConfig<TShortcuts extends RegleShortcutDefinition>({
|
|
286
|
-
modifiers,
|
|
287
|
-
shortcuts,
|
|
288
|
-
overrides
|
|
289
|
-
}: {
|
|
307
|
+
declare function defineRegleSchemaConfig<TShortcuts extends RegleShortcutDefinition>({ modifiers, shortcuts, overrides }: {
|
|
290
308
|
modifiers?: RegleBehaviourOptions;
|
|
291
309
|
shortcuts?: TShortcuts;
|
|
292
310
|
overrides?: GlobalConfigOverrides;
|
|
@@ -323,13 +341,13 @@ type CreateScopedUseRegleSchemaOptions<TCustomRegle extends useRegleSchemaFn<any
|
|
|
323
341
|
*
|
|
324
342
|
* @see {@link https://reglejs.dev/advanced-usage/scoped-validation Documentation}
|
|
325
343
|
*/
|
|
326
|
-
declare const createScopedUseRegleSchema: <TCustomRegle extends useRegleSchemaFn = useRegleSchemaFn, TAsRecord extends boolean = false, TReturnedRegle extends useRegleSchemaFn<any, any, any> =
|
|
344
|
+
declare const createScopedUseRegleSchema: <TCustomRegle extends useRegleSchemaFn = useRegleSchemaFn, TAsRecord extends boolean = false, TReturnedRegle extends useRegleSchemaFn<any, any, any> = TCustomRegle extends useRegleSchemaFn<infer S> ? useRegleSchemaFn<S, {
|
|
327
345
|
dispose: () => void;
|
|
328
346
|
register: () => void;
|
|
329
347
|
}, UseScopedRegleOptions<TAsRecord>> : useRegleSchemaFn<any, {
|
|
330
348
|
dispose: () => void;
|
|
331
349
|
register: () => void;
|
|
332
|
-
}, UseScopedRegleOptions<TAsRecord
|
|
350
|
+
}, UseScopedRegleOptions<TAsRecord>>>(options?: CreateScopedUseRegleSchemaOptions<TCustomRegle, TAsRecord>) => {
|
|
333
351
|
useScopedRegle: TReturnedRegle;
|
|
334
352
|
useCollectScope: useCollectScopeFn<TAsRecord>;
|
|
335
353
|
};
|
package/dist/regle-schemas.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @regle/schemas v1.
|
|
2
|
+
* @regle/schemas v1.29.0
|
|
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
|
*/
|
|
@@ -38,9 +38,10 @@ function setObjectError(obj, propsArg, value, isArray) {
|
|
|
38
38
|
}
|
|
39
39
|
if (!obj || typeof obj != "object") return false;
|
|
40
40
|
}
|
|
41
|
-
if (isArray)
|
|
42
|
-
|
|
43
|
-
|
|
41
|
+
if (isArray) {
|
|
42
|
+
if (!obj[lastProp]) obj[lastProp] = { $self: value };
|
|
43
|
+
else obj[lastProp].$self = (obj[lastProp].$self ??= []).concat(value);
|
|
44
|
+
} else if (!isNaN(parseInt(lastProp))) {
|
|
44
45
|
if (obj.$each == void 0) obj.$each = [];
|
|
45
46
|
obj.$each[lastProp] = (obj.$each[lastProp] ??= []).concat(value);
|
|
46
47
|
} else if (Array.isArray(obj[lastProp])) obj[lastProp] = obj[lastProp].concat(value);
|
|
@@ -167,41 +168,59 @@ function toReactive(objectRef, isDisabled, onAccess) {
|
|
|
167
168
|
firstRun.value = true;
|
|
168
169
|
});
|
|
169
170
|
});
|
|
170
|
-
|
|
171
|
+
const target = {};
|
|
172
|
+
const proxy = new Proxy(target, {
|
|
171
173
|
get(_, p, receiver) {
|
|
172
174
|
onAccess?.();
|
|
173
|
-
if (
|
|
175
|
+
if (Reflect.getOwnPropertyDescriptor(target, p)) return Reflect.get(target, p, receiver);
|
|
176
|
+
if (isDisabled.value && p !== `$value` && firstRun.value) return Reflect.get(target, p, receiver);
|
|
174
177
|
if (objectRef.value === void 0) return void 0;
|
|
175
178
|
return unref(Reflect.get(objectRef.value, p, receiver));
|
|
176
179
|
},
|
|
177
180
|
set(_, p, value) {
|
|
178
181
|
onAccess?.();
|
|
182
|
+
if (Reflect.getOwnPropertyDescriptor(target, p)) return Reflect.set(target, p, value);
|
|
179
183
|
if (isRef(objectRef.value[p]) && !isRef(value)) objectRef.value[p].value = value;
|
|
180
184
|
else objectRef.value[p] = value;
|
|
181
185
|
return true;
|
|
182
186
|
},
|
|
183
187
|
deleteProperty(_, p) {
|
|
184
188
|
onAccess?.();
|
|
189
|
+
if (Reflect.getOwnPropertyDescriptor(target, p)) return Reflect.deleteProperty(target, p);
|
|
185
190
|
return Reflect.deleteProperty(objectRef.value, p);
|
|
186
191
|
},
|
|
187
192
|
has(_, p) {
|
|
188
193
|
onAccess?.();
|
|
194
|
+
if (Reflect.has(target, p)) return true;
|
|
189
195
|
if (objectRef.value === void 0) return false;
|
|
190
196
|
return Reflect.has(objectRef.value, p);
|
|
191
197
|
},
|
|
192
198
|
ownKeys() {
|
|
193
199
|
onAccess?.();
|
|
194
|
-
|
|
195
|
-
return
|
|
200
|
+
const fromRef = objectRef.value === void 0 ? [] : Object.keys(objectRef.value);
|
|
201
|
+
return [.../* @__PURE__ */ new Set([...fromRef, ...Reflect.ownKeys(target)])];
|
|
196
202
|
},
|
|
197
|
-
getOwnPropertyDescriptor() {
|
|
203
|
+
getOwnPropertyDescriptor(_, p) {
|
|
198
204
|
onAccess?.();
|
|
205
|
+
const fromTarget = Reflect.getOwnPropertyDescriptor(target, p);
|
|
206
|
+
if (fromTarget) return fromTarget;
|
|
207
|
+
if (objectRef.value === void 0 || !Reflect.has(objectRef.value, p)) return;
|
|
199
208
|
return {
|
|
200
209
|
enumerable: true,
|
|
201
|
-
configurable: true
|
|
210
|
+
configurable: true,
|
|
211
|
+
get: () => unref(Reflect.get(objectRef.value, p)),
|
|
212
|
+
set: (value) => {
|
|
213
|
+
if (isRef(objectRef.value[p]) && !isRef(value)) objectRef.value[p].value = value;
|
|
214
|
+
else objectRef.value[p] = value;
|
|
215
|
+
}
|
|
202
216
|
};
|
|
217
|
+
},
|
|
218
|
+
defineProperty(_, p, attributes) {
|
|
219
|
+
onAccess?.();
|
|
220
|
+
return Reflect.defineProperty(target, p, attributes);
|
|
203
221
|
}
|
|
204
|
-
})
|
|
222
|
+
});
|
|
223
|
+
return reactive(proxy);
|
|
205
224
|
}
|
|
206
225
|
function getIssuePath(issue) {
|
|
207
226
|
return issue.path?.map((item) => typeof item === "object" ? item.key : item.toString()).join(".") ?? "";
|
|
@@ -354,10 +373,23 @@ function createUseRegleSchemaComposable(params) {
|
|
|
354
373
|
onValidate: false
|
|
355
374
|
}, ...defaultOptions } = options ?? {};
|
|
356
375
|
const { onUpdate: syncOnUpdate = false, onValidate: syncOnValidate = false } = syncState;
|
|
376
|
+
/**
|
|
377
|
+
* Options injected by the plugin (`RegleVuePlugin` / `defineRegleConfig`)
|
|
378
|
+
*/
|
|
379
|
+
const pluginOptions = inject(regleConfigSymbol, void 0) ?? {};
|
|
357
380
|
const resolvedOptions = {
|
|
381
|
+
...pluginOptions.modifiers,
|
|
358
382
|
...modifiers,
|
|
359
383
|
...defaultOptions
|
|
360
384
|
};
|
|
385
|
+
const mergedShortcuts = {
|
|
386
|
+
...pluginOptions.shortcuts,
|
|
387
|
+
...shortcuts
|
|
388
|
+
};
|
|
389
|
+
const mergedOverrides = {
|
|
390
|
+
...pluginOptions.overrides,
|
|
391
|
+
...overrides
|
|
392
|
+
};
|
|
361
393
|
const { processedState, isSingleField, initialState, originalState } = createSchemaState(state);
|
|
362
394
|
const customErrors = ref({});
|
|
363
395
|
const previousIssues = ref([]);
|
|
@@ -446,10 +478,10 @@ function createUseRegleSchemaComposable(params) {
|
|
|
446
478
|
schemaErrors: customErrors,
|
|
447
479
|
initialState,
|
|
448
480
|
originalState,
|
|
449
|
-
shortcuts,
|
|
481
|
+
shortcuts: mergedShortcuts,
|
|
450
482
|
schemaMode: true,
|
|
451
483
|
onValidate,
|
|
452
|
-
overrides
|
|
484
|
+
overrides: mergedOverrides
|
|
453
485
|
});
|
|
454
486
|
bindSchemaToCurrentScope();
|
|
455
487
|
return { r$: toReactive(regle.regle, isDisabled, () => {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @regle/schemas v1.
|
|
2
|
+
* @regle/schemas v1.29.0
|
|
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??(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=[]),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);a()&&u(async()=>{await l(),typeof window<`u`&&window.requestAnimationFrame(()=>{r.value=!0})});let i={},o=new Proxy(i,{get(a,o,s){if(n?.(),Reflect.getOwnPropertyDescriptor(i,o)||t.value&&o!==`$value`&&r.value)return Reflect.get(i,o,s);if(e.value!==void 0)return h(Reflect.get(e.value,o,s))},set(t,r,a){return n?.(),Reflect.getOwnPropertyDescriptor(i,r)?Reflect.set(i,r,a):(c(e.value[r])&&!c(a)?e.value[r].value=a:e.value[r]=a,!0)},deleteProperty(t,r){return n?.(),Reflect.getOwnPropertyDescriptor(i,r)?Reflect.deleteProperty(i,r):Reflect.deleteProperty(e.value,r)},has(t,r){return n?.(),Reflect.has(i,r)?!0:e.value!==void 0&&Reflect.has(e.value,r)},ownKeys(){n?.();let t=e.value===void 0?[]:Object.keys(e.value);return[...new Set([...t,...Reflect.ownKeys(i)])]},getOwnPropertyDescriptor(t,r){n?.();let a=Reflect.getOwnPropertyDescriptor(i,r);if(a)return a;if(!(e.value===void 0||!Reflect.has(e.value,r)))return{enumerable:!0,configurable:!0,get:()=>h(Reflect.get(e.value,r)),set:t=>{c(e.value[r])&&!c(t)?e.value[r].value=t:e.value[r]=t}}},defineProperty(e,t,r){return n?.(),Reflect.defineProperty(i,t,r)}});return f(o)}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)||`type`in e&&e.type===`array`||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),r.value=n.value?M(d.issues??[],i,m(a.rewardEarly),c):N({result:d,previousIssues:i,processedState:e,rewardEarly:m(a.rewardEarly),isValidate:c}),d.issues||(c&&s||!c&&o)&&(u(),e.value=v(e.value)?S(e.value,d.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.
|
|
3
|
+
"version": "1.29.0",
|
|
4
4
|
"description": "Schemas adapter for Regle",
|
|
5
5
|
"homepage": "https://reglejs.dev/",
|
|
6
6
|
"license": "MIT",
|
|
@@ -36,24 +36,24 @@
|
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
38
|
"@standard-schema/spec": "1.1.0",
|
|
39
|
-
"type-fest": "5.
|
|
40
|
-
"@regle/core": "1.
|
|
41
|
-
"@regle/rules": "1.
|
|
39
|
+
"type-fest": "5.8.0",
|
|
40
|
+
"@regle/core": "1.29.0",
|
|
41
|
+
"@regle/rules": "1.29.0"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
|
-
"@arethetypeswrong/core": "0.18.
|
|
44
|
+
"@arethetypeswrong/core": "0.18.5",
|
|
45
45
|
"@total-typescript/ts-reset": "0.6.1",
|
|
46
|
-
"@types/node": "24.13.
|
|
46
|
+
"@types/node": "24.13.3",
|
|
47
47
|
"@typescript/native": "npm:typescript@7.0.2",
|
|
48
48
|
"@vue/test-utils": "2.4.11",
|
|
49
|
-
"publint": "0.3.
|
|
50
|
-
"tsdown": "0.22.
|
|
51
|
-
"type-fest": "5.
|
|
49
|
+
"publint": "0.3.23",
|
|
50
|
+
"tsdown": "0.22.14",
|
|
51
|
+
"type-fest": "5.8.0",
|
|
52
52
|
"typescript": "6.0.3",
|
|
53
|
-
"valibot": "1.4.
|
|
54
|
-
"vitest": "4.1.
|
|
55
|
-
"vue": "3.5.
|
|
56
|
-
"vue-tsc": "3.3.
|
|
53
|
+
"valibot": "1.4.2",
|
|
54
|
+
"vitest": "4.1.10",
|
|
55
|
+
"vue": "3.5.41",
|
|
56
|
+
"vue-tsc": "3.3.9",
|
|
57
57
|
"zod": "4.4.3"
|
|
58
58
|
},
|
|
59
59
|
"peerDependencies": {
|