@regle/schemas 1.9.0-beta.1 → 1.9.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 +10 -134
- package/dist/regle-schemas.js +1 -3
- package/dist/regle-schemas.min.js +1 -1
- package/package.json +3 -3
package/dist/regle-schemas.d.ts
CHANGED
|
@@ -1238,7 +1238,7 @@ type CollectionRegleBehaviourOptions = FieldRegleBehaviourOptions & {
|
|
|
1238
1238
|
$deepCompare?: boolean;
|
|
1239
1239
|
};
|
|
1240
1240
|
type ShortcutCommonFn<T extends Record<string, any>> = {
|
|
1241
|
-
[x: string]: (element:
|
|
1241
|
+
[x: string]: (element: OmitByType<T, Function>) => unknown;
|
|
1242
1242
|
};
|
|
1243
1243
|
type RegleShortcutDefinition<TCustomRules extends Record<string, any> = {}> = {
|
|
1244
1244
|
/**
|
|
@@ -1338,28 +1338,6 @@ type RegleResult<Data extends Record<string, any> | any[] | unknown, TRules exte
|
|
|
1338
1338
|
valid: true;
|
|
1339
1339
|
data: IsUnknown<Data> extends true ? unknown : IsAny$1<Data> extends true ? unknown : HasNamedKeys<Data> extends true ? Data extends Array<infer U extends Record<string, any>> ? DeepSafeFormState<U, TRules>[] : Data extends Date | File ? SafeFieldProperty<Data, TRules> : Data extends Record<string, any> ? DeepSafeFormState<Data, TRules> : SafeFieldProperty<Data, TRules> : unknown;
|
|
1340
1340
|
};
|
|
1341
|
-
type RegleNestedResult<Data extends Record<string, any> | unknown, TRules extends ReglePartialRuleTree<any> | RegleFormPropertyType<any>> = RegleResult<Data, TRules> & ({
|
|
1342
|
-
valid: false;
|
|
1343
|
-
issues: RegleIssuesTree<Data>;
|
|
1344
|
-
errors: RegleErrorTree<Data>;
|
|
1345
|
-
} | {
|
|
1346
|
-
valid: true;
|
|
1347
|
-
issues: EmptyObject$1;
|
|
1348
|
-
errors: EmptyObject$1;
|
|
1349
|
-
});
|
|
1350
|
-
type RegleCollectionResult<Data extends any[], TRules extends ReglePartialRuleTree<any> | RegleFormPropertyType<any>> = RegleResult<Data, TRules> & ({
|
|
1351
|
-
valid: false;
|
|
1352
|
-
issues: RegleCollectionErrors<Data, true>;
|
|
1353
|
-
errors: RegleCollectionErrors<Data>;
|
|
1354
|
-
} | {
|
|
1355
|
-
valid: true;
|
|
1356
|
-
issues: EmptyObject$1;
|
|
1357
|
-
errors: EmptyObject$1;
|
|
1358
|
-
});
|
|
1359
|
-
type RegleFieldResult<Data extends any, TRules extends ReglePartialRuleTree<any> | RegleFormPropertyType<any>> = RegleResult<Data, TRules> & {
|
|
1360
|
-
issues: RegleFieldIssue<TRules>[];
|
|
1361
|
-
errors: string[];
|
|
1362
|
-
};
|
|
1363
1341
|
/**
|
|
1364
1342
|
* Infer safe output from any `r$` instance
|
|
1365
1343
|
*
|
|
@@ -1371,8 +1349,6 @@ type RegleFieldResult<Data extends any, TRules extends ReglePartialRuleTree<any>
|
|
|
1371
1349
|
type $InternalRegleResult = {
|
|
1372
1350
|
valid: boolean;
|
|
1373
1351
|
data: any;
|
|
1374
|
-
errors: $InternalRegleErrorTree | $InternalRegleCollectionErrors | string[];
|
|
1375
|
-
issues: $InternalRegleIssuesTree | $InternalRegleCollectionIssues | RegleFieldIssue[];
|
|
1376
1352
|
};
|
|
1377
1353
|
type DeepSafeFormState<TState extends Record<string, any>, TRules extends ReglePartialRuleTree<Record<string, any>, CustomRulesDeclarationTree> | RegleFormPropertyType<any, any> | undefined> = [unknown] extends [TState] ? {} : TRules extends undefined ? TState : TRules extends ReglePartialRuleTree<TState, CustomRulesDeclarationTree> ? Prettify<{ [K in keyof TState as IsPropertyOutputRequired<TState[K], TRules[K]> extends false ? K : never]?: SafeProperty<TState[K], TRules[K]> extends MaybeInput<infer M> ? MaybeOutput<M> : SafeProperty<TState[K], TRules[K]> } & { [K in keyof TState as IsPropertyOutputRequired<TState[K], TRules[K]> extends false ? never : K]-?: unknown extends SafeProperty<TState[K], TRules[K]> ? unknown : NonNullable<SafeProperty<TState[K], TRules[K]>> }> : TState;
|
|
1378
1354
|
type FieldHaveRequiredRule<TRule extends RegleFormPropertyType<any, any> | undefined = never> = TRule extends MaybeRef<RegleRuleDecl<any, any>> ? [unknown] extends UnwrapRef<TRule>['required'] ? NonNullable<UnwrapRef<TRule>['literal']> extends RegleRuleDefinition<any, any[], any, any, any, any> ? true : false : NonNullable<UnwrapRef<TRule>['required']> extends UnwrapRef<TRule>['required'] ? UnwrapRef<TRule>['required'] extends RegleRuleDefinition<any, infer Params, any, any, any, any> ? Params extends never[] ? true : false : false : false : false;
|
|
@@ -1458,72 +1434,6 @@ interface useRegleFn<TCustomRules extends Partial<AllRulesDeclarations>, TShortc
|
|
|
1458
1434
|
* Docs: {@link https://reglejs.dev/core-concepts/}
|
|
1459
1435
|
*/
|
|
1460
1436
|
|
|
1461
|
-
//#endregion
|
|
1462
|
-
//#region ../../node_modules/.pnpm/@standard-schema+spec@1.0.0/node_modules/@standard-schema/spec/dist/index.d.ts
|
|
1463
|
-
/** The Standard Schema interface. */
|
|
1464
|
-
interface StandardSchemaV1$1<Input = unknown, Output = Input> {
|
|
1465
|
-
/** The Standard Schema properties. */
|
|
1466
|
-
readonly "~standard": StandardSchemaV1$1.Props<Input, Output>;
|
|
1467
|
-
}
|
|
1468
|
-
declare namespace StandardSchemaV1$1 {
|
|
1469
|
-
/** The Standard Schema properties interface. */
|
|
1470
|
-
export interface Props<Input = unknown, Output = Input> {
|
|
1471
|
-
/** The version number of the standard. */
|
|
1472
|
-
readonly version: 1;
|
|
1473
|
-
/** The vendor name of the schema library. */
|
|
1474
|
-
readonly vendor: string;
|
|
1475
|
-
/** Validates unknown input values. */
|
|
1476
|
-
readonly validate: (value: unknown) => Result<Output> | Promise<Result<Output>>;
|
|
1477
|
-
/** Inferred types associated with the schema. */
|
|
1478
|
-
readonly types?: Types<Input, Output> | undefined;
|
|
1479
|
-
}
|
|
1480
|
-
/** The result interface of the validate function. */
|
|
1481
|
-
export type Result<Output> = SuccessResult<Output> | FailureResult;
|
|
1482
|
-
/** The result interface if validation succeeds. */
|
|
1483
|
-
export interface SuccessResult<Output> {
|
|
1484
|
-
/** The typed output value. */
|
|
1485
|
-
readonly value: Output;
|
|
1486
|
-
/** The non-existent issues. */
|
|
1487
|
-
readonly issues?: undefined;
|
|
1488
|
-
}
|
|
1489
|
-
/** The result interface if validation fails. */
|
|
1490
|
-
export interface FailureResult {
|
|
1491
|
-
/** The issues of failed validation. */
|
|
1492
|
-
readonly issues: ReadonlyArray<Issue>;
|
|
1493
|
-
}
|
|
1494
|
-
/** The issue interface of the failure output. */
|
|
1495
|
-
export interface Issue {
|
|
1496
|
-
/** The error message of the issue. */
|
|
1497
|
-
readonly message: string;
|
|
1498
|
-
/** The path of the issue, if any. */
|
|
1499
|
-
readonly path?: ReadonlyArray<PropertyKey | PathSegment> | undefined;
|
|
1500
|
-
}
|
|
1501
|
-
/** The path segment interface of the issue. */
|
|
1502
|
-
export interface PathSegment {
|
|
1503
|
-
/** The key representing a path segment. */
|
|
1504
|
-
readonly key: PropertyKey;
|
|
1505
|
-
}
|
|
1506
|
-
/** The Standard Schema types interface. */
|
|
1507
|
-
export interface Types<Input = unknown, Output = Input> {
|
|
1508
|
-
/** The input type of the schema. */
|
|
1509
|
-
readonly input: Input;
|
|
1510
|
-
/** The output type of the schema. */
|
|
1511
|
-
readonly output: Output;
|
|
1512
|
-
}
|
|
1513
|
-
/** Infers the input type of a Standard Schema. */
|
|
1514
|
-
export type InferInput<Schema extends StandardSchemaV1$1> = NonNullable<Schema["~standard"]["types"]>["input"];
|
|
1515
|
-
/** Infers the output type of a Standard Schema. */
|
|
1516
|
-
export type InferOutput<Schema extends StandardSchemaV1$1> = NonNullable<Schema["~standard"]["types"]>["output"];
|
|
1517
|
-
export {};
|
|
1518
|
-
}
|
|
1519
|
-
//#endregion
|
|
1520
|
-
//#region src/core/useRegle/useErrors.d.ts
|
|
1521
|
-
/**
|
|
1522
|
-
* Converts a nested $errors object to a flat array of string errors
|
|
1523
|
-
*
|
|
1524
|
-
* Can also flatten to an array containing the path of each error with the options.includePath
|
|
1525
|
-
*/
|
|
1526
|
-
|
|
1527
1437
|
//#endregion
|
|
1528
1438
|
//#region src/types/utils/mismatch.types.d.ts
|
|
1529
1439
|
/**
|
|
@@ -1871,7 +1781,7 @@ type RegleStatus<TState extends Record<string, any> | undefined = Record<string,
|
|
|
1871
1781
|
/** 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). */
|
|
1872
1782
|
$extractDirtyFields: (filterNullishValues?: boolean) => PartialDeep$1<TState>;
|
|
1873
1783
|
/** 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). */
|
|
1874
|
-
$validate: (
|
|
1784
|
+
$validate: () => Promise<RegleResult<JoinDiscriminatedUnions<TState>, TRules>>;
|
|
1875
1785
|
} & ProcessNestedFields$1<TState, TRules, TShortcuts> & ([TShortcuts['nested']] extends [never] ? {} : { [K in keyof TShortcuts['nested']]: ReturnType<NonNullable<TShortcuts['nested']>[K]> });
|
|
1876
1786
|
/**
|
|
1877
1787
|
* @internal
|
|
@@ -1938,7 +1848,7 @@ type RegleFieldStatus<TState extends any = any, TRules extends RegleFormProperty
|
|
|
1938
1848
|
/** 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). */
|
|
1939
1849
|
$extractDirtyFields: (filterNullishValues?: boolean) => MaybeOutput<TState>;
|
|
1940
1850
|
/** 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). */
|
|
1941
|
-
$validate: (
|
|
1851
|
+
$validate: () => Promise<RegleResult<TState, TRules>>;
|
|
1942
1852
|
/** This is reactive tree containing all the declared rules of your field. To know more about the rule properties check the rules properties section */
|
|
1943
1853
|
readonly $rules: ComputeFieldRules<TState, TRules>;
|
|
1944
1854
|
} & ([TShortcuts['fields']] extends [never] ? {} : { [K in keyof TShortcuts['fields']]: ReturnType<NonNullable<TShortcuts['fields']>[K]> });
|
|
@@ -1950,7 +1860,7 @@ type RegleFieldStatus<TState extends any = any, TRules extends RegleFormProperty
|
|
|
1950
1860
|
/**
|
|
1951
1861
|
* @public
|
|
1952
1862
|
*/
|
|
1953
|
-
interface RegleCommonStatus<TValue = any>
|
|
1863
|
+
interface RegleCommonStatus<TValue = any> {
|
|
1954
1864
|
/** Indicates whether the field is invalid. It becomes true if any associated rules return false. */
|
|
1955
1865
|
readonly $invalid: boolean;
|
|
1956
1866
|
/**
|
|
@@ -2099,7 +2009,7 @@ type RegleCollectionStatus<TState extends any[] = any[], TRules extends ReglePar
|
|
|
2099
2009
|
/** 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). */
|
|
2100
2010
|
$extractDirtyFields: (filterNullishValues?: boolean) => PartialDeep$1<TState>;
|
|
2101
2011
|
/** 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). */
|
|
2102
|
-
$validate: (
|
|
2012
|
+
$validate: () => Promise<RegleResult<JoinDiscriminatedUnions<TState>, JoinDiscriminatedUnions<TRules>>>;
|
|
2103
2013
|
} & ([TShortcuts['collections']] extends [never] ? {} : { [K in keyof TShortcuts['collections']]: ReturnType<NonNullable<TShortcuts['collections']>[K]> });
|
|
2104
2014
|
/**
|
|
2105
2015
|
* @internal
|
|
@@ -2121,31 +2031,13 @@ type RegleExternalCollectionErrors<TState extends Record<string, any>, TIssue ex
|
|
|
2121
2031
|
readonly $each?: RegleValidationErrors<TState, true, TIssue>[];
|
|
2122
2032
|
};
|
|
2123
2033
|
/** @internal */
|
|
2124
|
-
type $InternalRegleCollectionErrors = {
|
|
2125
|
-
readonly $self?: string[];
|
|
2126
|
-
readonly $each?: $InternalRegleErrors[];
|
|
2127
|
-
};
|
|
2128
|
-
type $InternalRegleErrorTree = {
|
|
2129
|
-
[x: string]: $InternalRegleErrors;
|
|
2130
|
-
};
|
|
2131
|
-
type $InternalRegleErrors = $InternalRegleCollectionErrors | string[] | $InternalRegleErrorTree;
|
|
2132
|
-
type $InternalRegleIssuesTree = {
|
|
2133
|
-
[x: string]: $InternalRegleIssues;
|
|
2134
|
-
};
|
|
2135
|
-
type $InternalRegleIssues = $InternalRegleCollectionIssues | RegleFieldIssue[] | $InternalRegleIssuesTree;
|
|
2136
|
-
type $InternalRegleCollectionIssues = {
|
|
2137
|
-
readonly $self?: RegleFieldIssue[];
|
|
2138
|
-
readonly $each?: $InternalRegleIssues[];
|
|
2139
|
-
};
|
|
2140
|
-
//#endregion
|
|
2141
|
-
//#region src/types/rules/compatibility.rules.d.ts
|
|
2142
2034
|
|
|
2143
2035
|
/** Supports both core Regle and schemas Regle for Zod/Valibot */
|
|
2144
2036
|
type SuperCompatibleRegleRoot = SuperCompatibleRegleStatus & {
|
|
2145
2037
|
$groups?: {
|
|
2146
2038
|
[x: string]: RegleValidationGroupOutput;
|
|
2147
2039
|
};
|
|
2148
|
-
$validate: (
|
|
2040
|
+
$validate: () => Promise<SuperCompatibleRegleResult>;
|
|
2149
2041
|
};
|
|
2150
2042
|
type SuperCompatibleRegleResult = $InternalRegleResult;
|
|
2151
2043
|
type SuperCompatibleRegleStatus = {
|
|
@@ -2174,12 +2066,10 @@ type MergedRegles<TRegles extends Record<string, SuperCompatibleRegleRoot>, TVal
|
|
|
2174
2066
|
readonly $errors: { [K in keyof TRegles]: TRegles[K]['$errors'] };
|
|
2175
2067
|
/** Collection of all the error messages, collected for all children properties. */
|
|
2176
2068
|
readonly $silentErrors: { [K in keyof TRegles]: TRegles[K]['$silentErrors'] };
|
|
2177
|
-
readonly $issues: { [K in keyof TRegles]: TRegles[K]['$issues'] };
|
|
2178
|
-
readonly $silentIssues: { [K in keyof TRegles]: TRegles[K]['$silentIssues'] };
|
|
2179
2069
|
/** 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). */
|
|
2180
2070
|
$extractDirtyFields: (filterNullishValues?: boolean) => PartialDeep$1<TValue>;
|
|
2181
2071
|
/** 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). */
|
|
2182
|
-
$validate: (
|
|
2072
|
+
$validate: () => Promise<MergedReglesResult<TRegles>>;
|
|
2183
2073
|
};
|
|
2184
2074
|
type MergedScopedRegles<TValue extends Record<string, unknown>[] = Record<string, unknown>[]> = Omit<MergedRegles<Record<string, SuperCompatibleRegleRoot>, TValue>, '$instances' | '$errors' | '$silentErrors' | '$value' | '$silentValue' | '$validate'> & {
|
|
2185
2075
|
/** Array of scoped Regles instances */
|
|
@@ -2190,16 +2080,10 @@ type MergedScopedRegles<TValue extends Record<string, unknown>[] = Record<string
|
|
|
2190
2080
|
readonly $errors: RegleValidationErrors<Record<string, unknown>>[];
|
|
2191
2081
|
/** Collection of all registered Regles instances silent errors */
|
|
2192
2082
|
readonly $silentErrors: RegleValidationErrors<Record<string, unknown>>[];
|
|
2193
|
-
/** Collection of all registered Regles instances issues */
|
|
2194
|
-
readonly $issues: RegleValidationErrors<Record<string, unknown>, false, true>[];
|
|
2195
|
-
/** Collection of all registered Regles instances silent issues */
|
|
2196
|
-
readonly $silentIssues: RegleValidationErrors<Record<string, unknown>, false, true>[];
|
|
2197
2083
|
/** 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). */
|
|
2198
|
-
$validate: (
|
|
2084
|
+
$validate: () => Promise<{
|
|
2199
2085
|
valid: boolean;
|
|
2200
2086
|
data: TValue;
|
|
2201
|
-
errors: RegleValidationErrors<Record<string, unknown>>[];
|
|
2202
|
-
issues: RegleValidationErrors<Record<string, unknown>>[];
|
|
2203
2087
|
}>;
|
|
2204
2088
|
};
|
|
2205
2089
|
type MergedReglesResult<TRegles extends Record<string, SuperCompatibleRegleRoot>> = {
|
|
@@ -2207,15 +2091,11 @@ type MergedReglesResult<TRegles extends Record<string, SuperCompatibleRegleRoot>
|
|
|
2207
2091
|
data: { [K in keyof TRegles]: Extract<PromiseReturn<ReturnType<TRegles[K]['$validate']>>, {
|
|
2208
2092
|
valid: false;
|
|
2209
2093
|
}>['data'] };
|
|
2210
|
-
errors: { [K in keyof TRegles]: TRegles[K]['$errors'] };
|
|
2211
|
-
issues: { [K in keyof TRegles]: TRegles[K]['$issues'] };
|
|
2212
2094
|
} | {
|
|
2213
2095
|
valid: true;
|
|
2214
2096
|
data: { [K in keyof TRegles]: Extract<PromiseReturn<ReturnType<TRegles[K]['$validate']>>, {
|
|
2215
2097
|
valid: true;
|
|
2216
2098
|
}>['data'] };
|
|
2217
|
-
errors: EmptyObject$1;
|
|
2218
|
-
issues: EmptyObject$1;
|
|
2219
2099
|
};
|
|
2220
2100
|
//#endregion
|
|
2221
2101
|
//#region src/core/createScopedUseRegle/useCollectScope.d.ts
|
|
@@ -2973,19 +2853,15 @@ type RegleSingleFieldSchema<TState extends Maybe<PrimitiveTypes>, TSchema extend
|
|
|
2973
2853
|
*/
|
|
2974
2854
|
r$: Raw<RegleSchemaFieldStatus<TState, TSchema, TShortcuts> & {
|
|
2975
2855
|
/** 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). */
|
|
2976
|
-
$validate: (
|
|
2856
|
+
$validate: () => Promise<RegleSchemaResult<TSchema>>;
|
|
2977
2857
|
}>;
|
|
2978
2858
|
} & TAdditionalReturnProperties;
|
|
2979
2859
|
type RegleSchemaResult<TSchema extends unknown> = {
|
|
2980
2860
|
valid: false;
|
|
2981
2861
|
data: PartialDeep<TSchema>;
|
|
2982
|
-
issues: RegleIssuesTree<TSchema>;
|
|
2983
|
-
errors: RegleErrorTree<TSchema>;
|
|
2984
2862
|
} | {
|
|
2985
2863
|
valid: true;
|
|
2986
2864
|
data: TSchema;
|
|
2987
|
-
issues: EmptyObject;
|
|
2988
|
-
errors: EmptyObject;
|
|
2989
2865
|
};
|
|
2990
2866
|
type ProcessNestedFields<TState extends Record<string, any>, TSchema extends Record<string, any>, TShortcuts extends RegleShortcutDefinition> = HasNamedKeys<TState> extends true ? { readonly [TKey in keyof JoinDiscriminatedUnions<TState>]: TKey extends keyof JoinDiscriminatedUnions<TSchema> ? InferRegleSchemaStatusType<NonNullable<JoinDiscriminatedUnions<TSchema>[TKey]>, JoinDiscriminatedUnions<TState>[TKey], TShortcuts> : never } & { 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 } : {};
|
|
2991
2867
|
/**
|
|
@@ -3008,7 +2884,7 @@ type RegleSchemaStatus<TState extends Record<string, any> = Record<string, any>,
|
|
|
3008
2884
|
$extractDirtyFields: (filterNullishValues?: boolean) => PartialDeep<TState>;
|
|
3009
2885
|
} & ProcessNestedFields<TState, TSchema, TShortcuts> & (IsRoot extends true ? {
|
|
3010
2886
|
/** 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). */
|
|
3011
|
-
$validate: (
|
|
2887
|
+
$validate: () => Promise<RegleSchemaResult<TSchema>>;
|
|
3012
2888
|
} : {}) & ([TShortcuts['nested']] extends [never] ? {} : { [K in keyof TShortcuts['nested']]: ReturnType<NonNullable<TShortcuts['nested']>[K]> });
|
|
3013
2889
|
/**
|
|
3014
2890
|
* @public
|
package/dist/regle-schemas.js
CHANGED
|
@@ -208,9 +208,7 @@ function createUseRegleSchemaComposable(options, shortcuts) {
|
|
|
208
208
|
try {
|
|
209
209
|
return {
|
|
210
210
|
valid: !(await computeErrors(true)).issues?.length,
|
|
211
|
-
data: processedState.value
|
|
212
|
-
errors: {},
|
|
213
|
-
issues: {}
|
|
211
|
+
data: processedState.value
|
|
214
212
|
};
|
|
215
213
|
} catch (e) {
|
|
216
214
|
return Promise.reject(e);
|
|
@@ -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";function s(e){return e?.constructor.name==`File`||e?.constructor.name==`FileList`}function c(e,t=!0){return e==null?!0:e instanceof Date?isNaN(e.getTime()):s(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 l(e){if(typeof e.source.flags==`string`)return e.source.flags;{let t=[];return e.global&&t.push(`g`),e.ignoreCase&&t.push(`i`),e.multiline&&t.push(`m`),e.sticky&&t.push(`y`),e.unicode&&t.push(`u`),t.join(``)}}function u(e){let t=e,n={}.toString.call(e).slice(8,-1);if(n==`Set`&&(t=new Set([...e].map(e=>u(e)))),n==`Map`&&(t=new Map([...e].map(e=>[u(e[0]),u(e[1])]))),n==`Date`&&(t=new Date(e.getTime())),n==`RegExp`&&(t=RegExp(e.source,l(e))),n==`Array`||n==`Object`)for(let n in t=Array.isArray(e)?[]:{},e)t[n]=u(e[n]);return t}function d(e){return e&&(e instanceof Date||e.constructor.name==`File`||e.constructor.name==`FileList`)?!1:typeof e==`object`&&!!e&&!Array.isArray(e)}function f(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;m(a);for(var o;o=i.shift();)if(m(o),isNaN(parseInt(o))?(e[o]===void 0&&(e[o]={}),e=e[o]):(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}:Array.isArray(e[a])?e[a]=e[a].concat(n):e[a]=n,!0}function p(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 m(e){if(e==`__proto__`||e==`constructor`||e==`prototype`)throw Error(`setting of prototype values not supported`)}function h(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 g(e,s){let c={autoDirty:e?.autoDirty,lazy:e?.lazy,rewardEarly:e?.rewardEarly,clearExternalErrorsOnChange:e?.clearExternalErrorsOnChange};function l(e,l,m){let g=n(()=>a(l)),{syncState:_={onUpdate:!1,onValidate:!1},...v}=m??{},{onUpdate:y=!1,onValidate:b=!1}=_,x={...c,...v},S=n(()=>!d(C.value)),C=r(e)?e:i(e),w=i(d(C.value)?{...u(C.value)}:u(C.value)),T=d(C.value)?{...u(C.value)}:u(C.value),E=i({}),D;if(!g.value?.[`~standard`])throw Error(`Only "standard-schema" compatible libraries are supported`);function O(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(p(C.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})=>{f(t,n,[r],e)}),t}async function k(e=!1){let t=g.value[`~standard`].validate(C.value);return t instanceof Promise&&(t=await t),S.value?E.value=t.issues?.map(e=>({$message:e.message,$property:e.path?.[e.path.length-1]?.toString()??`-`,$rule:`schema`,...e}))??[]:E.value=O(t),t.issues||(e&&b||!e&&y)&&(A?.(),d(C.value)?C.value=h(C.value,t.value):C.value=t.value,j()),t}let A;function j(){A=o([C,g],()=>k(),{deep:!0})}return j(),k(),D=async()=>{try{return{valid:!(await k(!0)).issues?.length,data:C.value
|
|
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";function s(e){return e?.constructor.name==`File`||e?.constructor.name==`FileList`}function c(e,t=!0){return e==null?!0:e instanceof Date?isNaN(e.getTime()):s(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 l(e){if(typeof e.source.flags==`string`)return e.source.flags;{let t=[];return e.global&&t.push(`g`),e.ignoreCase&&t.push(`i`),e.multiline&&t.push(`m`),e.sticky&&t.push(`y`),e.unicode&&t.push(`u`),t.join(``)}}function u(e){let t=e,n={}.toString.call(e).slice(8,-1);if(n==`Set`&&(t=new Set([...e].map(e=>u(e)))),n==`Map`&&(t=new Map([...e].map(e=>[u(e[0]),u(e[1])]))),n==`Date`&&(t=new Date(e.getTime())),n==`RegExp`&&(t=RegExp(e.source,l(e))),n==`Array`||n==`Object`)for(let n in t=Array.isArray(e)?[]:{},e)t[n]=u(e[n]);return t}function d(e){return e&&(e instanceof Date||e.constructor.name==`File`||e.constructor.name==`FileList`)?!1:typeof e==`object`&&!!e&&!Array.isArray(e)}function f(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;m(a);for(var o;o=i.shift();)if(m(o),isNaN(parseInt(o))?(e[o]===void 0&&(e[o]={}),e=e[o]):(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}:Array.isArray(e[a])?e[a]=e[a].concat(n):e[a]=n,!0}function p(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 m(e){if(e==`__proto__`||e==`constructor`||e==`prototype`)throw Error(`setting of prototype values not supported`)}function h(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 g(e,s){let c={autoDirty:e?.autoDirty,lazy:e?.lazy,rewardEarly:e?.rewardEarly,clearExternalErrorsOnChange:e?.clearExternalErrorsOnChange};function l(e,l,m){let g=n(()=>a(l)),{syncState:_={onUpdate:!1,onValidate:!1},...v}=m??{},{onUpdate:y=!1,onValidate:b=!1}=_,x={...c,...v},S=n(()=>!d(C.value)),C=r(e)?e:i(e),w=i(d(C.value)?{...u(C.value)}:u(C.value)),T=d(C.value)?{...u(C.value)}:u(C.value),E=i({}),D;if(!g.value?.[`~standard`])throw Error(`Only "standard-schema" compatible libraries are supported`);function O(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(p(C.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})=>{f(t,n,[r],e)}),t}async function k(e=!1){let t=g.value[`~standard`].validate(C.value);return t instanceof Promise&&(t=await t),S.value?E.value=t.issues?.map(e=>({$message:e.message,$property:e.path?.[e.path.length-1]?.toString()??`-`,$rule:`schema`,...e}))??[]:E.value=O(t),t.issues||(e&&b||!e&&y)&&(A?.(),d(C.value)?C.value=h(C.value,t.value):C.value=t.value,j()),t}let A;function j(){A=o([C,g],()=>k(),{deep:!0})}return j(),k(),D=async()=>{try{return{valid:!(await k(!0)).issues?.length,data:C.value}}catch(e){return Promise.reject(e)}},{r$:t({scopeRules:n(()=>({})),state:C,options:x,schemaErrors:E,initialState:w,originalState:T,shortcuts:s,schemaMode:!0,onValidate:D}).regle}}return l}const _=g();function v(e,t){return e}function y(){function e(e,t){return t}return e}const b=y();function x({modifiers:e,shortcuts:t}){let n=g(e,t),r=y();return{useRegleSchema:n,inferSchema:r}}const{useCollectScope:S,useScopedRegle:C}=e({customUseRegle:_}),w=t=>{let{customStore:n,customUseRegle:r=_,asRecord:i=!1}=t??{};return e({customStore:n,customUseRegle:r,asRecord:i})};export{w as createScopedUseRegleSchema,x as defineRegleSchemaConfig,b as inferSchema,S as useCollectSchemaScope,_ as useRegleSchema,C as useScopedRegleSchema,v as withDeps};
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@regle/schemas",
|
|
3
|
-
"version": "1.9.0
|
|
3
|
+
"version": "1.9.0",
|
|
4
4
|
"description": "Schemas adapter for Regle",
|
|
5
5
|
"dependencies": {
|
|
6
6
|
"@standard-schema/spec": "1.0.0",
|
|
7
|
-
"@regle/core": "1.9.0
|
|
8
|
-
"@regle/rules": "1.9.0
|
|
7
|
+
"@regle/core": "1.9.0",
|
|
8
|
+
"@regle/rules": "1.9.0"
|
|
9
9
|
},
|
|
10
10
|
"peerDependencies": {
|
|
11
11
|
"valibot": "^1.0.0",
|