@regle/schemas 1.2.0-beta.2 → 1.2.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.
@@ -53,6 +53,46 @@ Unfortunately, `Record<string, never>`, `Record<keyof any, never>` and `Record<n
53
53
  */
54
54
  type EmptyObject = {[emptyObjectSymbol]?: never};
55
55
 
56
+ /**
57
+ Extract all optional keys from the given type.
58
+
59
+ This is useful when you want to create a new type that contains different type values for the optional keys only.
60
+
61
+ @example
62
+ ```
63
+ import type {OptionalKeysOf, Except} from 'type-fest';
64
+
65
+ interface User {
66
+ name: string;
67
+ surname: string;
68
+
69
+ luckyNumber?: number;
70
+ }
71
+
72
+ const REMOVE_FIELD = Symbol('remove field symbol');
73
+ type UpdateOperation<Entity extends object> = Except<Partial<Entity>, OptionalKeysOf<Entity>> & {
74
+ [Key in OptionalKeysOf<Entity>]?: Entity[Key] | typeof REMOVE_FIELD;
75
+ };
76
+
77
+ const update1: UpdateOperation<User> = {
78
+ name: 'Alice'
79
+ };
80
+
81
+ const update2: UpdateOperation<User> = {
82
+ name: 'Bob',
83
+ luckyNumber: REMOVE_FIELD
84
+ };
85
+ ```
86
+
87
+ @category Utilities
88
+ */
89
+ type OptionalKeysOf<BaseType extends object> =
90
+ BaseType extends unknown // For distributing `BaseType`
91
+ ? (keyof {
92
+ [Key in keyof BaseType as BaseType extends Record<Key, BaseType[Key]> ? never : Key]: never
93
+ }) & (keyof BaseType) // Intersect with `keyof BaseType` to ensure result of `OptionalKeysOf<BaseType>` is always assignable to `keyof BaseType`
94
+ : never; // Should never happen
95
+
56
96
  /**
57
97
  Extract all required keys from the given type.
58
98
 
@@ -77,11 +117,10 @@ const validator2 = createValidation<User>('surname', value => value.length < 25)
77
117
 
78
118
  @category Utilities
79
119
  */
80
- type RequiredKeysOf<BaseType extends object> = Exclude<{
81
- [Key in keyof BaseType]: BaseType extends Record<Key, BaseType[Key]>
82
- ? Key
83
- : never
84
- }[keyof BaseType], undefined>;
120
+ type RequiredKeysOf<BaseType extends object> =
121
+ BaseType extends unknown // For distributing `BaseType`
122
+ ? Exclude<keyof BaseType, OptionalKeysOf<BaseType>>
123
+ : never; // Should never happen
85
124
 
86
125
  /**
87
126
  Returns a boolean for whether the given type is `never`.
@@ -466,45 +505,6 @@ type IfAny<T, TypeIfAny = true, TypeIfNotAny = false> = (
466
505
  IsAny<T> extends true ? TypeIfAny : TypeIfNotAny
467
506
  );
468
507
 
469
- /**
470
- Extract all optional keys from the given type.
471
-
472
- This is useful when you want to create a new type that contains different type values for the optional keys only.
473
-
474
- @example
475
- ```
476
- import type {OptionalKeysOf, Except} from 'type-fest';
477
-
478
- interface User {
479
- name: string;
480
- surname: string;
481
-
482
- luckyNumber?: number;
483
- }
484
-
485
- const REMOVE_FIELD = Symbol('remove field symbol');
486
- type UpdateOperation<Entity extends object> = Except<Partial<Entity>, OptionalKeysOf<Entity>> & {
487
- [Key in OptionalKeysOf<Entity>]?: Entity[Key] | typeof REMOVE_FIELD;
488
- };
489
-
490
- const update1: UpdateOperation<User> = {
491
- name: 'Alice'
492
- };
493
-
494
- const update2: UpdateOperation<User> = {
495
- name: 'Bob',
496
- luckyNumber: REMOVE_FIELD
497
- };
498
- ```
499
-
500
- @category Utilities
501
- */
502
- type OptionalKeysOf<BaseType extends object> = Exclude<{
503
- [Key in keyof BaseType]: BaseType extends Record<Key, BaseType[Key]>
504
- ? never
505
- : Key
506
- }[keyof BaseType], undefined>;
507
-
508
508
  /**
509
509
  Matches any primitive, `void`, `Date`, or `RegExp` value.
510
510
  */
@@ -571,7 +571,11 @@ type ApplyDefaultOptions<
571
571
  IfNever<SpecifiedOptions, Defaults,
572
572
  Simplify<Merge<Defaults, {
573
573
  [Key in keyof SpecifiedOptions
574
- as Key extends OptionalKeysOf<Options> ? undefined extends SpecifiedOptions[Key] ? never : Key : Key
574
+ as Key extends OptionalKeysOf<Options>
575
+ ? Extract<SpecifiedOptions[Key], undefined> extends never
576
+ ? Key
577
+ : never
578
+ : Key
575
579
  ]: SpecifiedOptions[Key]
576
580
  }> & Required<Options>> // `& Required<Options>` ensures that `ApplyDefaultOptions<SomeOption, ...>` is always assignable to `Required<SomeOption>`
577
581
  >>;
@@ -671,27 +675,29 @@ const partialSettings: PartialDeep<Settings, {recurseIntoArrays: true}> = {
671
675
  type PartialDeep<T, Options extends PartialDeepOptions = {}> =
672
676
  _PartialDeep<T, ApplyDefaultOptions<PartialDeepOptions, DefaultPartialDeepOptions, Options>>;
673
677
 
674
- type _PartialDeep<T, Options extends Required<PartialDeepOptions>> = T extends BuiltIns | (((...arguments_: any[]) => unknown)) | (new (...arguments_: any[]) => unknown)
678
+ type _PartialDeep<T, Options extends Required<PartialDeepOptions>> = T extends BuiltIns | ((new (...arguments_: any[]) => unknown))
675
679
  ? T
676
- : T extends Map<infer KeyType, infer ValueType>
677
- ? PartialMapDeep<KeyType, ValueType, Options>
678
- : T extends Set<infer ItemType>
679
- ? PartialSetDeep<ItemType, Options>
680
- : T extends ReadonlyMap<infer KeyType, infer ValueType>
681
- ? PartialReadonlyMapDeep<KeyType, ValueType, Options>
682
- : T extends ReadonlySet<infer ItemType>
683
- ? PartialReadonlySetDeep<ItemType, Options>
684
- : T extends object
685
- ? T extends ReadonlyArray<infer ItemType> // Test for arrays/tuples, per https://github.com/microsoft/TypeScript/issues/35156
686
- ? Options['recurseIntoArrays'] extends true
687
- ? ItemType[] extends T // Test for arrays (non-tuples) specifically
688
- ? readonly ItemType[] extends T // Differentiate readonly and mutable arrays
689
- ? ReadonlyArray<_PartialDeep<Options['allowUndefinedInNonTupleArrays'] extends false ? ItemType : ItemType | undefined, Options>>
690
- : Array<_PartialDeep<Options['allowUndefinedInNonTupleArrays'] extends false ? ItemType : ItemType | undefined, Options>>
691
- : PartialObjectDeep<T, Options> // Tuples behave properly
692
- : T // If they don't opt into array testing, just use the original type
693
- : PartialObjectDeep<T, Options>
694
- : unknown;
680
+ : IsNever<keyof T> extends true // For functions with no properties
681
+ ? T
682
+ : T extends Map<infer KeyType, infer ValueType>
683
+ ? PartialMapDeep<KeyType, ValueType, Options>
684
+ : T extends Set<infer ItemType>
685
+ ? PartialSetDeep<ItemType, Options>
686
+ : T extends ReadonlyMap<infer KeyType, infer ValueType>
687
+ ? PartialReadonlyMapDeep<KeyType, ValueType, Options>
688
+ : T extends ReadonlySet<infer ItemType>
689
+ ? PartialReadonlySetDeep<ItemType, Options>
690
+ : T extends object
691
+ ? T extends ReadonlyArray<infer ItemType> // Test for arrays/tuples, per https://github.com/microsoft/TypeScript/issues/35156
692
+ ? Options['recurseIntoArrays'] extends true
693
+ ? ItemType[] extends T // Test for arrays (non-tuples) specifically
694
+ ? readonly ItemType[] extends T // Differentiate readonly and mutable arrays
695
+ ? ReadonlyArray<_PartialDeep<Options['allowUndefinedInNonTupleArrays'] extends false ? ItemType : ItemType | undefined, Options>>
696
+ : Array<_PartialDeep<Options['allowUndefinedInNonTupleArrays'] extends false ? ItemType : ItemType | undefined, Options>>
697
+ : PartialObjectDeep<T, Options> // Tuples behave properly
698
+ : T // If they don't opt into array testing, just use the original type
699
+ : PartialObjectDeep<T, Options>
700
+ : unknown;
695
701
 
696
702
  /**
697
703
  Same as `PartialDeep`, but accepts only `Map`s and as inputs. Internal helper for `PartialDeep`.
@@ -716,9 +722,12 @@ type PartialReadonlySetDeep<T, Options extends Required<PartialDeepOptions>> = {
716
722
  /**
717
723
  Same as `PartialDeep`, but accepts only `object`s as inputs. Internal helper for `PartialDeep`.
718
724
  */
719
- type PartialObjectDeep<ObjectType extends object, Options extends Required<PartialDeepOptions>> = {
720
- [KeyType in keyof ObjectType]?: _PartialDeep<ObjectType[KeyType], Options>
721
- };
725
+ type PartialObjectDeep<ObjectType extends object, Options extends Required<PartialDeepOptions>> =
726
+ (ObjectType extends (...arguments_: any) => unknown
727
+ ? (...arguments_: Parameters<ObjectType>) => ReturnType<ObjectType>
728
+ : {}) & ({
729
+ [KeyType in keyof ObjectType]?: _PartialDeep<ObjectType[KeyType], Options>
730
+ });
722
731
 
723
732
  interface RegleSchema<TState extends Record<string, any>, TSchema extends Record<string, any>, TShortcuts extends RegleShortcutDefinition = {}> {
724
733
  /**
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@regle/schemas",
3
- "version": "1.2.0-beta.2",
3
+ "version": "1.2.0-beta.3",
4
4
  "description": "Schemas adapter for Regle",
5
5
  "dependencies": {
6
6
  "@standard-schema/spec": "1.0.0",
7
- "@regle/core": "1.2.0-beta.2",
8
- "@regle/rules": "1.2.0-beta.2"
7
+ "@regle/core": "1.2.0-beta.3",
8
+ "@regle/rules": "1.2.0-beta.3"
9
9
  },
10
10
  "peerDependencies": {
11
11
  "valibot": "^1.0.0",
@@ -25,23 +25,23 @@
25
25
  },
26
26
  "devDependencies": {
27
27
  "@total-typescript/ts-reset": "0.6.1",
28
- "@types/node": "22.13.17",
28
+ "@types/node": "22.15.3",
29
29
  "@typescript-eslint/eslint-plugin": "8.28.0",
30
30
  "@typescript-eslint/parser": "8.28.0",
31
31
  "@vue/test-utils": "2.4.6",
32
- "eslint": "9.15.0",
32
+ "eslint": "9.25.1",
33
33
  "eslint-config-prettier": "9.1.0",
34
- "eslint-plugin-vue": "9.31.0",
34
+ "eslint-plugin-vue": "9.33.0",
35
35
  "prettier": "3.5.3",
36
36
  "tsup": "8.4.0",
37
- "type-fest": "4.38.0",
38
- "typescript": "5.8.2",
37
+ "type-fest": "4.40.1",
38
+ "typescript": "5.8.3",
39
39
  "valibot": "1.0.0",
40
- "vitest": "3.1.1",
40
+ "vitest": "3.1.2",
41
41
  "vue": "3.5.13",
42
42
  "vue-eslint-parser": "10.1.3",
43
- "vue-tsc": "2.2.8",
44
- "zod": "3.24.2"
43
+ "vue-tsc": "2.2.10",
44
+ "zod": "3.24.3"
45
45
  },
46
46
  "type": "module",
47
47
  "exports": {