@pawover/kit 0.0.0-beta.1 → 0.0.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.
@@ -1 +1 @@
1
- {"version":3,"file":"patches-fetchEventSource.d.ts","names":["IsAny","T","NoInfer","IsAny","IsOptionalKeyOf","Type","Key","Record","IsOptionalKeyOf","OptionalKeysOf","Type","Key","OptionalKeysOf","RequiredKeysOf","Type","Exclude","IsNever","T","IsNever","If","Type","IfBranch","ElseBranch","Simplify","T","KeyType","IsNever","IsEqual","A","B","_IsEqual","G","OmitIndexSignature","ObjectType","KeyType","Record","PickIndexSignature","ObjectType","KeyType","Record","OmitIndexSignature","PickIndexSignature","Simplify","SimpleMerge","Destination","Source","Key","Merge","Simplify","IsEqual","KeysOfUnion","RequiredKeysOf","Merge","OptionalKeysOf","IsAny","If","IsNever","FilterDefinedKeys","FilterOptionalKeys","MapsSetsOrArrays","NonRecursiveType","ToString","BuildObject","Key","Value","CopiedFrom","PropertyKey","Pick","NumberKey","IsPlainObject","T","ObjectValue","K","NumberK","UndefinedToOptional","Exclude","HomomorphicPick","Keys","P","Extract","ValueOfUnion","Union","ReadonlyKeysOfUnion","ApplyDefaultOptions","Options","Defaults","SpecifiedOptions","Required","Omit","Record","Partial","CollapseLiterals","ApplyDefaultOptions","IsEqual","Filter","KeyType","ExcludeType","ExceptOptions","DefaultExceptOptions","Except","ObjectType","KeysType","Options","_Except","Required","Record","Partial"],"sources":["../node_modules/.pnpm/type-fest@5.3.1/node_modules/type-fest/source/is-any.d.ts","../node_modules/.pnpm/type-fest@5.3.1/node_modules/type-fest/source/is-optional-key-of.d.ts","../node_modules/.pnpm/type-fest@5.3.1/node_modules/type-fest/source/optional-keys-of.d.ts","../node_modules/.pnpm/type-fest@5.3.1/node_modules/type-fest/source/required-keys-of.d.ts","../node_modules/.pnpm/type-fest@5.3.1/node_modules/type-fest/source/is-never.d.ts","../node_modules/.pnpm/type-fest@5.3.1/node_modules/type-fest/source/if.d.ts","../node_modules/.pnpm/type-fest@5.3.1/node_modules/type-fest/source/simplify.d.ts","../node_modules/.pnpm/type-fest@5.3.1/node_modules/type-fest/source/is-equal.d.ts","../node_modules/.pnpm/type-fest@5.3.1/node_modules/type-fest/source/omit-index-signature.d.ts","../node_modules/.pnpm/type-fest@5.3.1/node_modules/type-fest/source/pick-index-signature.d.ts","../node_modules/.pnpm/type-fest@5.3.1/node_modules/type-fest/source/merge.d.ts","../node_modules/.pnpm/type-fest@5.3.1/node_modules/type-fest/source/internal/object.d.ts","../node_modules/.pnpm/type-fest@5.3.1/node_modules/type-fest/source/except.d.ts","../src/patches/fetchEventSource/parse.ts","../src/patches/fetchEventSource/fetchEventSource.ts"],"sourcesContent":["/**\nReturns a boolean for whether the given type is `any`.\n\n@link https://stackoverflow.com/a/49928360/1490091\n\nUseful in type utilities, such as disallowing `any`s to be passed to a function.\n\n@example\n```\nimport type {IsAny} from 'type-fest';\n\nconst typedObject = {a: 1, b: 2} as const;\nconst anyObject: any = {a: 1, b: 2};\n\nfunction get<O extends (IsAny<O> extends true ? {} : Record<string, number>), K extends keyof O = keyof O>(object: O, key: K) {\n\treturn object[key];\n}\n\nconst typedA = get(typedObject, 'a');\n//=> 1\n\nconst anyA = get(anyObject, 'a');\n//=> any\n```\n\n@category Type Guard\n@category Utilities\n*/\nexport type IsAny<T> = 0 extends 1 & NoInfer<T> ? true : false;\n\nexport {};\n","import type {IsAny} from './is-any.d.ts';\n\n/**\nReturns a boolean for whether the given key is an optional key of type.\n\nThis is useful when writing utility types or schema validators that need to differentiate `optional` keys.\n\n@example\n```\nimport type {IsOptionalKeyOf} from 'type-fest';\n\ntype User = {\n\tname: string;\n\tsurname: string;\n\n\tluckyNumber?: number;\n};\n\ntype Admin = {\n\tname: string;\n\tsurname?: string;\n};\n\ntype T1 = IsOptionalKeyOf<User, 'luckyNumber'>;\n//=> true\n\ntype T2 = IsOptionalKeyOf<User, 'name'>;\n//=> false\n\ntype T3 = IsOptionalKeyOf<User, 'name' | 'luckyNumber'>;\n//=> boolean\n\ntype T4 = IsOptionalKeyOf<User | Admin, 'name'>;\n//=> false\n\ntype T5 = IsOptionalKeyOf<User | Admin, 'surname'>;\n//=> boolean\n```\n\n@category Type Guard\n@category Utilities\n*/\nexport type IsOptionalKeyOf<Type extends object, Key extends keyof Type> =\n\tIsAny<Type | Key> extends true ? never\n\t\t: Key extends keyof Type\n\t\t\t? Type extends Record<Key, Type[Key]>\n\t\t\t\t? false\n\t\t\t\t: true\n\t\t\t: false;\n\nexport {};\n","import type {IsOptionalKeyOf} from './is-optional-key-of.d.ts';\n\n/**\nExtract all optional keys from the given type.\n\nThis is useful when you want to create a new type that contains different type values for the optional keys only.\n\n@example\n```\nimport type {OptionalKeysOf, Except} from 'type-fest';\n\ntype User = {\n\tname: string;\n\tsurname: string;\n\n\tluckyNumber?: number;\n};\n\nconst REMOVE_FIELD = Symbol('remove field symbol');\ntype UpdateOperation<Entity extends object> = Except<Partial<Entity>, OptionalKeysOf<Entity>> & {\n\t[Key in OptionalKeysOf<Entity>]?: Entity[Key] | typeof REMOVE_FIELD;\n};\n\nconst update1: UpdateOperation<User> = {\n\tname: 'Alice',\n};\n\nconst update2: UpdateOperation<User> = {\n\tname: 'Bob',\n\tluckyNumber: REMOVE_FIELD,\n};\n```\n\n@category Utilities\n*/\nexport type OptionalKeysOf<Type extends object> =\n\tType extends unknown // For distributing `Type`\n\t\t? (keyof {[Key in keyof Type as\n\t\t\tIsOptionalKeyOf<Type, Key> extends false\n\t\t\t\t? never\n\t\t\t\t: Key\n\t\t\t]: never\n\t\t}) & keyof Type // Intersect with `keyof Type` to ensure result of `OptionalKeysOf<Type>` is always assignable to `keyof Type`\n\t\t: never; // Should never happen\n\nexport {};\n","import type {OptionalKeysOf} from './optional-keys-of.d.ts';\n\n/**\nExtract all required keys from the given type.\n\nThis is useful when you want to create a new type that contains different type values for the required keys only or use the list of keys for validation purposes, etc...\n\n@example\n```\nimport type {RequiredKeysOf} from 'type-fest';\n\ndeclare function createValidation<\n\tEntity extends object,\n\tKey extends RequiredKeysOf<Entity> = RequiredKeysOf<Entity>,\n>(field: Key, validator: (value: Entity[Key]) => boolean): (entity: Entity) => boolean;\n\ntype User = {\n\tname: string;\n\tsurname: string;\n\tluckyNumber?: number;\n};\n\nconst validator1 = createValidation<User>('name', value => value.length < 25);\nconst validator2 = createValidation<User>('surname', value => value.length < 25);\n\n// @ts-expect-error\nconst validator3 = createValidation<User>('luckyNumber', value => value > 0);\n// Error: Argument of type '\"luckyNumber\"' is not assignable to parameter of type '\"name\" | \"surname\"'.\n```\n\n@category Utilities\n*/\nexport type RequiredKeysOf<Type extends object> =\n\tType extends unknown // For distributing `Type`\n\t\t? Exclude<keyof Type, OptionalKeysOf<Type>>\n\t\t: never; // Should never happen\n\nexport {};\n","/**\nReturns a boolean for whether the given type is `never`.\n\n@link https://github.com/microsoft/TypeScript/issues/31751#issuecomment-498526919\n@link https://stackoverflow.com/a/53984913/10292952\n@link https://www.zhenghao.io/posts/ts-never\n\nUseful in type utilities, such as checking if something does not occur.\n\n@example\n```\nimport type {IsNever, And} from 'type-fest';\n\ntype A = IsNever<never>;\n//=> true\n\ntype B = IsNever<any>;\n//=> false\n\ntype C = IsNever<unknown>;\n//=> false\n\ntype D = IsNever<never[]>;\n//=> false\n\ntype E = IsNever<object>;\n//=> false\n\ntype F = IsNever<string>;\n//=> false\n```\n\n@example\n```\nimport type {IsNever} from 'type-fest';\n\ntype IsTrue<T> = T extends true ? true : false;\n\n// When a distributive conditional is instantiated with `never`, the entire conditional results in `never`.\ntype A = IsTrue<never>;\n// ^? type A = never\n\n// If you don't want that behaviour, you can explicitly add an `IsNever` check before the distributive conditional.\ntype IsTrueFixed<T> =\n\tIsNever<T> extends true ? false : T extends true ? true : false;\n\ntype B = IsTrueFixed<never>;\n// ^? type B = false\n```\n\n@category Type Guard\n@category Utilities\n*/\nexport type IsNever<T> = [T] extends [never] ? true : false;\n\nexport {};\n","import type {IsNever} from './is-never.d.ts';\n\n/**\nAn if-else-like type that resolves depending on whether the given `boolean` type is `true` or `false`.\n\nUse-cases:\n- You can use this in combination with `Is*` types to create an if-else-like experience. For example, `If<IsAny<any>, 'is any', 'not any'>`.\n\nNote:\n- Returns a union of if branch and else branch if the given type is `boolean` or `any`. For example, `If<boolean, 'Y', 'N'>` will return `'Y' | 'N'`.\n- Returns the else branch if the given type is `never`. For example, `If<never, 'Y', 'N'>` will return `'N'`.\n\n@example\n```\nimport type {If} from 'type-fest';\n\ntype A = If<true, 'yes', 'no'>;\n//=> 'yes'\n\ntype B = If<false, 'yes', 'no'>;\n//=> 'no'\n\ntype C = If<boolean, 'yes', 'no'>;\n//=> 'yes' | 'no'\n\ntype D = If<any, 'yes', 'no'>;\n//=> 'yes' | 'no'\n\ntype E = If<never, 'yes', 'no'>;\n//=> 'no'\n```\n\n@example\n```\nimport type {If, IsAny, IsNever} from 'type-fest';\n\ntype A = If<IsAny<unknown>, 'is any', 'not any'>;\n//=> 'not any'\n\ntype B = If<IsNever<never>, 'is never', 'not never'>;\n//=> 'is never'\n```\n\n@example\n```\nimport type {If, IsEqual} from 'type-fest';\n\ntype IfEqual<T, U, IfBranch, ElseBranch> = If<IsEqual<T, U>, IfBranch, ElseBranch>;\n\ntype A = IfEqual<string, string, 'equal', 'not equal'>;\n//=> 'equal'\n\ntype B = IfEqual<string, number, 'equal', 'not equal'>;\n//=> 'not equal'\n```\n\nNote: Sometimes using the `If` type can make an implementation non–tail-recursive, which can impact performance. In such cases, it’s better to use a conditional directly. Refer to the following example:\n\n@example\n```\nimport type {If, IsEqual, StringRepeat} from 'type-fest';\n\ntype HundredZeroes = StringRepeat<'0', 100>;\n\n// The following implementation is not tail recursive\ntype Includes<S extends string, Char extends string> =\n\tS extends `${infer First}${infer Rest}`\n\t\t? If<IsEqual<First, Char>,\n\t\t\t'found',\n\t\t\tIncludes<Rest, Char>>\n\t\t: 'not found';\n\n// Hence, instantiations with long strings will fail\n// @ts-expect-error\ntype Fails = Includes<HundredZeroes, '1'>;\n// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n// Error: Type instantiation is excessively deep and possibly infinite.\n\n// However, if we use a simple conditional instead of `If`, the implementation becomes tail-recursive\ntype IncludesWithoutIf<S extends string, Char extends string> =\n\tS extends `${infer First}${infer Rest}`\n\t\t? IsEqual<First, Char> extends true\n\t\t\t? 'found'\n\t\t\t: IncludesWithoutIf<Rest, Char>\n\t\t: 'not found';\n\n// Now, instantiations with long strings will work\ntype Works = IncludesWithoutIf<HundredZeroes, '1'>;\n//=> 'not found'\n```\n\n@category Type Guard\n@category Utilities\n*/\nexport type If<Type extends boolean, IfBranch, ElseBranch> =\n\tIsNever<Type> extends true\n\t\t? ElseBranch\n\t\t: Type extends true\n\t\t\t? IfBranch\n\t\t\t: ElseBranch;\n\nexport {};\n","/**\nUseful to flatten the type output to improve type hints shown in editors. And also to transform an interface into a type to aide with assignability.\n\n@example\n```\nimport type {Simplify} from 'type-fest';\n\ntype PositionProps = {\n\ttop: number;\n\tleft: number;\n};\n\ntype SizeProps = {\n\twidth: number;\n\theight: number;\n};\n\n// In your editor, hovering over `Props` will show a flattened object with all the properties.\ntype Props = Simplify<PositionProps & SizeProps>;\n```\n\nSometimes it is desired to pass a value as a function argument that has a different type. At first inspection it may seem assignable, and then you discover it is not because the `value`'s type definition was defined as an interface. In the following example, `fn` requires an argument of type `Record<string, unknown>`. If the value is defined as a literal, then it is assignable. And if the `value` is defined as type using the `Simplify` utility the value is assignable. But if the `value` is defined as an interface, it is not assignable because the interface is not sealed and elsewhere a non-string property could be added to the interface.\n\nIf the type definition must be an interface (perhaps it was defined in a third-party npm package), then the `value` can be defined as `const value: Simplify<SomeInterface> = ...`. Then `value` will be assignable to the `fn` argument. Or the `value` can be cast as `Simplify<SomeInterface>` if you can't re-declare the `value`.\n\n@example\n```\nimport type {Simplify} from 'type-fest';\n\ninterface SomeInterface {\n\tfoo: number;\n\tbar?: string;\n\tbaz: number | undefined;\n}\n\ntype SomeType = {\n\tfoo: number;\n\tbar?: string;\n\tbaz: number | undefined;\n};\n\nconst literal = {foo: 123, bar: 'hello', baz: 456};\nconst someType: SomeType = literal;\nconst someInterface: SomeInterface = literal;\n\ndeclare function fn(object: Record<string, unknown>): void;\n\nfn(literal); // Good: literal object type is sealed\nfn(someType); // Good: type is sealed\n// @ts-expect-error\nfn(someInterface); // Error: Index signature for type 'string' is missing in type 'someInterface'. Because `interface` can be re-opened\nfn(someInterface as Simplify<SomeInterface>); // Good: transform an `interface` into a `type`\n```\n\n@link https://github.com/microsoft/TypeScript/issues/15300\n@see {@link SimplifyDeep}\n@category Object\n*/\nexport type Simplify<T> = {[KeyType in keyof T]: T[KeyType]} & {};\n\nexport {};\n","import type {IsNever} from './is-never.d.ts';\n/**\nReturns a boolean for whether the two given types are equal.\n\n@link https://github.com/microsoft/TypeScript/issues/27024#issuecomment-421529650\n@link https://stackoverflow.com/questions/68961864/how-does-the-equals-work-in-typescript/68963796#68963796\n\nUse-cases:\n- If you want to make a conditional branch based on the result of a comparison of two types.\n\n@example\n```\nimport type {IsEqual} from 'type-fest';\n\n// This type returns a boolean for whether the given array includes the given item.\n// `IsEqual` is used to compare the given array at position 0 and the given item and then return true if they are equal.\ntype Includes<Value extends readonly any[], Item> =\n\tValue extends readonly [Value[0], ...infer rest]\n\t\t? IsEqual<Value[0], Item> extends true\n\t\t\t? true\n\t\t\t: Includes<rest, Item>\n\t\t: false;\n```\n\n@category Type Guard\n@category Utilities\n*/\nexport type IsEqual<A, B> =\n\t[A] extends [B]\n\t\t? [B] extends [A]\n\t\t\t? _IsEqual<A, B>\n\t\t\t: false\n\t\t: false;\n\n// This version fails the `equalWrappedTupleIntersectionToBeNeverAndNeverExpanded` test in `test-d/is-equal.ts`.\ntype _IsEqual<A, B> =\n\t(<G>() => G extends A & G | G ? 1 : 2) extends\n\t(<G>() => G extends B & G | G ? 1 : 2)\n\t\t? true\n\t\t: false;\n\nexport {};\n","/**\nOmit any index signatures from the given object type, leaving only explicitly defined properties.\n\nThis is the counterpart of `PickIndexSignature`.\n\nUse-cases:\n- Remove overly permissive signatures from third-party types.\n\nThis type was taken from this [StackOverflow answer](https://stackoverflow.com/a/68261113/420747).\n\nIt relies on the fact that an empty object (`{}`) is assignable to an object with just an index signature, like `Record<string, unknown>`, but not to an object with explicitly defined keys, like `Record<'foo' | 'bar', unknown>`.\n\n(The actual value type, `unknown`, is irrelevant and could be any type. Only the key type matters.)\n\n```\nconst indexed: Record<string, unknown> = {}; // Allowed\n\n// @ts-expect-error\nconst keyed: Record<'foo', unknown> = {}; // Error\n// => TS2739: Type '{}' is missing the following properties from type 'Record<\"foo\" | \"bar\", unknown>': foo, bar\n```\n\nInstead of causing a type error like the above, you can also use a [conditional type](https://www.typescriptlang.org/docs/handbook/2/conditional-types.html) to test whether a type is assignable to another:\n\n```\ntype Indexed = {} extends Record<string, unknown>\n\t? '✅ `{}` is assignable to `Record<string, unknown>`'\n\t: '❌ `{}` is NOT assignable to `Record<string, unknown>`';\n// => '✅ `{}` is assignable to `Record<string, unknown>`'\n\ntype Keyed = {} extends Record<'foo' | 'bar', unknown>\n\t? '✅ `{}` is assignable to `Record<\\'foo\\' | \\'bar\\', unknown>`'\n\t: '❌ `{}` is NOT assignable to `Record<\\'foo\\' | \\'bar\\', unknown>`';\n// => \"❌ `{}` is NOT assignable to `Record<'foo' | 'bar', unknown>`\"\n```\n\nUsing a [mapped type](https://www.typescriptlang.org/docs/handbook/2/mapped-types.html#further-exploration), you can then check for each `KeyType` of `ObjectType`...\n\n```\ntype OmitIndexSignature<ObjectType> = {\n\t[KeyType in keyof ObjectType // Map each key of `ObjectType`...\n\t]: ObjectType[KeyType]; // ...to its original value, i.e. `OmitIndexSignature<Foo> == Foo`.\n};\n```\n\n...whether an empty object (`{}`) would be assignable to an object with that `KeyType` (`Record<KeyType, unknown>`)...\n\n```\ntype OmitIndexSignature<ObjectType> = {\n\t[KeyType in keyof ObjectType\n\t// Is `{}` assignable to `Record<KeyType, unknown>`?\n\tas {} extends Record<KeyType, unknown>\n\t\t? never // ✅ `{}` is assignable to `Record<KeyType, unknown>`\n\t\t: KeyType // ❌ `{}` is NOT assignable to `Record<KeyType, unknown>`\n\t]: ObjectType[KeyType];\n};\n```\n\nIf `{}` is assignable, it means that `KeyType` is an index signature and we want to remove it. If it is not assignable, `KeyType` is a \"real\" key and we want to keep it.\n\n@example\n```\nimport type {OmitIndexSignature} from 'type-fest';\n\ntype Example = {\n\t// These index signatures will be removed.\n\t[x: string]: any;\n\t[x: number]: any;\n\t[x: symbol]: any;\n\t[x: `head-${string}`]: string;\n\t[x: `${string}-tail`]: string;\n\t[x: `head-${string}-tail`]: string;\n\t[x: `${bigint}`]: string;\n\t[x: `embedded-${number}`]: string;\n\n\t// These explicitly defined keys will remain.\n\tfoo: 'bar';\n\tqux?: 'baz';\n};\n\ntype ExampleWithoutIndexSignatures = OmitIndexSignature<Example>;\n// => { foo: 'bar'; qux?: 'baz' | undefined; }\n```\n\n@see {@link PickIndexSignature}\n@category Object\n*/\nexport type OmitIndexSignature<ObjectType> = {\n\t[KeyType in keyof ObjectType as {} extends Record<KeyType, unknown>\n\t\t? never\n\t\t: KeyType]: ObjectType[KeyType];\n};\n\nexport {};\n","/**\nPick only index signatures from the given object type, leaving out all explicitly defined properties.\n\nThis is the counterpart of `OmitIndexSignature`.\n\n@example\n```\nimport type {PickIndexSignature} from 'type-fest';\n\ndeclare const symbolKey: unique symbol;\n\ntype Example = {\n\t// These index signatures will remain.\n\t[x: string]: unknown;\n\t[x: number]: unknown;\n\t[x: symbol]: unknown;\n\t[x: `head-${string}`]: string;\n\t[x: `${string}-tail`]: string;\n\t[x: `head-${string}-tail`]: string;\n\t[x: `${bigint}`]: string;\n\t[x: `embedded-${number}`]: string;\n\n\t// These explicitly defined keys will be removed.\n\t['kebab-case-key']: string;\n\t[symbolKey]: string;\n\tfoo: 'bar';\n\tqux?: 'baz';\n};\n\ntype ExampleIndexSignature = PickIndexSignature<Example>;\n// {\n// \t[x: string]: unknown;\n// \t[x: number]: unknown;\n// \t[x: symbol]: unknown;\n// \t[x: `head-${string}`]: string;\n// \t[x: `${string}-tail`]: string;\n// \t[x: `head-${string}-tail`]: string;\n// \t[x: `${bigint}`]: string;\n// \t[x: `embedded-${number}`]: string;\n// }\n```\n\n@see {@link OmitIndexSignature}\n@category Object\n*/\nexport type PickIndexSignature<ObjectType> = {\n\t[KeyType in keyof ObjectType as {} extends Record<KeyType, unknown>\n\t\t? KeyType\n\t\t: never]: ObjectType[KeyType];\n};\n\nexport {};\n","import type {OmitIndexSignature} from './omit-index-signature.d.ts';\nimport type {PickIndexSignature} from './pick-index-signature.d.ts';\nimport type {Simplify} from './simplify.d.ts';\n\n// Merges two objects without worrying about index signatures.\ntype SimpleMerge<Destination, Source> = {\n\t[Key in keyof Destination as Key extends keyof Source ? never : Key]: Destination[Key];\n} & Source;\n\n/**\nMerge two types into a new type. Keys of the second type overrides keys of the first type.\n\n@example\n```\nimport type {Merge} from 'type-fest';\n\ntype Foo = {\n\t[x: string]: unknown;\n\t[x: number]: unknown;\n\tfoo: string;\n\tbar: symbol;\n};\n\ntype Bar = {\n\t[x: number]: number;\n\t[x: symbol]: unknown;\n\tbar: Date;\n\tbaz: boolean;\n};\n\nexport type FooBar = Merge<Foo, Bar>;\n// => {\n// \t[x: string]: unknown;\n// \t[x: number]: number;\n// \t[x: symbol]: unknown;\n// \tfoo: string;\n// \tbar: Date;\n// \tbaz: boolean;\n// }\n```\n\n@category Object\n*/\nexport type Merge<Destination, Source> =\nSimplify<\n\tSimpleMerge<PickIndexSignature<Destination>, PickIndexSignature<Source>>\n\t& SimpleMerge<OmitIndexSignature<Destination>, OmitIndexSignature<Source>>\n>;\n\nexport {};\n","import type {Simplify} from '../simplify.d.ts';\nimport type {IsEqual} from '../is-equal.d.ts';\nimport type {KeysOfUnion} from '../keys-of-union.d.ts';\nimport type {RequiredKeysOf} from '../required-keys-of.d.ts';\nimport type {Merge} from '../merge.d.ts';\nimport type {OptionalKeysOf} from '../optional-keys-of.d.ts';\nimport type {IsAny} from '../is-any.d.ts';\nimport type {If} from '../if.d.ts';\nimport type {IsNever} from '../is-never.d.ts';\nimport type {FilterDefinedKeys, FilterOptionalKeys} from './keys.d.ts';\nimport type {MapsSetsOrArrays, NonRecursiveType} from './type.d.ts';\nimport type {ToString} from './string.d.ts';\n\n/**\nCreate an object type with the given key `<Key>` and value `<Value>`.\n\nIt will copy the prefix and optional status of the same key from the given object `CopiedFrom` into the result.\n\n@example\n```\ntype A = BuildObject<'a', string>;\n//=> {a: string}\n\n// Copy `readonly` and `?` from the key `a` of `{readonly a?: any}`\ntype B = BuildObject<'a', string, {readonly a?: any}>;\n//=> {readonly a?: string}\n```\n*/\nexport type BuildObject<Key extends PropertyKey, Value, CopiedFrom extends object = {}> =\n\tKey extends keyof CopiedFrom\n\t\t? Pick<{[_ in keyof CopiedFrom]: Value}, Key>\n\t\t: Key extends `${infer NumberKey extends number}`\n\t\t\t? NumberKey extends keyof CopiedFrom\n\t\t\t\t? Pick<{[_ in keyof CopiedFrom]: Value}, NumberKey>\n\t\t\t\t: {[_ in Key]: Value}\n\t\t\t: {[_ in Key]: Value};\n\n/**\nReturns a boolean for whether the given type is a plain key-value object.\n*/\nexport type IsPlainObject<T> =\n\tIsNever<T> extends true\n\t\t? false\n\t\t: T extends NonRecursiveType | MapsSetsOrArrays\n\t\t\t? false\n\t\t\t: T extends object\n\t\t\t\t? true\n\t\t\t\t: false;\n\n/**\nExtract the object field type if T is an object and K is a key of T, return `never` otherwise.\n\nIt creates a type-safe way to access the member type of `unknown` type.\n*/\nexport type ObjectValue<T, K> =\n\tK extends keyof T\n\t\t? T[K]\n\t\t: ToString<K> extends keyof T\n\t\t\t? T[ToString<K>]\n\t\t\t: K extends `${infer NumberK extends number}`\n\t\t\t\t? NumberK extends keyof T\n\t\t\t\t\t? T[NumberK]\n\t\t\t\t\t: never\n\t\t\t\t: never;\n\n/**\nFor an object T, if it has any properties that are a union with `undefined`, make those into optional properties instead.\n\n@example\n```\ntype User = {\n\tfirstName: string;\n\tlastName: string | undefined;\n};\n\ntype OptionalizedUser = UndefinedToOptional<User>;\n//=> {\n// \tfirstName: string;\n// \tlastName?: string;\n// }\n```\n*/\nexport type UndefinedToOptional<T extends object> = Simplify<\n\t{\n\t// Property is not a union with `undefined`, keep it as-is.\n\t\t[Key in keyof Pick<T, FilterDefinedKeys<T>>]: T[Key];\n\t} & {\n\t// Property _is_ a union with defined value. Set as optional (via `?`) and remove `undefined` from the union.\n\t\t[Key in keyof Pick<T, FilterOptionalKeys<T>>]?: Exclude<T[Key], undefined>;\n\t}\n>;\n\n/**\nWorks similar to the built-in `Pick` utility type, except for the following differences:\n- Distributes over union types and allows picking keys from any member of the union type.\n- Primitives types are returned as-is.\n- Picks all keys if `Keys` is `any`.\n- Doesn't pick `number` from a `string` index signature.\n\n@example\n```\ntype ImageUpload = {\n\turl: string;\n\tsize: number;\n\tthumbnailUrl: string;\n};\n\ntype VideoUpload = {\n\turl: string;\n\tduration: number;\n\tencodingFormat: string;\n};\n\n// Distributes over union types and allows picking keys from any member of the union type\ntype MediaDisplay = HomomorphicPick<ImageUpload | VideoUpload, \"url\" | \"size\" | \"duration\">;\n//=> {url: string; size: number} | {url: string; duration: number}\n\n// Primitive types are returned as-is\ntype Primitive = HomomorphicPick<string | number, 'toUpperCase' | 'toString'>;\n//=> string | number\n\n// Picks all keys if `Keys` is `any`\ntype Any = HomomorphicPick<{a: 1; b: 2} | {c: 3}, any>;\n//=> {a: 1; b: 2} | {c: 3}\n\n// Doesn't pick `number` from a `string` index signature\ntype IndexSignature = HomomorphicPick<{[k: string]: unknown}, number>;\n//=> {}\n*/\nexport type HomomorphicPick<T, Keys extends KeysOfUnion<T>> = {\n\t[P in keyof T as Extract<P, Keys>]: T[P]\n};\n\n/**\nExtract all possible values for a given key from a union of object types.\n\n@example\n```\ntype Statuses = ValueOfUnion<{id: 1; status: 'open'} | {id: 2; status: 'closed'}, 'status'>;\n//=> \"open\" | \"closed\"\n```\n*/\nexport type ValueOfUnion<Union, Key extends KeysOfUnion<Union>> =\n\tUnion extends unknown ? Key extends keyof Union ? Union[Key] : never : never;\n\n/**\nExtract all readonly keys from a union of object types.\n\n@example\n```\ntype User = {\n\treadonly id: string;\n\tname: string;\n};\n\ntype Post = {\n\treadonly id: string;\n\treadonly author: string;\n\tbody: string;\n};\n\ntype ReadonlyKeys = ReadonlyKeysOfUnion<User | Post>;\n//=> \"id\" | \"author\"\n```\n*/\nexport type ReadonlyKeysOfUnion<Union> = Union extends unknown ? keyof {\n\t[Key in keyof Union as IsEqual<{[K in Key]: Union[Key]}, {readonly [K in Key]: Union[Key]}> extends true ? Key : never]: never\n} : never;\n\n/**\nMerges user specified options with default options.\n\n@example\n```\ntype PathsOptions = {maxRecursionDepth?: number; leavesOnly?: boolean};\ntype DefaultPathsOptions = {maxRecursionDepth: 10; leavesOnly: false};\ntype SpecifiedOptions = {leavesOnly: true};\n\ntype Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOptions>;\n//=> {maxRecursionDepth: 10; leavesOnly: true}\n```\n\n@example\n```\n// Complains if default values are not provided for optional options\n\ntype PathsOptions = {maxRecursionDepth?: number; leavesOnly?: boolean};\ntype DefaultPathsOptions = {maxRecursionDepth: 10};\ntype SpecifiedOptions = {};\n\ntype Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOptions>;\n// ~~~~~~~~~~~~~~~~~~~\n// Property 'leavesOnly' is missing in type 'DefaultPathsOptions' but required in type '{ maxRecursionDepth: number; leavesOnly: boolean; }'.\n```\n\n@example\n```\n// Complains if an option's default type does not conform to the expected type\n\ntype PathsOptions = {maxRecursionDepth?: number; leavesOnly?: boolean};\ntype DefaultPathsOptions = {maxRecursionDepth: 10; leavesOnly: 'no'};\ntype SpecifiedOptions = {};\n\ntype Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOptions>;\n// ~~~~~~~~~~~~~~~~~~~\n// Types of property 'leavesOnly' are incompatible. Type 'string' is not assignable to type 'boolean'.\n```\n\n@example\n```\n// Complains if an option's specified type does not conform to the expected type\n\ntype PathsOptions = {maxRecursionDepth?: number; leavesOnly?: boolean};\ntype DefaultPathsOptions = {maxRecursionDepth: 10; leavesOnly: false};\ntype SpecifiedOptions = {leavesOnly: 'yes'};\n\ntype Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOptions>;\n// ~~~~~~~~~~~~~~~~\n// Types of property 'leavesOnly' are incompatible. Type 'string' is not assignable to type 'boolean'.\n```\n*/\nexport type ApplyDefaultOptions<\n\tOptions extends object,\n\tDefaults extends Simplify<Omit<Required<Options>, RequiredKeysOf<Options>> & Partial<Record<RequiredKeysOf<Options>, never>>>,\n\tSpecifiedOptions extends Options,\n> =\n\tIf<IsAny<SpecifiedOptions>, Defaults,\n\t\tIf<IsNever<SpecifiedOptions>, Defaults,\n\t\t\tSimplify<Merge<Defaults, {\n\t\t\t\t[Key in keyof SpecifiedOptions\n\t\t\t\tas Key extends OptionalKeysOf<Options> ? undefined extends SpecifiedOptions[Key] ? never : Key : Key\n\t\t\t\t]: SpecifiedOptions[Key]\n\t\t\t}> & Required<Options>>>>; // `& Required<Options>` ensures that `ApplyDefaultOptions<SomeOption, ...>` is always assignable to `Required<SomeOption>`\n\n/**\nCollapses literal types in a union into their corresponding primitive types, when possible. For example, `CollapseLiterals<'foo' | 'bar' | (string & {})>` returns `string`.\n\nNote: This doesn't collapse literals within tagged types. For example, `CollapseLiterals<Tagged<'foo' | (string & {}), 'Tag'>>` returns `(\"foo\" & Tag<\"Tag\", never>) | (string & Tag<\"Tag\", never>)` and not `string & Tag<\"Tag\", never>`.\n\nUse-case: For collapsing unions created using {@link LiteralUnion}.\n\n@example\n```\nimport type {LiteralUnion} from 'type-fest';\n\ntype A = CollapseLiterals<'foo' | 'bar' | (string & {})>;\n//=> string\n\ntype B = CollapseLiterals<LiteralUnion<1 | 2 | 3, number>>;\n//=> number\n\ntype C = CollapseLiterals<LiteralUnion<'onClick' | 'onChange', `on${string}`>>;\n//=> `on${string}`\n\ntype D = CollapseLiterals<'click' | 'change' | (`on${string}` & {})>;\n//=> 'click' | 'change' | `on${string}`\n\ntype E = CollapseLiterals<LiteralUnion<'foo' | 'bar', string> | null | undefined>;\n//=> string | null | undefined\n```\n*/\nexport type CollapseLiterals<T> = {} extends T\n\t? T\n\t: T extends infer U & {}\n\t\t? U\n\t\t: T;\n\nexport {};\n","import type {ApplyDefaultOptions} from './internal/index.d.ts';\nimport type {IsEqual} from './is-equal.d.ts';\n\n/**\nFilter out keys from an object.\n\nReturns `never` if `Exclude` is strictly equal to `Key`.\nReturns `never` if `Key` extends `Exclude`.\nReturns `Key` otherwise.\n\n@example\n```\ntype Filtered = Filter<'foo', 'foo'>;\n//=> never\n```\n\n@example\n```\ntype Filtered = Filter<'bar', string>;\n//=> never\n```\n\n@example\n```\ntype Filtered = Filter<'bar', 'foo'>;\n//=> 'bar'\n```\n\n@see {Except}\n*/\ntype Filter<KeyType, ExcludeType> = IsEqual<KeyType, ExcludeType> extends true ? never : (KeyType extends ExcludeType ? never : KeyType);\n\nexport type ExceptOptions = {\n\t/**\n\tDisallow assigning non-specified properties.\n\n\tNote that any omitted properties in the resulting type will be present in autocomplete as `undefined`.\n\n\t@default false\n\t*/\n\trequireExactProps?: boolean;\n};\n\ntype DefaultExceptOptions = {\n\trequireExactProps: false;\n};\n\n/**\nCreate a type from an object type without certain keys.\n\nWe recommend setting the `requireExactProps` option to `true`.\n\nThis type is a stricter version of [`Omit`](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-5.html#the-omit-helper-type). The `Omit` type does not restrict the omitted keys to be keys present on the given type, while `Except` does. The benefits of a stricter type are avoiding typos and allowing the compiler to pick up on rename refactors automatically.\n\nThis type was proposed to the TypeScript team, which declined it, saying they prefer that libraries implement stricter versions of the built-in types ([microsoft/TypeScript#30825](https://github.com/microsoft/TypeScript/issues/30825#issuecomment-523668235)).\n\n@example\n```\nimport type {Except} from 'type-fest';\n\ntype Foo = {\n\ta: number;\n\tb: string;\n};\n\ntype FooWithoutA = Except<Foo, 'a'>;\n//=> {b: string}\n\n// @ts-expect-error\nconst fooWithoutA: FooWithoutA = {a: 1, b: '2'};\n//=> errors: 'a' does not exist in type '{ b: string; }'\n\ntype FooWithoutB = Except<Foo, 'b', {requireExactProps: true}>;\n//=> {a: number} & Partial<Record<\"b\", never>>\n\n// @ts-expect-error\nconst fooWithoutB: FooWithoutB = {a: 1, b: '2'};\n//=> errors at 'b': Type 'string' is not assignable to type 'undefined'.\n\n// The `Omit` utility type doesn't work when omitting specific keys from objects containing index signatures.\n\n// Consider the following example:\n\ntype UserData = {\n\t[metadata: string]: string;\n\temail: string;\n\tname: string;\n\trole: 'admin' | 'user';\n};\n\n// `Omit` clearly doesn't behave as expected in this case:\ntype PostPayload = Omit<UserData, 'email'>;\n//=> { [x: string]: string; [x: number]: string; }\n\n// In situations like this, `Except` works better.\n// It simply removes the `email` key while preserving all the other keys.\ntype PostPayloadFixed = Except<UserData, 'email'>;\n//=> { [x: string]: string; name: string; role: 'admin' | 'user'; }\n```\n\n@category Object\n*/\nexport type Except<ObjectType, KeysType extends keyof ObjectType, Options extends ExceptOptions = {}> =\n\t_Except<ObjectType, KeysType, ApplyDefaultOptions<ExceptOptions, DefaultExceptOptions, Options>>;\n\ntype _Except<ObjectType, KeysType extends keyof ObjectType, Options extends Required<ExceptOptions>> = {\n\t[KeyType in keyof ObjectType as Filter<KeyType, KeysType>]: ObjectType[KeyType];\n} & (Options['requireExactProps'] extends true\n\t? Partial<Record<KeysType, never>>\n\t: {});\n\nexport {};\n"],"x_google_ignoreList":[0,1,2,3,4,5,6,7,8,9,10,11,12],"mappings":";;AA4BA;;;;ACcA;;;;;;;;;;;;;;;;ACPA;;;;;;;AAOaU,KFdDV,KEcCU,CAAAA,CAAAA,CAAAA,GAAAA,CAAAA,SAAAA,CAAAA,GFdwBR,OEcxBQ,CFdgCT,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OptionalKeyOf","Type","Key","Record","IsOptionalKeyOf","OptionalKeysOf","Type","Key","OptionalKeysOf","RequiredKeysOf","Type","Exclude","IsNever","T","IsNever","If","Type","IfBranch","ElseBranch","Simplify","T","KeyType","IsNever","IsEqual","A","B","_IsEqual","G","OmitIndexSignature","ObjectType","KeyType","Record","PickIndexSignature","ObjectType","KeyType","Record","OmitIndexSignature","PickIndexSignature","Simplify","SimpleMerge","Destination","Source","Key","Merge","Simplify","IsEqual","KeysOfUnion","RequiredKeysOf","Merge","OptionalKeysOf","IsAny","If","IsNever","FilterDefinedKeys","FilterOptionalKeys","MapsSetsOrArrays","NonRecursiveType","ToString","BuildObject","Key","Value","CopiedFrom","PropertyKey","Pick","NumberKey","IsPlainObject","T","ObjectValue","K","NumberK","UndefinedToOptional","Exclude","HomomorphicPick","Keys","P","Extract","ValueOfUnion","Union","ReadonlyKeysOfUnion","ApplyDefaultOptions","Options","Defaults","SpecifiedOptions","Required","Omit","Record","Partial","CollapseLiterals","ApplyDefaultOptions","IsEqual","Filter","KeyType","ExcludeType","ExceptOptions","DefaultExceptOptions","Except","ObjectType","KeysType","Options","_Except","Required","Record","Partial"],"sources":["../node_modules/.pnpm/type-fest@5.3.1/node_modules/type-fest/source/is-any.d.ts","../node_modules/.pnpm/type-fest@5.3.1/node_modules/type-fest/source/is-optional-key-of.d.ts","../node_modules/.pnpm/type-fest@5.3.1/node_modules/type-fest/source/optional-keys-of.d.ts","../node_modules/.pnpm/type-fest@5.3.1/node_modules/type-fest/source/required-keys-of.d.ts","../node_modules/.pnpm/type-fest@5.3.1/node_modules/type-fest/source/is-never.d.ts","../node_modules/.pnpm/type-fest@5.3.1/node_modules/type-fest/source/if.d.ts","../node_modules/.pnpm/type-fest@5.3.1/node_modules/type-fest/source/simplify.d.ts","../node_modules/.pnpm/type-fest@5.3.1/node_modules/type-fest/source/is-equal.d.ts","../node_modules/.pnpm/type-fest@5.3.1/node_modules/type-fest/source/omit-index-signature.d.ts","../node_modules/.pnpm/type-fest@5.3.1/node_modules/type-fest/source/pick-index-signature.d.ts","../node_modules/.pnpm/type-fest@5.3.1/node_modules/type-fest/source/merge.d.ts","../node_modules/.pnpm/type-fest@5.3.1/node_modules/type-fest/source/internal/object.d.ts","../node_modules/.pnpm/type-fest@5.3.1/node_modules/type-fest/source/except.d.ts","../src/patches/fetchEventSource/parse.ts","../src/patches/fetchEventSource/fetchEventSource.ts"],"sourcesContent":["/**\nReturns a boolean for whether the given type is `any`.\n\n@link https://stackoverflow.com/a/49928360/1490091\n\nUseful in type utilities, such as disallowing `any`s to be passed to a function.\n\n@example\n```\nimport type {IsAny} from 'type-fest';\n\nconst typedObject = {a: 1, b: 2} as const;\nconst anyObject: any = {a: 1, b: 2};\n\nfunction get<O extends (IsAny<O> extends true ? {} : Record<string, number>), K extends keyof O = keyof O>(object: O, key: K) {\n\treturn object[key];\n}\n\nconst typedA = get(typedObject, 'a');\n//=> 1\n\nconst anyA = get(anyObject, 'a');\n//=> any\n```\n\n@category Type Guard\n@category Utilities\n*/\nexport type IsAny<T> = 0 extends 1 & NoInfer<T> ? true : false;\n\nexport {};\n","import type {IsAny} from './is-any.d.ts';\n\n/**\nReturns a boolean for whether the given key is an optional key of type.\n\nThis is useful when writing utility types or schema validators that need to differentiate `optional` keys.\n\n@example\n```\nimport type {IsOptionalKeyOf} from 'type-fest';\n\ntype User = {\n\tname: string;\n\tsurname: string;\n\n\tluckyNumber?: number;\n};\n\ntype Admin = {\n\tname: string;\n\tsurname?: string;\n};\n\ntype T1 = IsOptionalKeyOf<User, 'luckyNumber'>;\n//=> true\n\ntype T2 = IsOptionalKeyOf<User, 'name'>;\n//=> false\n\ntype T3 = IsOptionalKeyOf<User, 'name' | 'luckyNumber'>;\n//=> boolean\n\ntype T4 = IsOptionalKeyOf<User | Admin, 'name'>;\n//=> false\n\ntype T5 = IsOptionalKeyOf<User | Admin, 'surname'>;\n//=> boolean\n```\n\n@category Type Guard\n@category Utilities\n*/\nexport type IsOptionalKeyOf<Type extends object, Key extends keyof Type> =\n\tIsAny<Type | Key> extends true ? never\n\t\t: Key extends keyof Type\n\t\t\t? Type extends Record<Key, Type[Key]>\n\t\t\t\t? false\n\t\t\t\t: true\n\t\t\t: false;\n\nexport {};\n","import type {IsOptionalKeyOf} from './is-optional-key-of.d.ts';\n\n/**\nExtract all optional keys from the given type.\n\nThis is useful when you want to create a new type that contains different type values for the optional keys only.\n\n@example\n```\nimport type {OptionalKeysOf, Except} from 'type-fest';\n\ntype User = {\n\tname: string;\n\tsurname: string;\n\n\tluckyNumber?: number;\n};\n\nconst REMOVE_FIELD = Symbol('remove field symbol');\ntype UpdateOperation<Entity extends object> = Except<Partial<Entity>, OptionalKeysOf<Entity>> & {\n\t[Key in OptionalKeysOf<Entity>]?: Entity[Key] | typeof REMOVE_FIELD;\n};\n\nconst update1: UpdateOperation<User> = {\n\tname: 'Alice',\n};\n\nconst update2: UpdateOperation<User> = {\n\tname: 'Bob',\n\tluckyNumber: REMOVE_FIELD,\n};\n```\n\n@category Utilities\n*/\nexport type OptionalKeysOf<Type extends object> =\n\tType extends unknown // For distributing `Type`\n\t\t? (keyof {[Key in keyof Type as\n\t\t\tIsOptionalKeyOf<Type, Key> extends false\n\t\t\t\t? never\n\t\t\t\t: Key\n\t\t\t]: never\n\t\t}) & keyof Type // Intersect with `keyof Type` to ensure result of `OptionalKeysOf<Type>` is always assignable to `keyof Type`\n\t\t: never; // Should never happen\n\nexport {};\n","import type {OptionalKeysOf} from './optional-keys-of.d.ts';\n\n/**\nExtract all required keys from the given type.\n\nThis is useful when you want to create a new type that contains different type values for the required keys only or use the list of keys for validation purposes, etc...\n\n@example\n```\nimport type {RequiredKeysOf} from 'type-fest';\n\ndeclare function createValidation<\n\tEntity extends object,\n\tKey extends RequiredKeysOf<Entity> = RequiredKeysOf<Entity>,\n>(field: Key, validator: (value: Entity[Key]) => boolean): (entity: Entity) => boolean;\n\ntype User = {\n\tname: string;\n\tsurname: string;\n\tluckyNumber?: number;\n};\n\nconst validator1 = createValidation<User>('name', value => value.length < 25);\nconst validator2 = createValidation<User>('surname', value => value.length < 25);\n\n// @ts-expect-error\nconst validator3 = createValidation<User>('luckyNumber', value => value > 0);\n// Error: Argument of type '\"luckyNumber\"' is not assignable to parameter of type '\"name\" | \"surname\"'.\n```\n\n@category Utilities\n*/\nexport type RequiredKeysOf<Type extends object> =\n\tType extends unknown // For distributing `Type`\n\t\t? Exclude<keyof Type, OptionalKeysOf<Type>>\n\t\t: never; // Should never happen\n\nexport {};\n","/**\nReturns a boolean for whether the given type is `never`.\n\n@link https://github.com/microsoft/TypeScript/issues/31751#issuecomment-498526919\n@link https://stackoverflow.com/a/53984913/10292952\n@link https://www.zhenghao.io/posts/ts-never\n\nUseful in type utilities, such as checking if something does not occur.\n\n@example\n```\nimport type {IsNever, And} from 'type-fest';\n\ntype A = IsNever<never>;\n//=> true\n\ntype B = IsNever<any>;\n//=> false\n\ntype C = IsNever<unknown>;\n//=> false\n\ntype D = IsNever<never[]>;\n//=> false\n\ntype E = IsNever<object>;\n//=> false\n\ntype F = IsNever<string>;\n//=> false\n```\n\n@example\n```\nimport type {IsNever} from 'type-fest';\n\ntype IsTrue<T> = T extends true ? true : false;\n\n// When a distributive conditional is instantiated with `never`, the entire conditional results in `never`.\ntype A = IsTrue<never>;\n// ^? type A = never\n\n// If you don't want that behaviour, you can explicitly add an `IsNever` check before the distributive conditional.\ntype IsTrueFixed<T> =\n\tIsNever<T> extends true ? false : T extends true ? true : false;\n\ntype B = IsTrueFixed<never>;\n// ^? type B = false\n```\n\n@category Type Guard\n@category Utilities\n*/\nexport type IsNever<T> = [T] extends [never] ? true : false;\n\nexport {};\n","import type {IsNever} from './is-never.d.ts';\n\n/**\nAn if-else-like type that resolves depending on whether the given `boolean` type is `true` or `false`.\n\nUse-cases:\n- You can use this in combination with `Is*` types to create an if-else-like experience. For example, `If<IsAny<any>, 'is any', 'not any'>`.\n\nNote:\n- Returns a union of if branch and else branch if the given type is `boolean` or `any`. For example, `If<boolean, 'Y', 'N'>` will return `'Y' | 'N'`.\n- Returns the else branch if the given type is `never`. For example, `If<never, 'Y', 'N'>` will return `'N'`.\n\n@example\n```\nimport type {If} from 'type-fest';\n\ntype A = If<true, 'yes', 'no'>;\n//=> 'yes'\n\ntype B = If<false, 'yes', 'no'>;\n//=> 'no'\n\ntype C = If<boolean, 'yes', 'no'>;\n//=> 'yes' | 'no'\n\ntype D = If<any, 'yes', 'no'>;\n//=> 'yes' | 'no'\n\ntype E = If<never, 'yes', 'no'>;\n//=> 'no'\n```\n\n@example\n```\nimport type {If, IsAny, IsNever} from 'type-fest';\n\ntype A = If<IsAny<unknown>, 'is any', 'not any'>;\n//=> 'not any'\n\ntype B = If<IsNever<never>, 'is never', 'not never'>;\n//=> 'is never'\n```\n\n@example\n```\nimport type {If, IsEqual} from 'type-fest';\n\ntype IfEqual<T, U, IfBranch, ElseBranch> = If<IsEqual<T, U>, IfBranch, ElseBranch>;\n\ntype A = IfEqual<string, string, 'equal', 'not equal'>;\n//=> 'equal'\n\ntype B = IfEqual<string, number, 'equal', 'not equal'>;\n//=> 'not equal'\n```\n\nNote: Sometimes using the `If` type can make an implementation non–tail-recursive, which can impact performance. In such cases, it’s better to use a conditional directly. Refer to the following example:\n\n@example\n```\nimport type {If, IsEqual, StringRepeat} from 'type-fest';\n\ntype HundredZeroes = StringRepeat<'0', 100>;\n\n// The following implementation is not tail recursive\ntype Includes<S extends string, Char extends string> =\n\tS extends `${infer First}${infer Rest}`\n\t\t? If<IsEqual<First, Char>,\n\t\t\t'found',\n\t\t\tIncludes<Rest, Char>>\n\t\t: 'not found';\n\n// Hence, instantiations with long strings will fail\n// @ts-expect-error\ntype Fails = Includes<HundredZeroes, '1'>;\n// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n// Error: Type instantiation is excessively deep and possibly infinite.\n\n// However, if we use a simple conditional instead of `If`, the implementation becomes tail-recursive\ntype IncludesWithoutIf<S extends string, Char extends string> =\n\tS extends `${infer First}${infer Rest}`\n\t\t? IsEqual<First, Char> extends true\n\t\t\t? 'found'\n\t\t\t: IncludesWithoutIf<Rest, Char>\n\t\t: 'not found';\n\n// Now, instantiations with long strings will work\ntype Works = IncludesWithoutIf<HundredZeroes, '1'>;\n//=> 'not found'\n```\n\n@category Type Guard\n@category Utilities\n*/\nexport type If<Type extends boolean, IfBranch, ElseBranch> =\n\tIsNever<Type> extends true\n\t\t? ElseBranch\n\t\t: Type extends true\n\t\t\t? IfBranch\n\t\t\t: ElseBranch;\n\nexport {};\n","/**\nUseful to flatten the type output to improve type hints shown in editors. And also to transform an interface into a type to aide with assignability.\n\n@example\n```\nimport type {Simplify} from 'type-fest';\n\ntype PositionProps = {\n\ttop: number;\n\tleft: number;\n};\n\ntype SizeProps = {\n\twidth: number;\n\theight: number;\n};\n\n// In your editor, hovering over `Props` will show a flattened object with all the properties.\ntype Props = Simplify<PositionProps & SizeProps>;\n```\n\nSometimes it is desired to pass a value as a function argument that has a different type. At first inspection it may seem assignable, and then you discover it is not because the `value`'s type definition was defined as an interface. In the following example, `fn` requires an argument of type `Record<string, unknown>`. If the value is defined as a literal, then it is assignable. And if the `value` is defined as type using the `Simplify` utility the value is assignable. But if the `value` is defined as an interface, it is not assignable because the interface is not sealed and elsewhere a non-string property could be added to the interface.\n\nIf the type definition must be an interface (perhaps it was defined in a third-party npm package), then the `value` can be defined as `const value: Simplify<SomeInterface> = ...`. Then `value` will be assignable to the `fn` argument. Or the `value` can be cast as `Simplify<SomeInterface>` if you can't re-declare the `value`.\n\n@example\n```\nimport type {Simplify} from 'type-fest';\n\ninterface SomeInterface {\n\tfoo: number;\n\tbar?: string;\n\tbaz: number | undefined;\n}\n\ntype SomeType = {\n\tfoo: number;\n\tbar?: string;\n\tbaz: number | undefined;\n};\n\nconst literal = {foo: 123, bar: 'hello', baz: 456};\nconst someType: SomeType = literal;\nconst someInterface: SomeInterface = literal;\n\ndeclare function fn(object: Record<string, unknown>): void;\n\nfn(literal); // Good: literal object type is sealed\nfn(someType); // Good: type is sealed\n// @ts-expect-error\nfn(someInterface); // Error: Index signature for type 'string' is missing in type 'someInterface'. Because `interface` can be re-opened\nfn(someInterface as Simplify<SomeInterface>); // Good: transform an `interface` into a `type`\n```\n\n@link https://github.com/microsoft/TypeScript/issues/15300\n@see {@link SimplifyDeep}\n@category Object\n*/\nexport type Simplify<T> = {[KeyType in keyof T]: T[KeyType]} & {};\n\nexport {};\n","import type {IsNever} from './is-never.d.ts';\n/**\nReturns a boolean for whether the two given types are equal.\n\n@link https://github.com/microsoft/TypeScript/issues/27024#issuecomment-421529650\n@link https://stackoverflow.com/questions/68961864/how-does-the-equals-work-in-typescript/68963796#68963796\n\nUse-cases:\n- If you want to make a conditional branch based on the result of a comparison of two types.\n\n@example\n```\nimport type {IsEqual} from 'type-fest';\n\n// This type returns a boolean for whether the given array includes the given item.\n// `IsEqual` is used to compare the given array at position 0 and the given item and then return true if they are equal.\ntype Includes<Value extends readonly any[], Item> =\n\tValue extends readonly [Value[0], ...infer rest]\n\t\t? IsEqual<Value[0], Item> extends true\n\t\t\t? true\n\t\t\t: Includes<rest, Item>\n\t\t: false;\n```\n\n@category Type Guard\n@category Utilities\n*/\nexport type IsEqual<A, B> =\n\t[A] extends [B]\n\t\t? [B] extends [A]\n\t\t\t? _IsEqual<A, B>\n\t\t\t: false\n\t\t: false;\n\n// This version fails the `equalWrappedTupleIntersectionToBeNeverAndNeverExpanded` test in `test-d/is-equal.ts`.\ntype _IsEqual<A, B> =\n\t(<G>() => G extends A & G | G ? 1 : 2) extends\n\t(<G>() => G extends B & G | G ? 1 : 2)\n\t\t? true\n\t\t: false;\n\nexport {};\n","/**\nOmit any index signatures from the given object type, leaving only explicitly defined properties.\n\nThis is the counterpart of `PickIndexSignature`.\n\nUse-cases:\n- Remove overly permissive signatures from third-party types.\n\nThis type was taken from this [StackOverflow answer](https://stackoverflow.com/a/68261113/420747).\n\nIt relies on the fact that an empty object (`{}`) is assignable to an object with just an index signature, like `Record<string, unknown>`, but not to an object with explicitly defined keys, like `Record<'foo' | 'bar', unknown>`.\n\n(The actual value type, `unknown`, is irrelevant and could be any type. Only the key type matters.)\n\n```\nconst indexed: Record<string, unknown> = {}; // Allowed\n\n// @ts-expect-error\nconst keyed: Record<'foo', unknown> = {}; // Error\n// => TS2739: Type '{}' is missing the following properties from type 'Record<\"foo\" | \"bar\", unknown>': foo, bar\n```\n\nInstead of causing a type error like the above, you can also use a [conditional type](https://www.typescriptlang.org/docs/handbook/2/conditional-types.html) to test whether a type is assignable to another:\n\n```\ntype Indexed = {} extends Record<string, unknown>\n\t? '✅ `{}` is assignable to `Record<string, unknown>`'\n\t: '❌ `{}` is NOT assignable to `Record<string, unknown>`';\n// => '✅ `{}` is assignable to `Record<string, unknown>`'\n\ntype Keyed = {} extends Record<'foo' | 'bar', unknown>\n\t? '✅ `{}` is assignable to `Record<\\'foo\\' | \\'bar\\', unknown>`'\n\t: '❌ `{}` is NOT assignable to `Record<\\'foo\\' | \\'bar\\', unknown>`';\n// => \"❌ `{}` is NOT assignable to `Record<'foo' | 'bar', unknown>`\"\n```\n\nUsing a [mapped type](https://www.typescriptlang.org/docs/handbook/2/mapped-types.html#further-exploration), you can then check for each `KeyType` of `ObjectType`...\n\n```\ntype OmitIndexSignature<ObjectType> = {\n\t[KeyType in keyof ObjectType // Map each key of `ObjectType`...\n\t]: ObjectType[KeyType]; // ...to its original value, i.e. `OmitIndexSignature<Foo> == Foo`.\n};\n```\n\n...whether an empty object (`{}`) would be assignable to an object with that `KeyType` (`Record<KeyType, unknown>`)...\n\n```\ntype OmitIndexSignature<ObjectType> = {\n\t[KeyType in keyof ObjectType\n\t// Is `{}` assignable to `Record<KeyType, unknown>`?\n\tas {} extends Record<KeyType, unknown>\n\t\t? never // ✅ `{}` is assignable to `Record<KeyType, unknown>`\n\t\t: KeyType // ❌ `{}` is NOT assignable to `Record<KeyType, unknown>`\n\t]: ObjectType[KeyType];\n};\n```\n\nIf `{}` is assignable, it means that `KeyType` is an index signature and we want to remove it. If it is not assignable, `KeyType` is a \"real\" key and we want to keep it.\n\n@example\n```\nimport type {OmitIndexSignature} from 'type-fest';\n\ntype Example = {\n\t// These index signatures will be removed.\n\t[x: string]: any;\n\t[x: number]: any;\n\t[x: symbol]: any;\n\t[x: `head-${string}`]: string;\n\t[x: `${string}-tail`]: string;\n\t[x: `head-${string}-tail`]: string;\n\t[x: `${bigint}`]: string;\n\t[x: `embedded-${number}`]: string;\n\n\t// These explicitly defined keys will remain.\n\tfoo: 'bar';\n\tqux?: 'baz';\n};\n\ntype ExampleWithoutIndexSignatures = OmitIndexSignature<Example>;\n// => { foo: 'bar'; qux?: 'baz' | undefined; }\n```\n\n@see {@link PickIndexSignature}\n@category Object\n*/\nexport type OmitIndexSignature<ObjectType> = {\n\t[KeyType in keyof ObjectType as {} extends Record<KeyType, unknown>\n\t\t? never\n\t\t: KeyType]: ObjectType[KeyType];\n};\n\nexport {};\n","/**\nPick only index signatures from the given object type, leaving out all explicitly defined properties.\n\nThis is the counterpart of `OmitIndexSignature`.\n\n@example\n```\nimport type {PickIndexSignature} from 'type-fest';\n\ndeclare const symbolKey: unique symbol;\n\ntype Example = {\n\t// These index signatures will remain.\n\t[x: string]: unknown;\n\t[x: number]: unknown;\n\t[x: symbol]: unknown;\n\t[x: `head-${string}`]: string;\n\t[x: `${string}-tail`]: string;\n\t[x: `head-${string}-tail`]: string;\n\t[x: `${bigint}`]: string;\n\t[x: `embedded-${number}`]: string;\n\n\t// These explicitly defined keys will be removed.\n\t['kebab-case-key']: string;\n\t[symbolKey]: string;\n\tfoo: 'bar';\n\tqux?: 'baz';\n};\n\ntype ExampleIndexSignature = PickIndexSignature<Example>;\n// {\n// \t[x: string]: unknown;\n// \t[x: number]: unknown;\n// \t[x: symbol]: unknown;\n// \t[x: `head-${string}`]: string;\n// \t[x: `${string}-tail`]: string;\n// \t[x: `head-${string}-tail`]: string;\n// \t[x: `${bigint}`]: string;\n// \t[x: `embedded-${number}`]: string;\n// }\n```\n\n@see {@link OmitIndexSignature}\n@category Object\n*/\nexport type PickIndexSignature<ObjectType> = {\n\t[KeyType in keyof ObjectType as {} extends Record<KeyType, unknown>\n\t\t? KeyType\n\t\t: never]: ObjectType[KeyType];\n};\n\nexport {};\n","import type {OmitIndexSignature} from './omit-index-signature.d.ts';\nimport type {PickIndexSignature} from './pick-index-signature.d.ts';\nimport type {Simplify} from './simplify.d.ts';\n\n// Merges two objects without worrying about index signatures.\ntype SimpleMerge<Destination, Source> = {\n\t[Key in keyof Destination as Key extends keyof Source ? never : Key]: Destination[Key];\n} & Source;\n\n/**\nMerge two types into a new type. Keys of the second type overrides keys of the first type.\n\n@example\n```\nimport type {Merge} from 'type-fest';\n\ntype Foo = {\n\t[x: string]: unknown;\n\t[x: number]: unknown;\n\tfoo: string;\n\tbar: symbol;\n};\n\ntype Bar = {\n\t[x: number]: number;\n\t[x: symbol]: unknown;\n\tbar: Date;\n\tbaz: boolean;\n};\n\nexport type FooBar = Merge<Foo, Bar>;\n// => {\n// \t[x: string]: unknown;\n// \t[x: number]: number;\n// \t[x: symbol]: unknown;\n// \tfoo: string;\n// \tbar: Date;\n// \tbaz: boolean;\n// }\n```\n\n@category Object\n*/\nexport type Merge<Destination, Source> =\nSimplify<\n\tSimpleMerge<PickIndexSignature<Destination>, PickIndexSignature<Source>>\n\t& SimpleMerge<OmitIndexSignature<Destination>, OmitIndexSignature<Source>>\n>;\n\nexport {};\n","import type {Simplify} from '../simplify.d.ts';\nimport type {IsEqual} from '../is-equal.d.ts';\nimport type {KeysOfUnion} from '../keys-of-union.d.ts';\nimport type {RequiredKeysOf} from '../required-keys-of.d.ts';\nimport type {Merge} from '../merge.d.ts';\nimport type {OptionalKeysOf} from '../optional-keys-of.d.ts';\nimport type {IsAny} from '../is-any.d.ts';\nimport type {If} from '../if.d.ts';\nimport type {IsNever} from '../is-never.d.ts';\nimport type {FilterDefinedKeys, FilterOptionalKeys} from './keys.d.ts';\nimport type {MapsSetsOrArrays, NonRecursiveType} from './type.d.ts';\nimport type {ToString} from './string.d.ts';\n\n/**\nCreate an object type with the given key `<Key>` and value `<Value>`.\n\nIt will copy the prefix and optional status of the same key from the given object `CopiedFrom` into the result.\n\n@example\n```\ntype A = BuildObject<'a', string>;\n//=> {a: string}\n\n// Copy `readonly` and `?` from the key `a` of `{readonly a?: any}`\ntype B = BuildObject<'a', string, {readonly a?: any}>;\n//=> {readonly a?: string}\n```\n*/\nexport type BuildObject<Key extends PropertyKey, Value, CopiedFrom extends object = {}> =\n\tKey extends keyof CopiedFrom\n\t\t? Pick<{[_ in keyof CopiedFrom]: Value}, Key>\n\t\t: Key extends `${infer NumberKey extends number}`\n\t\t\t? NumberKey extends keyof CopiedFrom\n\t\t\t\t? Pick<{[_ in keyof CopiedFrom]: Value}, NumberKey>\n\t\t\t\t: {[_ in Key]: Value}\n\t\t\t: {[_ in Key]: Value};\n\n/**\nReturns a boolean for whether the given type is a plain key-value object.\n*/\nexport type IsPlainObject<T> =\n\tIsNever<T> extends true\n\t\t? false\n\t\t: T extends NonRecursiveType | MapsSetsOrArrays\n\t\t\t? false\n\t\t\t: T extends object\n\t\t\t\t? true\n\t\t\t\t: false;\n\n/**\nExtract the object field type if T is an object and K is a key of T, return `never` otherwise.\n\nIt creates a type-safe way to access the member type of `unknown` type.\n*/\nexport type ObjectValue<T, K> =\n\tK extends keyof T\n\t\t? T[K]\n\t\t: ToString<K> extends keyof T\n\t\t\t? T[ToString<K>]\n\t\t\t: K extends `${infer NumberK extends number}`\n\t\t\t\t? NumberK extends keyof T\n\t\t\t\t\t? T[NumberK]\n\t\t\t\t\t: never\n\t\t\t\t: never;\n\n/**\nFor an object T, if it has any properties that are a union with `undefined`, make those into optional properties instead.\n\n@example\n```\ntype User = {\n\tfirstName: string;\n\tlastName: string | undefined;\n};\n\ntype OptionalizedUser = UndefinedToOptional<User>;\n//=> {\n// \tfirstName: string;\n// \tlastName?: string;\n// }\n```\n*/\nexport type UndefinedToOptional<T extends object> = Simplify<\n\t{\n\t// Property is not a union with `undefined`, keep it as-is.\n\t\t[Key in keyof Pick<T, FilterDefinedKeys<T>>]: T[Key];\n\t} & {\n\t// Property _is_ a union with defined value. Set as optional (via `?`) and remove `undefined` from the union.\n\t\t[Key in keyof Pick<T, FilterOptionalKeys<T>>]?: Exclude<T[Key], undefined>;\n\t}\n>;\n\n/**\nWorks similar to the built-in `Pick` utility type, except for the following differences:\n- Distributes over union types and allows picking keys from any member of the union type.\n- Primitives types are returned as-is.\n- Picks all keys if `Keys` is `any`.\n- Doesn't pick `number` from a `string` index signature.\n\n@example\n```\ntype ImageUpload = {\n\turl: string;\n\tsize: number;\n\tthumbnailUrl: string;\n};\n\ntype VideoUpload = {\n\turl: string;\n\tduration: number;\n\tencodingFormat: string;\n};\n\n// Distributes over union types and allows picking keys from any member of the union type\ntype MediaDisplay = HomomorphicPick<ImageUpload | VideoUpload, \"url\" | \"size\" | \"duration\">;\n//=> {url: string; size: number} | {url: string; duration: number}\n\n// Primitive types are returned as-is\ntype Primitive = HomomorphicPick<string | number, 'toUpperCase' | 'toString'>;\n//=> string | number\n\n// Picks all keys if `Keys` is `any`\ntype Any = HomomorphicPick<{a: 1; b: 2} | {c: 3}, any>;\n//=> {a: 1; b: 2} | {c: 3}\n\n// Doesn't pick `number` from a `string` index signature\ntype IndexSignature = HomomorphicPick<{[k: string]: unknown}, number>;\n//=> {}\n*/\nexport type HomomorphicPick<T, Keys extends KeysOfUnion<T>> = {\n\t[P in keyof T as Extract<P, Keys>]: T[P]\n};\n\n/**\nExtract all possible values for a given key from a union of object types.\n\n@example\n```\ntype Statuses = ValueOfUnion<{id: 1; status: 'open'} | {id: 2; status: 'closed'}, 'status'>;\n//=> \"open\" | \"closed\"\n```\n*/\nexport type ValueOfUnion<Union, Key extends KeysOfUnion<Union>> =\n\tUnion extends unknown ? Key extends keyof Union ? Union[Key] : never : never;\n\n/**\nExtract all readonly keys from a union of object types.\n\n@example\n```\ntype User = {\n\treadonly id: string;\n\tname: string;\n};\n\ntype Post = {\n\treadonly id: string;\n\treadonly author: string;\n\tbody: string;\n};\n\ntype ReadonlyKeys = ReadonlyKeysOfUnion<User | Post>;\n//=> \"id\" | \"author\"\n```\n*/\nexport type ReadonlyKeysOfUnion<Union> = Union extends unknown ? keyof {\n\t[Key in keyof Union as IsEqual<{[K in Key]: Union[Key]}, {readonly [K in Key]: Union[Key]}> extends true ? Key : never]: never\n} : never;\n\n/**\nMerges user specified options with default options.\n\n@example\n```\ntype PathsOptions = {maxRecursionDepth?: number; leavesOnly?: boolean};\ntype DefaultPathsOptions = {maxRecursionDepth: 10; leavesOnly: false};\ntype SpecifiedOptions = {leavesOnly: true};\n\ntype Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOptions>;\n//=> {maxRecursionDepth: 10; leavesOnly: true}\n```\n\n@example\n```\n// Complains if default values are not provided for optional options\n\ntype PathsOptions = {maxRecursionDepth?: number; leavesOnly?: boolean};\ntype DefaultPathsOptions = {maxRecursionDepth: 10};\ntype SpecifiedOptions = {};\n\ntype Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOptions>;\n// ~~~~~~~~~~~~~~~~~~~\n// Property 'leavesOnly' is missing in type 'DefaultPathsOptions' but required in type '{ maxRecursionDepth: number; leavesOnly: boolean; }'.\n```\n\n@example\n```\n// Complains if an option's default type does not conform to the expected type\n\ntype PathsOptions = {maxRecursionDepth?: number; leavesOnly?: boolean};\ntype DefaultPathsOptions = {maxRecursionDepth: 10; leavesOnly: 'no'};\ntype SpecifiedOptions = {};\n\ntype Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOptions>;\n// ~~~~~~~~~~~~~~~~~~~\n// Types of property 'leavesOnly' are incompatible. Type 'string' is not assignable to type 'boolean'.\n```\n\n@example\n```\n// Complains if an option's specified type does not conform to the expected type\n\ntype PathsOptions = {maxRecursionDepth?: number; leavesOnly?: boolean};\ntype DefaultPathsOptions = {maxRecursionDepth: 10; leavesOnly: false};\ntype SpecifiedOptions = {leavesOnly: 'yes'};\n\ntype Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOptions>;\n// ~~~~~~~~~~~~~~~~\n// Types of property 'leavesOnly' are incompatible. Type 'string' is not assignable to type 'boolean'.\n```\n*/\nexport type ApplyDefaultOptions<\n\tOptions extends object,\n\tDefaults extends Simplify<Omit<Required<Options>, RequiredKeysOf<Options>> & Partial<Record<RequiredKeysOf<Options>, never>>>,\n\tSpecifiedOptions extends Options,\n> =\n\tIf<IsAny<SpecifiedOptions>, Defaults,\n\t\tIf<IsNever<SpecifiedOptions>, Defaults,\n\t\t\tSimplify<Merge<Defaults, {\n\t\t\t\t[Key in keyof SpecifiedOptions\n\t\t\t\tas Key extends OptionalKeysOf<Options> ? undefined extends SpecifiedOptions[Key] ? never : Key : Key\n\t\t\t\t]: SpecifiedOptions[Key]\n\t\t\t}> & Required<Options>>>>; // `& Required<Options>` ensures that `ApplyDefaultOptions<SomeOption, ...>` is always assignable to `Required<SomeOption>`\n\n/**\nCollapses literal types in a union into their corresponding primitive types, when possible. For example, `CollapseLiterals<'foo' | 'bar' | (string & {})>` returns `string`.\n\nNote: This doesn't collapse literals within tagged types. For example, `CollapseLiterals<Tagged<'foo' | (string & {}), 'Tag'>>` returns `(\"foo\" & Tag<\"Tag\", never>) | (string & Tag<\"Tag\", never>)` and not `string & Tag<\"Tag\", never>`.\n\nUse-case: For collapsing unions created using {@link LiteralUnion}.\n\n@example\n```\nimport type {LiteralUnion} from 'type-fest';\n\ntype A = CollapseLiterals<'foo' | 'bar' | (string & {})>;\n//=> string\n\ntype B = CollapseLiterals<LiteralUnion<1 | 2 | 3, number>>;\n//=> number\n\ntype C = CollapseLiterals<LiteralUnion<'onClick' | 'onChange', `on${string}`>>;\n//=> `on${string}`\n\ntype D = CollapseLiterals<'click' | 'change' | (`on${string}` & {})>;\n//=> 'click' | 'change' | `on${string}`\n\ntype E = CollapseLiterals<LiteralUnion<'foo' | 'bar', string> | null | undefined>;\n//=> string | null | undefined\n```\n*/\nexport type CollapseLiterals<T> = {} extends T\n\t? T\n\t: T extends infer U & {}\n\t\t? U\n\t\t: T;\n\nexport {};\n","import type {ApplyDefaultOptions} from './internal/index.d.ts';\nimport type {IsEqual} from './is-equal.d.ts';\n\n/**\nFilter out keys from an object.\n\nReturns `never` if `Exclude` is strictly equal to `Key`.\nReturns `never` if `Key` extends `Exclude`.\nReturns `Key` otherwise.\n\n@example\n```\ntype Filtered = Filter<'foo', 'foo'>;\n//=> never\n```\n\n@example\n```\ntype Filtered = Filter<'bar', string>;\n//=> never\n```\n\n@example\n```\ntype Filtered = Filter<'bar', 'foo'>;\n//=> 'bar'\n```\n\n@see {Except}\n*/\ntype Filter<KeyType, ExcludeType> = IsEqual<KeyType, ExcludeType> extends true ? never : (KeyType extends ExcludeType ? never : KeyType);\n\nexport type ExceptOptions = {\n\t/**\n\tDisallow assigning non-specified properties.\n\n\tNote that any omitted properties in the resulting type will be present in autocomplete as `undefined`.\n\n\t@default false\n\t*/\n\trequireExactProps?: boolean;\n};\n\ntype DefaultExceptOptions = {\n\trequireExactProps: false;\n};\n\n/**\nCreate a type from an object type without certain keys.\n\nWe recommend setting the `requireExactProps` option to `true`.\n\nThis type is a stricter version of [`Omit`](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-5.html#the-omit-helper-type). The `Omit` type does not restrict the omitted keys to be keys present on the given type, while `Except` does. The benefits of a stricter type are avoiding typos and allowing the compiler to pick up on rename refactors automatically.\n\nThis type was proposed to the TypeScript team, which declined it, saying they prefer that libraries implement stricter versions of the built-in types ([microsoft/TypeScript#30825](https://github.com/microsoft/TypeScript/issues/30825#issuecomment-523668235)).\n\n@example\n```\nimport type {Except} from 'type-fest';\n\ntype Foo = {\n\ta: number;\n\tb: string;\n};\n\ntype FooWithoutA = Except<Foo, 'a'>;\n//=> {b: string}\n\n// @ts-expect-error\nconst fooWithoutA: FooWithoutA = {a: 1, b: '2'};\n//=> errors: 'a' does not exist in type '{ b: string; }'\n\ntype FooWithoutB = Except<Foo, 'b', {requireExactProps: true}>;\n//=> {a: number} & Partial<Record<\"b\", never>>\n\n// @ts-expect-error\nconst fooWithoutB: FooWithoutB = {a: 1, b: '2'};\n//=> errors at 'b': Type 'string' is not assignable to type 'undefined'.\n\n// The `Omit` utility type doesn't work when omitting specific keys from objects containing index signatures.\n\n// Consider the following example:\n\ntype UserData = {\n\t[metadata: string]: string;\n\temail: string;\n\tname: string;\n\trole: 'admin' | 'user';\n};\n\n// `Omit` clearly doesn't behave as expected in this case:\ntype PostPayload = Omit<UserData, 'email'>;\n//=> { [x: string]: string; [x: number]: string; }\n\n// In situations like this, `Except` works better.\n// It simply removes the `email` key while preserving all the other keys.\ntype PostPayloadFixed = Except<UserData, 'email'>;\n//=> { [x: string]: string; name: string; role: 'admin' | 'user'; }\n```\n\n@category Object\n*/\nexport type Except<ObjectType, KeysType extends keyof ObjectType, Options extends ExceptOptions = {}> =\n\t_Except<ObjectType, KeysType, ApplyDefaultOptions<ExceptOptions, DefaultExceptOptions, Options>>;\n\ntype _Except<ObjectType, KeysType extends keyof ObjectType, Options extends Required<ExceptOptions>> = {\n\t[KeyType in keyof ObjectType as Filter<KeyType, KeysType>]: ObjectType[KeyType];\n} & (Options['requireExactProps'] extends true\n\t? Partial<Record<KeysType, never>>\n\t: {});\n\nexport {};\n"],"x_google_ignoreList":[0,1,2,3,4,5,6,7,8,9,10,11,12],"mappings":";;AA4BA;;;;ACcA;;;;;;;;;;;;;;;;ACPA;;;;;;;AAOaU,KFdDV,KEcCU,CAAAA,CAAAA,CAAAA,GAAAA,CAAAA,SAAAA,CAAAA,GFdwBR,OEcxBQ,CFdgCT,CEchCS,CAAAA,GAAAA,IAAAA,GAAAA,KAAAA;;;;;;ADAb;;;;;;;;;;;;;;;;ACPA;;;;;;;;;;;;ACHA;;;;;;;;;KFUYN,yDAAuDC,QAClEF,KGUWa,CHVLX,IGUKW,GHVEV,KGUK,CAAA,SAAA,IAAQ,GAAA,KAAA,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EAAoBC;;;EAAPC,IAAAA,EAAAA,MAAAA;EAAM;;;;ECVZE,iBAAc,CAAA,EAAA,MAAAC,GAAAA,SAAA;;;;KY3Bd,yBAAA,cAAuC,oBAAoB;KAC3D,0BAAA,gBAA0C;KAC1C,4BAAA,WAAuC,8BAA8B;AbgCrEN,Ka/BA,0BAAA,Gb+BeE,CAAAA,KAAA,EAAA,OAAA,EAAA,GAAA,MAAA,GAAA,SAAA,Ga/BuD,Ob+BvD,CAAA,MAAA,GAAA,SAAA,CAAA;AAAwCD,Ua9BlD,uBAAA,SAAgC,Mb8BkBA,Ca9BX,Wb8BWA,EAAAA,SAAAA,CAAAA,CAAAA;EAC5DA;;;;EACeA,OAAAA,CAAAA,Ea3BV,Wb2BUA,Ga3BI,Wb2BJA,CAAAA,OAAAA,EAAAA,Ea3B2B,Wb2B3BA,CAAAA,GAAAA,SAAAA;EACjBA;;;;EAAaE,MAAAA,CAAAA,EatBP,yBbsBOA,GAAAA,SAAAA;EAAM;;;;ECVZE,OAAAA,CAAAA,EYNA,0BZMc,GAAA,SAAA;EACzBC;;;;EAEEF,SAAAA,CAAAA,EYHW,4BZGXA,GAAAA,SAAAA;EAEGG;;;;;;ECRME,OAAAA,CAAAA,EWWA,0BXXc,GAAA,SAAA;EACzBC;;;;;EACU,aAAA,CAAA,EAAA,OAAA,GAAA,SAAA;;;;ACmBX;;;;ACyCA;;;EAEIQ,KAAAA,CAAAA,EAAAA,OSjCa,KTiCbA,GAAAA,SAAAA;;;;;;iBS1BY,gBAAA,QAAwB,uBAAuB,sCAAmC"}
@@ -51,8 +51,8 @@ function isBoolean(value) {
51
51
  * 判断是否为对象类型
52
52
  * - 可选是否检查原型为 `Object.prototype`,防止原型链污染
53
53
  *
54
- * @param value - 待检查值
55
- * @param prototypeCheck - 是否进行原型检查,默认 `true`
54
+ * @param value 待检查值
55
+ * @param prototypeCheck 是否进行原型检查,默认 `true`
56
56
  */
57
57
  function isObject(value, prototypeCheck = true) {
58
58
  const check = resolvePrototypeString(value) === PROTOTYPE_TAGS.object;
@@ -70,7 +70,7 @@ function isFunction(value) {
70
70
  /**
71
71
  * 检查 value 是否为 NaN
72
72
  *
73
- * @param value - 待检查值
73
+ * @param value 待检查值
74
74
  */
75
75
  function isNaN(value) {
76
76
  return Number.isNaN(value);
@@ -78,8 +78,8 @@ function isNaN(value) {
78
78
  /**
79
79
  * 检查 value 是否为整数
80
80
  *
81
- * @param value - 待检查值
82
- * @param safeCheck - 是否附加安全数检查
81
+ * @param value 待检查值
82
+ * @param safeCheck 是否附加安全数检查
83
83
  */
84
84
  function isInteger(value, safeCheck = true) {
85
85
  const check = Number.isInteger(value);
@@ -89,8 +89,8 @@ function isInteger(value, safeCheck = true) {
89
89
  * 检查 value 是否为正整数
90
90
  * - 此函数中 `0` 不被视为正整数
91
91
  *
92
- * @param value - 待检查值
93
- * @param safeCheck - 是否附加安全数检查
92
+ * @param value 待检查值
93
+ * @param safeCheck 是否附加安全数检查
94
94
  */
95
95
  function isPositiveInteger(value, safeCheck = true) {
96
96
  return isInteger(value, safeCheck) && value > 0;
@@ -1 +1 @@
1
- {"version":3,"file":"patches-fetchEventSource.js","names":["result: ReadableStreamReadResult<Uint8Array>","buffer: Uint8Array | undefined","position: number","fieldLength: number","reconnectionTimer: NodeJS.Timeout","curRequestController: AbortController"],"sources":["../src/utils/typeof/types.ts","../src/utils/typeof/isAbortSignal.ts","../src/utils/typeof/isBoolean.ts","../src/utils/typeof/isObject.ts","../src/utils/typeof/isFunction.ts","../src/utils/typeof/isNumber.ts","../src/utils/typeof/isReadableStream.ts","../src/patches/fetchEventSource/parse.ts","../src/patches/fetchEventSource/fetchEventSource.ts"],"sourcesContent":["export const PROTOTYPE_TAGS = {\n abortSignal: \"[object AbortSignal]\",\n array: \"[object Array]\",\n asyncFunction: \"[object AsyncFunction]\",\n asyncGeneratorFunction: \"[object AsyncGeneratorFunction]\",\n bigInt: \"[object BigInt]\",\n blob: \"[object Blob]\",\n boolean: \"[object Boolean]\",\n date: \"[object Date]\",\n error: \"[object Error]\",\n file: \"[object File]\",\n function: \"[object Function]\",\n generatorFunction: \"[object GeneratorFunction]\",\n map: \"[object Map]\",\n null: \"[object Null]\",\n number: \"[object Number]\",\n object: \"[object Object]\",\n promise: \"[object Promise]\",\n readableStream: \"[object ReadableStream]\",\n regExp: \"[object RegExp]\",\n set: \"[object Set]\",\n string: \"[object String]\",\n symbol: \"[object Symbol]\",\n undefined: \"[object Undefined]\",\n URLSearchParams: \"[object URLSearchParams]\",\n weakMap: \"[object WeakMap]\",\n weakSet: \"[object WeakSet]\",\n webSocket: \"[object WebSocket]\",\n window: \"[object Window]\",\n} as const;\n\nexport const TYPED_ARRAY_TAGS = new Set([\n \"[object Int8Array]\",\n \"[object Uint8Array]\",\n \"[object Uint8ClampedArray]\",\n \"[object Int16Array]\",\n \"[object Uint16Array]\",\n \"[object Int32Array]\",\n \"[object Uint32Array]\",\n \"[object Float32Array]\",\n \"[object Float64Array]\",\n \"[object BigInt64Array]\",\n \"[object BigUint64Array]\",\n]);\n\nexport function resolvePrototypeString(value: unknown) {\n return Object.prototype.toString.call(value);\n}\n","import { PROTOTYPE_TAGS, resolvePrototypeString } from \"./types\";\n\nexport function isAbortSignal(value: unknown): value is AbortSignal {\n return resolvePrototypeString(value) === PROTOTYPE_TAGS.abortSignal;\n}\n","export function isBoolean(value: unknown): value is boolean {\n return typeof value === \"boolean\";\n}\n","import { PROTOTYPE_TAGS, resolvePrototypeString } from \"./types\";\n\n/**\n * 判断是否为对象类型\n * - 可选是否检查原型为 `Object.prototype`,防止原型链污染\n *\n * @param value - 待检查值\n * @param prototypeCheck - 是否进行原型检查,默认 `true`\n */\nexport function isObject(value: unknown, prototypeCheck = true): value is Record<PropertyKey, unknown> {\n const check = resolvePrototypeString(value) === PROTOTYPE_TAGS.object;\n\n return prototypeCheck ? check && Object.getPrototypeOf(value) === Object.prototype : check;\n}\n","import { PROTOTYPE_TAGS, resolvePrototypeString } from \"./types\";\n\nexport function isFunction(value: unknown): value is AnyFunction {\n return typeof value === \"function\";\n}\n\nexport function isAsyncFunction(value: unknown): value is AnyAsyncFunction {\n return isFunction(value) && resolvePrototypeString(value) === PROTOTYPE_TAGS.asyncFunction;\n}\n\nexport function isGeneratorFunction(value: unknown): value is AnyGeneratorFunction {\n return isFunction(value) && resolvePrototypeString(value) === PROTOTYPE_TAGS.generatorFunction;\n}\n\nexport function isAsyncGeneratorFunction(value: unknown): value is AnyAsyncGeneratorFunction {\n return isFunction(value) && resolvePrototypeString(value) === PROTOTYPE_TAGS.asyncGeneratorFunction;\n}\n","/**\n * 检查 value 是否为 number 类型\n *\n * @param value - 待检查值\n * @param checkNaN - 是否排除 `NaN`,默认为 `true`\n */\nexport function isNumber(value: unknown, checkNaN = true): value is number {\n return typeof value === \"number\" && (!checkNaN || !isNaN(value));\n}\n\n/**\n * 检查 value 是否为 NaN\n *\n * @param value - 待检查值\n */\nexport function isNaN(value: unknown): value is number {\n return Number.isNaN(value);\n}\n\n/**\n * 检查 value 是否为整数\n *\n * @param value - 待检查值\n * @param safeCheck - 是否附加安全数检查\n */\nexport function isInteger(value: unknown, safeCheck = true): value is number {\n const check = Number.isInteger(value);\n\n return safeCheck ? check && Number.isSafeInteger(value) : check;\n}\n\n/**\n * 检查 value 是否为正整数\n * - 此函数中 `0` 不被视为正整数\n *\n * @param value - 待检查值\n * @param safeCheck - 是否附加安全数检查\n */\nexport function isPositiveInteger(value: unknown, safeCheck = true): value is number {\n return isInteger(value, safeCheck) && value > 0;\n}\n\n/**\n * 检查 value 是否为负整数\n * - 此函数中 `0` 不被视为负整数\n *\n * @param value - 待检查值\n * @param safeCheck - 是否附加安全数检查\n */\nexport function isNegativeInteger(value: unknown, safeCheck = true): value is number {\n return isInteger(value, safeCheck) && value < 0;\n}\n\n/**\n * 检查 value 是否为 Infinity\n * - 排除 `NaN`\n *\n * @param value - 待检查值\n */\nexport function isInfinity(value: unknown): value is number {\n return isNumber(value) && (Number.POSITIVE_INFINITY === value || Number.NEGATIVE_INFINITY === value);\n}\n\n/**\n * 检查 value 是否类似 Infinity\n * - 排除 `NaN`\n *\n * @param value - 待检查值\n */\nexport function isInfinityLike(value: unknown): boolean {\n const check = isInfinity(value);\n\n if (check) {\n return check;\n }\n\n if (typeof value === \"string\") {\n const v = value.trim().toLowerCase();\n\n return v === \"infinity\" || v === \"-infinity\" || v === \"+infinity\";\n }\n\n return false;\n}\n","import { isFunction, isObject } from \"../index\";\nimport { PROTOTYPE_TAGS, resolvePrototypeString } from \"./types\";\n\n/**\n * Checks if a value is a WHATWG ReadableStream instance.\n *\n * - Uses `Object.prototype.toString` where supported (modern browsers, Node.js ≥18).\n * - Falls back to duck-typing in older environments.\n * - Resistant to basic forgery, but not 100% secure in all polyfill scenarios.\n *\n * ⚠️ Note: In older Node.js (<18) or with non-compliant polyfills, this may return false positives or negatives.\n */\nexport function isReadableStream(value: unknown): value is ReadableStream {\n // Modern environments (Chrome 52+, Firefox 57+, Safari 10.1+, Node.js 18+)\n if (resolvePrototypeString(value) === PROTOTYPE_TAGS.readableStream) {\n return true;\n }\n\n // Fallback for older browsers / polyfills (e.g., web-streams-polyfill)\n return isObject(value) && isFunction(value[\"getReader\"]) && isFunction(value[\"pipeThrough\"]);\n}\n","import { isNaN, isReadableStream } from \"../../utils\";\n\nconst CONTROL_CHARS_ENUM = {\n NEW_LINE: 10,\n CARRIAGE_RETURN: 13,\n SPACE: 32,\n COLON: 58,\n} as const;\n\n/**\n * Represents a message sent in an event stream\n * https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#Event_stream_format\n */\nexport interface EventSourceMessage {\n /**\n * The event ID to set the EventSource object's last event ID value.\n */\n id: string;\n /**\n * A string identifying the type of event described.\n */\n event: string;\n /**\n * The event data\n */\n data: string;\n /**\n * The delay to wait before reconnection.\n * @unit ms\n */\n reconnectionDelay?: number | undefined;\n}\n\n/**\n * Converts a ReadableStream into a callback pattern.\n * @param stream The input ReadableStream.\n * @param onChunk A function that will be called on each new byte chunk in the stream.\n * @returns A promise that will be resolved when the stream closes.\n */\nexport async function getBytes(stream: ReadableStream<Uint8Array> | AsyncIterable<Uint8Array>, onChunk: (array: Uint8Array) => void) {\n if (isReadableStream(stream)) {\n const reader = stream.getReader();\n let result: ReadableStreamReadResult<Uint8Array>;\n while (!(result = await reader.read()).done) {\n onChunk(result.value);\n }\n } else {\n for await (const chunk of stream) {\n onChunk(chunk);\n }\n }\n}\n\n/**\n * Parses arbitrary byte chunks into EventSource line buffers.\n * Each line should be of the format \"field: value\" and ends with \\r, \\n, or \\r\\n.\n * @param onLine A function that will be called on each new EventSource line.\n * @returns A function that should be called for each incoming byte chunk.\n */\nexport function getLines(onLine: (line: Uint8Array, fieldLength: number) => void) {\n let buffer: Uint8Array | undefined;\n let position: number; // current read position\n let fieldLength: number; // length of the `field` portion of the line\n let discardTrailingNewline = false;\n\n // return a function that can process each incoming byte chunk:\n return function onChunk(arr: Uint8Array) {\n if (buffer === undefined) {\n buffer = arr;\n position = 0;\n fieldLength = -1;\n } else {\n // we're still parsing the old line. Append the new bytes into buffer:\n buffer = concat(buffer, arr);\n }\n\n const bufLength = buffer.length;\n let lineStart = 0; // index where the current line starts\n while (position < bufLength) {\n if (discardTrailingNewline) {\n if (buffer[position] === CONTROL_CHARS_ENUM.NEW_LINE) {\n lineStart = ++position; // skip to next char\n }\n\n discardTrailingNewline = false;\n }\n\n // start looking forward till the end of line:\n let lineEnd = -1; // index of the \\r or \\n char\n for (; position < bufLength && lineEnd === -1; ++position) {\n switch (buffer[position]) {\n case CONTROL_CHARS_ENUM.COLON:\n if (fieldLength === -1) {\n // first colon in line\n fieldLength = position - lineStart;\n }\n break;\n // @ts-ignore:7029 \\r case below should fallthrough to \\n:\n case CONTROL_CHARS_ENUM.CARRIAGE_RETURN:\n discardTrailingNewline = true;\n\n // eslint-disable-next-line no-fallthrough\n case CONTROL_CHARS_ENUM.NEW_LINE:\n lineEnd = position;\n break;\n\n default:\n break;\n }\n }\n\n if (lineEnd === -1) {\n // We reached the end of the buffer but the line hasn't ended.\n // Wait for the next arr and then continue parsing:\n break;\n }\n\n // we've reached the line end, send it out:\n onLine(buffer.subarray(lineStart, lineEnd), fieldLength);\n lineStart = position; // we're now on the next line\n fieldLength = -1;\n }\n\n if (lineStart === bufLength) {\n buffer = undefined; // we've finished reading it\n } else if (lineStart !== 0) {\n // Create a new view into buffer beginning at lineStart so we don't\n // need to copy over the previous lines when we get the new arr:\n buffer = buffer.subarray(lineStart);\n position -= lineStart;\n }\n };\n}\n\n/**\n * Parses line buffers into EventSourceMessages.\n * @param onId A function that will be called on each `id` field.\n * @param onReconnect A function that will be called on each `retry` field.\n * @param onMessage A function that will be called on each message.\n * @returns A function that should be called for each incoming line buffer.\n */\nexport function getMessages(\n onMessage?: (message: EventSourceMessage) => void,\n onId?: (id: string) => void,\n onReconnect?: (delay: number) => void,\n) {\n const decoder = new TextDecoder();\n let message = createMessage();\n\n // return a function that can process each incoming line buffer:\n return function onLine(line: Uint8Array, fieldLength: number) {\n if (line.length === 0) {\n // If the data buffer's last character is a U+000A LINE FEED (LF) character, then remove the last character from the data buffer.\n if (message.data.endsWith(\"\\n\")) {\n message.data = message.data.substring(0, message.data.length - 1);\n }\n\n // empty line denotes end of message. Trigger the callback and start a new message:\n onMessage?.(message);\n message = createMessage();\n } else if (fieldLength > 0) {\n // exclude comments and lines with no values\n // line is of format \"<field>:<value>\" or \"<field>: <value>\"\n // https://html.spec.whatwg.org/multipage/server-sent-events.html#event-stream-interpretation\n const field = decoder.decode(line.subarray(0, fieldLength));\n const valueOffset = fieldLength + (line[fieldLength + 1] === CONTROL_CHARS_ENUM.SPACE ? 2 : 1);\n const value = decoder.decode(line.subarray(valueOffset));\n\n switch (field) {\n case \"id\":\n onId?.((message.id = value));\n break;\n\n case \"event\":\n message.event = value;\n break;\n\n case \"data\":\n // Append the field value to the data buffer, then append a single U+000A LINE FEED (LF) character to the data buffer.\n message.data = message.data + value + \"\\n\";\n break;\n\n case \"reconnectionDelay\":\n {\n const reconnectionDelay = parseInt(value, 10);\n if (!isNaN(reconnectionDelay)) {\n // per spec, ignore non-integers\n onReconnect?.((message.reconnectionDelay = reconnectionDelay));\n }\n }\n\n break;\n\n default:\n break;\n }\n }\n };\n}\n\nfunction concat(a: Uint8Array, b: Uint8Array) {\n const res = new Uint8Array(a.length + b.length);\n res.set(a);\n res.set(b, a.length);\n\n return res;\n}\n\nfunction createMessage(): EventSourceMessage {\n // data, event, and id must be initialized to empty strings:\n // https://html.spec.whatwg.org/multipage/server-sent-events.html#event-stream-interpretation\n // retry should be initialized to undefined so we return a consistent shape\n // to the js engine all the time: https://mathiasbynens.be/notes/shapes-ics#takeaways\n return { id: \"\", event: \"\", data: \"\", reconnectionDelay: undefined };\n}\n","import type { Except } from \"type-fest\";\nimport { isAbortSignal, isBoolean, isFunction, isPositiveInteger } from \"../../utils\";\nimport { type EventSourceMessage, getBytes, getLines, getMessages } from \"./parse\";\n\nconst RECONNECTION_DELAY = 1000;\nconst EVENT_STREAM_CONTENT_TYPE = \"text/event-stream\";\nconst LAST_EVENT_ID = \"LAST_EVENT_ID\";\n\nexport type FetchEventSourceOpenEvent = (response: Response) => void | Promise<void>;\nexport type FetchEventSourceCloseEvent = () => void | Promise<void>;\nexport type FetchEventSourceMessageEvent = (event: EventSourceMessage) => void | Promise<void>;\nexport type FetchEventSourceErrorEvent = (error: unknown) => number | undefined | Promise<number | undefined>;\nexport interface FetchEventSourceOptions extends Except<RequestInit, \"headers\"> {\n /**\n * The request headers.\n * FetchEventSource only supports the plain object format.\n */\n headers?: PlainObject | AnyFunction<unknown[], PlainObject> | undefined;\n\n /**\n * Called when a response is received.\n * Use this to validate that the response actually matches what you expect (and throw if it doesn't.) If not provided, will default to a basic validation to ensure the content-type is text/event-stream.\n */\n onopen?: FetchEventSourceOpenEvent | undefined;\n\n /**\n * Called when a response finishes.\n * If you don't expect the server to kill the connection, you can throw an exception here and retry using onerror.\n */\n onclose?: FetchEventSourceCloseEvent | undefined;\n\n /**\n * Called when a message is received.\n * Unlike the default browser EventSource.onmessage, this callback is called for _all_ events, even ones with a custom `event` field.\n */\n onmessage?: FetchEventSourceMessageEvent | undefined;\n\n /**\n * Called when there is any error making the request / processing messages / handling callbacks etc.\n * Use this to control the retry strategy: if the error is fatal, rethrow the error inside the callback to stop the entire operation.\n * Otherwise, you can return an interval (in milliseconds) after which the request will automatically retry (with the last-event-id).\n * If this callback is not specified, or it returns undefined, fetchEventSource will treat every error as retryable and will try again after 1 second.\n */\n onerror?: FetchEventSourceErrorEvent | undefined;\n\n /**\n * By default, will keep the request open even if the document is hidden.\n * If false, fetchEventSource will close the request and reopen it automatically when the document becomes visible again.\n * @default true\n */\n isKeepConnect?: boolean | undefined;\n\n /**\n * The delay to wait before reconnection.\n * @unit ms\n * @default 1000\n */\n reconnectionDelay?: number | undefined;\n\n /**\n * The Fetch function to use.\n * @default fetch\n */\n fetch?: typeof fetch | undefined;\n}\n\n/**\n * `@microsoft/fetch-event-source` 的修补版本\n * @see https://github.com/Azure/fetch-event-source\n */\nexport function fetchEventSource(input: RequestInfo, options?: FetchEventSourceOptions | undefined) {\n const {\n headers: inputHeaders,\n isKeepConnect: inputIsKeepConnect,\n reconnectionDelay: inputReconnectionDelay,\n onopen,\n onclose,\n onmessage,\n onerror,\n fetch: inputFetch,\n signal,\n ...rest\n } = options || {};\n\n return new Promise<void>((resolve, reject) => {\n const fetchFn = inputFetch ?? fetch;\n const isKeepConnect = isBoolean(inputIsKeepConnect) ? inputIsKeepConnect : true;\n let reconnectionDelay = isPositiveInteger(inputReconnectionDelay) ? inputReconnectionDelay : RECONNECTION_DELAY;\n let reconnectionTimer: NodeJS.Timeout;\n let curRequestController: AbortController;\n const requestHeaders = isFunction(inputHeaders) ? inputHeaders() : { ...inputHeaders };\n if (!requestHeaders[\"accept\"]) {\n requestHeaders[\"accept\"] = EVENT_STREAM_CONTENT_TYPE;\n }\n\n function onVisibilityChange() {\n // close existing request on every visibility change\n curRequestController.abort();\n if (!document?.hidden) {\n // page is now visible again, recreate request\n create();\n }\n }\n\n if (typeof document !== \"undefined\" && !isKeepConnect) {\n document.addEventListener(\"visibilitychange\", onVisibilityChange);\n }\n\n function dispose() {\n if (typeof document !== \"undefined\" && !isKeepConnect) {\n document.removeEventListener(\"visibilitychange\", onVisibilityChange);\n }\n clearTimeout(reconnectionTimer);\n curRequestController.abort();\n }\n\n function onSignalAbort() {\n dispose();\n // don't waste time constructing/logging errors\n resolve();\n }\n\n // if the incoming signal aborts, dispose resources and resolve\n if (isAbortSignal(signal)) {\n signal.addEventListener(\"abort\", onSignalAbort);\n }\n\n async function create() {\n if (curRequestController) {\n curRequestController.abort();\n }\n // Store the AbortController instance in function scope to prevent race conditions\n // This ensures that when error handling occurs, we check the abort status\n // of the correct controller instance that was associated with this specific request,\n // rather than potentially checking a new controller created by a subsequent request.\n //\n // Race condition example:\n // 1. Request A starts with Controller A\n // 2. Tab becomes hidden -> Controller A is aborted\n // 3. Tab becomes visible -> Request B starts with Controller B\n // 4. Request A's error handler executes\n // Without this fix, it would check Controller B's status instead of A's\n const currentController = new AbortController();\n curRequestController = currentController;\n\n try {\n const response = await fetchFn(input, {\n ...rest,\n headers: requestHeaders as AnyObject,\n signal: curRequestController.signal,\n });\n\n if (isFunction(onopen)) {\n await onopen(response);\n } else {\n const contentType = response.headers.get(\"content-type\");\n if (!contentType?.startsWith(EVENT_STREAM_CONTENT_TYPE)) {\n throw new Error(`Expected content-type to be ${EVENT_STREAM_CONTENT_TYPE}, Actual: ${contentType}`);\n }\n }\n\n function onId(id: string) {\n if (id) {\n // store the id and send it back on the next retry:\n requestHeaders[LAST_EVENT_ID] = id;\n } else {\n // don't send the last-event-id header anymore:\n delete requestHeaders[LAST_EVENT_ID];\n }\n }\n function onReconnect(delay: number) {\n reconnectionDelay = delay;\n }\n\n await getBytes(response.body!, getLines(getMessages(onmessage, onId, onReconnect)));\n\n onclose?.();\n dispose();\n resolve();\n } catch (error) {\n if (!currentController.signal.aborted) {\n // if we haven't aborted the request ourselves:\n try {\n // check if we need to retry:\n const delay = await onerror?.(error) ?? reconnectionDelay;\n clearTimeout(reconnectionTimer);\n reconnectionTimer = setTimeout(create, delay);\n } catch (innerError) {\n // we should not retry anymore:\n dispose();\n reject(innerError);\n }\n }\n }\n }\n\n create();\n });\n}\n"],"mappings":";AAAA,MAAa,iBAAiB;CAC5B,aAAa;CACb,OAAO;CACP,eAAe;CACf,wBAAwB;CACxB,QAAQ;CACR,MAAM;CACN,SAAS;CACT,MAAM;CACN,OAAO;CACP,MAAM;CACN,UAAU;CACV,mBAAmB;CACnB,KAAK;CACL,MAAM;CACN,QAAQ;CACR,QAAQ;CACR,SAAS;CACT,gBAAgB;CAChB,QAAQ;CACR,KAAK;CACL,QAAQ;CACR,QAAQ;CACR,WAAW;CACX,iBAAiB;CACjB,SAAS;CACT,SAAS;CACT,WAAW;CACX,QAAQ;CACT;AAgBD,SAAgB,uBAAuB,OAAgB;AACrD,QAAO,OAAO,UAAU,SAAS,KAAK,MAAM;;;;;AC5C9C,SAAgB,cAAc,OAAsC;AAClE,QAAO,uBAAuB,MAAM,KAAK,eAAe;;;;;ACH1D,SAAgB,UAAU,OAAkC;AAC1D,QAAO,OAAO,UAAU;;;;;;;;;;;;ACQ1B,SAAgB,SAAS,OAAgB,iBAAiB,MAA6C;CACrG,MAAM,QAAQ,uBAAuB,MAAM,KAAK,eAAe;AAE/D,QAAO,iBAAiB,SAAS,OAAO,eAAe,MAAM,KAAK,OAAO,YAAY;;;;;ACVvF,SAAgB,WAAW,OAAsC;AAC/D,QAAO,OAAO,UAAU;;;;;;;;;;ACY1B,SAAgB,MAAM,OAAiC;AACrD,QAAO,OAAO,MAAM,MAAM;;;;;;;;AAS5B,SAAgB,UAAU,OAAgB,YAAY,MAAuB;CAC3E,MAAM,QAAQ,OAAO,UAAU,MAAM;AAErC,QAAO,YAAY,SAAS,OAAO,cAAc,MAAM,GAAG;;;;;;;;;AAU5D,SAAgB,kBAAkB,OAAgB,Y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AAW,0BAA0B,CACrD,OAAM,IAAI,MAAM,+BAA+B,0BAA0B,YAAY,cAAc;;IAIvG,SAAS,KAAK,IAAY;AACxB,SAAI,GAEF,gBAAe,iBAAiB;SAGhC,QAAO,eAAe;;IAG1B,SAAS,YAAY,OAAe;AAClC,yBAAoB;;AAGtB,UAAM,SAAS,SAAS,MAAO,SAAS,YAAY,WAAW,MAAM,YAAY,CAAC,CAAC;AAEnF,eAAW;AACX,aAAS;AACT,aAAS;YACF,OAAO;AACd,QAAI,CAAC,kBAAkB,OAAO,QAE5B,KAAI;KAEF,MAAM,QAAQ,MAAM,UAAU,MAAM,IAAI;AACxC,kBAAa,kBAAkB;AAC/B,yBAAoB,WAAW,QAAQ,MAAM;aACtC,YAAY;AAEnB,cAAS;AACT,YAAO,WAAW;;;;AAM1B,UAAQ;GACR"}
1
+ {"version":3,"file":"patches-fetchEventSource.js","names":["result: ReadableStreamReadResult<Uint8Array>","buffer: Uint8Array | undefined","position: number","fieldLength: number","reconnectionTimer: NodeJS.Timeout","curRequestController: AbortController"],"sources":["../src/utils/typeof/types.ts","../src/utils/typeof/isAbortSignal.ts","../src/utils/typeof/isBoolean.ts","../src/utils/typeof/isObject.ts","../src/utils/typeof/isFunction.ts","../src/utils/typeof/isNumber.ts","../src/utils/typeof/isReadableStream.ts","../src/patches/fetchEventSource/parse.ts","../src/patches/fetchEventSource/fetchEventSource.ts"],"sourcesContent":["export const PROTOTYPE_TAGS = {\n abortSignal: \"[object AbortSignal]\",\n array: \"[object Array]\",\n asyncFunction: \"[object AsyncFunction]\",\n asyncGeneratorFunction: \"[object AsyncGeneratorFunction]\",\n bigInt: \"[object BigInt]\",\n blob: \"[object Blob]\",\n boolean: \"[object Boolean]\",\n date: \"[object Date]\",\n error: \"[object Error]\",\n file: \"[object File]\",\n function: \"[object Function]\",\n generatorFunction: \"[object GeneratorFunction]\",\n map: \"[object Map]\",\n null: \"[object Null]\",\n number: \"[object Number]\",\n object: \"[object Object]\",\n promise: \"[object Promise]\",\n readableStream: \"[object ReadableStream]\",\n regExp: \"[object RegExp]\",\n set: \"[object Set]\",\n string: \"[object String]\",\n symbol: \"[object Symbol]\",\n undefined: \"[object Undefined]\",\n URLSearchParams: \"[object URLSearchParams]\",\n weakMap: \"[object WeakMap]\",\n weakSet: \"[object WeakSet]\",\n webSocket: \"[object WebSocket]\",\n window: \"[object Window]\",\n} as const;\n\nexport const TYPED_ARRAY_TAGS = new Set([\n \"[object Int8Array]\",\n \"[object Uint8Array]\",\n \"[object Uint8ClampedArray]\",\n \"[object Int16Array]\",\n \"[object Uint16Array]\",\n \"[object Int32Array]\",\n \"[object Uint32Array]\",\n \"[object Float32Array]\",\n \"[object Float64Array]\",\n \"[object BigInt64Array]\",\n \"[object BigUint64Array]\",\n]);\n\nexport function resolvePrototypeString(value: unknown) {\n return Object.prototype.toString.call(value);\n}\n","import { PROTOTYPE_TAGS, resolvePrototypeString } from \"./types\";\n\nexport function isAbortSignal(value: unknown): value is AbortSignal {\n return resolvePrototypeString(value) === PROTOTYPE_TAGS.abortSignal;\n}\n","export function isBoolean(value: unknown): value is boolean {\n return typeof value === \"boolean\";\n}\n","import { PROTOTYPE_TAGS, resolvePrototypeString } from \"./types\";\n\n/**\n * 判断是否为对象类型\n * - 可选是否检查原型为 `Object.prototype`,防止原型链污染\n *\n * @param value 待检查值\n * @param prototypeCheck 是否进行原型检查,默认 `true`\n */\nexport function isObject(value: unknown, prototypeCheck = true): value is Record<PropertyKey, unknown> {\n const check = resolvePrototypeString(value) === PROTOTYPE_TAGS.object;\n\n return prototypeCheck ? check && Object.getPrototypeOf(value) === Object.prototype : check;\n}\n","import { PROTOTYPE_TAGS, resolvePrototypeString } from \"./types\";\n\nexport function isFunction(value: unknown): value is AnyFunction {\n return typeof value === \"function\";\n}\n\nexport function isAsyncFunction(value: unknown): value is AnyAsyncFunction {\n return isFunction(value) && resolvePrototypeString(value) === PROTOTYPE_TAGS.asyncFunction;\n}\n\nexport function isGeneratorFunction(value: unknown): value is AnyGeneratorFunction {\n return isFunction(value) && resolvePrototypeString(value) === PROTOTYPE_TAGS.generatorFunction;\n}\n\nexport function isAsyncGeneratorFunction(value: unknown): value is AnyAsyncGeneratorFunction {\n return isFunction(value) && resolvePrototypeString(value) === PROTOTYPE_TAGS.asyncGeneratorFunction;\n}\n","/**\n * 检查 value 是否为 number 类型\n *\n * @param value 待检查值\n * @param checkNaN 是否排除 `NaN`,默认为 `true`\n */\nexport function isNumber(value: unknown, checkNaN = true): value is number {\n return typeof value === \"number\" && (!checkNaN || !isNaN(value));\n}\n\n/**\n * 检查 value 是否为 NaN\n *\n * @param value 待检查值\n */\nexport function isNaN(value: unknown): value is number {\n return Number.isNaN(value);\n}\n\n/**\n * 检查 value 是否为整数\n *\n * @param value 待检查值\n * @param safeCheck 是否附加安全数检查\n */\nexport function isInteger(value: unknown, safeCheck = true): value is number {\n const check = Number.isInteger(value);\n\n return safeCheck ? check && Number.isSafeInteger(value) : check;\n}\n\n/**\n * 检查 value 是否为正整数\n * - 此函数中 `0` 不被视为正整数\n *\n * @param value 待检查值\n * @param safeCheck 是否附加安全数检查\n */\nexport function isPositiveInteger(value: unknown, safeCheck = true): value is number {\n return isInteger(value, safeCheck) && value > 0;\n}\n\n/**\n * 检查 value 是否为负整数\n * - 此函数中 `0` 不被视为负整数\n *\n * @param value 待检查值\n * @param safeCheck 是否附加安全数检查\n */\nexport function isNegativeInteger(value: unknown, safeCheck = true): value is number {\n return isInteger(value, safeCheck) && value < 0;\n}\n\n/**\n * 检查 value 是否为 Infinity\n * - 排除 `NaN`\n *\n * @param value 待检查值\n */\nexport function isInfinity(value: unknown): value is number {\n return isNumber(value) && (Number.POSITIVE_INFINITY === value || Number.NEGATIVE_INFINITY === value);\n}\n\n/**\n * 检查 value 是否类似 Infinity\n * - 排除 `NaN`\n *\n * @param value 待检查值\n */\nexport function isInfinityLike(value: unknown): boolean {\n const check = isInfinity(value);\n\n if (check) {\n return check;\n }\n\n if (typeof value === \"string\") {\n const v = value.trim().toLowerCase();\n\n return v === \"infinity\" || v === \"-infinity\" || v === \"+infinity\";\n }\n\n return false;\n}\n","import { isFunction, isObject } from \"../index\";\nimport { PROTOTYPE_TAGS, resolvePrototypeString } from \"./types\";\n\n/**\n * Checks if a value is a WHATWG ReadableStream instance.\n *\n * - Uses `Object.prototype.toString` where supported (modern browsers, Node.js ≥18).\n * - Falls back to duck-typing in older environments.\n * - Resistant to basic forgery, but not 100% secure in all polyfill scenarios.\n *\n * ⚠️ Note: In older Node.js (<18) or with non-compliant polyfills, this may return false positives or negatives.\n */\nexport function isReadableStream(value: unknown): value is ReadableStream {\n // Modern environments (Chrome 52+, Firefox 57+, Safari 10.1+, Node.js 18+)\n if (resolvePrototypeString(value) === PROTOTYPE_TAGS.readableStream) {\n return true;\n }\n\n // Fallback for older browsers / polyfills (e.g., web-streams-polyfill)\n return isObject(value) && isFunction(value[\"getReader\"]) && isFunction(value[\"pipeThrough\"]);\n}\n","import { isNaN, isReadableStream } from \"../../utils\";\n\nconst CONTROL_CHARS_ENUM = {\n NEW_LINE: 10,\n CARRIAGE_RETURN: 13,\n SPACE: 32,\n COLON: 58,\n} as const;\n\n/**\n * Represents a message sent in an event stream\n * https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#Event_stream_format\n */\nexport interface EventSourceMessage {\n /**\n * The event ID to set the EventSource object's last event ID value.\n */\n id: string;\n /**\n * A string identifying the type of event described.\n */\n event: string;\n /**\n * The event data\n */\n data: string;\n /**\n * The delay to wait before reconnection.\n * @unit ms\n */\n reconnectionDelay?: number | undefined;\n}\n\n/**\n * Converts a ReadableStream into a callback pattern.\n * @param stream The input ReadableStream.\n * @param onChunk A function that will be called on each new byte chunk in the stream.\n * @returns A promise that will be resolved when the stream closes.\n */\nexport async function getBytes(stream: ReadableStream<Uint8Array> | AsyncIterable<Uint8Array>, onChunk: (array: Uint8Array) => void) {\n if (isReadableStream(stream)) {\n const reader = stream.getReader();\n let result: ReadableStreamReadResult<Uint8Array>;\n while (!(result = await reader.read()).done) {\n onChunk(result.value);\n }\n } else {\n for await (const chunk of stream) {\n onChunk(chunk);\n }\n }\n}\n\n/**\n * Parses arbitrary byte chunks into EventSource line buffers.\n * Each line should be of the format \"field: value\" and ends with \\r, \\n, or \\r\\n.\n * @param onLine A function that will be called on each new EventSource line.\n * @returns A function that should be called for each incoming byte chunk.\n */\nexport function getLines(onLine: (line: Uint8Array, fieldLength: number) => void) {\n let buffer: Uint8Array | undefined;\n let position: number; // current read position\n let fieldLength: number; // length of the `field` portion of the line\n let discardTrailingNewline = false;\n\n // return a function that can process each incoming byte chunk:\n return function onChunk(arr: Uint8Array) {\n if (buffer === undefined) {\n buffer = arr;\n position = 0;\n fieldLength = -1;\n } else {\n // we're still parsing the old line. Append the new bytes into buffer:\n buffer = concat(buffer, arr);\n }\n\n const bufLength = buffer.length;\n let lineStart = 0; // index where the current line starts\n while (position < bufLength) {\n if (discardTrailingNewline) {\n if (buffer[position] === CONTROL_CHARS_ENUM.NEW_LINE) {\n lineStart = ++position; // skip to next char\n }\n\n discardTrailingNewline = false;\n }\n\n // start looking forward till the end of line:\n let lineEnd = -1; // index of the \\r or \\n char\n for (; position < bufLength && lineEnd === -1; ++position) {\n switch (buffer[position]) {\n case CONTROL_CHARS_ENUM.COLON:\n if (fieldLength === -1) {\n // first colon in line\n fieldLength = position - lineStart;\n }\n break;\n // @ts-ignore:7029 \\r case below should fallthrough to \\n:\n case CONTROL_CHARS_ENUM.CARRIAGE_RETURN:\n discardTrailingNewline = true;\n\n // eslint-disable-next-line no-fallthrough\n case CONTROL_CHARS_ENUM.NEW_LINE:\n lineEnd = position;\n break;\n\n default:\n break;\n }\n }\n\n if (lineEnd === -1) {\n // We reached the end of the buffer but the line hasn't ended.\n // Wait for the next arr and then continue parsing:\n break;\n }\n\n // we've reached the line end, send it out:\n onLine(buffer.subarray(lineStart, lineEnd), fieldLength);\n lineStart = position; // we're now on the next line\n fieldLength = -1;\n }\n\n if (lineStart === bufLength) {\n buffer = undefined; // we've finished reading it\n } else if (lineStart !== 0) {\n // Create a new view into buffer beginning at lineStart so we don't\n // need to copy over the previous lines when we get the new arr:\n buffer = buffer.subarray(lineStart);\n position -= lineStart;\n }\n };\n}\n\n/**\n * Parses line buffers into EventSourceMessages.\n * @param onId A function that will be called on each `id` field.\n * @param onReconnect A function that will be called on each `retry` field.\n * @param onMessage A function that will be called on each message.\n * @returns A function that should be called for each incoming line buffer.\n */\nexport function getMessages(\n onMessage?: (message: EventSourceMessage) => void,\n onId?: (id: string) => void,\n onReconnect?: (delay: number) => void,\n) {\n const decoder = new TextDecoder();\n let message = createMessage();\n\n // return a function that can process each incoming line buffer:\n return function onLine(line: Uint8Array, fieldLength: number) {\n if (line.length === 0) {\n // If the data buffer's last character is a U+000A LINE FEED (LF) character, then remove the last character from the data buffer.\n if (message.data.endsWith(\"\\n\")) {\n message.data = message.data.substring(0, message.data.length - 1);\n }\n\n // empty line denotes end of message. Trigger the callback and start a new message:\n onMessage?.(message);\n message = createMessage();\n } else if (fieldLength > 0) {\n // exclude comments and lines with no values\n // line is of format \"<field>:<value>\" or \"<field>: <value>\"\n // https://html.spec.whatwg.org/multipage/server-sent-events.html#event-stream-interpretation\n const field = decoder.decode(line.subarray(0, fieldLength));\n const valueOffset = fieldLength + (line[fieldLength + 1] === CONTROL_CHARS_ENUM.SPACE ? 2 : 1);\n const value = decoder.decode(line.subarray(valueOffset));\n\n switch (field) {\n case \"id\":\n onId?.((message.id = value));\n break;\n\n case \"event\":\n message.event = value;\n break;\n\n case \"data\":\n // Append the field value to the data buffer, then append a single U+000A LINE FEED (LF) character to the data buffer.\n message.data = message.data + value + \"\\n\";\n break;\n\n case \"reconnectionDelay\":\n {\n const reconnectionDelay = parseInt(value, 10);\n if (!isNaN(reconnectionDelay)) {\n // per spec, ignore non-integers\n onReconnect?.((message.reconnectionDelay = reconnectionDelay));\n }\n }\n\n break;\n\n default:\n break;\n }\n }\n };\n}\n\nfunction concat(a: Uint8Array, b: Uint8Array) {\n const res = new Uint8Array(a.length + b.length);\n res.set(a);\n res.set(b, a.length);\n\n return res;\n}\n\nfunction createMessage(): EventSourceMessage {\n // data, event, and id must be initialized to empty strings:\n // https://html.spec.whatwg.org/multipage/server-sent-events.html#event-stream-interpretation\n // retry should be initialized to undefined so we return a consistent shape\n // to the js engine all the time: https://mathiasbynens.be/notes/shapes-ics#takeaways\n return { id: \"\", event: \"\", data: \"\", reconnectionDelay: undefined };\n}\n","import type { Except } from \"type-fest\";\nimport { isAbortSignal, isBoolean, isFunction, isPositiveInteger } from \"../../utils\";\nimport { type EventSourceMessage, getBytes, getLines, getMessages } from \"./parse\";\n\nconst RECONNECTION_DELAY = 1000;\nconst EVENT_STREAM_CONTENT_TYPE = \"text/event-stream\";\nconst LAST_EVENT_ID = \"LAST_EVENT_ID\";\n\nexport type FetchEventSourceOpenEvent = (response: Response) => void | Promise<void>;\nexport type FetchEventSourceCloseEvent = () => void | Promise<void>;\nexport type FetchEventSourceMessageEvent = (event: EventSourceMessage) => void | Promise<void>;\nexport type FetchEventSourceErrorEvent = (error: unknown) => number | undefined | Promise<number | undefined>;\nexport interface FetchEventSourceOptions extends Except<RequestInit, \"headers\"> {\n /**\n * The request headers.\n * FetchEventSource only supports the plain object format.\n */\n headers?: PlainObject | AnyFunction<unknown[], PlainObject> | undefined;\n\n /**\n * Called when a response is received.\n * Use this to validate that the response actually matches what you expect (and throw if it doesn't.) If not provided, will default to a basic validation to ensure the content-type is text/event-stream.\n */\n onopen?: FetchEventSourceOpenEvent | undefined;\n\n /**\n * Called when a response finishes.\n * If you don't expect the server to kill the connection, you can throw an exception here and retry using onerror.\n */\n onclose?: FetchEventSourceCloseEvent | undefined;\n\n /**\n * Called when a message is received.\n * Unlike the default browser EventSource.onmessage, this callback is called for _all_ events, even ones with a custom `event` field.\n */\n onmessage?: FetchEventSourceMessageEvent | undefined;\n\n /**\n * Called when there is any error making the request / processing messages / handling callbacks etc.\n * Use this to control the retry strategy: if the error is fatal, rethrow the error inside the callback to stop the entire operation.\n * Otherwise, you can return an interval (in milliseconds) after which the request will automatically retry (with the last-event-id).\n * If this callback is not specified, or it returns undefined, fetchEventSource will treat every error as retryable and will try again after 1 second.\n */\n onerror?: FetchEventSourceErrorEvent | undefined;\n\n /**\n * By default, will keep the request open even if the document is hidden.\n * If false, fetchEventSource will close the request and reopen it automatically when the document becomes visible again.\n * @default true\n */\n isKeepConnect?: boolean | undefined;\n\n /**\n * The delay to wait before reconnection.\n * @unit ms\n * @default 1000\n */\n reconnectionDelay?: number | undefined;\n\n /**\n * The Fetch function to use.\n * @default fetch\n */\n fetch?: typeof fetch | undefined;\n}\n\n/**\n * `@microsoft/fetch-event-source` 的修补版本\n * @see https://github.com/Azure/fetch-event-source\n */\nexport function fetchEventSource(input: RequestInfo, options?: FetchEventSourceOptions | undefined) {\n const {\n headers: inputHeaders,\n isKeepConnect: inputIsKeepConnect,\n reconnectionDelay: inputReconnectionDelay,\n onopen,\n onclose,\n onmessage,\n onerror,\n fetch: inputFetch,\n signal,\n ...rest\n } = options || {};\n\n return new Promise<void>((resolve, reject) => {\n const fetchFn = inputFetch ?? fetch;\n const isKeepConnect = isBoolean(inputIsKeepConnect) ? inputIsKeepConnect : true;\n let reconnectionDelay = isPositiveInteger(inputReconnectionDelay) ? inputReconnectionDelay : RECONNECTION_DELAY;\n let reconnectionTimer: NodeJS.Timeout;\n let curRequestController: AbortController;\n const requestHeaders = isFunction(inputHeaders) ? inputHeaders() : { ...inputHeaders };\n if (!requestHeaders[\"accept\"]) {\n requestHeaders[\"accept\"] = EVENT_STREAM_CONTENT_TYPE;\n }\n\n function onVisibilityChange() {\n // close existing request on every visibility change\n curRequestController.abort();\n if (!document?.hidden) {\n // page is now visible again, recreate request\n create();\n }\n }\n\n if (typeof document !== \"undefined\" && !isKeepConnect) {\n document.addEventListener(\"visibilitychange\", onVisibilityChange);\n }\n\n function dispose() {\n if (typeof document !== \"undefined\" && !isKeepConnect) {\n document.removeEventListener(\"visibilitychange\", onVisibilityChange);\n }\n clearTimeout(reconnectionTimer);\n curRequestController.abort();\n }\n\n function onSignalAbort() {\n dispose();\n // don't waste time constructing/logging errors\n resolve();\n }\n\n // if the incoming signal aborts, dispose resources and resolve\n if (isAbortSignal(signal)) {\n signal.addEventListener(\"abort\", onSignalAbort);\n }\n\n async function create() {\n if (curRequestController) {\n curRequestController.abort();\n }\n // Store the AbortController instance in function scope to prevent race conditions\n // This ensures that when error handling occurs, we check the abort status\n // of the correct controller instance that was associated with this specific request,\n // rather than potentially checking a new controller created by a subsequent request.\n //\n // Race condition example:\n // 1. Request A starts with Controller A\n // 2. Tab becomes hidden -> Controller A is aborted\n // 3. Tab becomes visible -> Request B starts with Controller B\n // 4. Request A's error handler executes\n // Without this fix, it would check Controller B's status instead of A's\n const currentController = new AbortController();\n curRequestController = currentController;\n\n try {\n const response = await fetchFn(input, {\n ...rest,\n headers: requestHeaders as AnyObject,\n signal: curRequestController.signal,\n });\n\n if (isFunction(onopen)) {\n await onopen(response);\n } else {\n const contentType = response.headers.get(\"content-type\");\n if (!contentType?.startsWith(EVENT_STREAM_CONTENT_TYPE)) {\n throw new Error(`Expected content-type to be ${EVENT_STREAM_CONTENT_TYPE}, Actual: ${contentType}`);\n }\n }\n\n function onId(id: string) {\n if (id) {\n // store the id and send it back on the next retry:\n requestHeaders[LAST_EVENT_ID] = id;\n } else {\n // don't send the last-event-id header anymore:\n delete requestHeaders[LAST_EVENT_ID];\n }\n }\n function onReconnect(delay: number) {\n reconnectionDelay = delay;\n }\n\n await getBytes(response.body!, getLines(getMessages(onmessage, onId, onReconnect)));\n\n onclose?.();\n dispose();\n resolve();\n } catch (error) {\n if (!currentController.signal.aborted) {\n // if we haven't aborted the request ourselves:\n try {\n // check if we need to retry:\n const delay = await onerror?.(error) ?? reconnectionDelay;\n clearTimeout(reconnectionTimer);\n reconnectionTimer = setTimeout(create, delay);\n } catch (innerError) {\n // we should not retry anymore:\n dispose();\n reject(innerError);\n }\n }\n }\n }\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AAoB;;AAGtB,UAAM,SAAS,SAAS,MAAO,SAAS,YAAY,WAAW,MAAM,YAAY,CAAC,CAAC;AAEnF,eAAW;AACX,aAAS;AACT,aAAS;YACF,OAAO;AACd,QAAI,CAAC,kBAAkB,OAAO,QAE5B,KAAI;KAEF,MAAM,QAAQ,MAAM,UAAU,MAAM,IAAI;AACxC,kBAAa,kBAAkB;AAC/B,yBAAoB,WAAW,QAAQ,MAAM;aACtC,YAAY;AAEnB,cAAS;AACT,YAAO,WAAW;;;;AAM1B,UAAQ;GACR"}
package/metadata.json CHANGED
@@ -72,7 +72,10 @@
72
72
  "stringTemplate",
73
73
  "stringToJson",
74
74
  "stringToNumber",
75
+ "stringToPosix",
75
76
  "stringToValues",
77
+ "stringTrim",
78
+ "stringTruncate",
76
79
  "to",
77
80
  "toMathBignumber",
78
81
  "toMathDecimal",
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "description": "pawover's kit",
5
5
  "license": "MIT",
6
6
  "type": "module",
7
- "version": "0.0.0-beta.1",
7
+ "version": "0.0.0-beta.3",
8
8
  "packageManager": "pnpm@10.20.0",
9
9
  "engines": {
10
10
  "node": ">=22.20.0"
@@ -60,8 +60,8 @@
60
60
  "zod": "^4.2.1"
61
61
  },
62
62
  "devDependencies": {
63
- "@pawover/eslint-rules": "0.0.0-alpha.12",
64
- "@pawover/types": "0.0.0-alpha.8",
63
+ "@pawover/eslint-rules": "^0.0.0-alpha.24",
64
+ "@pawover/types": "^0.0.0-alpha.8",
65
65
  "@stylistic/eslint-plugin": "^5.6.1",
66
66
  "@types/fs-extra": "^11.0.4",
67
67
  "@types/node": "^25.0.3",