API Reference
Helper Types

Helper Types

The types exported by the @ibnlanre/builder package are built on top of a set of helper types. These types are not intended to be used directly by consumers. Nor are they exported by the package. They are included here for reference purposes. And their definitions may be different from the actual implementation.

Dictionary

The Dictionary type represents a generic object type with string keys and unknown values. This type is not exported from the package but is used internally to represent objects with arbitrary keys and values.

Signature

type Dictionary = Record<string, unknown>;

Primitives

The Primitives type represents the set of primitive types in TypeScript. This type is used to filter out primitive values from the register object.

Signature

type Primitives = string | number | bigint | boolean | null | undefined;

Join

The Join type represents a function that joins a list of primitive values into a single string. This type is used to generate the keys and values of the builder object.

Signature

type Serialize<Head extends Primitives> =
  Head extends Exclude<Primitives, null | undefined>
    ? Head extends bigint
      ? `${Head}n`
      : `${Head}`
    : "";
 
type JoinHelper<
  Head,
  Rest extends unknown[],
  Separator extends string,
> = Head extends Primitives
  ? Rest extends []
    ? `${Serialize<Head>}`
    : Rest extends Primitives[]
      ? `${Serialize<Head>}${Separator}${Join<Rest, Separator>}`
      : ""
  : "";
 
type Join<
  List extends ReadonlyArray<Primitives>,
  Separator extends string = "",
> = List extends [infer Head, ...infer Rest]
  ? JoinHelper<Head, Rest, Separator>
  : "";

Paths

The Paths type represents a union of all possible paths in a register object. This type is used to generate all possible paths in the builder object.

Signature

type PathsHelper<
  Prefix extends readonly string[],
  Key extends string,
  Separator extends string = ".",
> = Values<[...Prefix, Key], Separator>;
 
type Paths<
  Register extends Dictionary,
  Prefix extends readonly string[] = [],
  Separator extends string = ".",
> = Register extends Dictionary
  ? {
      [Key in keyof Register]: Key extends string | number
        ? Register[Key] extends Dictionary
          ?
              | PathsHelper<Prefix, `${Key}`, Separator>
              | PathsHelper<
                  Prefix,
                  `${Key}${Separator}${Paths<Register[Key], [], Separator>}`,
                  Separator
                >
          : PathsHelper<Prefix, `${Key}`, Separator>
        : never;
    }[keyof Register]
  : never;

Values

The Values type represents a union of all possible values in a register object. This type is used to generate all possible values in the builder object.

Signature

type Values<
  List extends readonly string[],
  Separator extends string = ".",
  Result extends string = "",
> = List extends [infer Head extends string, ...infer Tail extends string[]]
  ? Result extends ""
    ? Values<Tail, Separator, `${Head}`>
    : Result | Values<Tail, Separator, `${Result}${Separator}${Head}`>
  : Result;