{"version":3,"file":"primitives.cjs","names":["checkKeys"],"sources":["../../src/types/primitives.ts"],"sourcesContent":["import type {\n  _UnionToIntersection2,\n  DeepPartial,\n  Fn,\n  NOmit,\n  NotUndefined,\n  PrimitiveObject,\n  Ru,\n  UnionToIntersection,\n} from '#bemedev/globals/types';\nimport type { DEFAULT_DELIMITER } from '#constants';\nimport type { EventObject } from '#events';\nimport type {\n  State,\n  StateExtended,\n  StateP,\n  StatePextended,\n} from '#states';\nimport { checkKeys } from '#utils';\n\nexport type IsString_F = (value: unknown) => value is string;\n\n/**\n * Single or readonly array type of {@linkcode T}.\n */\nexport type SingleOrArrayR<T> = T | readonly T[];\n\n/**\n * Single or readonly array type of {@linkcode T} with at least one element.\n * This type is useful when you want to ensure that the value is either a single\n * element of type {@linkcode T} or an array containing at least one element of\n * type {@linkcode T}.\n */\nexport type SingleOrArrayL<T> = T | readonly [...(readonly T[]), T];\n\n/**\n * Describer keys used to define the name and description of an object.\n */\nexport const DESCRIBER_KEYS = ['name', 'description'] as const;\n\n/**\n * Describer type that contains a name and a description.\n */\nexport type Describer = Record<(typeof DESCRIBER_KEYS)[number], string>;\n\n/**\n * Retrieves the name property from a Describer type.\n */\nexport type FromDescriber<T extends Describer> = T['name'];\n\n/**\n * A {@linkcode Describer} type where the description property is optional.\n */\nexport type Describer2 = NOmit<Describer, 'description'> &\n  Partial<Pick<Describer, 'description'>>;\n\nexport const isFunction = (value: unknown): value is Fn => {\n  return typeof value === 'function';\n};\n\nexport const isString: IsString_F = value => {\n  return typeof value === 'string';\n};\n\nexport const isDescriber = (arg: any): arg is Describer => {\n  const out = checkKeys(arg, ...DESCRIBER_KEYS);\n  return out;\n};\n\nexport const fromDescriber = (value: string | Describer) => {\n  return isDescriber(value) ? value.name : value;\n};\n\n/**\n * Can be used after\n */\nexport type NotReadonly<T> = {\n  -readonly [P in keyof T]: T[P];\n};\n\n/**\n * Can be used after\n */\nexport type Define<T, U> = T extends undefined\n  ? U\n  : undefined extends T\n    ? NotUndefined<T>\n    : T;\n\n// #region group type ChangeProperties\n\n// #region type ChangePropertyOption\n/**\n * Option for changing a property access in an object.\n */\ntype ChangePropertyOption =\n  | 'readonly'\n  | 'readonly_undefined'\n  | 'normal'\n  | 'undefined';\n// #endregion\n\n// #region type ChangeProperty\n\n/**\n * Changes the property access of a specific property in an object type.\n *\n * @template T - The object type to change.\n * @template name - The name of the property of {@linkcode T} to change.\n * @template replace - The name of the property to replace the original property with.\n * @template : {@linkcode ChangePropertyOption} [option] - The option for changing the property access.\n *\n * @remarks Can be used\n *\n * @see {@linkcode NOmit} for removing a property from an object type.\n */\n\nexport type ChangeProperty<\n  T extends object,\n  name extends keyof T,\n  replace extends string,\n  option extends ChangePropertyOption = 'normal',\n> = NOmit<T, name> &\n  (name extends any\n    ? option extends 'readonly'\n      ? { +readonly [key in replace]: T[name] }\n      : option extends 'readonly_undefined'\n        ? { +readonly [key in replace]+?: T[name] }\n        : option extends 'undefined'\n          ? { [key in replace]+?: T[name] }\n          : { [key in replace]: T[name] }\n    : never);\n// #endregion\n\ntype _KeyStrings<\n  T extends object,\n  AddObjectKey extends boolean = true,\n  Key extends keyof T = keyof T,\n> = Key extends string\n  ? NotUndefined<T[Key]> extends object\n    ? {\n        [key in keyof T]: (T[key] extends infer T2 extends object\n          ? UnionToIntersection<_KeyStrings<T2, AddObjectKey>>\n          : never) &\n          (AddObjectKey extends true\n            ? { [key in HighMy]: string }\n            : NonNullable<object>);\n      }\n    : { [key in Key]: string }\n  : never;\n\nexport type KeyStrings<\n  T extends object,\n  AddObjectKey extends boolean = true,\n  Key extends keyof T = keyof T,\n> = _UnionToIntersection2<_KeyStrings<T, AddObjectKey, Key>>;\n\nexport type HighMy = '@my';\n\ntype __ChangeProperties<\n  T extends object,\n  U extends DeepPartial<KeyStrings<T>> = DeepPartial<KeyStrings<T>>,\n> = {\n  [key in keyof T as key extends keyof U\n    ? U[key] extends infer U1\n      ? U1 extends { [key in HighMy]: string }\n        ? U1[HighMy]\n        : U1 extends string\n          ? U1\n          : key\n      : never\n    : key]: key extends keyof U\n    ? T[key] extends infer T1 extends object\n      ? Omit<U[key], HighMy> extends infer U1 extends DeepPartial<\n          KeyStrings<T1, true>\n        >\n        ? __ChangeProperties<T1, U1>\n        : never\n      : T[key]\n    : T[key];\n};\n\ntype _ChangeProperties<\n  T extends object,\n  U extends DeepPartial<KeyStrings<T>> = DeepPartial<KeyStrings<T>>,\n  option extends Extract<ChangePropertyOption, 'normal' | 'undefined'> =\n    'normal',\n> =\n  __ChangeProperties<T, U> extends infer Tn\n    ? option extends 'undefined'\n      ? DeepPartial<Tn>\n      : Tn\n    : never;\n\n// #region type ChangeProperties\n/**\n * Changes the properties of an object type based on a partial object type.\n *\n * @template T - The object type to change.\n * @template U - The partial object type that defines the changes.\n * @template : {@linkcode ChangePropertyOption} [option] - The option for changing the property access.\n *\n * @remarks This can be usefull after\n *\n * @see {@linkcode DeepPartial} for creating a deep partial type.\n * @see {@linkcode KeyStrings} for creating a type with string keys.\n * @see {@linkcode _ChangeProperties} for changing a single property access.\n */\nexport type ChangeProperties<\n  T extends object,\n  U extends DeepPartial<KeyStrings<T>> = DeepPartial<KeyStrings<T>>,\n  option extends Extract<ChangePropertyOption, 'normal' | 'undefined'> =\n    'normal',\n> =\n  DeepPartial<KeyStrings<T>> extends U\n    ? T\n    : _ChangeProperties<T, U, option>;\n// #endregion\n\n// #endregion\n\n/**\n * Remap an object by adding an `__id` property.\n *\n * @template T - The object type to remap.\n */\nexport type Identify<T> = T extends object ? T & { __id: string } : T;\n\n/**\n * A helper type to reduce an array type to its element type.\n * It extracts the element type from an array type, whether it is a readonly array or a\n * mutable array.\n *\n * @template T - The type to reduce.\n */\nexport type ReduceArray<T> = T extends readonly (infer U1)[]\n  ? U1\n  : T extends (infer U2)[]\n    ? U2\n    : T;\n\n/**\n * The inverse of {@linkcode ReduceArray}.\n * Takes a type and wraps it in a readonly array, or returns it as-is if already an array.\n *\n * @template T - The type to wrap.\n */\nexport type ToArray<T> = T extends readonly unknown[]\n  ? T\n  : T extends unknown[]\n    ? T\n    : readonly T[];\n\n/**\n * An helper to write common function signatures.\n *\n * @template : {@linkcode EventsMap} [E] - The events map used in the function.\n * @template : {@linkcode ActorsConfigMap} [A] - The actors configuration map used in the function.\n * @template Pc - The private context.\n * @template : {@linkcode PrimitiveObject} [Tc] - The context of the function, defaults to any object.\n * @template R - The return type of the function, defaults to any.\n *\n * @see {@linkcode ToEvents2} for converting events and promisees to a map.\n */\nexport type FnR<\n  E extends EventObject = EventObject,\n  Pc = any,\n  Tc extends PrimitiveObject = PrimitiveObject,\n  T extends string = string,\n  R = any,\n> = (state: StateExtended<E, Pc, Tc, T>) => R;\n\n/**\n * A helper type to reduce a function signature to its context and events map.\n *\n * @template : {@linkcode EventsMap} [E] - The events map used in the function.\n * @template : {@linkcode ActorsConfigMap} [A] - The actors configuration map used in the function.\n * @template : {@linkcode PrimitiveObject} [Tc] - The context of the function, defaults to any object.\n * @template R - The return type of the function, defaults to any.\n *\n * @remarks This function signature is a reduced version of {@linkcode FnR} without the private context.\n *\n * @see {@linkcode ToEvents2} for converting events and promisees to a map.\n */\nexport type FnReduced<\n  E extends EventObject = EventObject,\n  Tc extends PrimitiveObject = PrimitiveObject,\n  T extends string = string,\n  R = any,\n> = (state: State<E, Tc, T>) => R;\n\nexport type EventToType<T extends string | { type: string }> = T extends {\n  type: infer U extends string;\n}\n  ? U\n  : T extends string\n    ? T\n    : never;\n\ntype _FnMap<\n  E extends EventObject = EventObject,\n  Pc = any,\n  Tc extends PrimitiveObject = PrimitiveObject,\n  T extends string = string,\n  R = any,\n  Ex extends string = never,\n  TT extends Exclude<E, Ex | { type: Ex }> = Exclude<E, Ex | { type: Ex }>,\n> = {\n  [key in EventToType<TT>]?: (\n    state: StatePextended<\n      Extract<TT, { type: key }>['payload'],\n      Pc,\n      Tc,\n      T\n    >,\n  ) => R;\n} & {\n  else?: FnR<E, Pc, Tc, T, R>;\n};\n\ntype _FnMapReduced<\n  E extends EventObject = EventObject,\n  Tc extends PrimitiveObject = PrimitiveObject,\n  T extends string = string,\n  R = any,\n  Ex extends string = never,\n  /**\n   * @deprecated\n   * Used internally\n   */\n  TT extends Exclude<E, Ex | { type: Ex }> = Exclude<E, Ex | { type: Ex }>,\n> = {\n  [key in TT['type']]?: (\n    state: StateP<Extract<TT, { type: key }>['payload'], Tc, T>,\n  ) => R;\n} & {\n  else?: FnReduced<E, Tc, T, R>;\n};\n\nexport type FnMap<\n  E extends EventObject = EventObject,\n  Pc = any,\n  Tc extends PrimitiveObject = PrimitiveObject,\n  T extends string = string,\n  R = any,\n  Ex extends string = never,\n> = FnR<E, Pc, Tc, T, R> | _FnMap<E, Pc, Tc, T, R, Ex>;\n\n/**\n * A helper type to reduce a function signature to its context and events map.\n *\n * @template : {@linkcode AllEvent} [E] - All Events map used in the function.\n\n * @template : {@linkcode PrimitiveObject} [Tc] - The context of the function, defaults to any object.\n * @template R - The return type of the function, defaults to any.\n *\n * @see {@linkcode ToEvents2} for converting events and promisees to a map.\n * @see {@linkcode FnReduced} for a more generic function signature.\n * @see {@linkcode Extract}\n */\nexport type FnMapR<\n  E extends EventObject = EventObject,\n  Tc extends PrimitiveObject = PrimitiveObject,\n  T extends string = string,\n  R = any,\n  Ex extends string = never,\n> = FnReduced<E, Tc, T, R> | _FnMapReduced<E, Tc, T, R, Ex>;\n\n/**\n * A type that represents a record with string keys and values of type {@linkcode T}.\n *\n * @see {@linkcode Record} for more details.\n */\nexport type RecordS<T = unknown> = Record<string, T>;\n\n/**\n * A type that represents all values of type {@linkcode T},\n *\n * @see {@linkcode NotUndefined}\n */\nexport type ValuesOf<T> = NotUndefined<\n  NotUndefined<T>[keyof NotUndefined<T>]\n>;\n\n/**\n * A type that represents a record with string keys and values of type {@linkcode R}.\n *\n * @template S - The string keys of the record.\n * @template R - The type of the values in the record, optional\n *\n * @see {@linkcode Record} for more details.\n * @remarks Simplified version of {@linkcode Record}\n */\nexport type KeyU<S extends string, R = unknown> = Record<S, R>;\n\n/**\n * The partial version of {@linkcode KeyU}.\n *\n * @template S - The string keys of the record.\n * @template R - The type of the values in the record, optional\n *\n * @see {@linkcode Partial}\n */\nexport type KeyO<S extends string, R = unknown> = Partial<KeyU<S, R>>;\n\n/**\n * Extracts the string type from a union type {@linkcode T}.\n *\n * @template T - The union type to extract the string type from.\n *\n * @see {@linkcode Extract} for more details.\n */\nexport type ExtractS<T> = Extract<T, string>;\n\n/**\n * A type that represents a true object, which is an object that does not have\n * any iterable properties or the `SymbolConstructor` property.\n *\n * @remarks This type is useful to ensure that the object is a plain object\n * without any special properties.\n *\n * @see {@linkcode Ru} for a utility type that represents a true object.\n * @see {@linkcode SymbolConstructor} for the symbol constructor type.\n */\nexport type TrueObject = Ru & {\n  [Symbol.iterator]?: never;\n  //@ts-expect-error - 'SymbolConstructor' does not exist on type 'object'\n  [SymbolConstructor]?: never;\n};\n\n/**\n * A type that represents a not defined.\n *\n * @remarks This type is useful when you want to allow a value to be absent or\n * explicitly set to `null` or `undefined`.\n *\n * @remarks Can be usefull after.\n *\n */\nexport type NoValue = void | undefined | null;\n\nexport type Delimiter = typeof DEFAULT_DELIMITER;\n\n// #region NoExtraKeys\n\n/**\n * Extracts keys from type T that represent object properties which should be\n * recursively processed for no-extra-keys validation.\n *\n * @template T - The type to extract recursive keys from.\n * @template Schema - The schema type to compare against.\n */\ntype RecursiveObjectKeys<T, Schema> = {\n  [K in keyof T & keyof Schema]: T[K] extends TrueObject ? K : never;\n}[keyof T & keyof Schema];\n\n/**\n * Generic type that restricts extra keys deeply on any object type.\n * Works with partial objects and ensures all keys match the schema exactly.\n *\n * @template T - The type to validate (the actual value type).\n * @template Schema - The schema type that defines allowed keys.\n *\n * @remarks\n * This type performs deep validation ensuring:\n * 1. No extra keys are present at the top level\n * 2. All nested object properties are recursively validated\n * 3. Works with partial/optional properties\n * 4. Preserves readonly modifiers\n *\n * @example\n * ```typescript\n * type MySchema = {\n *   name: string;\n *   config?: {\n *     value: number;\n *     nested?: {\n *       deep: boolean;\n *     };\n *   };\n * };\n *\n * // Valid - all keys match schema\n * type Valid = NoExtraKeys<{ name: 'test'; config: { value: 1 } }, MySchema>;\n *\n * // Invalid - 'extra' key is not in schema, will be typed as 'never'\n * type Invalid = NoExtraKeys<{ name: 'test'; extra: true }, MySchema>;\n * ```\n *\n * @see {@linkcode NoExtraKeysStrict} for a stricter version that requires exact match.\n */\nexport type NoExtraKeys<T, Schema> = T & {\n  [K in Exclude<keyof T, keyof Schema>]: never;\n} & {\n  [K in RecursiveObjectKeys<T, Schema>]?: NoExtraKeys<\n    NotUndefined<T[K]>,\n    NotUndefined<Schema[K]>\n  >;\n};\n\n/**\n * A stricter version of {@linkcode NoExtraKeys} that also validates\n * that all keys in the schema are present in the type T.\n *\n * @template T - The type to validate (the actual value type).\n * @template Schema - The schema type that defines allowed keys.\n *\n * @remarks\n * Use this when you want to ensure not only that there are no extra keys,\n * but also that all required keys from the schema are present.\n *\n * @example\n * ```typescript\n * type MySchema = {\n *   name: string;\n *   value: number;\n * };\n *\n * // T must have both 'name' and 'value'\n * type Strict = NoExtraKeysStrict<{ name: 'test'; value: 1 }, MySchema>;\n * ```\n */\nexport type NoExtraKeysStrict<T extends Schema, Schema> = NoExtraKeys<\n  T,\n  Schema\n>;\n\n/**\n * Deep version of {@linkcode NoExtraKeys} that processes Record types\n * (objects with dynamic string keys).\n *\n * @template T - The Record type to validate.\n * @template Schema - The schema type for each value in the record.\n *\n * @example\n * ```typescript\n * type StateSchema = {\n *   target: string;\n *   initial?: string;\n * };\n *\n * type States = NoExtraKeysRecord<\n *   { idle: { target: 'active' }; active: { target: 'idle' } },\n *   StateSchema\n * >;\n * ```\n */\nexport type NoExtraKeysRecord<T extends Record<string, any>, Schema> = {\n  [K in keyof T]: NoExtraKeys<T[K], Schema>;\n};\n\n/**\n * Utility type to create a no-extra-keys validator for a specific schema.\n * This is useful when you want to create reusable type validators.\n *\n * @template Schema - The schema type to validate against.\n *\n * @example\n * ```typescript\n * type ConfigSchema = {\n *   name: string;\n *   options?: {\n *     enabled: boolean;\n *   };\n * };\n *\n * type ValidConfig<T extends ConfigSchema> = NoExtraKeysFor<ConfigSchema, T>;\n *\n * // Usage\n * function createConfig<T extends ConfigSchema>(config: ValidConfig<T>): T {\n *   return config as T;\n * }\n * ```\n */\nexport type NoExtraKeysFor<\n  Schema,\n  T extends Partial<Schema>,\n> = NoExtraKeys<T, Schema>;\n\n// #endregion NoExtraKeys\n\n/**\n * Filters an array type to only include elements that match a condition type.\n *\n * @template Arr - The array type to filter.\n * @template Condition - The condition type to filter by.\n *\n * @example\n * ```typescript\n * type Numbers = FilterArray<[1, 'two', 3, 'four', 5], number>;\n * // Result: [1, 3, 5]\n * ```\n */\nexport type FilterArray<\n  Arr extends readonly unknown[],\n  Condition,\n> = Arr extends readonly [infer Head, ...infer Tail]\n  ? Head extends Condition\n    ? [Head, ...FilterArray<Tail, Condition>]\n    : FilterArray<Tail, Condition>\n  : [];\n\nexport type DeeperPartial<T> = DeepPartial<T> | undefined;\n\nexport type OptionalDefinition<P, V extends string> = undefined extends P\n  ? { [K in V]?: P }\n  : { [K in V]: P };\n"],"mappings":";;;;;;;AAsCA,MAAa,iBAAiB,CAAC,QAAQ,cAAc;AAkBrD,MAAa,cAAc,UAAgC;AACzD,QAAO,OAAO,UAAU;;AAG1B,MAAa,YAAuB,UAAS;AAC3C,QAAO,OAAO,UAAU;;AAG1B,MAAa,eAAe,QAA+B;AAEzD,QADYA,gCAAAA,UAAU,KAAK,GAAG,eAAe;;AAI/C,MAAa,iBAAiB,UAA8B;AAC1D,QAAO,YAAY,MAAM,GAAG,MAAM,OAAO"}