@regle/schemas 1.1.0-beta.1 → 1.1.0-beta.3
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 +575 -35
- package/dist/regle-schemas.min.mjs +1 -1
- package/dist/regle-schemas.mjs +2 -2
- package/package.json +16 -23
- package/dist/regle-schemas.cjs +0 -250
- package/dist/regle-schemas.d.cts +0 -360
- package/dist/regle-schemas.min.cjs +0 -1
- package/index.cjs +0 -7
- package/index.js +0 -7
package/dist/regle-schemas.d.cts
DELETED
|
@@ -1,360 +0,0 @@
|
|
|
1
|
-
import { Maybe, PrimitiveTypes, RegleShortcutDefinition, RegleFieldStatus, RegleCommonStatus, JoinDiscriminatedUnions, RegleRuleStatus, RegleCollectionErrors, RegleErrorTree, DeepMaybeRef, RegleBehaviourOptions, MismatchInfo, DeepReactiveState, LocalRegleBehaviourOptions, NoInferLegacy } from '@regle/core';
|
|
2
|
-
import { StandardSchemaV1 } from '@standard-schema/spec';
|
|
3
|
-
import { Raw, MaybeRef, MaybeRefOrGetter, UnwrapNestedRefs } from 'vue';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
Matches any [primitive value](https://developer.mozilla.org/en-US/docs/Glossary/Primitive).
|
|
7
|
-
|
|
8
|
-
@category Type
|
|
9
|
-
*/
|
|
10
|
-
type Primitive =
|
|
11
|
-
| null
|
|
12
|
-
| undefined
|
|
13
|
-
| string
|
|
14
|
-
| number
|
|
15
|
-
| boolean
|
|
16
|
-
| symbol
|
|
17
|
-
| bigint;
|
|
18
|
-
|
|
19
|
-
declare global {
|
|
20
|
-
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions -- It has to be an `interface` so that it can be merged.
|
|
21
|
-
interface SymbolConstructor {
|
|
22
|
-
readonly observable: symbol;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
declare const emptyObjectSymbol: unique symbol;
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
Represents a strictly empty plain object, the `{}` value.
|
|
30
|
-
|
|
31
|
-
When you annotate something as the type `{}`, it can be anything except `null` and `undefined`. This means that you cannot use `{}` to represent an empty plain object ([read more](https://stackoverflow.com/questions/47339869/typescript-empty-object-and-any-difference/52193484#52193484)).
|
|
32
|
-
|
|
33
|
-
@example
|
|
34
|
-
```
|
|
35
|
-
import type {EmptyObject} from 'type-fest';
|
|
36
|
-
|
|
37
|
-
// The following illustrates the problem with `{}`.
|
|
38
|
-
const foo1: {} = {}; // Pass
|
|
39
|
-
const foo2: {} = []; // Pass
|
|
40
|
-
const foo3: {} = 42; // Pass
|
|
41
|
-
const foo4: {} = {a: 1}; // Pass
|
|
42
|
-
|
|
43
|
-
// With `EmptyObject` only the first case is valid.
|
|
44
|
-
const bar1: EmptyObject = {}; // Pass
|
|
45
|
-
const bar2: EmptyObject = 42; // Fail
|
|
46
|
-
const bar3: EmptyObject = []; // Fail
|
|
47
|
-
const bar4: EmptyObject = {a: 1}; // Fail
|
|
48
|
-
```
|
|
49
|
-
|
|
50
|
-
Unfortunately, `Record<string, never>`, `Record<keyof any, never>` and `Record<never, never>` do not work. See {@link https://github.com/sindresorhus/type-fest/issues/395 #395}.
|
|
51
|
-
|
|
52
|
-
@category Object
|
|
53
|
-
*/
|
|
54
|
-
type EmptyObject = {[emptyObjectSymbol]?: never};
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
Extract the element of an array that also works for array union.
|
|
58
|
-
|
|
59
|
-
Returns `never` if T is not an array.
|
|
60
|
-
|
|
61
|
-
It creates a type-safe way to access the element type of `unknown` type.
|
|
62
|
-
*/
|
|
63
|
-
type ArrayElement<T> = T extends readonly unknown[] ? T[0] : never;
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
Matches any primitive, `void`, `Date`, or `RegExp` value.
|
|
67
|
-
*/
|
|
68
|
-
type BuiltIns = Primitive | void | Date | RegExp;
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
@see PartialDeep
|
|
72
|
-
*/
|
|
73
|
-
type PartialDeepOptions = {
|
|
74
|
-
/**
|
|
75
|
-
Whether to affect the individual elements of arrays and tuples.
|
|
76
|
-
|
|
77
|
-
@default false
|
|
78
|
-
*/
|
|
79
|
-
readonly recurseIntoArrays?: boolean;
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
Create a type from another type with all keys and nested keys set to optional.
|
|
84
|
-
|
|
85
|
-
Use-cases:
|
|
86
|
-
- Merging a default settings/config object with another object, the second object would be a deep partial of the default object.
|
|
87
|
-
- Mocking and testing complex entities, where populating an entire object with its keys would be redundant in terms of the mock or test.
|
|
88
|
-
|
|
89
|
-
@example
|
|
90
|
-
```
|
|
91
|
-
import type {PartialDeep} from 'type-fest';
|
|
92
|
-
|
|
93
|
-
const settings: Settings = {
|
|
94
|
-
textEditor: {
|
|
95
|
-
fontSize: 14;
|
|
96
|
-
fontColor: '#000000';
|
|
97
|
-
fontWeight: 400;
|
|
98
|
-
}
|
|
99
|
-
autocomplete: false;
|
|
100
|
-
autosave: true;
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
const applySavedSettings = (savedSettings: PartialDeep<Settings>) => {
|
|
104
|
-
return {...settings, ...savedSettings};
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
settings = applySavedSettings({textEditor: {fontWeight: 500}});
|
|
108
|
-
```
|
|
109
|
-
|
|
110
|
-
By default, this does not affect elements in array and tuple types. You can change this by passing `{recurseIntoArrays: true}` as the second type argument:
|
|
111
|
-
|
|
112
|
-
```
|
|
113
|
-
import type {PartialDeep} from 'type-fest';
|
|
114
|
-
|
|
115
|
-
interface Settings {
|
|
116
|
-
languages: string[];
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
const partialSettings: PartialDeep<Settings, {recurseIntoArrays: true}> = {
|
|
120
|
-
languages: [undefined]
|
|
121
|
-
};
|
|
122
|
-
```
|
|
123
|
-
|
|
124
|
-
@category Object
|
|
125
|
-
@category Array
|
|
126
|
-
@category Set
|
|
127
|
-
@category Map
|
|
128
|
-
*/
|
|
129
|
-
type PartialDeep<T, Options extends PartialDeepOptions = {}> = T extends BuiltIns | (((...arguments_: any[]) => unknown)) | (new (...arguments_: any[]) => unknown)
|
|
130
|
-
? T
|
|
131
|
-
: T extends Map<infer KeyType, infer ValueType>
|
|
132
|
-
? PartialMapDeep<KeyType, ValueType, Options>
|
|
133
|
-
: T extends Set<infer ItemType>
|
|
134
|
-
? PartialSetDeep<ItemType, Options>
|
|
135
|
-
: T extends ReadonlyMap<infer KeyType, infer ValueType>
|
|
136
|
-
? PartialReadonlyMapDeep<KeyType, ValueType, Options>
|
|
137
|
-
: T extends ReadonlySet<infer ItemType>
|
|
138
|
-
? PartialReadonlySetDeep<ItemType, Options>
|
|
139
|
-
: T extends object
|
|
140
|
-
? T extends ReadonlyArray<infer ItemType> // Test for arrays/tuples, per https://github.com/microsoft/TypeScript/issues/35156
|
|
141
|
-
? Options['recurseIntoArrays'] extends true
|
|
142
|
-
? ItemType[] extends T // Test for arrays (non-tuples) specifically
|
|
143
|
-
? readonly ItemType[] extends T // Differentiate readonly and mutable arrays
|
|
144
|
-
? ReadonlyArray<PartialDeep<ItemType | undefined, Options>>
|
|
145
|
-
: Array<PartialDeep<ItemType | undefined, Options>>
|
|
146
|
-
: PartialObjectDeep<T, Options> // Tuples behave properly
|
|
147
|
-
: T // If they don't opt into array testing, just use the original type
|
|
148
|
-
: PartialObjectDeep<T, Options>
|
|
149
|
-
: unknown;
|
|
150
|
-
|
|
151
|
-
/**
|
|
152
|
-
Same as `PartialDeep`, but accepts only `Map`s and as inputs. Internal helper for `PartialDeep`.
|
|
153
|
-
*/
|
|
154
|
-
type PartialMapDeep<KeyType, ValueType, Options extends PartialDeepOptions> = {} & Map<PartialDeep<KeyType, Options>, PartialDeep<ValueType, Options>>;
|
|
155
|
-
|
|
156
|
-
/**
|
|
157
|
-
Same as `PartialDeep`, but accepts only `Set`s as inputs. Internal helper for `PartialDeep`.
|
|
158
|
-
*/
|
|
159
|
-
type PartialSetDeep<T, Options extends PartialDeepOptions> = {} & Set<PartialDeep<T, Options>>;
|
|
160
|
-
|
|
161
|
-
/**
|
|
162
|
-
Same as `PartialDeep`, but accepts only `ReadonlyMap`s as inputs. Internal helper for `PartialDeep`.
|
|
163
|
-
*/
|
|
164
|
-
type PartialReadonlyMapDeep<KeyType, ValueType, Options extends PartialDeepOptions> = {} & ReadonlyMap<PartialDeep<KeyType, Options>, PartialDeep<ValueType, Options>>;
|
|
165
|
-
|
|
166
|
-
/**
|
|
167
|
-
Same as `PartialDeep`, but accepts only `ReadonlySet`s as inputs. Internal helper for `PartialDeep`.
|
|
168
|
-
*/
|
|
169
|
-
type PartialReadonlySetDeep<T, Options extends PartialDeepOptions> = {} & ReadonlySet<PartialDeep<T, Options>>;
|
|
170
|
-
|
|
171
|
-
/**
|
|
172
|
-
Same as `PartialDeep`, but accepts only `object`s as inputs. Internal helper for `PartialDeep`.
|
|
173
|
-
*/
|
|
174
|
-
type PartialObjectDeep<ObjectType extends object, Options extends PartialDeepOptions> = {
|
|
175
|
-
[KeyType in keyof ObjectType]?: PartialDeep<ObjectType[KeyType], Options>
|
|
176
|
-
};
|
|
177
|
-
|
|
178
|
-
interface RegleSchema<TState extends Record<string, any>, TSchema extends Record<string, any>, TShortcuts extends RegleShortcutDefinition = {}> {
|
|
179
|
-
/**
|
|
180
|
-
* r$ is a reactive object containing the values, errors, dirty state and all the necessary validations properties you'll need to display informations.
|
|
181
|
-
*
|
|
182
|
-
* To see the list of properties: {@link https://reglejs.dev/core-concepts/validation-properties}
|
|
183
|
-
*/
|
|
184
|
-
r$: Raw<RegleSchemaStatus<TState, TSchema, TShortcuts, true>>;
|
|
185
|
-
}
|
|
186
|
-
interface RegleSingleFieldSchema<TState extends Maybe<PrimitiveTypes>, TSchema extends Record<string, any>, TShortcuts extends RegleShortcutDefinition = {}> {
|
|
187
|
-
/**
|
|
188
|
-
* r$ is a reactive object containing the values, errors, dirty state and all the necessary validations properties you'll need to display informations.
|
|
189
|
-
*
|
|
190
|
-
* To see the list of properties: {@link https://reglejs.dev/core-concepts/validation-properties}
|
|
191
|
-
*/
|
|
192
|
-
r$: Raw<RegleFieldStatus<TState, TSchema, TShortcuts>>;
|
|
193
|
-
}
|
|
194
|
-
type RegleSchemaResult<TSchema extends unknown> = {
|
|
195
|
-
valid: false;
|
|
196
|
-
data: PartialDeep<TSchema>;
|
|
197
|
-
} | {
|
|
198
|
-
valid: true;
|
|
199
|
-
data: TSchema;
|
|
200
|
-
};
|
|
201
|
-
/**
|
|
202
|
-
* @public
|
|
203
|
-
*/
|
|
204
|
-
type RegleSchemaStatus<TState extends Record<string, any> = Record<string, any>, TSchema extends Record<string, any> = Record<string, any>, TShortcuts extends RegleShortcutDefinition = {}, IsRoot extends boolean = false> = Omit<RegleCommonStatus<TState>, IsRoot extends false ? '$pending' : ''> & {
|
|
205
|
-
/** 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. */
|
|
206
|
-
readonly $fields: {
|
|
207
|
-
readonly [TKey in keyof JoinDiscriminatedUnions<TState>]: TKey extends keyof JoinDiscriminatedUnions<TSchema> ? InferRegleSchemaStatusType<NonNullable<JoinDiscriminatedUnions<TSchema>[TKey]>, JoinDiscriminatedUnions<TState>[TKey], TShortcuts> : never;
|
|
208
|
-
} & {
|
|
209
|
-
readonly [TKey in keyof JoinDiscriminatedUnions<TState> as TKey extends keyof JoinDiscriminatedUnions<TSchema> ? JoinDiscriminatedUnions<TSchema>[TKey] extends NonNullable<JoinDiscriminatedUnions<TSchema>[TKey]> ? TKey : never : never]-?: TKey extends keyof JoinDiscriminatedUnions<TSchema> ? InferRegleSchemaStatusType<NonNullable<JoinDiscriminatedUnions<TSchema>[TKey]>, JoinDiscriminatedUnions<TState>[TKey], TShortcuts> : never;
|
|
210
|
-
};
|
|
211
|
-
/** Collection of all the error messages, collected for all children properties and nested forms.
|
|
212
|
-
*
|
|
213
|
-
* Only contains errors from properties where $dirty equals true. */
|
|
214
|
-
readonly $errors: RegleErrorTree<TState>;
|
|
215
|
-
/** Collection of all the error messages, collected for all children properties. */
|
|
216
|
-
readonly $silentErrors: RegleErrorTree<TState>;
|
|
217
|
-
/** 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). */
|
|
218
|
-
$extractDirtyFields: (filterNullishValues?: boolean) => PartialDeep<TState>;
|
|
219
|
-
} & (IsRoot extends true ? {
|
|
220
|
-
/** 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). */
|
|
221
|
-
$validate: () => Promise<RegleSchemaResult<TSchema>>;
|
|
222
|
-
} : {}) & ([TShortcuts['nested']] extends [never] ? {} : {
|
|
223
|
-
[K in keyof TShortcuts['nested']]: ReturnType<NonNullable<TShortcuts['nested']>[K]>;
|
|
224
|
-
});
|
|
225
|
-
/**
|
|
226
|
-
* @public
|
|
227
|
-
*/
|
|
228
|
-
type InferRegleSchemaStatusType<TSchema extends unknown, TState extends unknown, TShortcuts extends RegleShortcutDefinition = {}> = NonNullable<TSchema> extends Array<infer A extends Record<string, any>> ? RegleSchemaCollectionStatus<A, TState extends Array<any> ? TState : [], TShortcuts> : NonNullable<TState> extends Date | File ? RegleSchemaFieldStatus<TSchema, TState, TShortcuts> : unknown extends TState ? RegleSchemaFieldStatus<TSchema extends EmptyObject ? unknown : TSchema, TState, TShortcuts> : NonNullable<TSchema> extends Record<string, any> ? RegleSchemaStatus<NonNullable<TState> extends Record<string, any> ? NonNullable<TState> : {}, NonNullable<TSchema>, TShortcuts> : RegleSchemaFieldStatus<TSchema, TState, TShortcuts>;
|
|
229
|
-
/**
|
|
230
|
-
* @public
|
|
231
|
-
*/
|
|
232
|
-
type RegleSchemaFieldStatus<TSchema extends unknown, TState = any, TShortcuts extends RegleShortcutDefinition = {}> = Omit<RegleCommonStatus<TState>, '$pending'> & {
|
|
233
|
-
/** Collection of all the error messages, collected for all children properties and nested forms.
|
|
234
|
-
*
|
|
235
|
-
* Only contains errors from properties where $dirty equals true. */
|
|
236
|
-
readonly $errors: string[];
|
|
237
|
-
/** Collection of all the error messages, collected for all children properties and nested forms. */
|
|
238
|
-
readonly $silentErrors: string[];
|
|
239
|
-
/** 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). */
|
|
240
|
-
readonly $externalErrors?: string[];
|
|
241
|
-
/** Represents the inactive status. Is true when this state have empty rules */
|
|
242
|
-
readonly $inactive: boolean;
|
|
243
|
-
/** This is reactive tree containing all the declared rules of your field. To know more about the rule properties check the rules properties section */
|
|
244
|
-
readonly $rules: {
|
|
245
|
-
[`~validator`]: RegleRuleStatus<TState, []>;
|
|
246
|
-
};
|
|
247
|
-
/** 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). */
|
|
248
|
-
$extractDirtyFields: (filterNullishValues?: boolean) => PartialDeep<TState>;
|
|
249
|
-
} & ([TShortcuts['fields']] extends [never] ? {} : {
|
|
250
|
-
[K in keyof TShortcuts['fields']]: ReturnType<NonNullable<TShortcuts['fields']>[K]>;
|
|
251
|
-
});
|
|
252
|
-
/**
|
|
253
|
-
* @public
|
|
254
|
-
*/
|
|
255
|
-
type RegleSchemaCollectionStatus<TSchema extends Record<string, any>, TState extends any[], TShortcuts extends RegleShortcutDefinition = {}> = Omit<RegleSchemaFieldStatus<TSchema, TState, TShortcuts>, '$errors' | '$silentErrors' | '$validate'> & {
|
|
256
|
-
/** Collection of status of every item in your collection. Each item will be a field you can access, or map on it to display your elements. */
|
|
257
|
-
readonly $each: Array<InferRegleSchemaStatusType<NonNullable<TSchema>, ArrayElement<TState>, TShortcuts>>;
|
|
258
|
-
/** 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. */
|
|
259
|
-
readonly $self: RegleSchemaFieldStatus<TSchema, TState, TShortcuts>;
|
|
260
|
-
/** Collection of all the error messages, collected for all children properties and nested forms.
|
|
261
|
-
*
|
|
262
|
-
* Only contains errors from properties where $dirty equals true. */
|
|
263
|
-
readonly $errors: RegleCollectionErrors<TSchema>;
|
|
264
|
-
/** Collection of all the error messages, collected for all children properties and nested forms. */
|
|
265
|
-
readonly $silentErrors: RegleCollectionErrors<TSchema>;
|
|
266
|
-
/** 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). */
|
|
267
|
-
$extractDirtyFields: (filterNullishValues?: boolean) => PartialDeep<TState>;
|
|
268
|
-
} & ([TShortcuts['collections']] extends [never] ? {} : {
|
|
269
|
-
[K in keyof TShortcuts['collections']]: ReturnType<NonNullable<TShortcuts['collections']>[K]>;
|
|
270
|
-
});
|
|
271
|
-
|
|
272
|
-
interface useRegleSchemaFn<TShortcuts extends RegleShortcutDefinition<any> = never> {
|
|
273
|
-
/**
|
|
274
|
-
* Primitive parameter
|
|
275
|
-
* */
|
|
276
|
-
<TState extends Maybe<PrimitiveTypes>, TRules extends StandardSchemaV1<TState>>(state: MaybeRef<TState>, rulesFactory: MaybeRefOrGetter<TRules>, options?: Partial<DeepMaybeRef<RegleBehaviourOptions>>): RegleSingleFieldSchema<TState, TRules, TShortcuts>;
|
|
277
|
-
/**
|
|
278
|
-
* Object parameter
|
|
279
|
-
* */
|
|
280
|
-
<TState extends Record<string, any>, TSchema extends StandardSchemaV1<Record<string, any>> & TValid, TValid = StandardSchemaV1.InferInput<TSchema> extends PartialDeep<UnwrapNestedRefs<TState>, {
|
|
281
|
-
recurseIntoArrays: true;
|
|
282
|
-
}> ? {} : MismatchInfo<UnwrapNestedRefs<TState>, PartialDeep<StandardSchemaV1.InferInput<TSchema>, {
|
|
283
|
-
recurseIntoArrays: true;
|
|
284
|
-
}>>>(state: MaybeRef<TState> | DeepReactiveState<TState>, schema: MaybeRef<TSchema>, options?: Partial<DeepMaybeRef<RegleBehaviourOptions>> & LocalRegleBehaviourOptions<UnwrapNestedRefs<TState>, {}, never>): RegleSchema<UnwrapNestedRefs<TState>, StandardSchemaV1.InferInput<TSchema>, TShortcuts>;
|
|
285
|
-
}
|
|
286
|
-
/**
|
|
287
|
-
* useRegle serves as the foundation for validation logic.
|
|
288
|
-
*
|
|
289
|
-
* It accepts the following inputs:
|
|
290
|
-
*
|
|
291
|
-
* @param state - This can be a plain object, a ref, a reactive object, or a structure containing nested refs.
|
|
292
|
-
* @param schema - These should align with the structure of your state.
|
|
293
|
-
* @param modifiers - customize regle behaviour
|
|
294
|
-
*
|
|
295
|
-
* ```ts
|
|
296
|
-
* import { useRegleSchema } from '@regle/schemas';
|
|
297
|
-
import * as v from 'valibot';
|
|
298
|
-
|
|
299
|
-
const { r$ } = useRegleSchema({ name: '' }, v.object({
|
|
300
|
-
name: v.pipe(v.string(), v.minLength(3))
|
|
301
|
-
}))
|
|
302
|
-
* ```
|
|
303
|
-
* Docs: {@link https://reglejs.dev/integrations/valibot#usage}
|
|
304
|
-
*/
|
|
305
|
-
declare const useRegleSchema: useRegleSchemaFn<RegleShortcutDefinition<any>>;
|
|
306
|
-
|
|
307
|
-
/**
|
|
308
|
-
*
|
|
309
|
-
* Force dependency on any RPC schema
|
|
310
|
-
* ```ts
|
|
311
|
-
* const foo = ref('');
|
|
312
|
-
*
|
|
313
|
-
* const schema = computed(() => v.object({
|
|
314
|
-
* name: withDeps(
|
|
315
|
-
* v.pipe(v.string(), v.check((value) => value === foo.value)),
|
|
316
|
-
* [foo.value]
|
|
317
|
-
* )
|
|
318
|
-
* }))
|
|
319
|
-
*
|
|
320
|
-
* useRegleSchema({name: ''}, schema)
|
|
321
|
-
* ```
|
|
322
|
-
*/
|
|
323
|
-
declare function withDeps<TSchema extends StandardSchemaV1, TParams extends unknown[] = []>(schema: TSchema, depsArray: [...TParams]): TSchema;
|
|
324
|
-
|
|
325
|
-
interface inferSchemaFn {
|
|
326
|
-
<TState extends Record<string, any>, TSchema extends StandardSchemaV1<Record<string, any>> & TValid, TValid = UnwrapNestedRefs<TState> extends PartialDeep<StandardSchemaV1.InferInput<TSchema>, {
|
|
327
|
-
recurseIntoArrays: true;
|
|
328
|
-
}> ? {} : MismatchInfo<UnwrapNestedRefs<TState>, PartialDeep<StandardSchemaV1.InferInput<TSchema>, {
|
|
329
|
-
recurseIntoArrays: true;
|
|
330
|
-
}>>>(state: MaybeRef<TState> | DeepReactiveState<TState> | undefined, rulesFactory: TSchema): NoInferLegacy<TSchema>;
|
|
331
|
-
<TState extends PrimitiveTypes, TSchema extends StandardSchemaV1 & TValid, TValid = TState extends StandardSchemaV1.InferInput<TSchema> ? {} : MismatchInfo<TState, StandardSchemaV1.InferInput<TSchema>>>(state: MaybeRef<TState>, rulesFactory: TSchema): NoInferLegacy<TSchema>;
|
|
332
|
-
}
|
|
333
|
-
/**
|
|
334
|
-
* Rule type helper to provide autocomplete and typecheck to your form rules or part of your form rules
|
|
335
|
-
* It will just return the rules without any processing.
|
|
336
|
-
*
|
|
337
|
-
* @param state - The state reference
|
|
338
|
-
* @param schema - Your schema
|
|
339
|
-
*/
|
|
340
|
-
declare const inferSchema: inferSchemaFn;
|
|
341
|
-
|
|
342
|
-
/**
|
|
343
|
-
* Define a global regle configuration, where you can:
|
|
344
|
-
* - Define global modifiers
|
|
345
|
-
* - Define shortcuts
|
|
346
|
-
*
|
|
347
|
-
* It will return:
|
|
348
|
-
*
|
|
349
|
-
* - a `useRegleSchema` composable that can typecheck your custom rules
|
|
350
|
-
* - an `inferSchema` helper that can typecheck your custom rules
|
|
351
|
-
*/
|
|
352
|
-
declare function defineRegleSchemaConfig<TShortcuts extends RegleShortcutDefinition>({ modifiers, shortcuts, }: {
|
|
353
|
-
modifiers?: RegleBehaviourOptions;
|
|
354
|
-
shortcuts?: TShortcuts;
|
|
355
|
-
}): {
|
|
356
|
-
useRegleSchema: useRegleSchemaFn<TShortcuts>;
|
|
357
|
-
inferSchema: inferSchemaFn;
|
|
358
|
-
};
|
|
359
|
-
|
|
360
|
-
export { type InferRegleSchemaStatusType, type RegleSchema, type RegleSchemaCollectionStatus, type RegleSchemaFieldStatus, type RegleSchemaResult, type RegleSchemaStatus, type RegleSingleFieldSchema, defineRegleSchemaConfig, inferSchema, useRegleSchema, withDeps };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
'use strict';var core=require('@regle/core'),vue=require('vue');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 f(e){let t=e,r={}.toString.call(e).slice(8,-1);if(r=="Set"&&(t=new Set([...e].map(a=>f(a)))),r=="Map"&&(t=new Map([...e].map(a=>[f(a[0]),f(a[1])]))),r=="Date"&&(t=new Date(e.getTime())),r=="RegExp"&&(t=RegExp(e.source,C(e))),r=="Array"||r=="Object"){t=Array.isArray(e)?[]:{};for(let a in e)t[a]=f(e[a]);}return t}function S(e){return e&&(e instanceof Date||e.constructor.name=="File"||e.constructor.name=="FileList")?false:typeof e=="object"&&e!==null&&!Array.isArray(e)}function v(e,t,r,a){var n,s;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");if(s=n.pop(),!s)return false;w(s);for(var o;o=n.shift();)if(w(o),isNaN(parseInt(o))?(typeof e[o]>"u"&&(e[o]={}),e=e[o]):((e.$each??=[])[o]={},e=e.$each[o]),!e||typeof e!="object")return false;return a?e[s]?e[s].$self=(e[s].$self??=[]).concat(r):e[s]={...e[s],$self:r}:Array.isArray(e[s])?e[s]=e[s].concat(r):e[s]=r,true}function I(e,t,r){if(!e)return r;var a,n;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");for(;a.length;)if(n=a.shift(),!e||!n||(e=e[n],e===void 0))return r;return e}function w(e){if(e=="__proto__"||e=="constructor"||e=="prototype")throw new Error("setting of prototype values not supported")}function R(e,t){let r={autoDirty:e?.autoDirty,lazy:e?.lazy,rewardEarly:e?.rewardEarly,clearExternalErrorsOnChange:e?.clearExternalErrorsOnChange};function a(n,s,o){let E=vue.ref({}),p=vue.computed(()=>vue.unref(s)),V={...r,...o},N=vue.computed(()=>!S(l.value)),l=vue.isRef(n)?n:vue.ref(n),A=vue.ref(S(l.value)?{...f(l.value)}:f(l.value)),y=vue.ref({}),T;if(!p.value?.["~standard"])throw new Error('Only "standard-schema" compatible libraries are supported');function B(i){let m={};return i.issues&&i.issues.map(c=>{let x=c.path?.map(d=>typeof d=="object"?d.key:d.toString()).join(".")??"",h=c.path?.[c.path.length-1],U=(typeof h=="object"&&"value"in h?Array.isArray(h.value):false)||("type"in c?c.type==="array":false)||Array.isArray(I(l.value,x));return {path:x,message:c.message,isArray:U}}).forEach(c=>{v(m,c.path,[c.message],c.isArray);}),m}async function D(){let i=p.value["~standard"].validate(l.value);return i instanceof Promise&&(i=await i),N.value?y.value=i.issues?.map(m=>m.message)??[]:y.value=B(i),i}return vue.watch([l,p],D,{deep:true,immediate:true}),T=async()=>{try{return {valid:!(await D()).issues?.length,data:l.value}}catch(i){return Promise.reject(i)}},{r$:core.useRootStorage({scopeRules:E,state:l,options:V,schemaErrors:y,initialState:A,shortcuts:t,schemaMode:true,onValidate:T}).regle}}return a}var M=R();function O(e,t){return e}function g(){function e(t,r){return r}return e}var b=g();function F({modifiers:e,shortcuts:t}){let r=R(e,t),a=g();return {useRegleSchema:r,inferSchema:a}}exports.defineRegleSchemaConfig=F;exports.inferSchema=b;exports.useRegleSchema=M;exports.withDeps=O;
|
package/index.cjs
DELETED