@xsai/stream-object 0.2.0 → 0.2.2

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.
Files changed (2) hide show
  1. package/dist/index.d.ts +34 -129
  2. package/package.json +2 -2
package/dist/index.d.ts CHANGED
@@ -22,109 +22,6 @@ declare global {
22
22
  }
23
23
  }
24
24
 
25
- /**
26
- Convert a union type to an intersection type using [distributive conditional types](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-8.html#distributive-conditional-types).
27
-
28
- Inspired by [this Stack Overflow answer](https://stackoverflow.com/a/50375286/2172153).
29
-
30
- @example
31
- ```
32
- import type {UnionToIntersection} from 'type-fest';
33
-
34
- type Union = {the(): void} | {great(arg: string): void} | {escape: boolean};
35
-
36
- type Intersection = UnionToIntersection<Union>;
37
- //=> {the(): void; great(arg: string): void; escape: boolean};
38
- ```
39
-
40
- A more applicable example which could make its way into your library code follows.
41
-
42
- @example
43
- ```
44
- import type {UnionToIntersection} from 'type-fest';
45
-
46
- class CommandOne {
47
- commands: {
48
- a1: () => undefined,
49
- b1: () => undefined,
50
- }
51
- }
52
-
53
- class CommandTwo {
54
- commands: {
55
- a2: (argA: string) => undefined,
56
- b2: (argB: string) => undefined,
57
- }
58
- }
59
-
60
- const union = [new CommandOne(), new CommandTwo()].map(instance => instance.commands);
61
- type Union = typeof union;
62
- //=> {a1(): void; b1(): void} | {a2(argA: string): void; b2(argB: string): void}
63
-
64
- type Intersection = UnionToIntersection<Union>;
65
- //=> {a1(): void; b1(): void; a2(argA: string): void; b2(argB: string): void}
66
- ```
67
-
68
- @category Type
69
- */
70
- type UnionToIntersection<Union> = (
71
- // `extends unknown` is always going to be the case and is used to convert the
72
- // `Union` into a [distributive conditional
73
- // type](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-8.html#distributive-conditional-types).
74
- Union extends unknown
75
- // The union type is used as the only argument to a function since the union
76
- // of function arguments is an intersection.
77
- ? (distributedUnion: Union) => void
78
- // This won't happen.
79
- : never
80
- // Infer the `Intersection` type since TypeScript represents the positional
81
- // arguments of unions of functions as an intersection of the union.
82
- ) extends ((mergedIntersection: infer Intersection) => void)
83
- // The `& Union` is to allow indexing by the resulting type
84
- ? Intersection & Union
85
- : never;
86
-
87
- /**
88
- Create a union of all keys from a given type, even those exclusive to specific union members.
89
-
90
- Unlike the native `keyof` keyword, which returns keys present in **all** union members, this type returns keys from **any** member.
91
-
92
- @link https://stackoverflow.com/a/49402091
93
-
94
- @example
95
- ```
96
- import type {KeysOfUnion} from 'type-fest';
97
-
98
- type A = {
99
- common: string;
100
- a: number;
101
- };
102
-
103
- type B = {
104
- common: string;
105
- b: string;
106
- };
107
-
108
- type C = {
109
- common: string;
110
- c: boolean;
111
- };
112
-
113
- type Union = A | B | C;
114
-
115
- type CommonKeys = keyof Union;
116
- //=> 'common'
117
-
118
- type AllKeys = KeysOfUnion<Union>;
119
- //=> 'common' | 'a' | 'b' | 'c'
120
- ```
121
-
122
- @category Object
123
- */
124
- type KeysOfUnion<ObjectType> =
125
- // Hack to fix https://github.com/sindresorhus/type-fest/issues/1008
126
- keyof UnionToIntersection<ObjectType extends unknown ? Record<keyof ObjectType, never> : never>;
127
-
128
25
  /**
129
26
  Extract all optional keys from the given type.
130
27
 
@@ -158,9 +55,12 @@ const update2: UpdateOperation<User> = {
158
55
 
159
56
  @category Utilities
160
57
  */
161
- type OptionalKeysOf<BaseType extends object> = KeysOfUnion<{
162
- [Key in keyof BaseType as BaseType extends Record<Key, BaseType[Key]> ? never : Key]: never
163
- }>;
58
+ type OptionalKeysOf<BaseType extends object> =
59
+ BaseType extends unknown // For distributing `BaseType`
60
+ ? (keyof {
61
+ [Key in keyof BaseType as BaseType extends Record<Key, BaseType[Key]> ? never : Key]: never
62
+ }) & (keyof BaseType) // Intersect with `keyof BaseType` to ensure result of `OptionalKeysOf<BaseType>` is always assignable to `keyof BaseType`
63
+ : never; // Should never happen
164
64
 
