🧰 Essentials | Types - traced-fabric/core GitHub Wiki

🔧 JSON type

All exported JSON types.

type JSONPrimitive = string | number | boolean | null | undefined;
type JSONObject = { [_key: string]: JSONValue };
type JSONArray = Array<JSONValue>;

type JSONStructure = JSONObject | JSONArray;
type JSONValue = JSONPrimitive | JSONStructure;

🔧 Mutation type

The definition of the mutation includes:

  1. targetChain (array of TTarget) - the path to the mutated property.
type TTarget = string | number;
// that is then used as targetChain: TTarget[];
  1. mutated - the JSONStructure that was mutated (array | object)
export enum EMutated {
  object = 'object',
  array = 'array',
}
  1. type - the type of mutation that happened. Different for object and array types.
export enum EObjectMutation {
  set = 'set',
  delete = 'delete',
}

export enum EArrayMutation {
  set = 'set',
  delete = 'delete',

  push = 'push',
  reverse = 'reverse',
  shift = 'shift',
  unshift = 'unshift',
}
  1. value - the new data that was added. Varies on type.
type TObjectMutation = {
  mutated: EMutated.object;
  targetChain: TTarget[];
} & ({
  type: EObjectMutation.set;
  value: JSONValue;
} | {
  type: EObjectMutation.delete;
  value?: never;
});
type TArrayMutation = {
  mutated: EMutated.array;
  targetChain: TTarget[];
} & ({
  type: EArrayMutation.set;
  value: JSONValue;
} | {
  type:
    EArrayMutation.push |
    EArrayMutation.unshift;
  value: JSONValue[];
} | {
  type:
    EArrayMutation.delete |
    EArrayMutation.reverse |
    EArrayMutation.shift;
  value?: never;
});

The joined type for all of this will be

type TMutation = TObjectMutation | TArrayMutation;
⚠️ **GitHub.com Fallback** ⚠️