import { StandardSchemaDictionary } from "./standard.js"; import { Format, Partial } from "ts-vista"; type CompleteExtension = Readonly<{ /** Inner extensions to merge. */extends: readonly Extension[]; /** The env variable definitions. */ define: Define; }>; /** Environment variables extension. */ type Extension = Format, "extends">>; /** Convert a union of object types into their intersection. */ type UnionToIntersection = (U extends unknown ? (x: U) => void : never) extends ((x: infer I) => void) ? I : never; /** * Collapse a tuple of extensions to `Record` when empty, * otherwise the intersection of `Mapper` applied to each element. */ type CollapseExt[], Mapper> = [Ext] extends [readonly never[]] ? Record : UnionToIntersection; /** Merge two dictionaries, with `A` winning on key collision. */ type MergeWinLeft = { [K in keyof A | keyof B]: K extends keyof A ? A[K] : K extends keyof B ? B[K] : never }; /** * The `define` schemas of an extension, * collapsed to an empty record when broad. */ type ExtensionDefineSchemas> = string extends keyof NonNullable ? Record : NonNullable; /** The intersection of `define` schemas contributed by inner extensions. */ type ExtensionDefines[]> = CollapseExt>; /** * The flattened `define` after merging inner extensions * with the outer `define` applied last. */ type MergedExtensionDefine[] = readonly never[]> = MergeWinLeft>; /** * Extract the inferred output of an extension's `define`, * collapsed to an empty record when broad. */ type ExtensionDefineOutput> = NonNullable extends StandardSchemaDictionary ? string extends keyof StandardSchemaDictionary.InferOutput> ? Record : StandardSchemaDictionary.InferOutput> : Record; /** The inferred env output contributed by different extensions. */ type ExtensionOutputs[]> = CollapseExt>; /** The merged output of user-defined variables and variables from extensions. */ type MergedEnvOutput[]> = MergeWinLeft, ExtensionOutputs>; export type { Extension, ExtensionDefineOutput, ExtensionOutputs, MergedEnvOutput, MergedExtensionDefine, UnionToIntersection }; //# sourceMappingURL=extension.d.ts.map