165
65
  /**
166
66
  Extract all required keys from the given type.
@@ -735,27 +635,29 @@ const partialSettings: PartialDeep<Settings, {recurseIntoArrays: true}> = {
735
635
  type PartialDeep<T, Options extends PartialDeepOptions = {}> =
736
636
  _PartialDeep<T, ApplyDefaultOptions<PartialDeepOptions, DefaultPartialDeepOptions, Options>>;
737
637
 
738
- type _PartialDeep<T, Options extends Required<PartialDeepOptions>> = T extends BuiltIns | (((...arguments_: any[]) => unknown)) | (new (...arguments_: any[]) => unknown)
638
+ type _PartialDeep<T, Options extends Required<PartialDeepOptions>> = T extends BuiltIns | ((new (...arguments_: any[]) => unknown))
739
639
  ? T
740
- : T extends Map<infer KeyType, infer ValueType>
741
- ? PartialMapDeep<KeyType, ValueType, Options>
742
- : T extends Set<infer ItemType>
743
- ? PartialSetDeep<ItemType, Options>
744
- : T extends ReadonlyMap<infer KeyType, infer ValueType>
745
- ? PartialReadonlyMapDeep<KeyType, ValueType, Options>
746
- : T extends ReadonlySet<infer ItemType>
747
- ? PartialReadonlySetDeep<ItemType, Options>
748
- : T extends object
749
- ? T extends ReadonlyArray<infer ItemType> // Test for arrays/tuples, per https://github.com/microsoft/TypeScript/issues/35156
750
- ? Options['recurseIntoArrays'] extends true
751
- ? ItemType[] extends T // Test for arrays (non-tuples) specifically
752
- ? readonly ItemType[] extends T // Differentiate readonly and mutable arrays
753
- ? ReadonlyArray<_PartialDeep<Options['allowUndefinedInNonTupleArrays'] extends false ? ItemType : ItemType | undefined, Options>>
754
- : Array<_PartialDeep<Options['allowUndefinedInNonTupleArrays'] extends false ? ItemType : ItemType | undefined, Options>>
755
- : PartialObjectDeep<T, Options> // Tuples behave properly
756
- : T // If they don't opt into array testing, just use the original type
757
- : PartialObjectDeep<T, Options>
758
- : unknown;
640
+ : IsNever<keyof T> extends true // For functions with no properties
641
+ ? T
642
+ : T extends Map<infer KeyType, infer ValueType>
643
+ ? PartialMapDeep<KeyType, ValueType, Options>
644
+ : T extends Set<infer ItemType>
645
+ ? PartialSetDeep<ItemType, Options>
646
+ : T extends ReadonlyMap<infer KeyType, infer ValueType>
647
+ ? PartialReadonlyMapDeep<KeyType, ValueType, Options>
648
+ : T extends ReadonlySet<infer ItemType>
649
+ ? PartialReadonlySetDeep<ItemType, Options>
650
+ : T extends object
651
+ ? T extends ReadonlyArray<infer ItemType> // Test for arrays/tuples, per https://github.com/microsoft/TypeScript/issues/35156
652
+ ? Options['recurseIntoArrays'] extends true
653
+ ? ItemType[] extends T // Test for arrays (non-tuples) specifically
654
+ ? readonly ItemType[] extends T // Differentiate readonly and mutable arrays
655
+ ? ReadonlyArray<_PartialDeep<Options['allowUndefinedInNonTupleArrays'] extends false ? ItemType : ItemType | undefined, Options>>
656
+ : Array<_PartialDeep<Options['allowUndefinedInNonTupleArrays'] extends false ? ItemType : ItemType | undefined, Options>>
657
+ : PartialObjectDeep<T, Options> // Tuples behave properly
658
+ : T // If they don't opt into array testing, just use the original type
659
+ : PartialObjectDeep<T, Options>
660
+ : unknown;
759
661
 
760
662
  /**
761
663
  Same as `PartialDeep`, but accepts only `Map`s and as inputs. Internal helper for `PartialDeep`.
@@ -780,9 +682,12 @@ type PartialReadonlySetDeep<T, Options extends Required<PartialDeepOptions>> = {
780
682
  /**
781
683
  Same as `PartialDeep`, but accepts only `object`s as inputs. Internal helper for `PartialDeep`.
782
684
  */
783
- type PartialObjectDeep<ObjectType extends object, Options extends Required<PartialDeepOptions>> = {
784
- [KeyType in keyof ObjectType]?: _PartialDeep<ObjectType[KeyType], Options>
785
- };
685
+ type PartialObjectDeep<ObjectType extends object, Options extends Required<PartialDeepOptions>> =
686
+ (ObjectType extends (...arguments_: any) => unknown
687
+ ? (...arguments_: Parameters<ObjectType>) => ReturnType<ObjectType>
688
+ : {}) & ({
689
+ [KeyType in keyof ObjectType]?: _PartialDeep<ObjectType[KeyType], Options>
690
+ });
786
691
 
787
692
  interface StreamObjectOnFinishResult<T extends Schema> {
788
693
  object?: Infer<T>;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@xsai/stream-object",
3
3
  "type": "module",
4
- "version": "0.2.0",
4
+ "version": "0.2.2",
5
5
  "description": "extra-small AI SDK.",
6
6
  "author": "Moeru AI",
7
7
  "license": "MIT",
@@ -35,7 +35,7 @@
35
35
  "devDependencies": {
36
36
  "@valibot/to-json-schema": "^1.0.0",
37
37
  "best-effort-json-parser": "^1.1.3",
38
- "type-fest": "^4.39.0",
38
+ "type-fest": "^4.41.0",
39
39
  "valibot": "^1.0.0"
40
40
  },
41
41
  "scripts": {