import * as t from "io-ts"; //#region src/types.d.ts /** * An arbitrary object keyed by strings for naming consistency. */ type ObjByString = { [key in string]: any }; /** * An arbitrary function. */ type AnyFunction = (...args: any[]) => any; /** * An arbitrary array. */ type AnyArray = any[]; /** * The type of the underlying array. */ type ArrType = TData extends (infer DataT)[] ? DataT : never; /** * The type of the underlying promise. */ type PromiseType = TData extends Promise ? Result : TData; /** * The type of the underlying array or the identity of the input. */ type ArrOrIdentityType = TData extends (infer DataT)[] ? DataT : TData; /** * Helper to create `T` or `T[]`. */ type OrArray = T | T[]; /** * To make the inspected type more tractable than a bunch of intersections. */ type Identity = { [K in keyof T]: T[K] }; /** * Identity but recursive. */ type RecursiveIdentity = T extends AnyArray ? ArrType extends object ? Identity>[] : T : T extends string ? T : T extends object ? { [K in keyof T]: T[K] extends object ? Identity : T[K] } : T; /** * Make selected object keys defined by `K` optional in type `T`. */ type Optionalize = Identity & Partial>; /** * Make selected object keys required in type `T`. */ type Requirize = Identity & Required<{ [P in K]: T[P] }>>; /** * Convert keys of a type to strings. */ type Stringify = Omit & { [P in keyof T]: string }; /** * Extract string keys from an object. */ type StringKeys = Extract; /** * Extract associated values of string keys. */ type StringValues = TObj[keyof TObj]; /** * String keys without extends enforcement. */ type StringKeysSafe = T extends ObjByString ? StringKeys : undefined; /** * Extract the sub types of an object based on a condition. */ type SubType = Pick; /** * Inverse of `SubType`. */ type SubNotType = Pick; /** * `SubType`, but optional inputs become required. */ type SubTypeRequired = SubType, Condition>; /** * Names of properties in `T` with types that include `undefined`. */ type OptionalPropertyNames = { [K in keyof T]: undefined extends T[K] ? K : never }[keyof T]; /** * Common properties from `L` and `R` with `undefined` in `R[K]` replaced by `L[K]`. */ type SpreadProperties = { [P in K]: L[P] | Exclude }; /** * Type of `{ ...L, ...R }`, more accurate than `L & R`. */ type Spread = Identity> & Pick>> & Pick, keyof L>> & SpreadProperties & keyof L>>; /** * Soft spread. */ type Merge = Identity> & R>; /** * Convert unions to intersections. */ type UnionToIntersection = (U extends any ? (argument: U) => void : never) extends ((argument: infer Intersection) => void) ? Intersection : never; /** * Loop over an object and recursively replace all values. */ type RecursiveTypeReplace = T extends Promise ? Promise> : T extends ((...args: infer Args) => infer ReturnValue) ? (...args: Args) => RecursiveTypeReplace : T extends RegExp ? T : Extract extends never ? { [Key in keyof T]: RecursiveTypeReplace } : Exclude<{ [Key in keyof T]: RecursiveTypeReplace }, string> | TReplaceWith; /** * Recursively replace one type in an object. */ type RecursiveObjectReplace = TBase extends TReplaceCondition ? TReplaceWith : TBase extends (infer Item)[] ? RecursiveObjectReplace : TBase extends object ? { [Key in keyof TBase]: TBase[Key] extends (infer MatrixItem)[][] ? RecursiveObjectReplace[][] : TBase[Key] extends (infer MatrixItem)[][] | undefined ? RecursiveObjectReplace[][] | undefined : TBase[Key] extends (infer Item)[] ? RecursiveObjectReplace[] : TBase[Key] extends (infer Item)[] | undefined ? RecursiveObjectReplace[] | undefined : TBase[Key] extends TReplaceCondition ? TReplaceWith : TBase[Key] extends TReplaceCondition | undefined ? TReplaceWith | undefined : RecursiveObjectReplace } : TBase; /** * Make values nullable. */ type Nullable = { [K in keyof T]: T[K] | null }; /** * Deep partial of a type. */ type DeepPartial = { [P in keyof T]?: DeepPartial }; /** * Utility type that passes through the interface given that its keys are * exactly equal to the keys string union. */ type KeysStrictlyEqual = Interface; /** * Override fields in `T` with fields in `U`. */ type Override = Pick> & U; //#endregion //#region src/apply.d.ts /** * Apply a function to each value of an object while preserving the key types. */ declare function apply(obj: TInput, applyFunc: (value: TInput[keyof TInput], key: StringKeys, fullObj: typeof obj, index: number) => TOutput): { [key in keyof TInput]: TOutput }; /** * Async version of `apply`. */ declare function asyncApply(obj: TInput, applyFunc: (value: TInput[keyof TInput], key: StringKeys, fullObj: typeof obj, index: number) => Promise): Promise<{ [key in keyof TInput]: TOutput }>; /** * Convert a TypeScript enum to a value-to-value map and then call `apply`. */ declare function applyEnum(enm: { [key in string]: TEnum }, applyFunc: (value: TEnum, key: TEnum, fullObj: typeof enm, index: number) => TOutput): { [key in TEnum]: TOutput }; //#endregion //#region src/codecTools/decodeCodec.d.ts declare const CODEC_ERROR_MESSAGE = "Failed to decode codec:"; /** * Decode a codec, returning the decoded value or throwing an error. */ declare function decodeCodec(codec: TCodec, txt: unknown, parse?: boolean, customErrorFromContext?: ((validationContext: t.Context) => string) | undefined): t.TypeOf; //#endregion //#region src/codecTools/dictionary.d.ts /** * A record with optional keys. */ interface DictionaryC extends t.DictionaryType]?: t.TypeOf }, { [K in t.OutputOf]?: t.OutputOf }, unknown> {} /** * Helper to encode/decode a record with partial keys. */ declare const dictionary: (keys: D, values: C, name?: string) => DictionaryC; //#endregion //#region src/codecTools/FixedLengthString.d.ts /** * Brand for strings of fixed length. */ type FixedLengthStringBrand = { /** The expected length of the string. */readonly length: N; /** Unique symbol to ensure uniqueness of this type across modules/packages. */ readonly FixedLengthString: unique symbol; }; /** * Codec for strings constrained to a fixed length. */ declare const FixedLengthString: (len: N) => t.BrandC>; /** * Branded fixed-length string type. */ type FixedLengthString = t.TypeOf>>; //#endregion //#region src/codecTools/FixedLengthArray.d.ts /** * Brand for arrays with bounded length. */ interface FixedLengthArrayBrand extends Array { /** Unique symbol to ensure uniqueness of this type across modules/packages. */ readonly fixedLengthArray: unique symbol; /** The minimum length of the array. */ readonly min: number; /** The maximum length of the array. */ readonly max: number; } /** * Codec for arrays constrained to a fixed length range. */ declare const FixedLengthArray: (min: number, max: number, codec: C) => t.BrandC, FixedLengthArrayBrand>; /** * Branded fixed-length array type. */ type FixedLengthArray = t.TypeOf, FixedLengthArrayBrand>>; //#endregion //#region src/codecTools/partialRecord.d.ts /** * Like `t.record`, but where the keys are all optional to include. */ interface PartialRecordC extends t.DictionaryType]?: t.TypeOf }, { [K in t.OutputOf]?: t.OutputOf }, unknown> {} /** * Create an `io-ts` compatible partial record. */ declare const partialRecord: (domain: D, codomain: C, name?: string) => PartialRecordC; //#endregion //#region src/codecTools/isCodecError.d.ts /** * Checks an error message to see if it is an `io-ts` codec error. */ declare function isCodecError(err: Error): boolean; //#endregion //#region src/codecTools/NonEmptyString.d.ts /** * Brand for non-empty strings. */ type NonEmptyStringBrand = { /** Unique symbol to ensure uniqueness of this type across modules/packages. */readonly NonEmptyString: symbol; }; /** * Codec for non-empty trimmed strings. */ declare const NonEmptyString: t.BrandC; /** * Branded non-empty string type. */ type NonEmptyString = t.TypeOf; //#endregion //#region ../../node_modules/.pnpm/@types+json-schema@7.0.15/node_modules/@types/json-schema/index.d.ts // ================================================================================================== // JSON Schema Draft 07 // ================================================================================================== // https://tools.ietf.org/html/draft-handrews-json-schema-validation-01 // -------------------------------------------------------------------------------------------------- /** * Primitive type * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.1.1 */ type JSONSchema7TypeName = "string" // | "number" | "integer" | "boolean" | "object" | "array" | "null"; /** * Primitive type * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.1.1 */ type JSONSchema7Type = string // | number | boolean | JSONSchema7Object | JSONSchema7Array | null; // Workaround for infinite type recursion interface JSONSchema7Object { [key: string]: JSONSchema7Type; } // Workaround for infinite type recursion // https://github.com/Microsoft/TypeScript/issues/3496#issuecomment-128553540 interface JSONSchema7Array extends Array {} /** * Meta schema * * Recommended values: * - 'http://json-schema.org/schema#' * - 'http://json-schema.org/hyper-schema#' * - 'http://json-schema.org/draft-07/schema#' * - 'http://json-schema.org/draft-07/hyper-schema#' * * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-5 */ type JSONSchema7Version = string; /** * JSON Schema v7 * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01 */ type JSONSchema7Definition = JSONSchema7 | boolean; interface JSONSchema7 { $id?: string | undefined; $ref?: string | undefined; $schema?: JSONSchema7Version | undefined; $comment?: string | undefined; /** * @see https://datatracker.ietf.org/doc/html/draft-bhutton-json-schema-00#section-8.2.4 * @see https://datatracker.ietf.org/doc/html/draft-bhutton-json-schema-validation-00#appendix-A */ $defs?: { [key: string]: JSONSchema7Definition; } | undefined; /** * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.1 */ type?: JSONSchema7TypeName | JSONSchema7TypeName[] | undefined; enum?: JSONSchema7Type[] | undefined; const?: JSONSchema7Type | undefined; /** * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.2 */ multipleOf?: number | undefined; maximum?: number | undefined; exclusiveMaximum?: number | undefined; minimum?: number | undefined; exclusiveMinimum?: number | undefined; /** * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.3 */ maxLength?: number | undefined; minLength?: number | undefined; pattern?: string | undefined; /** * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.4 */ items?: JSONSchema7Definition | JSONSchema7Definition[] | undefined; additionalItems?: JSONSchema7Definition | undefined; maxItems?: number | undefined; minItems?: number | undefined; uniqueItems?: boolean | undefined; contains?: JSONSchema7Definition | undefined; /** * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.5 */ maxProperties?: number | undefined; minProperties?: number | undefined; required?: string[] | undefined; properties?: { [key: string]: JSONSchema7Definition; } | undefined; patternProperties?: { [key: string]: JSONSchema7Definition; } | undefined; additionalProperties?: JSONSchema7Definition | undefined; dependencies?: { [key: string]: JSONSchema7Definition | string[]; } | undefined; propertyNames?: JSONSchema7Definition | undefined; /** * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.6 */ if?: JSONSchema7Definition | undefined; then?: JSONSchema7Definition | undefined; else?: JSONSchema7Definition | undefined; /** * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.7 */ allOf?: JSONSchema7Definition[] | undefined; anyOf?: JSONSchema7Definition[] | undefined; oneOf?: JSONSchema7Definition[] | undefined; not?: JSONSchema7Definition | undefined; /** * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-7 */ format?: string | undefined; /** * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-8 */ contentMediaType?: string | undefined; contentEncoding?: string | undefined; /** * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-9 */ definitions?: { [key: string]: JSONSchema7Definition; } | undefined; /** * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-10 */ title?: string | undefined; description?: string | undefined; default?: JSONSchema7Type | undefined; readOnly?: boolean | undefined; writeOnly?: boolean | undefined; examples?: JSONSchema7Type | undefined; } //#endregion //#region src/codecTools/toJsonSchema.d.ts /** * Convert an `io-ts` codec to a JSON Schema (v7). */ declare const toJsonSchema: (rawType: any, strict?: boolean, alwaysIncludeRequired?: boolean) => JSONSchema7; //#endregion //#region src/codecTools/createDefaultCodec.d.ts /** * Creates a default value for an `io-ts` codec. */ declare const createDefaultCodec: (codec: C) => t.TypeOf; //#endregion //#region src/enum.d.ts /** * An enumerated value. */ type Enumerate = { [key in TKey]: T }; /** * A TypeScript enum with string values. */ type TypescriptEnum = { [key in string]: string } | { [key in number]: string }; /** * An input when defining an enum can be an object of string -> string or a list * of strings. */ type EnumInput = Enumerate | string[]; /** * Convert a list of strings to an enum-like object. */ declare function listToEnum(attributes: string[]): Enumerate; /** * Merge enum-like inputs into a single enum object. */ declare function createEnum(...attributes: EnumInput[]): Enumerate; /** * Filter an enum and return the keys that remain. */ declare function filterEnum(obj: T, filterFunc: (value: T[keyof T], key: keyof T, calculatedEnum: Enumerate) => boolean): (keyof T)[]; /** * Make an enum compatible with type inference without changing its runtime * shape. */ declare function makeEnum(value: T): T; //#endregion //#region src/enums.d.ts /** * The HTTP method types. */ declare const HttpMethod: { /** A GET request. */Get: "GET"; /** A POST request. */ Post: "POST"; /** A DELETE request. */ Delete: "DELETE"; /** A PUT request. */ Put: "PUT"; /** A PATCH request. */ Patch: "PATCH"; }; /** * The HTTP method string union. */ type HttpMethod = (typeof HttpMethod)[keyof typeof HttpMethod]; //#endregion //#region src/getEntries.d.ts /** * `Object.entries` that preserves entry types. */ declare function getEntries(obj: TObj): [TKey, TObj[TKey]][]; //#endregion //#region src/getKeys.d.ts /** * `Object.keys` for string keys only. */ declare function getStringKeys(obj: T): StringKeys[]; /** * `Object.keys` that preserves key types. */ declare function getKeys(obj: T): (keyof T)[]; //#endregion //#region src/getValues.d.ts /** * `Object.values` that preserves value types. */ declare function getValues(obj: { [key in string | number | symbol]: TValue }): TValue[]; //#endregion //#region src/groupBy.d.ts /** * A typed version of lodash's `groupBy`. */ declare function groupBy(iterable: TItem[], getKey: (item: TItem) => TKey): Map; //#endregion //#region src/gql.d.ts /** * Identify whether a string looks like a GraphQL interface/type/input * declaration. */ declare const INTERFACE_REGEX: RegExp; /** * A `gql` is simply a string branded with the associated GraphQL type. */ type Gql = string & { /** The TypeScript type definition that relates to the gql string. */graphQLType: TGraphQLType; }; /** * Template tag for GraphQL fragments with a small amount of interpolation * support for interface bodies. */ declare function gql(strings: TemplateStringsArray, ...expressions: (string | number)[]): Gql; //#endregion //#region src/invert.d.ts /** * Invert an object so the values look up the keys. Arrays are expanded and map * back to arrays of keys. */ declare function invert(obj: { [key in TKey]?: TValue }, throwOnDuplicate?: boolean): { [key in TValue extends (infer Item)[] ? Item : TValue]: TValue extends any[] ? TKey[] : TKey }; /** * Safely invert an object into `{ [value]: key[] }`. */ declare function invertSafe(obj: { [key in TKey]: TValue | TValue[] }): { [key in TValue]: TKey[] }; //#endregion //#region src/valuesOf.d.ts /** * Build an `io-ts` codec over the values of an enum-like object. */ declare function valuesOf(enm: { [key in string]: TEnum }): t.KeyofC<{ [key in TEnum]: unknown }>; //#endregion //#region src/findAllWithRegex.d.ts /** * The full match returned when `regex.exec` finds a match. */ interface RegExpMatch { /** The full regex match. */ fullMatch: string; /** The index in the text where the match was found. */ matchIndex: number; /** Whether the match satisfies an optional stricter regex. */ isStrict?: boolean; } /** * Definition for finding all regex matches and mapping capture groups to keys. */ interface FindAllRegExp { /** The regex to test. */ value: RegExp; /** * A stricter regex used to annotate matches that satisfy a more exact * standard. */ strict?: RegExp; /** Capture group names mapped by index. */ matches: readonly TMatchKeys[]; /** When true, skip validation of matches being the expected length. */ skipMatchValidation?: boolean; } /** * Use a regex with the global flag to find all matches and return the list with * capture groups mapped to named properties. */ declare function findAllWithRegex(regex: FindAllRegExp, text: string): ({ [key in TMatchKeys]: string } & RegExpMatch)[]; //#endregion //#region src/flattenObject.d.ts /** * Flattens a nested object into a single-level object with concatenated key * names. */ declare const flattenObject: ({ obj, prefix }: { /** The object to flatten. */obj: any; /** The prefix to prepend to keys while recursing. */ prefix?: string; }) => any; //#endregion //#region src/aggregateObjects.d.ts /** * Aggregates multiple objects into a single object by combining values of * matching keys into comma-separated strings. */ declare const aggregateObjects: ({ objs, wrap }: { /** The objects to aggregate in a single one. */objs: any[]; /** Whether to wrap the concatenated values in `[]`. */ wrap?: boolean; }) => any; //#endregion //#region src/transposeObjectArray.d.ts /** * Type representing a transposed array of objects. */ type TransposedObjectArray = { [P in K]: Array } & { /** Properties not selected for transposition. */rest: Array>; }; /** * Transpose an array of objects by converting selected properties into arrays * while keeping the remaining properties grouped in `rest`. */ declare const transposeObjectArray: ({ objects, properties, options }: { /** Array of objects to transpose. */objects: T[]; /** Property keys to transpose into arrays. */ properties: K[]; /** Options for how to transpose the array. */ options?: { /** Whether to include non-transposed properties in the final result. */includeOtherProperties?: boolean; }; }) => TransposedObjectArray; //#endregion //#region src/fromEntries.d.ts /** * `Object.fromEntries` that preserves entry types. */ declare function fromEntries>(entries: TEntries): { [K in TEntries[number] as K[0]]: K[1] }; //#endregion //#region src/noExcess.d.ts /** * Wrap an `io-ts` codec so validation fails when excess properties are present. */ declare const noExcess: (codec: C, name?: string) => NoExcessType; /** * A wrapper type used with `io-ts` to ensure there are not any excess keys. */ declare class NoExcessType extends t.Type { readonly type: C; readonly _tag: "NoExcessType"; constructor(name: string, is: NoExcessType['is'], validate: NoExcessType['validate'], encode: NoExcessType['encode'], type: C); } //#endregion export { AnyArray, AnyFunction, ArrOrIdentityType, ArrType, CODEC_ERROR_MESSAGE, DeepPartial, DictionaryC, EnumInput, Enumerate, FindAllRegExp, FixedLengthArray, FixedLengthArrayBrand, FixedLengthString, FixedLengthStringBrand, Gql, HttpMethod, INTERFACE_REGEX, Identity, KeysStrictlyEqual, Merge, NoExcessType, NonEmptyString, Nullable, ObjByString, Optionalize, OrArray, Override, PartialRecordC, PromiseType, RecursiveIdentity, RecursiveObjectReplace, RecursiveTypeReplace, RegExpMatch, Requirize, Spread, StringKeys, StringKeysSafe, StringValues, Stringify, SubNotType, SubType, SubTypeRequired, TypescriptEnum, UnionToIntersection, aggregateObjects, apply, applyEnum, asyncApply, createDefaultCodec, createEnum, decodeCodec, dictionary, filterEnum, findAllWithRegex, flattenObject, fromEntries, getEntries, getKeys, getStringKeys, getValues, gql, groupBy, invert, invertSafe, isCodecError, listToEnum, makeEnum, noExcess, partialRecord, toJsonSchema, transposeObjectArray, valuesOf }; //# sourceMappingURL=index.d.mts.map